Added compact mode for accounts

pull/194/merge
M66B 3 years ago
parent d38575caae
commit ae7599abfa

@ -76,6 +76,7 @@ import java.util.List;
public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHolder> {
private Fragment parentFragment;
private boolean settings;
private boolean compact;
private Context context;
private LifecycleOwner owner;
@ -240,6 +241,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvCreated.setVisibility(debug ? View.VISIBLE : View.GONE);
tvCreated.setText(context.getString(R.string.title_created_at,
account.created == null ? null : DTF.format(account.created)));
tvLast.setVisibility(compact ? View.GONE : View.VISIBLE);
tvLast.setText(context.getString(R.string.title_last_connected,
(account.last_connected == null ? "-" : DTF.format(account.last_connected)) +
(BuildConfig.DEBUG ?
@ -254,7 +256,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
Integer percent = (settings ? null : account.getQuotaPercentage());
tvUsage.setText(percent == null ? null : NF.format(percent) + "%");
tvUsage.setVisibility(percent == null ? View.GONE : View.VISIBLE);
tvUsage.setVisibility(percent == null || compact ? View.GONE : View.VISIBLE);
tvQuota.setText(context.getString(R.string.title_storage_quota,
(account.quota_usage == null ? "-" : Helper.humanReadableByteCount(account.quota_usage)),
(account.quota_limit == null ? "-" : Helper.humanReadableByteCount(account.quota_limit))));
@ -606,9 +608,10 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
}
}
AdapterAccount(final Fragment parentFragment, boolean settings) {
AdapterAccount(final Fragment parentFragment, boolean settings, boolean compact) {
this.parentFragment = parentFragment;
this.settings = settings;
this.compact = compact;
this.context = parentFragment.getContext();
this.owner = parentFragment.getViewLifecycleOwner();
@ -669,6 +672,11 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
diff.dispatchUpdatesTo(this);
}
void setCompact(boolean compact) {
if (this.compact != compact)
this.compact = compact;
}
private static class DiffCallback extends DiffUtil.Callback {
private List<TupleAccountEx> prev = new ArrayList<>();
private List<TupleAccountEx> next = new ArrayList<>();

@ -44,6 +44,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.Group;
import androidx.core.view.MenuCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer;
@ -67,6 +68,7 @@ public class FragmentAccounts extends FragmentBase {
private boolean settings;
private boolean cards;
private boolean compact;
private ViewGroup view;
private SwipeRefreshLayout swipeRefresh;
@ -91,6 +93,7 @@ public class FragmentAccounts extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
cards = prefs.getBoolean("cards", true);
compact = prefs.getBoolean("compact_accounts", false) && !settings;
}
@Override
@ -212,7 +215,7 @@ public class FragmentAccounts extends FragmentBase {
};
rvAccount.addItemDecoration(categoryDecorator);
adapter = new AdapterAccount(this, settings);
adapter = new AdapterAccount(this, settings, compact);
rvAccount.setAdapter(adapter);
fab.setOnClickListener(new View.OnClickListener() {
@ -348,6 +351,7 @@ public class FragmentAccounts extends FragmentBase {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_accounts, menu);
MenuCompat.setGroupDividerEnabled(menu, true);
super.onCreateOptionsMenu(menu, inflater);
}
@ -355,6 +359,8 @@ public class FragmentAccounts extends FragmentBase {
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_search).setVisible(!settings);
menu.findItem(R.id.menu_unified).setVisible(!settings);
menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_compact).setVisible(!settings);
menu.findItem(R.id.menu_theme).setVisible(!settings);
menu.findItem(R.id.menu_force_sync).setVisible(!settings);
@ -370,6 +376,9 @@ public class FragmentAccounts extends FragmentBase {
} else if (itemId == R.id.menu_unified) {
onMenuUnified();
return true;
} else if (itemId == R.id.menu_compact) {
onMenuCompact();
return true;
} else if (itemId == R.id.menu_theme) {
onMenuTheme();
return true;
@ -397,6 +406,26 @@ public class FragmentAccounts extends FragmentBase {
fragmentTransaction.commit();
}
private void onMenuCompact() {
compact = !compact;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("compact_accounts", compact).apply();
invalidateOptionsMenu();
adapter.setCompact(compact);
rvAccount.post(new Runnable() {
@Override
public void run() {
try {
adapter.notifyDataSetChanged();
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
private void onMenuTheme() {
new FragmentDialogTheme().show(getParentFragmentManager(), "messages:theme");
}

@ -14,13 +14,25 @@
android:title="@string/title_folders_unified"
app:showAsAction="always" />
<item
android:id="@+id/menu_theme"
android:title="@string/title_setup_theme"
app:showAsAction="never" />
<group android:id="@+id/group_appearance">
<item
android:id="@+id/menu_compact"
android:checkable="true"
android:title="@string/title_compact"
app:showAsAction="never" />
<item
android:id="@+id/menu_force_sync"
android:title="@string/title_force_sync"
app:showAsAction="never" />
<item
android:id="@+id/menu_theme"
android:title="@string/title_setup_theme"
app:showAsAction="never">
<menu />
</item>
</group>
<group android:id="@+id/group_operations">
<item
android:id="@+id/menu_force_sync"
android:title="@string/title_force_sync"
app:showAsAction="never" />
</group>
</menu>

Loading…
Cancel
Save