Swap spam/trash button

pull/30/head
M66B 6 years ago
parent 194b7e8dea
commit 8a309c6198

@ -198,12 +198,12 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_trash:
onActionDelete(id);
return true;
case R.id.action_spam: case R.id.action_spam:
onActionSpam(id); onActionSpam(id);
return true; return true;
case R.id.action_trash:
onActionDelete(id);
return true;
case R.id.action_move: case R.id.action_move:
onActionMove(id); onActionMove(id);
return true; return true;
@ -333,8 +333,8 @@ public class FragmentMessage extends FragmentEx {
top_navigation.getMenu().findItem(R.id.action_reply_all).setVisible(!outbox && message.cc != null); top_navigation.getMenu().findItem(R.id.action_reply_all).setVisible(!outbox && message.cc != null);
top_navigation.setVisibility(View.VISIBLE); top_navigation.setVisibility(View.VISIBLE);
bottom_navigation.getMenu().findItem(R.id.action_trash).setVisible(!outbox && !trash && hasTrash);
bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && !junk && hasJunk); bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && !junk && hasJunk);
bottom_navigation.getMenu().findItem(R.id.action_trash).setVisible(!outbox && !trash && hasTrash);
bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || hasUser)); bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || hasUser));
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(!outbox && !archive && hasArchive); bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(!outbox && !archive && hasArchive);
bottom_navigation.getMenu().findItem(R.id.action_reply).setVisible(!outbox); bottom_navigation.getMenu().findItem(R.id.action_reply).setVisible(!outbox);
@ -439,12 +439,10 @@ public class FragmentMessage extends FragmentEx {
.putExtra("action", "reply_all")); .putExtra("action", "reply_all"));
} }
private void onActionDelete(final long id) { private void onActionSpam(final long id) {
String folderType = (String) bottom_navigation.getTag();
if (EntityFolder.TYPE_TRASH.equals(folderType)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder builder
.setMessage(R.string.title_ask_delete) .setMessage(R.string.title_ask_spam)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -457,7 +455,8 @@ public class FragmentMessage extends FragmentEx {
message.ui_hide = true; message.ui_hide = true;
db.message().updateMessage(message); db.message().updateMessage(message);
EntityOperation.queue(getContext(), message, EntityOperation.DELETE); EntityFolder spam = db.folder().getFolderByType(message.account, EntityFolder.TYPE_JUNK);
EntityOperation.queue(getContext(), message, EntityOperation.MOVE, spam.id);
EntityOperation.process(getContext()); EntityOperation.process(getContext());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
@ -467,7 +466,17 @@ public class FragmentMessage extends FragmentEx {
} }
}) })
.setNegativeButton(android.R.string.cancel, null).show(); .setNegativeButton(android.R.string.cancel, null).show();
} else { }
private void onActionDelete(final long id) {
String folderType = (String) bottom_navigation.getTag();
if (EntityFolder.TYPE_TRASH.equals(folderType)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder
.setMessage(R.string.title_ask_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -477,8 +486,7 @@ public class FragmentMessage extends FragmentEx {
message.ui_hide = true; message.ui_hide = true;
db.message().updateMessage(message); db.message().updateMessage(message);
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TYPE_TRASH); EntityOperation.queue(getContext(), message, EntityOperation.DELETE);
EntityOperation.queue(getContext(), message, EntityOperation.MOVE, trash.id);
EntityOperation.process(getContext()); EntityOperation.process(getContext());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
@ -486,15 +494,9 @@ public class FragmentMessage extends FragmentEx {
} }
}); });
} }
} })
.setNegativeButton(android.R.string.cancel, null).show();
private void onActionSpam(final long id) { } else {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder
.setMessage(R.string.title_ask_spam)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -504,8 +506,8 @@ public class FragmentMessage extends FragmentEx {
message.ui_hide = true; message.ui_hide = true;
db.message().updateMessage(message); db.message().updateMessage(message);
EntityFolder spam = db.folder().getFolderByType(message.account, EntityFolder.TYPE_JUNK); EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TYPE_TRASH);
EntityOperation.queue(getContext(), message, EntityOperation.MOVE, spam.id); EntityOperation.queue(getContext(), message, EntityOperation.MOVE, trash.id);
EntityOperation.process(getContext()); EntityOperation.process(getContext());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
@ -513,8 +515,6 @@ public class FragmentMessage extends FragmentEx {
} }
}); });
} }
})
.setNegativeButton(android.R.string.cancel, null).show();
} }
private void onActionMove(final long id) { private void onActionMove(final long id) {

@ -2,18 +2,18 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_trash"
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_trash"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/action_spam" android:id="@+id/action_spam"
android:icon="@drawable/baseline_report_24" android:icon="@drawable/baseline_report_24"
android:title="@string/title_spam" android:title="@string/title_spam"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/action_trash"
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_trash"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/action_move" android:id="@+id/action_move"
android:icon="@drawable/baseline_folder_24" android:icon="@drawable/baseline_folder_24"

Loading…
Cancel
Save