mirror of https://github.com/M66B/FairEmail.git
Moved subscription management to folder long press menu
This commit is contained in:
parent
6d69005b52
commit
7b07850a91
|
@ -378,22 +378,27 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
popupMenu.getMenu().add(Menu.NONE, R.string.title_notify_folder, 8, R.string.title_notify_folder)
|
||||
.setCheckable(true).setChecked(folder.notify);
|
||||
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_enabled, 9, R.string.title_synchronize_enabled)
|
||||
boolean subscriptions = prefs.getBoolean("subscriptions", false);
|
||||
if (folder.subscribed != null && subscriptions)
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_subscribe, 9, R.string.title_subscribe)
|
||||
.setCheckable(true).setChecked(folder.subscribed);
|
||||
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_enabled, 10, R.string.title_synchronize_enabled)
|
||||
.setCheckable(true).setChecked(folder.synchronize);
|
||||
|
||||
if (!folder.read_only)
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, 10, R.string.title_edit_rules);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_properties, 11, R.string.title_edit_properties);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, 11, R.string.title_edit_rules);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_properties, 12, R.string.title_edit_properties);
|
||||
|
||||
if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
String channelId = EntityFolder.getNotificationChannelId(folder.id);
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = nm.getNotificationChannel(channelId);
|
||||
if (channel == null)
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, 12, R.string.title_create_channel);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, 13, R.string.title_create_channel);
|
||||
else {
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 13, R.string.title_edit_channel);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, 14, R.string.title_delete_channel);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 14, R.string.title_edit_channel);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, 15, R.string.title_delete_channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,6 +429,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
onActionProperty(item.getItemId(), !item.isChecked());
|
||||
return true;
|
||||
|
||||
case R.string.title_subscribe:
|
||||
onActionSubscribe();
|
||||
return true;
|
||||
|
||||
case R.string.title_delete_local:
|
||||
OnActionDeleteLocal(false);
|
||||
return true;
|
||||
|
@ -526,6 +535,29 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
}.execute(context, owner, args, "folder:enable");
|
||||
}
|
||||
|
||||
private void onActionSubscribe() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", folder.id);
|
||||
args.putBoolean("subscribed", !folder.subscribed);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
boolean subscribed = args.getBoolean("subscribed");
|
||||
|
||||
EntityOperation.subscribe(context, id, subscribed);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(parentFragment.getFragmentManager(), ex);
|
||||
}
|
||||
}.execute(context, owner, args, "folder:subscribe");
|
||||
}
|
||||
|
||||
private void OnActionDeleteLocal(final boolean browsed) {
|
||||
Bundle aargs = new Bundle();
|
||||
aargs.putString("question", context.getString(R.string.title_ask_delete_local));
|
||||
|
|
|
@ -21,7 +21,6 @@ package eu.faircode.email;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -43,7 +42,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
|
@ -77,7 +75,6 @@ public class FragmentFolder extends FragmentBase {
|
|||
private long id = -1;
|
||||
private long account = -1;
|
||||
private String parent = null;
|
||||
private Boolean subscribed = null;
|
||||
private boolean saving = false;
|
||||
private boolean deletable = false;
|
||||
|
||||
|
@ -233,7 +230,6 @@ public class FragmentFolder extends FragmentBase {
|
|||
cbAutoDelete.setEnabled(!cbKeepAll.isChecked());
|
||||
btnSave.setEnabled(true);
|
||||
|
||||
subscribed = (folder == null ? null : folder.subscribed != null && folder.subscribed);
|
||||
deletable = (folder != null && EntityFolder.USER.equals(folder.type));
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
@ -278,11 +274,6 @@ public class FragmentFolder extends FragmentBase {
|
|||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean subscriptions = prefs.getBoolean("subscriptions", false);
|
||||
|
||||
menu.findItem(R.id.menu_subscribe).setChecked(subscribed != null && subscribed);
|
||||
menu.findItem(R.id.menu_subscribe).setVisible(subscriptions && id > 0 && subscribed != null);
|
||||
menu.findItem(R.id.menu_delete).setVisible(id > 0 && !saving && deletable);
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
@ -290,11 +281,6 @@ public class FragmentFolder extends FragmentBase {
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_subscribe:
|
||||
subscribed = !item.isChecked();
|
||||
item.setChecked(subscribed);
|
||||
onMenuSubscribe();
|
||||
return true;
|
||||
case R.id.menu_delete:
|
||||
onMenuDelete();
|
||||
return true;
|
||||
|
@ -303,29 +289,6 @@ public class FragmentFolder extends FragmentBase {
|
|||
}
|
||||
}
|
||||
|
||||
private void onMenuSubscribe() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
args.putBoolean("subscribed", subscribed);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
boolean subscribed = args.getBoolean("subscribed");
|
||||
|
||||
EntityOperation.subscribe(context, id, subscribed);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(getFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "folder:subscribe");
|
||||
}
|
||||
|
||||
private void onMenuDelete() {
|
||||
Bundle aargs = new Bundle();
|
||||
aargs.putString("question", getString(R.string.title_folder_delete));
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/menu_subscribe"
|
||||
android:checkable="true"
|
||||
android:title="@string/title_subscribe"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_delete"
|
||||
android:title="@string/title_delete"
|
||||
|
|
Loading…
Reference in New Issue