Who can help me write a functioning chat? I have already created the mask in Droidscript with ChatGPT and it works so far but I can only write messages to myself and that is not the point.
cfg.MUI
cfg.Light
var serverIP = ""; // Hier die Server-IP-Adresse oder Hostnamen eingeben
var serverPort = 12345; // Hier den Port eingeben, über den die Verbindung hergestellt werden soll
//Called when application is started.
function OnStart() {
var color = MUI.colors.teal
app.InitializeUIKit(color.teal)
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "Linear", "VCenter,FillXY" )
lay.SetChildMargins(.02,.02,.02,.02 )
// Show login screen
Login(lay);
//Add layout to app.
app.AddLayout( lay )
}
function Msgs(lay) {
// Your message screen code here
Msglay = app.CreateLayout("Linear", "VCenter,FillXY")
Msglay.SetBackColor( "#000000" )
Msglay.SetSize(1,1)
scrl = app.CreateScroller(1, 0.9, "NoScrollBar")
scrl.SetBackColor( "#000000" )
lay2 = app.CreateLayout("Linear", "VCenter")
lay2.SetBackColor( "#000000" )
lay2.SetPadding(0, 0.02, 0, 0.02)
lay2.SetSize(1)
scrl.AddChild(lay2)
Msglay.AddChild(scrl)
horz = app.CreateLayout("Linear","Horizontal")
horz.SetSize(1,0.11)
horz.SetBackColor( "#333333" )
Msglay.AddChild(horz)
inputText = app.CreateTextEdit("",0.6,-1,"Singleline")
inputText.SetBackColor("#ffffff")
inputText.SetHint("Type here......")
inputText.SetTextColor("#000000")
horz.AddChild(inputText)
sendBtn = app.CreateButton("Send",0.2,-1)
sendBtn.SetOnTouch(function(){
var text = inputText.GetText();
inputText.SetText("");
// Here you can handle sending message or other actions
// Send message via API (replace API_ENDPOINT with actual endpoint)
var apiUrl = "http://" + serverIP + ":" + serverPort + "/send?message=" + encodeURIComponent(text);
app.HttpRequest("GET", apiUrl, function(res){
// Handle API response if needed
});
// Add sent message to text area
var sentMessage = "<b>You:</b> " + text + "<br>";
messageTextView.SetText(messageTextView.GetText() + sentMessage);
})
horz.AddChild(sendBtn)
// Text view to display messages
messageTextView = app.CreateTextEdit("", 1, 0.5, "MultiLine,ReadOnly,Html");
messageTextView.SetBackColor("#000000");
messageTextView.SetTextColor("#ffffff");
lay2.AddChild(messageTextView);
//Add layout to app.
lay.AddChild(Msglay)
}
function Login(lay) {
loginlay = app.CreateLayout( "Card" )
loginlay.SetSize(0.88,0.6)
loginlay.SetCornerRadius(5 )
loginlay.SetElevation(50)
contlay = app.CreateLayout( "Linear", "VCenter,FillXY" )
contlay.SetBackColor( "#ffffff" )
loginlay.AddChild(contlay)
//Create a text label and add it to layout.
userNme = MUI.CreateTEOutlineIconRight(0.8,null,"person","Enter name",true,"black","blue",contlay )
password = MUI.CreateTEOutlineIconRight(0.8,"password,small","lock","password",true,"black","blue",contlay )
btnLogin = MUI.CreateButtonFlat("Login",0.82,null,"white","blue",contlay)
layhorz = app.CreateLayout("Linear","Horizontal")
layhorz.SetChildMargins(.05,0.02,.05,.1)
contlay.AddChild(layhorz)
fgp = app.CreateText("Forgot password?")
fgp.SetTextColor( "#000099" )
layhorz.AddChild(fgp);
cna = app.CreateText("Create Account")
cna.SetOnTouchUp(function(){
app.ShowProgress("Loading...")
SignUp(lay)
lay.RemoveChild(loginlay)
})
cna.SetTextColor( "#009900" )
layhorz.AddChild(cna);
btnLogin.SetOnTouch(function(){
// Here you can handle the login process
// For now, just showing the message screen
Msgs(lay);
lay.RemoveChild(loginlay); // Remove login layout
})
//Add layout to app.
lay.AddChild(loginlay)
app.HideProgress()
}
function SignUp(lay) {
signlay = app.CreateLayout( "Card" )
signlay.SetSize(0.88,0.6)
signlay.SetCornerRadius(5 )
signlay.SetElevation(50)
contlay = app.CreateLayout( "Linear", "VCenter,FillXY" )
contlay.SetBackColor( "#ffffff" )
signlay.AddChild(contlay)
//Create a text label and add it to layout.
fname = MUI.CreateTEOutlineIconRight(0.8,null,"person","first name",true,"black","blue",contlay )
sname = MUI.CreateTEOutlineIconRight(0.8,null,"person","Surname",true,"black","blue",contlay )
password = MUI.CreateTEOutlineIconRight(0.8,"password,small","lock","password",true,"black","blue",contlay )
signup = MUI.CreateButtonFlat("SignUp",0.82,null,"white","blue",contlay)
layhorz = app.CreateLayout("Linear","Horizontal")
contlay.AddChild(layhorz)
alh = app.CreateText("Already have an account")
alh.SetOnTouchUp(function(){
app.ShowProgress("Loading...")
Login(lay)
lay.RemoveChild(signlay)
})
alh.SetTextColor( "#009900" )
layhorz.AddChild(alh);
//Add layout to app.
lay.AddChild(signlay)
app.HideProgress()
}