Thu, 26 Dec 2024 17:19:15 +0100
update status in contact list and conversations
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | package de.unixwork.im; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | import javax.swing.*; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | import java.awt.*; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | import java.awt.event.ActionEvent; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | import java.awt.event.ActionListener; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | import java.awt.event.KeyAdapter; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | import java.awt.event.KeyEvent; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | import java.time.LocalDateTime; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | import java.time.format.DateTimeFormatter; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | public class ConversationFrame extends JFrame implements MessageSendListener { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | private String xid; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | private JTextArea messageHistory; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | private JTextArea messageInput; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | private JButton sendButton; |
|
1
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
18 | private JButton secureButton; |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | private MessageSendListener messageSendListener; |
|
1
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
20 | |
|
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
21 | boolean isSecure = false; |
|
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
22 | |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | public ConversationFrame(String xid) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | this.xid = xid; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | setTitle(xid); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | setSize(500, 400); |
|
3
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
28 | //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | setLayout(new BorderLayout(5, 5)); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | // Top panel with top-right button |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | JPanel topPanel = new JPanel(new BorderLayout()); |
|
1
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
33 | secureButton = new JButton("Insecure"); |
|
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
34 | topPanel.add(secureButton, BorderLayout.EAST); |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | add(topPanel, BorderLayout.NORTH); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | // Split pane |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | splitPane.setResizeWeight(0.8); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | // Message history area (top part) |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | messageHistory = new JTextArea(); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | messageHistory.setEditable(false); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | JScrollPane messageHistoryScrollPane = new JScrollPane(messageHistory); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | splitPane.setTopComponent(messageHistoryScrollPane); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | // Message input area (bottom part) |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | JPanel inputPanel = new JPanel(new BorderLayout(5, 5)); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | messageInput = new JTextArea(3, 20); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | JScrollPane messageInputScrollPane = new JScrollPane(messageInput); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | sendButton = new JButton("Send"); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | inputPanel.add(messageInputScrollPane, BorderLayout.CENTER); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | inputPanel.add(sendButton, BorderLayout.EAST); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | splitPane.setBottomComponent(inputPanel); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | add(splitPane, BorderLayout.CENTER); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | // Configure input behavior |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | messageInput.addKeyListener(new KeyAdapter() { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | @Override |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | public void keyPressed(KeyEvent e) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | if (e.isControlDown()) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | messageInput.append("\n"); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | } else { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | e.consume(); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | triggerMessageSend(); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | }); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | // Button actions |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | sendButton.addActionListener(new ActionListener() { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | @Override |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | public void actionPerformed(ActionEvent e) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | triggerMessageSend(); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | }); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
|
1
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
81 | secureButton.addActionListener(new ActionListener() { |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | @Override |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | public void actionPerformed(ActionEvent e) { |
|
1
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
84 | if(isSecure) { |
|
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
85 | |
|
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
86 | } else { |
|
42d0d099492b
add incomplete otr code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
87 | App.getInstance().getXmpp().startOTR(xid); |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | }); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | // message handler |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | setMessageSendListener(this); |
|
3
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
94 | |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
95 | // init presence |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
96 | PresenceInfo ps = App.getInstance().getPresenceForXID(xid); |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
97 | if(ps != null) { |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
98 | updatePresence(ps); |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
99 | } |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | public void addToLog(String message, boolean incoming, boolean secure) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | String prefix = incoming ? "< " : "> "; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | // Get the current date and time |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | LocalDateTime now = LocalDateTime.now(); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | // Define the desired format |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | // Format the current date and time |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | String formattedDateTime = now.format(formatter); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | appendToMessageHistory(prefix + formattedDateTime + ": " + message); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | @Override |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | public void onMessageSend(String message) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | addToLog(message, false, false); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | App.getInstance().getXmpp().sendMessage(xid, message, false); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | // Method to append text to the message history |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | public void appendToMessageHistory(String text) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | messageHistory.append(text + "\n"); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | // Method to set the message send listener |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | public void setMessageSendListener(MessageSendListener listener) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | this.messageSendListener = listener; |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | // Trigger the message send callback |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | private void triggerMessageSend() { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | if (messageSendListener != null) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | String message = messageInput.getText().trim(); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | if (!message.isEmpty()) { |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | messageSendListener.onMessageSend(message); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | messageInput.setText(""); |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | } |
|
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | |
|
3
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
142 | void updatePresence(PresenceInfo ps) { |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
143 | setTitle(ps.getOnlineStatus() + xid); |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
144 | } |
|
25a32e2dfde5
update status in contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
145 | |
|
0
f3095cda599e
add initial code with minimal working contact list and conversations
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | } |