Only load the database after successful authentication

This commit is contained in:
Jakob Nixdorf 2017-12-27 15:08:29 +01:00
parent 6ce1a60cef
commit 08ad01b3db
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 31 additions and 13 deletions

View file

@ -150,6 +150,23 @@ public class MainActivity extends BaseActivity
settings.setSortMode(mode);
}
private HashMap<String, Boolean> createTagsMap(ArrayList<Entry> entries) {
HashMap<String, Boolean> 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,12 +185,13 @@ 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() {
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<String, Boolean> 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<String, Boolean>());
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();
}
}
}

View file

@ -83,8 +83,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
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<EntryViewHolder>
return displayedEntries.size();
}
public ArrayList<Entry> getEntries() {
return entries;
}
public void addEntry(Entry e) {
if (! entries.contains(e)) {
entries.add(e);