Added archive, trash, junk buttons

This commit is contained in:
M66B 2020-03-02 18:12:36 +01:00
parent 02d3803c4c
commit 1e22e1abe1
2 changed files with 159 additions and 53 deletions

View File

@ -36,6 +36,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
@ -382,6 +383,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private ImageButton ibDecrypt; private ImageButton ibDecrypt;
private ImageButton ibVerify; private ImageButton ibVerify;
private ImageButton ibUndo; private ImageButton ibUndo;
private ImageButton ibArchive;
private ImageButton ibTrash;
private ImageButton ibJunk;
private ImageButton ibRemove; private ImageButton ibRemove;
private ImageButton ibMore; private ImageButton ibMore;
private TextView tvSignedData; private TextView tvSignedData;
@ -566,6 +570,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt = vsBody.findViewById(R.id.ibDecrypt); ibDecrypt = vsBody.findViewById(R.id.ibDecrypt);
ibVerify = vsBody.findViewById(R.id.ibVerify); ibVerify = vsBody.findViewById(R.id.ibVerify);
ibUndo = vsBody.findViewById(R.id.ibUndo); ibUndo = vsBody.findViewById(R.id.ibUndo);
ibArchive = vsBody.findViewById(R.id.ibArchive);
ibTrash = vsBody.findViewById(R.id.ibTrash);
ibJunk = vsBody.findViewById(R.id.ibJunk);
ibRemove = vsBody.findViewById(R.id.ibRemove); ibRemove = vsBody.findViewById(R.id.ibRemove);
ibMore = vsBody.findViewById(R.id.ibMore); ibMore = vsBody.findViewById(R.id.ibMore);
tvSignedData = vsBody.findViewById(R.id.tvSignedData); tvSignedData = vsBody.findViewById(R.id.tvSignedData);
@ -645,6 +652,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt.setOnClickListener(this); ibDecrypt.setOnClickListener(this);
ibVerify.setOnClickListener(this); ibVerify.setOnClickListener(this);
ibUndo.setOnClickListener(this); ibUndo.setOnClickListener(this);
ibArchive.setOnClickListener(this);
ibTrash.setOnClickListener(this);
ibJunk.setOnClickListener(this);
ibRemove.setOnClickListener(this); ibRemove.setOnClickListener(this);
ibMore.setOnClickListener(this); ibMore.setOnClickListener(this);
@ -713,6 +723,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt.setOnClickListener(null); ibDecrypt.setOnClickListener(null);
ibVerify.setOnClickListener(null); ibVerify.setOnClickListener(null);
ibUndo.setOnClickListener(null); ibUndo.setOnClickListener(null);
ibArchive.setOnClickListener(null);
ibTrash.setOnClickListener(null);
ibJunk.setOnClickListener(null);
ibRemove.setOnClickListener(null); ibRemove.setOnClickListener(null);
ibMore.setOnClickListener(null); ibMore.setOnClickListener(null);
@ -1140,6 +1153,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt.setVisibility(View.GONE); ibDecrypt.setVisibility(View.GONE);
ibVerify.setVisibility(View.GONE); ibVerify.setVisibility(View.GONE);
ibUndo.setVisibility(View.GONE); ibUndo.setVisibility(View.GONE);
ibArchive.setVisibility(View.GONE);
ibTrash.setVisibility(View.GONE);
ibJunk.setVisibility(View.GONE);
ibRemove.setVisibility(View.GONE); ibRemove.setVisibility(View.GONE);
ibMore.setVisibility(View.GONE); ibMore.setVisibility(View.GONE);
tvSignedData.setVisibility(View.GONE); tvSignedData.setVisibility(View.GONE);
@ -1288,6 +1304,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean cross_hint = prefs.getBoolean("cross_hint", true); boolean cross_hint = prefs.getBoolean("cross_hint", true);
boolean normal = context.getResources().getConfiguration()
.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL);
vSeparator.setVisibility(View.VISIBLE); vSeparator.setVisibility(View.VISIBLE);
ibFull.setEnabled(false); ibFull.setEnabled(false);
@ -1297,10 +1315,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt.setVisibility(View.GONE); ibDecrypt.setVisibility(View.GONE);
ibVerify.setVisibility(View.GONE); ibVerify.setVisibility(View.GONE);
ibUndo.setVisibility(EntityFolder.OUTBOX.equals(message.folderType) ? View.VISIBLE : View.GONE); ibUndo.setVisibility(EntityFolder.OUTBOX.equals(message.folderType) ? View.VISIBLE : View.GONE);
ibRemove.setVisibility(message.folderReadOnly ? View.GONE : View.VISIBLE);
ibArchive.setVisibility(View.GONE);
ibTrash.setVisibility(View.GONE);
ibJunk.setVisibility(View.GONE);
ibRemove.setVisibility(normal || message.folderReadOnly ? View.GONE : View.VISIBLE);
tvCrossHint.setVisibility(!normal && cross_hint ? View.VISIBLE : View.GONE);
if (normal)
onActionRemove(message, true);
ibMore.setVisibility(EntityFolder.OUTBOX.equals(message.folderType) ? View.GONE : View.VISIBLE); ibMore.setVisibility(EntityFolder.OUTBOX.equals(message.folderType) ? View.GONE : View.VISIBLE);
tvSignedData.setVisibility(View.GONE); tvSignedData.setVisibility(View.GONE);
tvCrossHint.setVisibility(cross_hint ? View.VISIBLE : View.GONE);
// Addresses // Addresses
ibExpanderAddress.setImageLevel(show_addresses ? 0 /* less */ : 1 /* more */); ibExpanderAddress.setImageLevel(show_addresses ? 0 /* less */ : 1 /* more */);
@ -2284,8 +2310,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.ibUndo: case R.id.ibUndo:
onActionUndo(message); onActionUndo(message);
break; break;
case R.id.ibArchive:
onActionArchive(message);
break;
case R.id.ibTrash:
onActionTrash(message, (Boolean) ibTrash.getTag());
break;
case R.id.ibJunk:
onActionJunk(message);
break;
case R.id.ibRemove: case R.id.ibRemove:
onActionRemove(message); onActionRemove(message, false);
break; break;
case R.id.ibMore: case R.id.ibMore:
onActionMore(message); onActionMore(message);
@ -3012,10 +3047,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
properties.move(message.id, EntityFolder.INBOX); properties.move(message.id, EntityFolder.INBOX);
} }
private void onActionRemove(TupleMessageEx message) { private void onActionRemove(TupleMessageEx message, boolean normal) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (!normal) {
prefs.edit().putBoolean("cross_hint", false).apply(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
tvCrossHint.setVisibility(View.GONE); prefs.edit().putBoolean("cross_hint", false).apply();
tvCrossHint.setVisibility(View.GONE);
if (EntityFolder.OUTBOX.equals(message.folderType)) {
onActionDelete(message);
return;
}
}
// Setup actions // Setup actions
Bundle sargs = new Bundle(); Bundle sargs = new Bundle();
@ -3036,11 +3078,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (amessage == null || !amessage.id.equals(id)) if (amessage == null || !amessage.id.equals(id))
return; return;
if (EntityFolder.OUTBOX.equals(message.folderType)) {
onActionDelete(message);
return;
}
boolean hasArchive = false; boolean hasArchive = false;
boolean hasTrash = false; boolean hasTrash = false;
boolean hasJunk = false; boolean hasJunk = false;
@ -3056,53 +3093,74 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType);
boolean inTrash = EntityFolder.TRASH.equals(message.folderType); boolean inTrash = EntityFolder.TRASH.equals(message.folderType);
boolean inJunk = EntityFolder.JUNK.equals(message.folderType); boolean inJunk = EntityFolder.JUNK.equals(message.folderType);
boolean outbox = EntityFolder.OUTBOX.equals(message.folderType);
final boolean delete = (inTrash || !hasTrash); boolean archive = (!message.folderReadOnly && message.uid != null && (hasArchive && !inArchive));
boolean trash = ((!message.folderReadOnly && message.uid != null) || outbox || debug);
boolean junk = (!message.folderReadOnly && message.uid != null && (hasJunk && !inJunk));
if (!hasArchive && !hasJunk) { final boolean delete = (inTrash || !hasTrash || outbox || message.uid == null);
if (delete)
onActionDelete(message);
else
properties.move(message.id, EntityFolder.TRASH);
return;
}
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibMore); if (normal) {
popupMenu.inflate(R.menu.popup_message_remove); ibTrash.setTag(delete);
popupMenu.getMenu().findItem(R.id.menu_archive).setEnabled(message.uid != null && (hasArchive && !inArchive));
popupMenu.getMenu().findItem(R.id.menu_trash).setEnabled(message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_junk).setEnabled(message.uid != null && (hasJunk && !inJunk));
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE);
@Override ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE);
public boolean onMenuItemClick(MenuItem target) { ibJunk.setVisibility(junk ? View.VISIBLE : View.GONE);
switch (target.getItemId()) { } else {
case R.id.menu_archive: if (!hasArchive && !hasJunk) {
properties.move(message.id, EntityFolder.ARCHIVE); if (delete)
return true; onActionDelete(message);
case R.id.menu_trash: else
if (delete) properties.move(message.id, EntityFolder.TRASH);
onActionDelete(message); return;
else
properties.move(message.id, EntityFolder.TRASH);
return true;
case R.id.menu_junk:
onActionJunk(message);
return true;
default:
return false;
}
} }
});
popupMenu.show(); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibMore);
popupMenu.inflate(R.menu.popup_message_remove);
popupMenu.getMenu().findItem(R.id.menu_archive).setEnabled(archive);
popupMenu.getMenu().findItem(R.id.menu_trash).setEnabled(trash);
popupMenu.getMenu().findItem(R.id.menu_junk).setEnabled(junk);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) {
case R.id.menu_archive:
onActionArchive(message);
return true;
case R.id.menu_trash:
onActionTrash(message, delete);
return true;
case R.id.menu_junk:
onActionJunk(message);
return true;
default:
return false;
}
}
});
popupMenu.show();
}
} }
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
} }
}.setLog(false).execute(context, owner, sargs, "message:actions"); }.setLog(false).execute(context, owner, sargs, "message:more");
}
private void onActionArchive(TupleMessageEx message) {
properties.move(message.id, EntityFolder.ARCHIVE);
}
private void onActionTrash(TupleMessageEx message, boolean delete) {
if (delete)
onActionDelete(message);
else
properties.move(message.id, EntityFolder.TRASH);
} }
private void onActionDelete(TupleMessageEx message) { private void onActionDelete(TupleMessageEx message) {

View File

@ -40,7 +40,7 @@
android:id="@+id/ibRemove" android:id="@+id/ibRemove"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_marginStart="12dp" android:layout_marginStart="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_delete" android:contentDescription="@string/title_delete"
android:foregroundTint="?android:attr/textColorSecondary" android:foregroundTint="?android:attr/textColorSecondary"
@ -52,11 +52,59 @@
app:layout_goneMarginStart="0dp" app:layout_goneMarginStart="0dp"
app:srcCompat="@drawable/baseline_close_24" /> app:srcCompat="@drawable/baseline_close_24" />
<ImageButton
android:id="@+id/ibJunk"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_spam"
android:foregroundTint="?android:attr/textColorSecondary"
android:padding="3dp"
android:scaleType="fitCenter"
android:tooltipText="@string/title_spam"
app:layout_constraintStart_toEndOf="@id/ibMore"
app:layout_constraintTop_toBottomOf="@id/vSeparator"
app:layout_goneMarginStart="0dp"
app:srcCompat="@drawable/baseline_flag_24" />
<ImageButton
android:id="@+id/ibTrash"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_delete"
android:foregroundTint="?android:attr/textColorSecondary"
android:padding="3dp"
android:scaleType="fitCenter"
android:tooltipText="@string/title_delete"
app:layout_constraintStart_toEndOf="@id/ibJunk"
app:layout_constraintTop_toBottomOf="@id/vSeparator"
app:layout_goneMarginStart="0dp"
app:srcCompat="@drawable/baseline_delete_24" />
<ImageButton
android:id="@+id/ibArchive"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_archive"
android:foregroundTint="?android:attr/textColorSecondary"
android:padding="3dp"
android:scaleType="fitCenter"
android:tooltipText="@string/title_archive"
app:layout_constraintStart_toEndOf="@id/ibTrash"
app:layout_constraintTop_toBottomOf="@id/vSeparator"
app:layout_goneMarginStart="0dp"
app:srcCompat="@drawable/baseline_archive_24" />
<ImageButton <ImageButton
android:id="@+id/ibUndo" android:id="@+id/ibUndo"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_undo" android:contentDescription="@string/title_undo"
android:foregroundTint="?android:attr/textColorSecondary" android:foregroundTint="?android:attr/textColorSecondary"
@ -71,7 +119,7 @@
android:id="@+id/ibVerify" android:id="@+id/ibVerify"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_sign" android:contentDescription="@string/title_sign"
android:foregroundTint="?android:attr/textColorSecondary" android:foregroundTint="?android:attr/textColorSecondary"
@ -86,7 +134,7 @@
android:id="@+id/ibDecrypt" android:id="@+id/ibDecrypt"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_decrypt" android:contentDescription="@string/title_decrypt"
android:foregroundTint="?android:attr/textColorSecondary" android:foregroundTint="?android:attr/textColorSecondary"
@ -101,7 +149,7 @@
android:id="@+id/ibUnsubscribe" android:id="@+id/ibUnsubscribe"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_legend_show_unsubscribe" android:contentDescription="@string/title_legend_show_unsubscribe"
android:foregroundTint="?android:attr/textColorSecondary" android:foregroundTint="?android:attr/textColorSecondary"
@ -116,7 +164,7 @@
android:id="@+id/ibImages" android:id="@+id/ibImages"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="9dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_legend_show_images" android:contentDescription="@string/title_legend_show_images"
android:foregroundTint="?android:attr/textColorSecondary" android:foregroundTint="?android:attr/textColorSecondary"