diff --git a/QKSMS/src/main/java/com/moez/QKSMS/receiver/MarkReadReceiver.java b/QKSMS/src/main/java/com/moez/QKSMS/receiver/MarkReadReceiver.java index da6ada1a..235badcc 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/receiver/MarkReadReceiver.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/receiver/MarkReadReceiver.java @@ -19,8 +19,6 @@ public class MarkReadReceiver extends BroadcastReceiver { readIntent.putExtra("thread_id", threadId); context.startService(readIntent); - if (QKReplyActivity.sIsShowing && threadId == QKReplyActivity.sThreadId) { - QKReplyActivity.close(); - } + QKReplyActivity.dismiss(threadId); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/service/PushbulletService.java b/QKSMS/src/main/java/com/moez/QKSMS/service/PushbulletService.java index a6ff06fd..de623ba9 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/service/PushbulletService.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/service/PushbulletService.java @@ -21,9 +21,7 @@ public class PushbulletService extends MessagingExtension { message.setType(com.moez.QKSMS.mmssms.Message.TYPE_SMSMMS); sendTransaction.sendNewMessage(message, conversation.getThreadId()); - if (QKReplyActivity.sIsShowing && conversation.getThreadId() == QKReplyActivity.sThreadId) { - QKReplyActivity.close(); - } + QKReplyActivity.dismiss(conversation.getThreadId()); NotificationManager.update(getApplicationContext()); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index fb93735e..e484e35d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -48,6 +48,7 @@ import com.moez.QKSMS.ui.dialog.DefaultSmsHelper; import com.moez.QKSMS.ui.dialog.QKDialog; import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment; import com.moez.QKSMS.ui.messagelist.MessageListFragment; +import com.moez.QKSMS.ui.popup.QKReplyActivity; import com.moez.QKSMS.ui.search.SearchFragment; import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu; @@ -417,6 +418,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen if (mContent != null && mContent instanceof MessageListFragment) { sThreadShowing = ((MessageListFragment) mContent).getThreadId(); + QKReplyActivity.dismiss(sThreadShowing); } else { sThreadShowing = 0; } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java index 291e1c64..c8524681 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java @@ -44,7 +44,7 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface. public static final String EXTRA_SHOW_KEYBOARD = "open_keyboard"; public static boolean sIsShowing = false; - public static long sThreadId; + private static long sThreadId; private Conversation mConversation; private ConversationLegacy mConversationLegacy; @@ -69,8 +69,9 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface. Bundle extras = getIntent().getExtras(); - mConversation = Conversation.get(this, extras.getLong(EXTRA_THREAD_ID), false); - mConversationLegacy = new ConversationLegacy(this, extras.getLong(EXTRA_THREAD_ID)); + sThreadId = extras.getLong(EXTRA_THREAD_ID); + mConversation = Conversation.get(this, sThreadId, false); + mConversationLegacy = new ConversationLegacy(this, sThreadId); // Set up the compose view. mComposeView = (ComposeView) findViewById(R.id.compose_view); @@ -165,7 +166,6 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface. mComposeView.saveDraft(); sIsShowing = false; - sThreadId = 0; // When the home button is pressed, this ensures that the QK Reply is shut down // Don't shut it down if it pauses and the screen is off though @@ -289,8 +289,23 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface. mCursor = null; } - public static void close() { - System.exit(0); + /** + * Other areas of the app can tell the QK Reply window to close itself if necessary + * + * 1. MainActivity. When it's resumed, we don't want any QK Reply windows to open, which may have + * happened while the screen was off. + * + * 2. PushbulletService. If a message is replied to via PB, close the window + * + * 3. MarkReadReceiver. A QK Reply window may have opened while the screen was off, so if it's marked + * as read from the lock screen via notification, the QK Reply window should be dismissed + */ + public static void dismiss(long threadId) { + if (sThreadId == threadId) { + sIsShowing = false; + sThreadId = 0; + System.exit(0); + } } @Override