Chat

163 views
Skip to first unread message

Thiemo Melhorn

unread,
Apr 18, 2024, 5:39:24 AMApr 18
to DroidScript
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()
}
Message has been deleted

Oarabile Koore

unread,
Apr 19, 2024, 4:16:13 AMApr 19
to DroidScript
I tried to do it, i currently just finished message box, ill complete it .

Thiemo Melhorn

unread,
Apr 20, 2024, 12:23:38 PMApr 20
to DroidScript
I just want to ask how people can write with other people. Do the ports have to be enabled in the router or is it possible if you are in the same network without them?

Oarabile Koore

unread,
Apr 20, 2024, 1:50:35 PMApr 20
to DroidScript
ohh i guess i percieved you wrong, i thought you were refering to UI clone of a chat, sorry/

Oarabile Koore

unread,
Apr 21, 2024, 5:24:14 AMApr 21
to DroidScript

Hi, I found a sample spk that Symbroson wrote a few years ago, hopefully it may help.
On Saturday, April 20, 2024 at 6:23:38 PM UTC+2 Thiemo Melhorn wrote:

Thiemo Melhorn

unread,
Apr 24, 2024, 12:43:15 AMApr 24
to DroidScript
I have already looked at the template or the example, but I would like to make something of my own. I want to create the server in an independent APK and have the client side as an independent APK.

Dave

unread,
Apr 24, 2024, 1:15:32 PMApr 24
to DroidScript
If you are in the beta group you can try out our new cloud services.  Then you can create a server side app using NodeJS to host your chat room online, and/or use the online Pocketbase database that is also bundled with the cloud services.

Note: It's part of Premium+ which is currently in beta and will be a few dollars extra compared to standard premium.

Reply all
Reply to author
Forward
0 new messages