Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit d37694d

Browse files
kunall17niftynei
authored andcommitted
Send Message Button Listener And Code.
1 parent c6d52b4 commit d37694d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import android.widget.ListView;
5050
import android.widget.SearchView;
5151
import android.widget.TextView;
52+
import android.widget.Toast;
5253

5354
import com.j256.ormlite.android.AndroidDatabaseResults;
5455
import com.zulip.android.database.DatabaseHelper;
@@ -66,6 +67,7 @@
6667
import com.zulip.android.models.PresenceType;
6768
import com.zulip.android.R;
6869
import com.zulip.android.models.Stream;
70+
import com.zulip.android.networking.AsyncSend;
6971
import com.zulip.android.util.ZLog;
7072
import com.zulip.android.ZulipApp;
7173
import com.zulip.android.gcm.GcmBroadcastReceiver;
@@ -429,9 +431,45 @@ public void onClick(View v) {
429431
switchView();
430432
}
431433
});
434+
sendBtn.setOnClickListener(new View.OnClickListener() {
435+
@Override
436+
public void onClick(View v) {
437+
sendMessage();
438+
}
439+
});
432440
setUpAdapter();
433441
streamActv.setAdapter(streamActvAdapter);
434442
topicActv.setAdapter(subjectActvAdapter);
443+
}
444+
445+
private void sendMessage() {
446+
447+
MessageType messageType = (isCurrentModeStream()) ? MessageType.STREAM_MESSAGE : MessageType.PRIVATE_MESSAGE;
448+
Message msg = new Message(app);
449+
msg.setSender(app.getYou());
450+
451+
if (messageType == MessageType.STREAM_MESSAGE) {
452+
msg.setType(messageType);
453+
msg.setStream(new Stream(streamActv.getText().toString()));
454+
msg.setSubject(topicActv.getText().toString());
455+
} else if (messageType == MessageType.PRIVATE_MESSAGE) {
456+
msg.setType(messageType);
457+
msg.setRecipient(topicActv.getText().toString().split(","));
458+
}
459+
msg.setContent(messageEt.getText().toString());
460+
AsyncSend sender = new AsyncSend(that, msg);
461+
sender.setCallback(new ZulipAsyncPushTask.AsyncTaskCompleteListener() {
462+
public void onTaskComplete(String result, JSONObject jsonObject) {
463+
Toast.makeText(ZulipActivity.this, R.string.message_sent, Toast.LENGTH_SHORT).show();
464+
messageEt.setText("");
465+
}
466+
public void onTaskFailure(String result) {
467+
Log.d("onTaskFailure", "Result: " + result);
468+
Toast.makeText(ZulipActivity.this, R.string.message_error, Toast.LENGTH_SHORT).show();
469+
}
470+
});
471+
sender.execute();
472+
}
435473

436474
public void setUpAdapter() {
437475
streamActvAdapter = new SimpleCursorAdapter(

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
<string name="hint_person">Person</string>
5454
<string name="hint_subject">Subject</string>
5555
<string name="hint_stream">Stream</string>
56+
<string name="message_sent">Message Sent!</string>
57+
<string name="message_error">Error sending Message</string>
5658

5759

5860
<string name="tap_message">Tap on a message to send reply</string>

0 commit comments

Comments
 (0)