|
49 | 49 | import android.widget.ListView;
|
50 | 50 | import android.widget.SearchView;
|
51 | 51 | import android.widget.TextView;
|
| 52 | +import android.widget.Toast; |
52 | 53 |
|
53 | 54 | import com.j256.ormlite.android.AndroidDatabaseResults;
|
54 | 55 | import com.zulip.android.database.DatabaseHelper;
|
|
66 | 67 | import com.zulip.android.models.PresenceType;
|
67 | 68 | import com.zulip.android.R;
|
68 | 69 | import com.zulip.android.models.Stream;
|
| 70 | +import com.zulip.android.networking.AsyncSend; |
69 | 71 | import com.zulip.android.util.ZLog;
|
70 | 72 | import com.zulip.android.ZulipApp;
|
71 | 73 | import com.zulip.android.gcm.GcmBroadcastReceiver;
|
@@ -429,9 +431,45 @@ public void onClick(View v) {
|
429 | 431 | switchView();
|
430 | 432 | }
|
431 | 433 | });
|
| 434 | + sendBtn.setOnClickListener(new View.OnClickListener() { |
| 435 | + @Override |
| 436 | + public void onClick(View v) { |
| 437 | + sendMessage(); |
| 438 | + } |
| 439 | + }); |
432 | 440 | setUpAdapter();
|
433 | 441 | streamActv.setAdapter(streamActvAdapter);
|
434 | 442 | 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 | + } |
435 | 473 |
|
436 | 474 | public void setUpAdapter() {
|
437 | 475 | streamActvAdapter = new SimpleCursorAdapter(
|
|
0 commit comments