diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index 6cffff8a..aec82e9e 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -150,6 +150,23 @@ public class MainActivity extends BaseActivity settings.setSortMode(mode); } + private HashMap createTagsMap(ArrayList entries) { + HashMap tagsHashMap = new HashMap<>(); + + for(Entry entry : entries) { + for(String tag : entry.getTags()) + tagsHashMap.put(tag, settings.getTagToggle(tag)); + } + + return tagsHashMap; + } + + private void populateAdapter() { + adapter.loadEntries(); + tagsDrawerAdapter.setTags(createTagsMap(adapter.getEntries())); + adapter.filterByTags(tagsDrawerAdapter.getActiveTags()); + } + // Initialize the main application @Override protected void onCreate(Bundle savedInstanceState) { @@ -168,13 +185,14 @@ public class MainActivity extends BaseActivity PreferenceManager.setDefaultValues(this, R.xml.preferences, false); settings.registerPreferenceChangeListener(this); - if (savedInstanceState == null) + if (settings.getAuthMethod() != Settings.AuthMethod.NONE && savedInstanceState == null) requireAuthentication = true; setBroadcastCallback(new BroadcastReceivedCallback() { @Override public void onReceivedScreenOff() { - requireAuthentication = true; + if (settings.getAuthMethod() != Settings.AuthMethod.NONE) + requireAuthentication = true; } }); @@ -203,16 +221,10 @@ public class MainActivity extends BaseActivity llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); - HashMap tagsHashMap = new HashMap<>(); - for(Entry entry : DatabaseHelper.loadDatabase(this)) { - for(String tag : entry.getTags()) - tagsHashMap.put(tag, settings.getTagToggle(tag)); - } - tagsDrawerAdapter = new TagsAdapter(this, tagsHashMap); - + tagsDrawerAdapter = new TagsAdapter(this, new HashMap()); adapter = new EntriesCardAdapter(this, tagsDrawerAdapter); - recList.setAdapter(adapter); + recList.setAdapter(adapter); recList.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { @@ -292,9 +304,11 @@ public class MainActivity extends BaseActivity public void onResume() { super.onResume(); - if (requireAuthentication) { + if (settings.getAuthMethod() != Settings.AuthMethod.NONE && requireAuthentication) { requireAuthentication = false; authenticate(); + } else { + populateAdapter(); } startUpdater(); @@ -360,6 +374,7 @@ public class MainActivity extends BaseActivity } } else { requireAuthentication = false; + populateAdapter(); } } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java index e7ccda64..3e4f48d9 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java @@ -83,8 +83,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter this.tagsFilterAdapter = tagsFilterAdapter; this.settings = new Settings(context); this.taskHandler = new Handler(); - - loadEntries(); + this.entries = new ArrayList<>(); } @Override @@ -92,6 +91,10 @@ public class EntriesCardAdapter extends RecyclerView.Adapter return displayedEntries.size(); } + public ArrayList getEntries() { + return entries; + } + public void addEntry(Entry e) { if (! entries.contains(e)) { entries.add(e);