mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Open conversation when view intent is launched
This commit is contained in:
@@ -282,7 +282,6 @@ public class Utils {
|
||||
*/
|
||||
public static long getOrCreateThreadId(Context context, String recipient) {
|
||||
Set<String> recipients = new HashSet<>();
|
||||
|
||||
recipients.add(recipient);
|
||||
return getOrCreateThreadId(context, recipients);
|
||||
}
|
||||
@@ -293,8 +292,31 @@ public class Utils {
|
||||
* @param recipients is the set of people message is being sent to
|
||||
* @return the thread_id to use in the database
|
||||
*/
|
||||
public static long getOrCreateThreadId(
|
||||
Context context, Set<String> recipients) {
|
||||
public static long getOrCreateThreadId(Context context, Set<String> recipients) {
|
||||
long threadId = getThreadId(context, recipients);
|
||||
Random random = new Random();
|
||||
return threadId == -1 ? random.nextLong() : threadId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current thread_id or -1 if none found
|
||||
* @param context is the context of the activity or service
|
||||
* @param recipient is the person message is being sent to
|
||||
* @return the thread_id to use in the database, -1 if none found
|
||||
*/
|
||||
public static long getThreadId(Context context, String recipient) {
|
||||
Set<String> recipients = new HashSet<>();
|
||||
recipients.add(recipient);
|
||||
return getThreadId(context, recipients);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current thread_id or -1 if none found
|
||||
* @param context is the context of the activity or service
|
||||
* @param recipients is the set of people message is being sent to
|
||||
* @return the thread_id to use in the database, -1 if none found
|
||||
*/
|
||||
public static long getThreadId(Context context, Set<String> recipients) {
|
||||
Uri.Builder uriBuilder = Uri.parse("content://mms-sms/threadID").buildUpon();
|
||||
|
||||
for (String recipient : recipients) {
|
||||
@@ -320,9 +342,7 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
return random.nextLong();
|
||||
//throw new IllegalArgumentException("Unable to find or allocate a thread ID.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static boolean isEmailAddress(String address) {
|
||||
|
||||
@@ -16,6 +16,8 @@ import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
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;
|
||||
@@ -33,6 +35,7 @@ import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||
import com.moez.QKSMS.common.utils.MessageUtils;
|
||||
import com.moez.QKSMS.common.utils.Units;
|
||||
import com.moez.QKSMS.data.Conversation;
|
||||
import com.moez.QKSMS.mmssms.Utils;
|
||||
import com.moez.QKSMS.receiver.IconColorReceiver;
|
||||
import com.moez.QKSMS.transaction.NotificationManager;
|
||||
import com.moez.QKSMS.transaction.SmsHelper;
|
||||
@@ -53,6 +56,7 @@ import com.moez.QKSMS.ui.welcome.WelcomeActivity;
|
||||
import com.nispok.snackbar.Snackbar;
|
||||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListener,
|
||||
@@ -429,10 +433,26 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
||||
setIntent(intent);
|
||||
|
||||
// This method is called whenever a MainActivity intent is started. Sometimes this is from a
|
||||
// notifications; other times it's from the user clicking on the app icon in the home
|
||||
// screen. If it has a thread id, then we know it's from a notification and we can set the
|
||||
// conversation.
|
||||
// notification; other times it's from the user clicking on the app icon in the home screen
|
||||
long threadId = getIntent().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 (getIntent().getData() != null) {
|
||||
String data = getIntent().getData().toString();
|
||||
String scheme = getIntent().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) {
|
||||
setConversation(threadId);
|
||||
}
|
||||
@@ -440,6 +460,13 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
||||
// 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 (!prefs.getBoolean(MMS_SETUP_DONT_ASK_AGAIN, false) &&
|
||||
TextUtils.isEmpty(prefs.getString(SettingsFragment.MMSC_URL, "")) &&
|
||||
|
||||
@@ -3,25 +3,19 @@ package com.moez.QKSMS.ui.popup;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import com.android.ex.chips.recipientchip.DrawableRecipientChip;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.data.Contact;
|
||||
import com.moez.QKSMS.data.ContactHelper;
|
||||
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||
import com.moez.QKSMS.interfaces.ActivityLauncher;
|
||||
import com.moez.QKSMS.interfaces.RecipientProvider;
|
||||
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||
import com.moez.QKSMS.ui.base.QKPopupActivity;
|
||||
import com.moez.QKSMS.ui.view.AutoCompleteContactView;
|
||||
import com.moez.QKSMS.ui.view.ComposeView;
|
||||
import com.moez.QKSMS.ui.view.StarredContactsView;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class QKComposeActivity extends QKPopupActivity implements ComposeView.OnSendListener, RecipientProvider,
|
||||
ActivityLauncher, AdapterView.OnItemClickListener {
|
||||
|
||||
@@ -54,40 +48,6 @@ public class QKComposeActivity extends QKPopupActivity implements ComposeView.On
|
||||
|
||||
// Apply different attachments based on the type.
|
||||
mCompose.loadMessageFromIntent(getIntent());
|
||||
|
||||
// Check for {sms,mms}{,to}: schemes, in which case we can set the recipients.
|
||||
if (getIntent().getData() != null) {
|
||||
String data = getIntent().getData().toString();
|
||||
String scheme = getIntent().getData().getScheme();
|
||||
|
||||
if (scheme.startsWith("smsto") || scheme.startsWith("mmsto")) {
|
||||
String address = data.replace("smsto:", "").replace("mmsto:", "");
|
||||
final Contact contact = Contact.get(formatPhoneNumber(address), true);
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRecipients.submitItem(contact.getName(), contact.getNumber(),
|
||||
ContactHelper.getPhotoUri(mContext, contact.getUri()));
|
||||
}
|
||||
}, 100);
|
||||
|
||||
} else if (scheme.startsWith("sms") || (scheme.startsWith("mms"))) {
|
||||
String address = data.replace("sms:", "").replace("mms:", "");
|
||||
final Contact contact = Contact.get(formatPhoneNumber(address), true);
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRecipients.submitItem(contact.getName(), contact.getNumber(),
|
||||
ContactHelper.getPhotoUri(mContext, contact.getUri()));
|
||||
}
|
||||
}, 100);
|
||||
|
||||
}
|
||||
|
||||
mCompose.requestReplyTextFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,13 +55,6 @@ public class QKComposeActivity extends QKPopupActivity implements ComposeView.On
|
||||
return R.layout.activity_qkcompose;
|
||||
}
|
||||
|
||||
private String formatPhoneNumber(String address) {
|
||||
address = URLDecoder.decode(address);
|
||||
address = "" + Html.fromHtml(address);
|
||||
address = PhoneNumberUtils.formatNumber(address);
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
Reference in New Issue
Block a user