Added subscribed only filter

This commit is contained in:
M66B 2020-03-31 13:43:58 +02:00
parent 5048b671f4
commit d9d8d6e6f1
9 changed files with 42 additions and 67 deletions

View File

@ -80,6 +80,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private long account;
private boolean show_compact;
private boolean show_hidden;
private boolean subscribed_only;
private IFolderSelectedListener listener;
private Context context;
@ -450,9 +451,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) {
boolean subscriptions = prefs.getBoolean("subscriptions", false);
if (folder.subscribed != null && subscriptions)
if (subscriptions)
popupMenu.getMenu().add(Menu.NONE, R.string.title_subscribe, 9, R.string.title_subscribe)
.setCheckable(true).setChecked(folder.subscribed);
.setCheckable(true).setChecked(folder.subscribed != null && folder.subscribed);
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_enabled, 10, R.string.title_synchronize_enabled)
.setCheckable(true).setChecked(folder.synchronize);
@ -617,7 +618,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private void onActionSubscribe() {
Bundle args = new Bundle();
args.putLong("id", folder.id);
args.putBoolean("subscribed", !folder.subscribed);
args.putBoolean("subscribed", !(folder.subscribed != null && folder.subscribed));
new SimpleTask<Void>() {
@Override
@ -743,6 +744,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
zoom = 1;
this.subscriptions = prefs.getBoolean("subscriptions", false);
this.subscribed_only = prefs.getBoolean("subscribed_only", false) && subscriptions;
this.debug = prefs.getBoolean("debug", false);
this.dp12 = Helper.dp2pixels(context, 12);
@ -778,6 +780,13 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}
}
void setSubscribedOnly(boolean subscribed_only) {
if (this.subscribed_only != subscribed_only) {
this.subscribed_only = subscribed_only;
set(all);
}
}
void setDisabled(List<Long> ids) {
disabledIds = ids;
}
@ -919,7 +928,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
Collections.sort(parents, parents.get(0).getComparator(context));
for (TupleFolderEx parent : parents)
if (!parent.hide || show_hidden) {
if ((!parent.hide || show_hidden) && (parent.subscribed || !subscribed_only)) {
parent.indentation = indentation;
result.add(parent);

View File

@ -1205,7 +1205,6 @@ class Core {
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean subscribed_only = prefs.getBoolean("subscribed_only", false);
boolean sync_folders = prefs.getBoolean("sync_folders", true);
// Get folder names
@ -1279,28 +1278,11 @@ class Core {
// Get remote folders
long start = new Date().getTime();
Folder[] ifolders = (subscribed_only
? defaultFolder.listSubscribed("*")
: defaultFolder.list("*"));
Folder[] ifolders = defaultFolder.list("*");
// Get subscribed folders
List<String> subscription = new ArrayList<>();
try {
Folder[] isubscribed = (subscribed_only ? ifolders : defaultFolder.listSubscribed("*"));
for (Folder ifolder : isubscribed)
subscription.add(ifolder.getFullName());
} catch (MessagingException ex) {
Log.e(account.name, ex);
}
if (subscribed_only && ifolders.length == 0) {
Log.i("No subscribed folders");
ifolders = defaultFolder.list("*");
}
long duration = new Date().getTime() - start;
Log.i("Remote folder count=" + ifolders.length +
" subscribed=" + subscription.size() +
" separator=" + separator +
" fetched in " + duration + " ms");
@ -1310,7 +1292,7 @@ class Core {
String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
String type = EntityFolder.getType(attrs, fullName, false);
boolean subscribed = subscription.contains(fullName);
boolean subscribed = ifolder.isSubscribed();
boolean selectable = true;
boolean inferiors = true;

View File

@ -654,7 +654,6 @@ public class FragmentAccount extends FragmentBase {
realm = null;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean subscribed_only = prefs.getBoolean("subscribed_only", false);
DB db = DB.getInstance(context);
@ -684,7 +683,6 @@ public class FragmentAccount extends FragmentBase {
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
String type = EntityFolder.getType(attrs, fullName, true);
boolean subscribed = ifolder.isSubscribed();
boolean selectable = true;
for (String attr : attrs)
@ -692,7 +690,7 @@ public class FragmentAccount extends FragmentBase {
selectable = false;
selectable = selectable && ((ifolder.getType() & IMAPFolder.HOLDS_MESSAGES) != 0);
if (type != null && selectable && (!subscribed_only || subscribed)) {
if (type != null && selectable) {
// Create entry
EntityFolder folder = db.folder().getFolderByName(id, fullName);
if (folder == null)

View File

@ -450,8 +450,14 @@ public class FragmentFolders extends FragmentBase {
@Override
public void onPrepareOptionsMenu(Menu menu) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean subscriptions = prefs.getBoolean("subscriptions", false);
boolean subscribed_only = prefs.getBoolean("subscribed_only", false);
menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_show_hidden).setChecked(show_hidden);
menu.findItem(R.id.menu_subscribed_only).setChecked(subscribed_only);
menu.findItem(R.id.menu_subscribed_only).setVisible(subscriptions);
menu.findItem(R.id.menu_apply_all).setVisible(account >= 0);
super.onPrepareOptionsMenu(menu);
@ -466,6 +472,9 @@ public class FragmentFolders extends FragmentBase {
case R.id.menu_show_hidden:
onMenuShowHidden();
return true;
case R.id.menu_subscribed_only:
onMenuSubscribedOnly();
return true;
case R.id.menu_apply_all:
onMenuApplyToAll();
return true;
@ -493,6 +502,14 @@ public class FragmentFolders extends FragmentBase {
adapter.setShowHidden(show_hidden);
}
private void onMenuSubscribedOnly() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean subscribed_only = !prefs.getBoolean("subscribed_only", false);
prefs.edit().putBoolean("subscribed_only", subscribed_only).apply();
getActivity().invalidateOptionsMenu();
adapter.setSubscribedOnly(subscribed_only);
}
private void onMenuApplyToAll() {
Bundle args = new Bundle();
args.putLong("account", account);

View File

@ -75,7 +75,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private SwitchCompat swSyncFolders;
private SwitchCompat swSubscriptions;
private TextView tvSubscriptionPro;
private SwitchCompat swSubscribedOnly;
private SwitchCompat swCheckMx;
private SwitchCompat swCheckReply;
private Group grpExempted;
@ -84,7 +83,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private final static String[] RESET_OPTIONS = new String[]{
"enabled", "poll_interval", "schedule", "schedule_start", "schedule_end",
"sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "sync_folders", "subscriptions", "subscribed_only",
"sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "sync_folders", "subscriptions",
"check_mx", "check_reply"
};
@ -121,7 +120,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swSyncFolders = view.findViewById(R.id.swSyncFolders);
swSubscriptions = view.findViewById(R.id.swSubscriptions);
tvSubscriptionPro = view.findViewById(R.id.tvSubscriptionPro);
swSubscribedOnly = view.findViewById(R.id.swSubscribedOnly);
swCheckMx = view.findViewById(R.id.swCheckMx);
swCheckReply = view.findViewById(R.id.swCheckReply);
grpExempted = view.findViewById(R.id.grpExempted);
@ -265,14 +263,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
Helper.linkPro(tvSubscriptionPro);
swSubscribedOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("subscribed_only", checked).apply();
ServiceSynchronize.reload(getContext(), null, false, "subscribed_only");
}
});
swCheckMx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -370,7 +360,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swSyncFolders.setChecked(prefs.getBoolean("sync_folders", true));
swSubscriptions.setChecked(prefs.getBoolean("subscriptions", false) && pro);
swSubscriptions.setEnabled(pro);
swSubscribedOnly.setChecked(prefs.getBoolean("subscribed_only", false));
swCheckMx.setChecked(prefs.getBoolean("check_mx", false));
swCheckReply.setChecked(prefs.getBoolean("check_reply", false));
}

View File

@ -122,7 +122,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"metered", "roaming", "rlah", // force reconnect
"ssl_harden", // force reconnect
"socks_enabled", "socks_proxy", // force reconnect
"subscribed_only", // force folder sync
"badge", "unseen_ignored", // force update badge/widget
"debug" // force reconnect
));

View File

@ -399,30 +399,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSubscriptions" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSubscribedOnly"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sync_subscribed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSubscriptionPro"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSubscribedOnlyHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_subscribed_only_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSubscribedOnly" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCheckMx"
android:layout_width="0dp"
@ -431,7 +407,7 @@
android:text="@string/title_advanced_check_mx"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSubscribedOnlyHint"
app:layout_constraintTop_toBottomOf="@id/tvSubscriptionPro"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

View File

@ -21,6 +21,12 @@
android:title="@string/title_show_folders"
app:showAsAction="never" />
<item
android:id="@+id/menu_subscribed_only"
android:checkable="true"
android:title="@string/title_subscribed_only"
app:showAsAction="never" />
<item
android:id="@+id/menu_apply_all"
android:title="@string/title_apply_to_all"

View File

@ -268,7 +268,6 @@
<string name="title_advanced_kept_removed">Check if old messages were removed from the server</string>
<string name="title_advanced_sync_folders">Synchronize folder list</string>
<string name="title_advanced_subscriptions">Manage folder subscriptions</string>
<string name="title_advanced_sync_subscribed">Synchronize subscribed folders only</string>
<string name="title_advanced_keyboard">Show keyboard by default</string>
<string name="title_advanced_suggest_local">Suggest locally stored contacts</string>
@ -460,7 +459,6 @@
<string name="title_advanced_deleted_unseen">When disabled, unread messages are kept on the device forever</string>
<string name="title_advanced_sync_kept_hint">This will transfer extra data and consume extra battery power, especially if a lot of messages are stored on the device</string>
<string name="title_advanced_sync_folders_hint">Disabling this will reduce data and battery usage somewhat, but will disable updating the list of folders too</string>
<string name="title_advanced_subscribed_only_hint">Enabling this will delete all local folders without subscription</string>
<string name="title_advanced_sync_delay_hint">This will slow down synchronizing messages</string>
<string name="title_advanced_suggest_local_hint">In addition to contacts provided by Android. Contact data will be stored for newly sent or received messages only when enabled.</string>
@ -642,6 +640,7 @@
<string name="title_folder_name">Folder name</string>
<string name="title_display_name">Display name</string>
<string name="title_show_folders">Show hidden folders</string>
<string name="title_subscribed_only">Subscribed only</string>
<string name="title_apply_to_all">Apply to all &#8230;</string>
<string name="title_hide_folder">Hide folder</string>
<string name="title_unified_folder">Show in unified inbox</string>