mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-04 11:54:10 +01:00
Allow enable/disable account/identity/folder from list
This commit is contained in:
@@ -23,13 +23,17 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
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 androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
@@ -57,7 +61,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
private NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
private DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
private View view;
|
||||
private View vwColor;
|
||||
private ImageView ivPrimary;
|
||||
@@ -96,10 +100,12 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
|
||||
private void wire() {
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
private void unwire() {
|
||||
view.setOnClickListener(null);
|
||||
view.setOnLongClickListener(null);
|
||||
}
|
||||
|
||||
private void bindTo(TupleAccountEx account) {
|
||||
@@ -166,6 +172,68 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
new Intent(settings ? ActivitySetup.ACTION_EDIT_ACCOUNT : ActivityView.ACTION_VIEW_FOLDERS)
|
||||
.putExtra("id", account.id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
int pos = getAdapterPosition();
|
||||
if (pos == RecyclerView.NO_POSITION)
|
||||
return false;
|
||||
|
||||
final TupleAccountEx account = items.get(pos);
|
||||
if (account.tbd != null)
|
||||
return false;
|
||||
|
||||
PopupMenu popupMenu = new PopupMenu(context, view);
|
||||
|
||||
popupMenu.getMenu().add(Menu.NONE, 1, 1, R.string.title_advanced_enabled)
|
||||
.setCheckable(true).setChecked(account.synchronize);
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case 1:
|
||||
onActionSync(!item.isChecked());
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void onActionSync(boolean sync) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", account.id);
|
||||
args.putBoolean("sync", sync);
|
||||
|
||||
new SimpleTask<Boolean>() {
|
||||
@Override
|
||||
protected Boolean onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
boolean sync = args.getBoolean("sync");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.account().setAccountSynchronize(id, sync);
|
||||
|
||||
return sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Boolean sync) {
|
||||
ServiceSynchronize.reload(context, "account set sync=" + sync);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "account:enable");
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
AdapterAccount(Context context, LifecycleOwner owner, boolean settings) {
|
||||
|
||||
@@ -110,11 +110,12 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||
private TwoStateOwner cowner = new TwoStateOwner(owner, "AdapterFolder");
|
||||
|
||||
private final static int action_synchronize_now = 1;
|
||||
private final static int action_delete_local = 2;
|
||||
private final static int action_delete_browsed = 3;
|
||||
private final static int action_empty_trash = 4;
|
||||
private final static int action_edit_properties = 5;
|
||||
private final static int action_edit_rules = 6;
|
||||
private final static int action_synchronize = 2;
|
||||
private final static int action_delete_local = 3;
|
||||
private final static int action_delete_browsed = 4;
|
||||
private final static int action_empty_trash = 5;
|
||||
private final static int action_edit_properties = 6;
|
||||
private final static int action_edit_rules = 7;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@@ -383,27 +384,35 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||
|
||||
popupMenu.getMenu().add(Menu.NONE, action_synchronize_now, 1, R.string.title_synchronize_now);
|
||||
|
||||
if (folder.account != null)
|
||||
popupMenu.getMenu().add(Menu.NONE, action_synchronize, 2, R.string.title_advanced_enabled)
|
||||
.setCheckable(true).setChecked(folder.synchronize);
|
||||
|
||||
if (folder.account != null) { // outbox
|
||||
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_delete_browsed, 3, R.string.title_delete_browsed);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 3, R.string.title_delete_local);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_delete_browsed, 4, R.string.title_delete_browsed);
|
||||
}
|
||||
|
||||
if (EntityFolder.TRASH.equals(folder.type))
|
||||
popupMenu.getMenu().add(Menu.NONE, action_empty_trash, 4, R.string.title_empty_trash);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_empty_trash, 5, R.string.title_empty_trash);
|
||||
|
||||
if (folder.account != null) {
|
||||
popupMenu.getMenu().add(Menu.NONE, action_edit_rules, 5, R.string.title_edit_rules);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 6, R.string.title_edit_properties);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_edit_rules, 6, R.string.title_edit_rules);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 7, R.string.title_edit_properties);
|
||||
}
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem target) {
|
||||
switch (target.getItemId()) {
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case action_synchronize_now:
|
||||
onActionSynchronizeNow();
|
||||
return true;
|
||||
|
||||
case action_synchronize:
|
||||
onActionSync(!item.isChecked());
|
||||
return true;
|
||||
|
||||
case action_delete_local:
|
||||
OnActionDeleteLocal(false);
|
||||
return true;
|
||||
@@ -481,6 +490,35 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||
}.execute(context, owner, args, "folder:sync");
|
||||
}
|
||||
|
||||
private void onActionSync(boolean sync) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", folder.id);
|
||||
args.putBoolean("sync", sync);
|
||||
|
||||
new SimpleTask<Boolean>() {
|
||||
@Override
|
||||
protected Boolean onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
boolean sync = args.getBoolean("sync");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.folder().setFolderSynchronize(id, sync);
|
||||
|
||||
return sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Boolean sync) {
|
||||
ServiceSynchronize.reload(context, "folder set sync=" + sync);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "folder:enable");
|
||||
}
|
||||
|
||||
private void OnActionDeleteLocal(final boolean browsed) {
|
||||
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_message, null);
|
||||
TextView tvMessage = dview.findViewById(R.id.tvMessage);
|
||||
|
||||
@@ -22,13 +22,18 @@ package eu.faircode.email;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
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 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;
|
||||
@@ -45,13 +50,14 @@ import java.util.Locale;
|
||||
|
||||
public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHolder> {
|
||||
private Context context;
|
||||
private LifecycleOwner owner;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
private List<TupleIdentityEx> items = new ArrayList<>();
|
||||
|
||||
private DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
private View view;
|
||||
private View vwColor;
|
||||
private ImageView ivSync;
|
||||
@@ -82,10 +88,12 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
||||
|
||||
private void wire() {
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
private void unwire() {
|
||||
view.setOnClickListener(null);
|
||||
view.setOnLongClickListener(null);
|
||||
}
|
||||
|
||||
private void bindTo(TupleIdentityEx identity) {
|
||||
@@ -130,10 +138,66 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
||||
new Intent(ActivitySetup.ACTION_EDIT_IDENTITY)
|
||||
.putExtra("id", identity.id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
int pos = getAdapterPosition();
|
||||
if (pos == RecyclerView.NO_POSITION)
|
||||
return false;
|
||||
|
||||
final TupleIdentityEx identity = items.get(pos);
|
||||
|
||||
PopupMenu popupMenu = new PopupMenu(context, view);
|
||||
|
||||
popupMenu.getMenu().add(Menu.NONE, 1, 1, R.string.title_advanced_enabled)
|
||||
.setCheckable(true).setChecked(identity.synchronize);
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case 1:
|
||||
onActionSync(!item.isChecked());
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AdapterIdentity(Context context) {
|
||||
private void onActionSync(boolean sync) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", identity.id);
|
||||
args.putBoolean("sync", sync);
|
||||
|
||||
new SimpleTask<Boolean>() {
|
||||
@Override
|
||||
protected Boolean onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
boolean sync = args.getBoolean("sync");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.identity().setIdentitySynchronize(id, sync);
|
||||
|
||||
return sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "identitty:enable");
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
AdapterIdentity(Context context, LifecycleOwner owner) {
|
||||
this.context = context;
|
||||
this.owner = owner;
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,9 @@ public interface DaoAccount {
|
||||
@Update
|
||||
void updateAccount(EntityAccount account);
|
||||
|
||||
@Query("UPDATE account SET synchronize = :synchronize WHERE id = :id")
|
||||
int setAccountSynchronize(long id, boolean synchronize);
|
||||
|
||||
@Query("UPDATE account SET state = :state WHERE id = :id")
|
||||
int setAccountState(long id, String state);
|
||||
|
||||
|
||||
@@ -162,6 +162,9 @@ public interface DaoFolder {
|
||||
@Insert
|
||||
long insertFolder(EntityFolder folder);
|
||||
|
||||
@Query("UPDATE folder SET synchronize = :synchronize WHERE id = :id")
|
||||
int setFolderSynchronize(long id, boolean synchronize);
|
||||
|
||||
@Query("UPDATE folder SET state = :state WHERE id = :id")
|
||||
int setFolderState(long id, String state);
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ public interface DaoIdentity {
|
||||
@Update
|
||||
void updateIdentity(EntityIdentity identity);
|
||||
|
||||
@Query("UPDATE identity SET synchronize = :synchronize WHERE id = :id")
|
||||
int setIdentitySynchronize(long id, boolean synchronize);
|
||||
|
||||
@Query("UPDATE identity SET state = :state WHERE id = :id")
|
||||
int setIdentityState(long id, String state);
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class FragmentIdentities extends FragmentBase {
|
||||
itemDecorator.setDrawable(getContext().getDrawable(R.drawable.divider));
|
||||
rvIdentity.addItemDecoration(itemDecorator);
|
||||
|
||||
adapter = new AdapterIdentity(getContext());
|
||||
adapter = new AdapterIdentity(getContext(), getViewLifecycleOwner());
|
||||
rvIdentity.setAdapter(adapter);
|
||||
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
Reference in New Issue
Block a user