From de2b20f5dd63be26816f967d2fafa9e16d8a411e Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 8 Sep 2018 06:23:53 +0000 Subject: [PATCH] Added popup menu to folder long press - Synchronize now - Delete local messages --- .../java/eu/faircode/email/AdapterFolder.java | 61 ++++++++++++++++--- .../eu/faircode/email/FragmentFolder.java | 4 -- .../eu/faircode/email/FragmentFolders.java | 2 +- app/src/main/res/values/strings.xml | 2 + 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 543a3330..25963a35 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -22,12 +22,16 @@ package eu.faircode.email; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; +import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import java.text.Collator; import java.util.ArrayList; @@ -37,6 +41,8 @@ import java.util.List; import java.util.Locale; import androidx.annotation.NonNull; +import androidx.appcompat.widget.PopupMenu; +import androidx.lifecycle.LifecycleOwner; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ListUpdateCallback; @@ -44,6 +50,7 @@ import androidx.recyclerview.widget.RecyclerView; public class AdapterFolder extends RecyclerView.Adapter { private Context context; + private LifecycleOwner owner; private List all = new ArrayList<>(); private List filtered = new ArrayList<>(); @@ -60,6 +67,9 @@ public class AdapterFolder extends RecyclerView.Adapter() { + @Override + protected Void onLoad(Context context, Bundle args) { + long id = args.getLong("id"); + DB.getInstance(context).message().deleteMessages(id); + return null; + } + + @Override + public void onException(Bundle args, Throwable ex) { + Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show(); + } + }.load(context, owner, args); + + break; + } + return true; + } + }); + + popupMenu.show(); return true; } } - AdapterFolder(Context context) { + AdapterFolder(Context context, LifecycleOwner owner) { this.context = context; + this.owner = owner; setHasStableIds(true); } diff --git a/app/src/main/java/eu/faircode/email/FragmentFolder.java b/app/src/main/java/eu/faircode/email/FragmentFolder.java index 441a1978..5735409b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolder.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolder.java @@ -100,10 +100,6 @@ public class FragmentFolder extends FragmentEx { if (!synchronize) db.folder().setFolderError(id, null); - EntityFolder folder = db.folder().getFolder(id); - if (!folder.synchronize) - db.message().deleteMessages(folder.id); - db.setTransactionSuccessful(); } finally { db.endTransaction(); diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index e4bd4489..c2ec4993 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -72,7 +72,7 @@ public class FragmentFolders extends FragmentEx { LinearLayoutManager llm = new LinearLayoutManager(getContext()); rvFolder.setLayoutManager(llm); - adapter = new AdapterFolder(getContext()); + adapter = new AdapterFolder(getContext(), getViewLifecycleOwner()); rvFolder.setAdapter(adapter); fab.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2dbcd4eb..2f9a90cd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -121,6 +121,8 @@ Insecure connections are not supported %1$s (%2$d) + Synchronize now + Delete local messages Synchronize (receive messages) Show in unified inbox Synchronize (days)