diff --git a/QKSMS/build.gradle b/QKSMS/build.gradle index 52c50486..de479764 100644 --- a/QKSMS/build.gradle +++ b/QKSMS/build.gradle @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' + classpath 'com.android.tools.build:gradle:1.2.3' } } apply plugin: 'com.android.application' diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/DialogHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/common/DialogHelper.java index 7e408f0b..bc92934c 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/DialogHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/DialogHelper.java @@ -4,6 +4,7 @@ import android.util.Log; import android.view.View; import com.moez.QKSMS.R; import com.moez.QKSMS.data.Conversation; +import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.conversationlist.ConversationListAdapter; import com.moez.QKSMS.ui.dialog.DefaultSmsHelper; @@ -21,6 +22,11 @@ public class DialogHelper { threadIds.add(threadId); showDeleteConversationDialog(context, threadIds); } + public static void showDeleteFailedConversationDialog(MainActivity context, long threadId) { + List threadIds = new ArrayList(); + threadIds.add(threadId); + showDeleteFailedConversationDialog(context, threadIds); + } public static void showDeleteConversationDialog(final MainActivity context, final List threadIds) { @@ -70,4 +76,23 @@ public class DialogHelper { }).setNegativeButton(R.string.cancel, null) .show(context.getFragmentManager(), QKDialog.CONFIRMATION_TAG); } + + public static void showDeleteFailedConversationDialog(final MainActivity context, final List threadIds) { + + new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null); + + new QKDialog() + .setContext(context) + .setTitle(R.string.delete_all_failed) + .setMessage(R.string.delete_all_failed_confirmation) + .setPositiveButton(R.string.yes, new View.OnClickListener() { + + @Override + public void onClick(View v) { + SmsHelper.deleteFailedMessages(context); + } + }).setNegativeButton(R.string.cancel, null) + .show(context.getFragmentManager(), QKDialog.CONFIRMATION_TAG); + + } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/data/Conversation.java b/QKSMS/src/main/java/com/moez/QKSMS/data/Conversation.java index 7cc9b78a..bb5ef824 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/data/Conversation.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/data/Conversation.java @@ -32,6 +32,7 @@ import com.moez.QKSMS.common.utils.AddressUtils; import com.moez.QKSMS.common.utils.PhoneNumberUtils; import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.SmsHelper; +import com.moez.QKSMS.ui.MainActivity; import java.util.ArrayList; import java.util.Collection; @@ -593,6 +594,7 @@ public class Conversation { */ public synchronized boolean hasError() { return mHasError; + } /** diff --git a/QKSMS/src/main/java/com/moez/QKSMS/data/ConversationLegacy.java b/QKSMS/src/main/java/com/moez/QKSMS/data/ConversationLegacy.java index 462099f1..126f107a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/data/ConversationLegacy.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/data/ConversationLegacy.java @@ -239,6 +239,7 @@ public class ConversationLegacy { return ids; } + public void markRead() { new Thread() { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java index 4797d808..bda9ec2f 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java @@ -542,6 +542,33 @@ public class SmsHelper { return messages; } + public static List deleteFailedMessages(Context context) { + + Log.d(TAG, "Deleting all failed messages"); + + List messages = new ArrayList(); + + try { + cursor = context.getContentResolver().query(SMS_CONTENT_PROVIDER, new String[]{COLUMN_ID}, FAILED_SELECTION, null, sortDateDesc); + cursor.moveToFirst(); + for (int i = 0; i < cursor.getCount(); i++) { + messages.add(new Message(context, cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_ID)))); + cursor.moveToNext(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + cursor.close(); + } + + for (Message m : messages) + { + Log.d(TAG,"Deleting failed message to " + m.getName() + "\n Body: " + m.getBody()); + m.delete(); + } + return messages; + } + /** * Add an SMS to the given URI. * diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java index a30d6c7f..c8743390 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java @@ -53,6 +53,7 @@ public class ConversationListFragment extends QKFragment implements LoaderManage private final int MENU_MARK_UNREAD = 5; private final int MENU_DELETE_CONVERSATION = 6; private final int MENU_MULTI_SELECT = 7; + private final int MENU_DELETE_FAILED = 8; private RecyclerView mRecyclerView; private FloatingActionButton mFab; @@ -195,6 +196,8 @@ public class ConversationListFragment extends QKFragment implements LoaderManage dialog.addMenuItem(R.string.menu_delete_conversation, MENU_DELETE_CONVERSATION); + dialog.addMenuItem(R.string.delete_failed, MENU_DELETE_FAILED); + dialog.buildMenu(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -233,6 +236,10 @@ public class ConversationListFragment extends QKFragment implements LoaderManage case MENU_DELETE_CONVERSATION: DialogHelper.showDeleteConversationDialog((MainActivity) mContext, threadId); break; + case MENU_DELETE_FAILED: + //Deletes all failed messages from all conversations + DialogHelper.showDeleteFailedConversationDialog((MainActivity) mContext, threadId); + break; } } }).show(((MainActivity) mContext).getFragmentManager(), "conversation options"); diff --git a/QKSMS/src/main/res/values/strings.xml b/QKSMS/src/main/res/values/strings.xml index dd8f1387..78d174e4 100644 --- a/QKSMS/src/main/res/values/strings.xml +++ b/QKSMS/src/main/res/values/strings.xml @@ -333,8 +333,12 @@ These changes will take effect the next time QKSMS is opened Delete conversation + + Delete conversation Are you sure you would like to delete the conversation? + + Are you sure you would like to all failed messages? (from all conversations) APNs not set @@ -346,6 +350,7 @@ Your message will be discarded because it has no valid recipients. + Delete failed messages Invalid code diff --git a/build.gradle b/build.gradle index 5770e82a..37dd7865 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,6 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.1' + classpath 'com.android.tools.build:gradle:1.2.3' } }