mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Added dialog to let user delete all failed messages
This commit is contained in:
committed by
Moez Bhatti
parent
bc4a25c417
commit
47df8e529f
@@ -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<Long> threadIds = new ArrayList<Long>();
|
||||
threadIds.add(threadId);
|
||||
showDeleteFailedConversationDialog(context, threadIds);
|
||||
}
|
||||
|
||||
public static void showDeleteConversationDialog(final MainActivity context, final List<Long> 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<Long> 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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -239,6 +239,7 @@ public class ConversationLegacy {
|
||||
return ids;
|
||||
}
|
||||
|
||||
|
||||
public void markRead() {
|
||||
|
||||
new Thread() {
|
||||
|
||||
@@ -542,6 +542,33 @@ public class SmsHelper {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public static List<Message> deleteFailedMessages(Context context) {
|
||||
|
||||
Log.d(TAG, "Deleting all failed messages");
|
||||
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user