Added quick actions config

This commit is contained in:
M66B 2022-05-13 11:19:36 +02:00
parent 545f9dace5
commit fcfe97700d
3 changed files with 166 additions and 26 deletions

View File

@ -293,10 +293,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private CardView cardMore;
private ImageButton ibLowImportance;
private ImageButton ibBatchSeen;
private ImageButton ibBatchFlag;
private ImageButton ibInbox;
private ImageButton ibArchive;
private ImageButton ibJunk;
private ImageButton ibTrash;
private ImageButton ibMoreSettings;
private FloatingActionButton fabSearch;
private FloatingActionButton fabError;
private ObjectAnimator animator;
@ -563,10 +565,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
cardMore = view.findViewById(R.id.cardMore);
ibLowImportance = view.findViewById(R.id.ibLowImportance);
ibBatchSeen = view.findViewById(R.id.ibBatchSeen);
ibBatchFlag = view.findViewById(R.id.ibBatchFlag);
ibInbox = view.findViewById(R.id.ibInbox);
ibArchive = view.findViewById(R.id.ibArchive);
ibJunk = view.findViewById(R.id.ibJunk);
ibTrash = view.findViewById(R.id.ibTrash);
ibMoreSettings = view.findViewById(R.id.ibMoreSettings);
fabSearch = view.findViewById(R.id.fabSearch);
fabError = view.findViewById(R.id.fabError);
@ -1307,6 +1311,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
});
ibBatchFlag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onActionFlagSelection(true, Color.TRANSPARENT, null, true);
}
});
ibInbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -1335,6 +1346,62 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
});
ibMoreSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(v.getContext(), getViewLifecycleOwner(), ibMoreSettings);
popupMenu.inflate(R.menu.popup_config_more);
popupMenu.getMenu().findItem(R.id.menu_importance_low)
.setChecked(prefs.getBoolean("more_importance_low", false));
popupMenu.getMenu().findItem(R.id.menu_seen)
.setChecked(prefs.getBoolean("more_seen", false));
popupMenu.getMenu().findItem(R.id.menu_flag)
.setChecked(prefs.getBoolean("more_flag", false));
popupMenu.getMenu().findItem(R.id.menu_inbox)
.setChecked(prefs.getBoolean("more_inbox", true));
popupMenu.getMenu().findItem(R.id.menu_archive)
.setChecked(prefs.getBoolean("more_archive", true));
popupMenu.getMenu().findItem(R.id.menu_junk)
.setChecked(prefs.getBoolean("more_junk", true));
popupMenu.getMenu().findItem(R.id.menu_trash)
.setChecked(prefs.getBoolean("more_trash", true));
popupMenu.insertIcons(v.getContext());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
String key;
int itemId = target.getItemId();
if (itemId == R.id.menu_importance_low)
key = "more_importance_low";
else if (itemId == R.id.menu_seen)
key = "more_seen";
else if (itemId == R.id.menu_flag)
key = "more_flag";
else if (itemId == R.id.menu_inbox)
key = "more_inbox";
else if (itemId == R.id.menu_archive)
key = "more_archive";
else if (itemId == R.id.menu_junk)
key = "more_junk";
else if (itemId == R.id.menu_trash)
key = "more_trash";
else
return false;
prefs.edit().putBoolean(key, !target.isChecked()).apply();
updateMore();
return true;
}
});
popupMenu.show();
}
});
fabSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -2617,7 +2684,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} else if (EntityMessage.SWIPE_ACTION_SEEN.equals(action))
onActionSeenSelection(!message.ui_seen, message.id, false);
else if (EntityMessage.SWIPE_ACTION_FLAG.equals(action))
onActionFlagSelection(!message.ui_flagged, Color.TRANSPARENT, message.id);
onActionFlagSelection(!message.ui_flagged, Color.TRANSPARENT, message.id, false);
else if (EntityMessage.SWIPE_ACTION_SNOOZE.equals(action))
if (ActivityBilling.isPro(getContext()))
onActionSnooze(message);
@ -2708,10 +2775,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onActionSeenSelection(false, message.id, false);
return true;
} else if (itemId == R.string.title_flag) {
onActionFlagSelection(true, Color.TRANSPARENT, message.id);
onActionFlagSelection(true, Color.TRANSPARENT, message.id, false);
return true;
} else if (itemId == R.string.title_unflag) {
onActionFlagSelection(false, Color.TRANSPARENT, message.id);
onActionFlagSelection(false, Color.TRANSPARENT, message.id, false);
return true;
} else if (itemId == R.string.title_snooze) {
onMenuSnooze();
@ -3393,10 +3460,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onHideSelection(false);
return true;
} else if (itemId == R.string.title_flag) {
onActionFlagSelection(true, Color.TRANSPARENT, null);
onActionFlagSelection(true, Color.TRANSPARENT, null, false);
return true;
} else if (itemId == R.string.title_unflag) {
onActionFlagSelection(false, Color.TRANSPARENT, null);
onActionFlagSelection(false, Color.TRANSPARENT, null, false);
return true;
} else if (itemId == R.string.title_flag_color) {
onActionFlagColorSelection();
@ -3612,7 +3679,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "messages:flag");
}
private void onActionFlagSelection(boolean flagged, int color, Long id) {
private void onActionFlagSelection(boolean flagged, int color, Long id, boolean clear) {
Bundle args = new Bundle();
args.putLongArray("ids", id == null ? getSelection() : new long[]{id});
args.putBoolean("flagged", flagged);
@ -3620,8 +3687,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
args.putBoolean("threading", threading &&
(id == null || viewType != AdapterMessage.ViewType.THREAD));
//if (selectionTracker != null)
// selectionTracker.clearSelection();
if (clear && selectionTracker != null)
selectionTracker.clearSelection();
new SimpleTask<Void>() {
@Override
@ -5760,22 +5827,25 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
protected void onExecuted(Bundle args, MoreResult result) {
boolean importance = (BuildConfig.DEBUG &&
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean importance = (prefs.getBoolean("more_importance_low", false) &&
!EntityMessage.PRIORITIY_LOW.equals(result.importance));
boolean seen = (prefs.getBoolean("more_seen", false) && result.unseen);
boolean flag = (prefs.getBoolean("more_flag", false) && result.unflagged);
boolean inbox = (prefs.getBoolean("more_inbox", true) && result.canInbox());
boolean archive = (prefs.getBoolean("more_archive", true) && result.canArchive());
boolean junk = (prefs.getBoolean("more_junk", true) && result.canJunk());
boolean trash = (prefs.getBoolean("more_trash", true) && result.canTrash());
ibLowImportance.setVisibility(importance ? View.VISIBLE : View.GONE);
ibBatchSeen.setVisibility(result.unseen ? View.VISIBLE : View.GONE);
ibInbox.setVisibility(result.canInbox() ? View.VISIBLE : View.GONE);
ibArchive.setVisibility(result.canArchive() ? View.VISIBLE : View.GONE);
ibJunk.setVisibility(result.canJunk() ? View.VISIBLE : View.GONE);
ibTrash.setVisibility(result.canTrash() ? View.VISIBLE : View.GONE);
cardMore.setVisibility(fabMore.isOrWillBeShown() &&
(importance ||
result.unseen ||
result.canInbox() ||
result.canArchive() ||
result.canJunk() ||
result.canTrash())
? View.VISIBLE : View.GONE);
ibBatchSeen.setVisibility(seen ? View.VISIBLE : View.GONE);
ibBatchFlag.setVisibility(flag ? View.VISIBLE : View.GONE);
ibInbox.setVisibility(inbox ? View.VISIBLE : View.GONE);
ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE);
ibJunk.setVisibility(junk ? View.VISIBLE : View.GONE);
ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE);
cardMore.setVisibility(fabMore.isOrWillBeShown() ? View.VISIBLE : View.GONE);
}
@Override
@ -7344,7 +7414,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
Bundle args = data.getBundleExtra("args");
onActionFlagSelection(true, args.getInt("color"), null);
onActionFlagSelection(true, args.getInt("color"), null, false);
}
break;
case REQUEST_MESSAGE_SNOOZE:

View File

@ -508,7 +508,7 @@
android:alpha="0.6"
app:cardBackgroundColor="?attr/colorActionBackground"
app:cardCornerRadius="3dp"
app:layout_anchor="@+id/fabMore"
app:layout_anchor="@id/fabMore"
app:layout_anchorGravity="center_vertical">
<eu.faircode.email.ConstraintLayoutEx
@ -530,7 +530,6 @@
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/baseline_arrow_downward_24" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibBatchSeen"
android:layout_width="48dp"
@ -545,6 +544,20 @@
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_drafts_24" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibBatchFlag"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_flag"
android:padding="6dp"
android:scaleType="fitCenter"
android:tint="@color/action_foreground"
android:tooltipText="@string/title_flag"
app:layout_constraintEnd_toStartOf="@+id/ibBatchSeen"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_star_24" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibInbox"
android:layout_width="48dp"
@ -555,7 +568,7 @@
android:scaleType="fitCenter"
android:tint="@color/action_foreground"
android:tooltipText="@string/title_folder_inbox"
app:layout_constraintEnd_toStartOf="@id/ibBatchSeen"
app:layout_constraintEnd_toStartOf="@id/ibBatchFlag"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_inbox_24" />
@ -600,6 +613,19 @@
app:layout_constraintEnd_toStartOf="@id/ibJunk"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_delete_24" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibMoreSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_setup"
android:padding="6dp"
android:tint="@color/action_foreground"
android:tooltipText="@string/title_setup"
app:layout_constraintEnd_toStartOf="@id/ibTrash"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_settings_24" />
</eu.faircode.email.ConstraintLayoutEx>
</androidx.cardview.widget.CardView>

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_importance_low"
android:checkable="true"
android:icon="@drawable/baseline_arrow_downward_24"
android:title="@string/title_importance_low" />
<item
android:id="@+id/menu_seen"
android:checkable="true"
android:icon="@drawable/twotone_drafts_24"
android:title="@string/title_seen" />
<item
android:id="@+id/menu_flag"
android:checkable="true"
android:icon="@drawable/twotone_star_24"
android:title="@string/title_flag" />
<item
android:id="@+id/menu_inbox"
android:checkable="true"
android:icon="@drawable/twotone_inbox_24"
android:title="@string/title_folder_inbox" />
<item
android:id="@+id/menu_archive"
android:checkable="true"
android:icon="@drawable/twotone_archive_24"
android:title="@string/title_archive" />
<item
android:id="@+id/menu_junk"
android:checkable="true"
android:icon="@drawable/twotone_report_24"
android:title="@string/title_folder_junk" />
<item
android:id="@+id/menu_trash"
android:checkable="true"
android:icon="@drawable/twotone_delete_24"
android:title="@string/title_trash" />
</menu>