Browse Source

Added popup menu to folder long press

- Synchronize now
- Delete local messages
main
M66B 6 years ago
parent
commit
de2b20f5dd
4 changed files with 57 additions and 12 deletions
  1. +54
    -7
      app/src/main/java/eu/faircode/email/AdapterFolder.java
  2. +0
    -4
      app/src/main/java/eu/faircode/email/FragmentFolder.java
  3. +1
    -1
      app/src/main/java/eu/faircode/email/FragmentFolders.java
  4. +2
    -0
      app/src/main/res/values/strings.xml

+ 54
- 7
app/src/main/java/eu/faircode/email/AdapterFolder.java View File

@ -22,12 +22,16 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,6 +41,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
import androidx.lifecycle.LifecycleOwner;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListUpdateCallback; import androidx.recyclerview.widget.ListUpdateCallback;
@ -44,6 +50,7 @@ import androidx.recyclerview.widget.RecyclerView;
public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder> { public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder> {
private Context context; private Context context;
private LifecycleOwner owner;
private List<TupleFolderEx> all = new ArrayList<>(); private List<TupleFolderEx> all = new ArrayList<>();
private List<TupleFolderEx> filtered = new ArrayList<>(); private List<TupleFolderEx> filtered = new ArrayList<>();
@ -60,6 +67,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
ImageView ivState; ImageView ivState;
TextView tvError; TextView tvError;
private final static int action_synchronize = 1;
private final static int action_delete_local = 2;
ViewHolder(View itemView) { ViewHolder(View itemView) {
super(itemView); super(itemView);
@ -158,19 +168,56 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (pos == RecyclerView.NO_POSITION) if (pos == RecyclerView.NO_POSITION)
return false; return false;
TupleFolderEx folder = filtered.get(pos);
Log.i(Helper.TAG, folder.name + " requesting sync");
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ServiceSynchronize.ACTION_SYNCHRONIZE_FOLDER)
.setType("account/" + (folder.account == null ? "outbox" : Long.toString(folder.account)))
.putExtra("folder", folder.id));
final TupleFolderEx folder = filtered.get(pos);
PopupMenu popupMenu = new PopupMenu(context, itemView);
popupMenu.getMenu().add(Menu.NONE, action_synchronize, 1, R.string.title_synchronize_now);
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) {
case action_synchronize:
Log.i(Helper.TAG, folder.name + " requesting sync");
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ServiceSynchronize.ACTION_SYNCHRONIZE_FOLDER)
.setType("account/" + (folder.account == null ? "outbox" : Long.toString(folder.account)))
.putExtra("folder", folder.id));
break;
case action_delete_local:
Bundle args = new Bundle();
args.putLong("id", folder.id);
new SimpleTask<Void>() {
@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; return true;
} }
} }
AdapterFolder(Context context) {
AdapterFolder(Context context, LifecycleOwner owner) {
this.context = context; this.context = context;
this.owner = owner;
setHasStableIds(true); setHasStableIds(true);
} }


+ 0
- 4
app/src/main/java/eu/faircode/email/FragmentFolder.java View File

@ -100,10 +100,6 @@ public class FragmentFolder extends FragmentEx {
if (!synchronize) if (!synchronize)
db.folder().setFolderError(id, null); db.folder().setFolderError(id, null);
EntityFolder folder = db.folder().getFolder(id);
if (!folder.synchronize)
db.message().deleteMessages(folder.id);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();


+ 1
- 1
app/src/main/java/eu/faircode/email/FragmentFolders.java View File

@ -72,7 +72,7 @@ public class FragmentFolders extends FragmentEx {
LinearLayoutManager llm = new LinearLayoutManager(getContext()); LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvFolder.setLayoutManager(llm); rvFolder.setLayoutManager(llm);
adapter = new AdapterFolder(getContext());
adapter = new AdapterFolder(getContext(), getViewLifecycleOwner());
rvFolder.setAdapter(adapter); rvFolder.setAdapter(adapter);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {


+ 2
- 0
app/src/main/res/values/strings.xml View File

@ -121,6 +121,8 @@
<string name="title_insecure">Insecure connections are not supported</string> <string name="title_insecure">Insecure connections are not supported</string>
<string name="title_folder_unseen" translatable="false">%1$s (%2$d)</string> <string name="title_folder_unseen" translatable="false">%1$s (%2$d)</string>
<string name="title_synchronize_now">Synchronize now</string>
<string name="title_delete_local">Delete local messages</string>
<string name="title_synchronize_folder">Synchronize (receive messages)</string> <string name="title_synchronize_folder">Synchronize (receive messages)</string>
<string name="title_unified_folder">Show in unified inbox</string> <string name="title_unified_folder">Show in unified inbox</string>
<string name="title_after">Synchronize (days)</string> <string name="title_after">Synchronize (days)</string>


Loading…
Cancel
Save