Add way to set view mode

This commit is contained in:
Michael Schättgen 2019-04-01 01:44:38 +02:00
parent f3ed79dc71
commit a293078603
3 changed files with 26 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import android.content.Intent;
import android.graphics.Rect;
import com.beemdevelopment.aegis.SortCategory;
import com.beemdevelopment.aegis.ViewMode;
import com.beemdevelopment.aegis.helpers.comparators.IssuerNameComparator;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import android.os.Bundle;
@ -168,8 +169,14 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
}
private void onPreferencesResult(int resultCode, Intent data) {
ViewMode viewMode = ViewMode.fromInteger(getPreferences().getCurrentViewMode());
_entryListView.setViewMode(viewMode);
// refresh the entire entry list if needed
if (data.getBooleanExtra("needsRecreate", false)) {
_entryListView.clearEntries();
_entryListView.addEntries(_db.getEntries());
recreate();
} else if (data.getBooleanExtra("needsRefresh", false)) {
boolean showAccountName = getPreferences().isAccountNameVisible();
@ -179,6 +186,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setTapToReveal(tapToReveal);
_entryListView.setTapToRevealTime(tapToRevealTime);
_entryListView.refresh(true);
}
}

View file

@ -6,6 +6,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.beemdevelopment.aegis.SortCategory;
import com.beemdevelopment.aegis.ViewMode;
import com.beemdevelopment.aegis.helpers.ItemTouchHelperAdapter;
import com.beemdevelopment.aegis.helpers.comparators.IssuerNameComparator;
import com.beemdevelopment.aegis.otp.HotpInfo;
@ -31,6 +32,8 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
private String _groupFilter;
private SortCategory _sortCategory;
private ViewMode _viewMode;
// keeps track of the viewholders that are currently bound
private List<EntryHolder> _holders;
@ -169,6 +172,10 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
_sortCategory = sortCategory;
}
public void setViewMode(ViewMode viewMode) {
_viewMode = viewMode;
}
@Override
public void onItemDismiss(int position) {
@ -203,6 +210,12 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
@Override
public EntryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_entry_compact, parent, false);
if (_viewMode == ViewMode.NORMAL) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_entry, parent, false);
} else if (_viewMode == ViewMode.COMPACT) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_entry_compact, parent, false);
}
return new EntryHolder(view);
}

View file

@ -15,6 +15,7 @@ import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import com.beemdevelopment.aegis.SortCategory;
import com.beemdevelopment.aegis.ViewMode;
import com.beemdevelopment.aegis.helpers.SimpleItemTouchHelperCallback;
import com.beemdevelopment.aegis.helpers.UiRefresher;
import com.beemdevelopment.aegis.otp.TotpInfo;
@ -101,6 +102,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
runLayoutAnimation(_rvKeyProfiles);
}
public void setViewMode(ViewMode viewMode) {
_adapter.setViewMode(viewMode);
}
public void refresh(boolean hard) {
if (_showProgress) {
_progressBar.refresh();