Added option to hide username for accounts

master
M66B 1 week ago
parent c02c994653
commit 05492aebf1

@ -83,6 +83,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private Fragment parentFragment; private Fragment parentFragment;
private boolean settings; private boolean settings;
private boolean compact; private boolean compact;
private boolean show_users;
private boolean show_folders; private boolean show_folders;
private Context context; private Context context;
@ -295,7 +296,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
if (account.provider != null && (BuildConfig.DEBUG || debug)) if (account.provider != null && (BuildConfig.DEBUG || debug))
user.append(" (").append(account.provider).append(')'); user.append(" (").append(account.provider).append(')');
tvUser.setText(user); tvUser.setText(user);
tvUser.setVisibility(View.VISIBLE); tvUser.setVisibility(show_users ? View.VISIBLE : View.GONE);
if ("connected".equals(account.state)) { if ("connected".equals(account.state)) {
ivState.setImageResource(R.drawable.twotone_cloud_done_24); ivState.setImageResource(R.drawable.twotone_cloud_done_24);
@ -332,10 +333,10 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
(account.last_connected == null ? "-" : DTF.format(account.last_connected)) + (account.last_connected == null ? "-" : DTF.format(account.last_connected)) +
(BuildConfig.DEBUG ? (BuildConfig.DEBUG ?
"/" + (account.last_modified == null ? "-" : DTF.format(account.last_modified)) + "/" + (account.last_modified == null ? "-" : DTF.format(account.last_modified)) +
" " + account.poll_interval + " " + account.poll_interval +
"/" + account.keep_alive_ok + "/" + account.keep_alive_ok +
"/" + account.keep_alive_failed + "/" + account.keep_alive_failed +
"/" + account.keep_alive_succeeded : ""))); "/" + account.keep_alive_succeeded : "")));
tvBackoff.setText(context.getString(R.string.title_backoff_until, tvBackoff.setText(context.getString(R.string.title_backoff_until,
account.backoff_until == null ? "-" : DTF.format(account.backoff_until))); account.backoff_until == null ? "-" : DTF.format(account.backoff_until)));
@ -951,10 +952,11 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
} }
} }
AdapterAccount(final Fragment parentFragment, boolean settings, boolean compact, boolean folders) { AdapterAccount(final Fragment parentFragment, boolean settings, boolean compact, boolean users, boolean folders) {
this.parentFragment = parentFragment; this.parentFragment = parentFragment;
this.settings = settings; this.settings = settings;
this.compact = compact; this.compact = compact;
this.show_users = users;
this.show_folders = folders; this.show_folders = folders;
this.context = parentFragment.getContext(); this.context = parentFragment.getContext();
@ -1054,6 +1056,11 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
this.compact = compact; this.compact = compact;
} }
void setShowUsers(boolean show_users) {
if (this.show_users != show_users)
this.show_users = show_users;
}
void setShowFolders(boolean show_folders) { void setShowFolders(boolean show_folders) {
if (this.show_folders != show_folders) { if (this.show_folders != show_folders) {
this.show_folders = show_folders; this.show_folders = show_folders;

@ -76,6 +76,7 @@ public class FragmentAccounts extends FragmentBase {
private boolean cards; private boolean cards;
private boolean dividers; private boolean dividers;
private boolean compact; private boolean compact;
private boolean show_users;
private boolean show_folders; private boolean show_folders;
private ViewGroup view; private ViewGroup view;
@ -102,6 +103,7 @@ public class FragmentAccounts extends FragmentBase {
cards = prefs.getBoolean("cards", true); cards = prefs.getBoolean("cards", true);
dividers = prefs.getBoolean("dividers", true); dividers = prefs.getBoolean("dividers", true);
compact = prefs.getBoolean("compact_accounts", false) && !settings; compact = prefs.getBoolean("compact_accounts", false) && !settings;
show_users = prefs.getBoolean("account_users", true) || settings;
show_folders = prefs.getBoolean("folders_accounts", false) && !settings; show_folders = prefs.getBoolean("folders_accounts", false) && !settings;
} }
@ -230,7 +232,7 @@ public class FragmentAccounts extends FragmentBase {
}; };
rvAccount.addItemDecoration(categoryDecorator); rvAccount.addItemDecoration(categoryDecorator);
adapter = new AdapterAccount(this, settings, compact, show_folders); adapter = new AdapterAccount(this, settings, compact, show_users, show_folders);
rvAccount.setAdapter(adapter); rvAccount.setAdapter(adapter);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@ -366,6 +368,8 @@ public class FragmentAccounts extends FragmentBase {
menu.findItem(R.id.menu_outbox).setVisible(!settings); menu.findItem(R.id.menu_outbox).setVisible(!settings);
menu.findItem(R.id.menu_compact).setChecked(compact); menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_compact).setVisible(!settings); menu.findItem(R.id.menu_compact).setVisible(!settings);
menu.findItem(R.id.menu_show_users).setChecked(show_users);
menu.findItem(R.id.menu_show_users).setVisible(!settings);
menu.findItem(R.id.menu_show_folders).setChecked(show_folders); menu.findItem(R.id.menu_show_folders).setChecked(show_folders);
menu.findItem(R.id.menu_show_folders).setVisible(!settings); menu.findItem(R.id.menu_show_folders).setVisible(!settings);
menu.findItem(R.id.menu_theme).setVisible(!settings); menu.findItem(R.id.menu_theme).setVisible(!settings);
@ -393,6 +397,9 @@ public class FragmentAccounts extends FragmentBase {
} else if (itemId == R.id.menu_compact) { } else if (itemId == R.id.menu_compact) {
onMenuCompact(); onMenuCompact();
return true; return true;
} else if (itemId == R.id.menu_show_users) {
onMenuShowUsers();
return true;
} else if (itemId == R.id.menu_show_folders) { } else if (itemId == R.id.menu_show_folders) {
onMenuShowFolders(); onMenuShowFolders();
return true; return true;
@ -462,6 +469,26 @@ public class FragmentAccounts extends FragmentBase {
}); });
} }
private void onMenuShowUsers() {
show_users = !show_users;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("account_users", show_users).apply();
invalidateOptionsMenu();
adapter.setShowUsers(show_users);
rvAccount.post(new Runnable() {
@Override
public void run() {
try {
adapter.notifyDataSetChanged();
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
private void onMenuShowFolders() { private void onMenuShowFolders() {
show_folders = !show_folders; show_folders = !show_folders;

@ -33,6 +33,12 @@
android:title="@string/title_compact" android:title="@string/title_compact"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_show_users"
android:checkable="true"
android:title="@string/title_user"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_show_folders" android:id="@+id/menu_show_folders"
android:checkable="true" android:checkable="true"

Loading…
Cancel
Save