forked from upstream-mirrors/quik
Launch MessageListActivity directly from intent
This commit is contained in:
@@ -39,6 +39,7 @@ import com.moez.QKSMS.receiver.WearableIntentReceiver;
|
||||
import com.moez.QKSMS.ui.MainActivity;
|
||||
import com.moez.QKSMS.ui.ThemeManager;
|
||||
import com.moez.QKSMS.ui.messagelist.MessageItem;
|
||||
import com.moez.QKSMS.ui.messagelist.MessageListActivity;
|
||||
import com.moez.QKSMS.ui.popup.QKComposeActivity;
|
||||
import com.moez.QKSMS.ui.popup.QKReplyActivity;
|
||||
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
||||
@@ -315,7 +316,7 @@ public class NotificationManager {
|
||||
PendingIntent PI;
|
||||
if (failedCursor.getCount() == 1) {
|
||||
title = sRes.getString(R.string.failed_message);
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
Intent intent = new Intent(context, MessageListActivity.class);
|
||||
intent.putExtra(MainActivity.EXTRA_THREAD_ID, failedCursor.getLong(0));
|
||||
PI = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else {
|
||||
@@ -474,7 +475,7 @@ public class NotificationManager {
|
||||
replyIntent.putExtra(QKReplyActivity.EXTRA_SHOW_KEYBOARD, true);
|
||||
final PendingIntent replyPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 0), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Intent threadIntent = new Intent(context, MainActivity.class);
|
||||
Intent threadIntent = new Intent(context, MessageListActivity.class);
|
||||
threadIntent.putExtra(MainActivity.EXTRA_THREAD_ID, threadId);
|
||||
final PendingIntent threadPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 1), threadIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
@@ -574,7 +575,7 @@ public class NotificationManager {
|
||||
replyIntent.putExtra(QKReplyActivity.EXTRA_SHOW_KEYBOARD, true);
|
||||
PendingIntent replyPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 0), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Intent threadIntent = new Intent(context, MainActivity.class);
|
||||
Intent threadIntent = new Intent(context, MessageListActivity.class);
|
||||
threadIntent.putExtra(MainActivity.EXTRA_THREAD_ID, threadId);
|
||||
PendingIntent threadPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 1), threadIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@@ -40,7 +38,6 @@ import com.moez.QKSMS.common.utils.MessageUtils;
|
||||
import com.moez.QKSMS.common.utils.Units;
|
||||
import com.moez.QKSMS.data.Conversation;
|
||||
import com.moez.QKSMS.enums.QKPreference;
|
||||
import com.moez.QKSMS.mmssms.Utils;
|
||||
import com.moez.QKSMS.receiver.IconColorReceiver;
|
||||
import com.moez.QKSMS.transaction.NotificationManager;
|
||||
import com.moez.QKSMS.transaction.SmsHelper;
|
||||
@@ -51,7 +48,6 @@ import com.moez.QKSMS.ui.dialog.ConversationSettingsDialog;
|
||||
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.MessageListActivity;
|
||||
import com.moez.QKSMS.ui.messagelist.MessageListFragment;
|
||||
import com.moez.QKSMS.ui.popup.QKReplyActivity;
|
||||
import com.moez.QKSMS.ui.search.SearchFragment;
|
||||
@@ -61,7 +57,6 @@ import com.moez.QKSMS.ui.welcome.WelcomeActivity;
|
||||
import org.ligi.snackengage.SnackEngage;
|
||||
import org.ligi.snackengage.snacks.BaseSnack;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
@@ -368,62 +363,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
NotificationManager.initQuickCompose(this, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* MainActivity has a "singleTask" launch mode, which means that if it is currently running
|
||||
* and another intent is launched to open it, instead of creating a new MainActivity it
|
||||
* just opens the current MainActivity. We use this so that when you click on notifications,
|
||||
* only one main activity is ever used.
|
||||
* <p>
|
||||
* onNewIntent() is called every time the homescreen shortcut is tapped, even if the app
|
||||
* is already running in the background. It's also called when the app is launched via other
|
||||
* intents
|
||||
* <p>
|
||||
* Docs:
|
||||
* http://developer.android.com/guide/components/tasks-and-back-stack.html#TaskLaunchModes
|
||||
*/
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
// onNewIntent doesn't change the result of getIntent() by default, so here we set it since
|
||||
// that makes the most sense.
|
||||
setIntent(intent);
|
||||
|
||||
// This method is called whenever a MainActivity intent is started. Sometimes this is from a
|
||||
// notification; other times it's from the user clicking on the app icon in the home screen
|
||||
long threadId = intent.getLongExtra(EXTRA_THREAD_ID, -1);
|
||||
|
||||
// The activity can also be launched by clicking on the message button from the contacts app
|
||||
// Check for {sms,mms}{,to}: schemes, in which case we know to open a conversation
|
||||
if (intent.getData() != null) {
|
||||
String data = intent.getData().toString();
|
||||
String scheme = intent.getData().getScheme();
|
||||
|
||||
if (scheme.startsWith("smsto") || scheme.startsWith("mmsto")) {
|
||||
String address = data.replace("smsto:", "").replace("mmsto:", "");
|
||||
threadId = Utils.getThreadId(this, formatPhoneNumber(address));
|
||||
} else if (scheme.startsWith("sms") || (scheme.startsWith("mms"))) {
|
||||
String address = data.replace("sms:", "").replace("mms:", "");
|
||||
threadId = Utils.getThreadId(this, formatPhoneNumber(address));
|
||||
}
|
||||
}
|
||||
|
||||
// If it has a thread id, then we know it's from a notification and we can set the
|
||||
// conversation.
|
||||
if (threadId != -1) {
|
||||
Log.v(TAG, "Opening thread: " + threadId);
|
||||
MessageListActivity.launch(this, threadId, -1, null, true);
|
||||
mSlidingMenu.showContent();
|
||||
}
|
||||
|
||||
// Otherwise we'll just resume what was previously there, which doesn't require any code.
|
||||
}
|
||||
|
||||
private String formatPhoneNumber(String address) {
|
||||
address = URLDecoder.decode(address);
|
||||
address = "" + Html.fromHtml(address);
|
||||
address = PhoneNumberUtils.formatNumber(address);
|
||||
return address;
|
||||
}
|
||||
|
||||
private void beginMmsSetup() {
|
||||
if (!mPrefs.getBoolean(MMS_SETUP_DONT_ASK_AGAIN, false) &&
|
||||
TextUtils.isEmpty(mPrefs.getString(SettingsFragment.MMSC_URL, "")) &&
|
||||
|
||||
@@ -2,17 +2,24 @@ package com.moez.QKSMS.ui.messagelist;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.common.DonationManager;
|
||||
import com.moez.QKSMS.mmssms.Utils;
|
||||
import com.moez.QKSMS.ui.base.QKActivity;
|
||||
import com.moez.QKSMS.ui.base.QKSwipeBackActivity;
|
||||
|
||||
public class MessageListActivity extends QKSwipeBackActivity {
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public static final String ARG_THREAD_ID = "threadId";
|
||||
public class MessageListActivity extends QKSwipeBackActivity {
|
||||
private final String TAG = "MessageListActivity";
|
||||
|
||||
public static final String ARG_THREAD_ID = "thread_id";
|
||||
public static final String ARG_ROW_ID = "rowId";
|
||||
public static final String ARG_HIGHLIGHT = "highlight";
|
||||
public static final String ARG_SHOW_IMMEDIATE = "showImmediate";
|
||||
@@ -44,13 +51,39 @@ public class MessageListActivity extends QKSwipeBackActivity {
|
||||
mRowId = intent.getLongExtra(ARG_ROW_ID, -1);
|
||||
mHighlight = intent.getStringExtra(ARG_HIGHLIGHT);
|
||||
mShowImmediate = intent.getBooleanExtra(ARG_SHOW_IMMEDIATE, false);
|
||||
|
||||
if (mThreadId == -1 && intent.getData() != null) {
|
||||
String data = intent.getData().toString();
|
||||
String scheme = intent.getData().getScheme();
|
||||
|
||||
String address = null;
|
||||
if (scheme.startsWith("smsto") || scheme.startsWith("mmsto")) {
|
||||
address = data.replace("smsto:", "").replace("mmsto:", "");
|
||||
} else if (scheme.startsWith("sms") || (scheme.startsWith("mms"))) {
|
||||
address = data.replace("sms:", "").replace("mms:", "");
|
||||
}
|
||||
|
||||
mThreadId = Utils.getOrCreateThreadId(this, formatPhoneNumber(address));
|
||||
}
|
||||
}
|
||||
|
||||
MessageListFragment fragment = MessageListFragment.getInstance(mThreadId, mRowId, mHighlight, mShowImmediate);
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.content_frame, fragment)
|
||||
.commitAllowingStateLoss();
|
||||
if (mThreadId != -1) {
|
||||
Log.v(TAG, "Opening thread: " + mThreadId);
|
||||
MessageListFragment fragment = MessageListFragment.getInstance(mThreadId, mRowId, mHighlight, mShowImmediate);
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.content_frame, fragment)
|
||||
.commitAllowingStateLoss();
|
||||
} else {
|
||||
// TODO log crashlytics event and show toast
|
||||
}
|
||||
}
|
||||
|
||||
private String formatPhoneNumber(String address) {
|
||||
address = URLDecoder.decode(address);
|
||||
address = "" + Html.fromHtml(address);
|
||||
address = PhoneNumberUtils.formatNumber(address);
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -133,7 +133,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
|
||||
private long mLastMessageId;
|
||||
private BackgroundQueryHandler mBackgroundQueryHandler;
|
||||
|
||||
public static final String ARG_THREAD_ID = "threadId";
|
||||
public static final String ARG_THREAD_ID = "thread_id";
|
||||
public static final String ARG_ROW_ID = "rowId";
|
||||
public static final String ARG_HIGHLIGHT = "highlight";
|
||||
public static final String ARG_SHOW_IMMEDIATE = "showImmediate";
|
||||
|
||||
Reference in New Issue
Block a user