Crash fix

This commit is contained in:
Moez Bhatti
2015-10-25 20:25:59 -04:00
parent 4e56ccf8d1
commit 5845e694ea
6 changed files with 14 additions and 29 deletions
@@ -24,7 +24,7 @@ public class DialogHelper {
}
public static void showDeleteFailedMessagesDialog(final MainActivity context, final long threadId) {
new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null);
new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null);
new QKDialog()
.setContext(context)
@@ -46,7 +46,7 @@ public class DialogHelper {
public static void showDeleteConversationDialog(final MainActivity context, final List<Long> threadIds) {
new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null);
new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null);
new QKDialog()
.setContext(context)
@@ -70,7 +70,7 @@ public class DialogHelper {
public static void showDeleteConversationsDialog(MainActivity context, final ConversationListAdapter adapter) {
new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null);
new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null);
final Conversation.ConversationQueryHandler handler = new Conversation.ConversationQueryHandler(context.getContentResolver());
@@ -246,7 +246,7 @@ public class ConversationLegacy {
long[] ids = getUnreadIds();
if (ids.length > 0) {
new DefaultSmsHelper(context, null, R.string.not_default_mark_read).showIfNotDefault(null);
new DefaultSmsHelper(context, R.string.not_default_mark_read).showIfNotDefault(null);
ContentValues cv = new ContentValues();
cv.put("read", true);
@@ -265,7 +265,7 @@ public class ConversationLegacy {
}
public void markUnread() {
new DefaultSmsHelper(context, null, R.string.not_default_mark_unread).showIfNotDefault(null);
new DefaultSmsHelper(context, R.string.not_default_mark_unread).showIfNotDefault(null);
try {
cursor = context.getContentResolver().query(getUri(), MessageColumns.PROJECTION, null, null, SmsHelper.sortDateDesc);
@@ -301,7 +301,7 @@ public class ConversationLegacy {
}
public void delete() { //TODO do this using AsyncQueryHandler
new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null);
new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null);
new AsyncTask<Void, Void, Void>() {
@@ -174,7 +174,7 @@ public class Message {
}
public void delete() {
new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null);
new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null);
try {
if (isMms()) {
@@ -335,7 +335,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
}
} else if (requestCode == WelcomeActivity.WELCOME_REQUEST_CODE) {
new DefaultSmsHelper(this, null, R.string.not_default_first).showIfNotDefault(null);
new DefaultSmsHelper(this, R.string.not_default_first).showIfNotDefault(null);
}
}
@@ -17,32 +17,22 @@ import java.lang.reflect.Field;
public class DefaultSmsHelper implements ActionClickListener {
public interface DefaultSmsResultListener {
public void onDefaultSmsResult(boolean success);
}
private Context mContext;
private int mMessage;
private DefaultSmsResultListener mListener;
private static long sLastShown;
private boolean mIsDefault = true;
// Listener is currently useless because we can't listen for response from the system dialog
public DefaultSmsHelper(Context context, DefaultSmsResultListener listener, int messageRes) {
public DefaultSmsHelper(Context context, int messageRes) {
mContext = context;
mListener = listener;
mMessage = messageRes != 0 ? messageRes : R.string.default_info;
//some phones do not defaultSmsPackage, they will be assigned to null
String defaultSmsPackage = Telephony.Sms.getDefaultSmsPackage(mContext);
if (Build.VERSION.SDK_INT < 19 || (defaultSmsPackage != null && defaultSmsPackage.equals
(mContext.getPackageName()))) {
if (mListener != null) {
mListener.onDefaultSmsResult(true);
}
mIsDefault = true;
if (Build.VERSION.SDK_INT >= 19) {
String defaultSmsPackage = Telephony.Sms.getDefaultSmsPackage(mContext);
mIsDefault = defaultSmsPackage != null && defaultSmsPackage.equals(mContext.getPackageName());
} else {
mIsDefault = false;
mIsDefault = true;
}
}
@@ -74,11 +64,6 @@ public class DefaultSmsHelper implements ActionClickListener {
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, mContext.getPackageName());
mContext.startActivity(intent);
if (mListener != null) {
// TODO figure out how to get response from system dialog. Maybe set up BaseActivity and use startActivityForResult?
// http://developer.android.com/training/basics/intents/result.html
}
}
private SnackbarType getSnackBarType() {
@@ -573,7 +573,7 @@ public class ComposeView extends LinearLayout implements View.OnClickListener, L
} else if (!isDefaultSmsApp) {
// Ask to become the default SMS app
new DefaultSmsHelper(mContext, null, R.string.not_default_send).showIfNotDefault(this);
new DefaultSmsHelper(mContext, R.string.not_default_send).showIfNotDefault(this);
} else if (!TextUtils.isEmpty(mReplyText.getText()) || mAttachment.hasAttachment()) {
if (mDelayedMessagingEnabled) {