Added archive/delete actions to conversation thread

This commit is contained in:
M66B 2018-11-17 08:51:03 +01:00
parent 68f4fe2e46
commit cce4bd8c60
3 changed files with 113 additions and 21 deletions

View File

@ -552,14 +552,27 @@ public class FragmentMessages extends FragmentEx {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
ViewModelMessages.Target[] pn = (ViewModelMessages.Target[]) bottom_navigation.getTag();
ViewModelMessages.Target target = (menuItem.getItemId() == R.id.action_prev ? pn[0] : pn[1]);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", target.account)
.putExtra("thread", target.thread)
.putExtra("found", target.found));
switch (menuItem.getItemId()) {
case R.id.action_delete:
onActionMove(EntityFolder.TRASH);
return true;
case R.id.action_archive:
onActionMove(EntityFolder.ARCHIVE);
return true;
case R.id.action_prev:
onActionNavigate(pn[0]);
return true;
case R.id.action_next:
onActionNavigate(pn[1]);
return true;
default:
return false;
}
}
});
@ -879,15 +892,33 @@ public class FragmentMessages extends FragmentEx {
else
fabMove.hide();
if (viewType == AdapterMessage.ViewType.THREAD) {
// Navigation
if (viewType == AdapterMessage.ViewType.THREAD)
db.folder().liveSystemFolders(account).observe(getViewLifecycleOwner(), new Observer<List<EntityFolder>>() {
@Override
public void onChanged(@Nullable List<EntityFolder> folders) {
boolean hasTrash = false;
boolean hasArchive = false;
if (folders != null)
for (EntityFolder folder : folders)
if (EntityFolder.TRASH.equals(folder.type))
hasTrash = true;
else if (EntityFolder.ARCHIVE.equals(folder.type))
hasArchive = true;
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
ViewModelMessages.Target[] pn = model.getPrevNext(thread);
bottom_navigation.setTag(pn);
bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(pn[0] != null);
bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(pn[1] != null);
bottom_navigation.setVisibility(!navigation || (pn[0] == null && pn[1] == null) ? View.GONE : View.VISIBLE);
} else {
bottom_navigation.getMenu().findItem(R.id.action_prev).setVisible(navigation);
bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(hasTrash);
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(hasArchive);
bottom_navigation.getMenu().findItem(R.id.action_next).setVisible(navigation);
bottom_navigation.setVisibility(View.VISIBLE);
}
});
else {
db.account().liveAccountDraft(account < 0 ? null : account).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
@Override
public void onChanged(EntityAccount account) {
@ -1189,7 +1220,7 @@ public class FragmentMessages extends FragmentEx {
@Override
public void onChanged(@Nullable PagedList<TupleMessageEx> messages) {
if (messages == null ||
(viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0)) {
(viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0 && !navigation)) {
finish();
return;
}
@ -1318,6 +1349,57 @@ public class FragmentMessages extends FragmentEx {
}.load(this, args);
}
private void onActionMove(String folderType) {
Bundle args = new Bundle();
args.putLong("account", account);
args.putString("thread", thread);
args.putString("folderType", folderType);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
long account = args.getLong("account");
String thread = args.getString("thread");
String folderType = args.getString("folderType");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityFolder target = db.folder().getFolderByType(account, folderType);
List<EntityMessage> messages = db.message().getMessageByThread(account, thread);
for (EntityMessage message : messages)
if (!target.id.equals(message.folder)) {
db.message().setMessageUiHide(message.id, true);
EntityOperation.queue(db, message, EntityOperation.MOVE, target.id);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), ex);
}
}.load(this, args);
}
private void onActionNavigate(ViewModelMessages.Target target) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", target.account)
.putExtra("thread", target.thread)
.putExtra("found", target.found));
}
ActivityBase.IBackPressedListener onBackPressedListener = new ActivityBase.IBackPressedListener() {
@Override
public boolean onBackPressed() {

View File

@ -167,11 +167,11 @@
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="?attr/colorSeparator"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:itemIconTint="@color/bottomnav_background"
app:itemTextColor="@color/bottomnav_background"
app:labelVisibilityMode="unlabeled"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

@ -6,6 +6,16 @@
android:icon="@drawable/baseline_navigate_before_24"
android:title="@string/title_previous" />
<item
android:id="@+id/action_delete"
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_trash" />
<item
android:id="@+id/action_archive"
android:icon="@drawable/baseline_archive_24"
android:title="@string/title_archive" />
<item
android:id="@+id/action_next"
android:icon="@drawable/baseline_navigate_next_24"