Android Question show conversation from selected specific user

Makumbi

Well-Known Member
Licensed User
Please help how can i modified this code so that i can get the conversation form a selected user from my database . i also wanted to be in position to delete just one single conversation please help . i tried other examples like Erel chat example but it looks so complicated i wanted to use this for my purpose please help me


B4X:
#Region  Project Attributes
    #ApplicationLabel: Exemplo CLV
    #VersionCode: 1
    #VersionName: 1.0
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private clvMensagens As CustomListView
    Private lbNome As Label
    Private lbMensagem As Label
    Private messageSize As Int = 85%x
    Private margin As Int = 2%x
    Private internalYMargin As Int = 2%y
    Private pWhite As Panel
    Private leftColor As Int = Colors.White
    Private rightColor As Int = Colors.RGB(255,243,209)
    Private border As Boolean = True
    Private borderColor As Int = Colors.Black
    Private borderWidth As Int = 1dip
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    
    
    
    
    'HERE IS A EXAMPLE OF HOW ADD CHAT MESSAGE WITH FOR
    For I = 0 To 4

        If i = 0 Then
            Add_Conversation(True,File.ReadString(File.DirAssets,"nome1.txt"),File.ReadString(File.DirAssets,"mensagem1.txt"))
        else if i = 1 Then
            Add_Conversation(False,File.ReadString(File.DirAssets,"nome2.txt"),File.ReadString(File.DirAssets,"mensagem2.txt"))
        else if i = 2 Then
            Add_Conversation(True,File.ReadString(File.DirAssets,"nome3.txt"),File.ReadString(File.DirAssets,"mensagem3.txt"))
        else if i = 3 Then
            Add_Conversation(False,File.ReadString(File.DirAssets,"nome1.txt"),File.ReadString(File.DirAssets,"mensagem1.txt"))
        else if i = 4 Then
            Add_Conversation(True,File.ReadString(File.DirAssets,"nome1.txt"),File.ReadString(File.DirAssets,"mensagem1.txt"))
        End If

    Next
    
    
    
    'HERE A SIMPLE EXAMPLE OF HOW ADD A MESSAGE
    Add_Conversation(True,"Douglas Farias","Hi all! Here is a simple message example")
    
    
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub






Sub Add_Conversation (leftChat As Boolean, name As String, message As String)
    
    Private p As Panel
    p.Initialize("p")
    p.Visible = False
    Activity.AddView(p,margin,0,messageSize,5%Y)
    p.LoadLayout("dentroClv")
    p.RemoveView
        
    'HERE WE ADD THE MESSAGE AND NAME TO LBNAME AND LBMESSAGE
    lbNome.Text = name
    lbMensagem.Text = message
        
        
        

    'GET IF IS LEFT OR RIGHT CHAT
    If leftChat Then
        pWhite.Left = margin
        lbNome.Gravity = Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
        lbMensagem.Gravity = Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
    Else
        pWhite.Left = 100%x - messageSize - margin
        lbNome.Gravity = Bit.Or(Gravity.RIGHT,Gravity.TOP)
        lbMensagem.Gravity = Bit.Or(Gravity.RIGHT,Gravity.TOP)
    End If
        
        
        
    'HERE WE GET THE MESSAGE AND NAME CHAT
    Private su As StringUtils
    lbNome.Top = 0 + internalYMargin
    lbNome.Height =su.MeasureMultilineTextHeight(lbNome,lbNome.Text)
    lbMensagem.Height =su.MeasureMultilineTextHeight(lbMensagem,lbMensagem.Text)
    lbMensagem.Top = lbNome.Top + lbNome.Height
        
        
    'LATER GET THE CORRECT SIZE NEEDED WE APPLY THIS TO PANEL
    p.Height = lbNome.Height + lbMensagem.Height + (internalYMargin * 2)
    pWhite.Height = lbNome.Height + lbMensagem.Height + (internalYMargin * 2)
    
    
    
    
    'HERE WE SET THE COLOR AND BORDER TO THE MESSAGE PANEL

    
    If border Then
        If leftChat Then
            Private cd As ColorDrawable
            cd.Initialize2(leftColor,5,borderWidth,borderColor)
            pWhite.Background = cd
        Else
            Private cd As ColorDrawable
            cd.Initialize2(rightColor,5,borderWidth,borderColor)
            pWhite.Background = cd
        End If
    Else
        If leftChat Then
            Private cd As ColorDrawable
            cd.Initialize2(leftColor,5,0,borderColor)
            pWhite.Background = cd
        Else
            Private cd As ColorDrawable
            cd.Initialize2(rightColor,5,0,borderColor)
            pWhite.Background = cd
        End If
    End If
    
    
    
    
        
        
    p.Visible = True
    'HERE WE ADD THE CONVERSATION PANEL WITH NAME AND MESSAGE TO CLV
    clvMensagens.Add(p,p.Height,0)
        
    

    
End Sub
 

Attachments

  • Screenshot_1586277009.png
    Screenshot_1586277009.png
    87.5 KB · Views: 79
  • Shipexample.zip
    77 KB · Views: 73

mangojack

Well-Known Member
Licensed User
Longtime User
Please help how can i modified this code ....



I have put together a simple example for you benefit.

It is an adaption of your above code taken from ... @Douglas Farias example CLV Simple Chat Example .... but saving chats to a SQL db instead.

Just click on the spinner to bring up previous chats.

1. I could not get the spinner to co-operate with startup prompt ( I don't use them and was not going to waste time getting it to work proper.)
2. I have not handled Keyboard ... so just backspace.

3. * there is a chat timestamp being written to the db (only used for sorting chats), but it can also be displayed in chat views. *
4. ** There is a Receive Button , to simulate / store incoming messages

This is a basic example in answer to your question.
I have no idea how you plan for these chat sessions to take place so the db structure might have to be expanded / improved

but .. this should give you a start ...

Start a New Thread In The Forum for any further questions / problems.


Edit : The example project has been updated.

now using the latest xCustomListView lib and a few small improvements.
 

Attachments

  • Chat_Sql example.zip
    11.9 KB · Views: 68
Last edited:
Upvote 0

Makumbi

Well-Known Member
Licensed User
how can i move the fileld for typing message just slightly up because it appears to be too down at my side . How can i delete just one single message from the chat 3. how can the field for typing messages a little bit wider . iam very greatfull for this in put i have suffered for days to get some thing like
 

Attachments

  • Screenshot_1586349852.png
    Screenshot_1586349852.png
    18.1 KB · Views: 54
Last edited:
Upvote 0

Makumbi

Well-Known Member
Licensed User
Edit : The uploaded example project ( Post #2) has been updated.

now using the latest xCustomListView lib and a few small improvenments.
i have checked the latest version but it does not show me how to enlarge the message text field because currently the text field for typing the message you want to send is very small i wanted it to be enlarge abit .i tried enlarging it but i failed . i wanted to enlarge it a bit because when some one is typing long sentences it hides them . i also wanted to delete one single message from the chat so that the deleted message is automatically deleted in the database as well .
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
i have checked the latest version but it does not show me how to enlarge the message text field

Because i never made those changes you have requested Above ! ... It was a simple upgrade to use the latest xCLV lib

Repeat : Start a New Thread In The Forum for any further questions / problems.

There is an abundance of Threads , Books, Docs etc. regarding positioning / resizing of views.
Search for Anchors, Designer scripts ...
Start reading some documentation ... https://www.b4x.com/android/documentation.html
Start Watching some videos... http://etp.b4x.com/
 
Upvote 0
Top