Added multiple selection quick actions

pull/207/head
M66B 3 years ago
parent e8406da5ff
commit 0893189b89

@ -125,6 +125,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.core.view.MenuCompat; import androidx.core.view.MenuCompat;
@ -289,6 +290,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private FloatingActionButton fabCompose; private FloatingActionButton fabCompose;
private FloatingActionButton fabMore; private FloatingActionButton fabMore;
private TextView tvSelectedCount; private TextView tvSelectedCount;
private CardView cardMore;
private ImageButton ibArchive;
private ImageButton ibJunk;
private ImageButton ibTrash;
private FloatingActionButton fabSearch; private FloatingActionButton fabSearch;
private FloatingActionButton fabError; private FloatingActionButton fabError;
private ObjectAnimator animator; private ObjectAnimator animator;
@ -416,7 +421,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
"time", "unread", "starred", "priority" "time", "unread", "starred", "priority"
)); ));
private static ExecutorService executor = Helper.getBackgroundExecutor(1, "decrypt"); private static ExecutorService executor = Helper.getBackgroundExecutor(1, "messages");
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -550,6 +555,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fabCompose = view.findViewById(R.id.fabCompose); fabCompose = view.findViewById(R.id.fabCompose);
fabMore = view.findViewById(R.id.fabMore); fabMore = view.findViewById(R.id.fabMore);
tvSelectedCount = view.findViewById(R.id.tvSelectedCount); tvSelectedCount = view.findViewById(R.id.tvSelectedCount);
cardMore = view.findViewById(R.id.cardMore);
ibArchive = view.findViewById(R.id.ibArchive);
ibJunk = view.findViewById(R.id.ibJunk);
ibTrash = view.findViewById(R.id.ibTrash);
fabSearch = view.findViewById(R.id.fabSearch); fabSearch = view.findViewById(R.id.fabSearch);
fabError = view.findViewById(R.id.fabError); fabError = view.findViewById(R.id.fabError);
@ -1276,6 +1285,27 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
}); });
ibArchive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onActionMoveSelection(EntityFolder.ARCHIVE, false);
}
});
ibJunk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onActionJunkSelection();
}
});
ibTrash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onActionMoveSelection(EntityFolder.TRASH, false);
}
});
fabSearch.setOnClickListener(new View.OnClickListener() { fabSearch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -1489,6 +1519,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fabMore.hide(); fabMore.hide();
tvSelectedCount.setVisibility(View.GONE); tvSelectedCount.setVisibility(View.GONE);
cardMore.setVisibility(View.GONE);
ibArchive.setVisibility(View.GONE);
ibJunk.setVisibility(View.GONE);
ibTrash.setVisibility(View.GONE);
fabError.hide(); fabError.hide();
if (viewType == AdapterMessage.ViewType.THREAD) { if (viewType == AdapterMessage.ViewType.THREAD) {
@ -5719,9 +5753,77 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} else } else
tvSelectedCount.setCompoundDrawablesRelative(null, null, null, null); tvSelectedCount.setCompoundDrawablesRelative(null, null, null, null);
tvSelectedCount.setVisibility(View.VISIBLE); tvSelectedCount.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLongArray("ids", getSelection());
new SimpleTask<Boolean[]>() {
@Override
protected Boolean[] onExecute(Context context, Bundle args) {
long[] ids = args.getLongArray("ids");
Boolean[] result = new Boolean[3];
result[0] = false;
result[1] = false;
result[2] = false;
DB db = DB.getInstance(context);
for (long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message == null)
continue;
EntityFolder folder = db.folder().getFolder(message.folder);
if (folder == null)
continue;
if (!result[0] &&
!EntityFolder.ARCHIVE.equals(folder.type)) {
EntityFolder archive = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE);
result[0] = (archive != null && archive.selectable);
}
if (!result[1] &&
!EntityFolder.JUNK.equals(folder.type) &&
!EntityFolder.DRAFTS.equals(folder.type)) {
EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK);
result[1] = (junk != null && junk.selectable);
}
if (!result[2] &&
!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.JUNK.equals(folder.type)) {
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
result[2] = (trash != null && trash.selectable);
}
if (result[0] && result[1] && result[2])
break;
}
return result;
}
@Override
protected void onExecuted(Bundle args, Boolean[] result) {
cardMore.setVisibility(fabMore.isOrWillBeShown() &&
(result[0] || result[1] || result[2])
? View.VISIBLE : View.GONE);
ibArchive.setVisibility(result[0] ? View.VISIBLE : View.GONE);
ibJunk.setVisibility(result[1] ? View.VISIBLE : View.GONE);
ibTrash.setVisibility(result[2] ? View.VISIBLE : View.GONE);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.setExecutor(executor).execute(this, args, "fabs");
} else { } else {
fabMore.hide(); fabMore.hide();
tvSelectedCount.setVisibility(View.GONE); tvSelectedCount.setVisibility(View.GONE);
cardMore.setVisibility(View.GONE);
} }
} }

@ -500,6 +500,66 @@
app:layout_anchor="@id/fabMore" app:layout_anchor="@id/fabMore"
app:layout_anchorGravity="center_horizontal|bottom" /> app:layout_anchorGravity="center_horizontal|bottom" />
<androidx.cardview.widget.CardView
android:id="@+id/cardMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:alpha="0.6"
app:cardBackgroundColor="?attr/colorActionBackground"
app:cardCornerRadius="3dp"
app:layout_anchor="@+id/fabMore"
app:layout_anchorGravity="center_vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="3dp">
<eu.faircode.email.FixedImageButton
android:id="@+id/ibArchive"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_archive"
android:padding="3dp"
android:scaleType="fitCenter"
android:tint="@color/action_foreground"
android:tooltipText="@string/title_archive"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_archive_24" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibJunk"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_folder_junk"
android:padding="3dp"
android:scaleType="fitCenter"
android:tint="@color/action_foreground"
android:tooltipText="@string/title_folder_junk"
app:layout_constraintEnd_toStartOf="@id/ibArchive"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_report_24" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibTrash"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_delete"
android:padding="3dp"
android:scaleType="fitCenter"
android:tint="@color/action_foreground"
android:tooltipText="@string/title_delete"
app:layout_constraintEnd_toStartOf="@id/ibJunk"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_delete_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabSearch" android:id="@+id/fabSearch"
android:layout_width="wrap_content" android:layout_width="wrap_content"

Loading…
Cancel
Save