From c44a6f5028ec0f22ff23602bfe7cfcaff708df2c Mon Sep 17 00:00:00 2001 From: RichyHBM Date: Thu, 16 Nov 2017 19:47:21 +0000 Subject: [PATCH] Apply patch changes --- .../andotp/Activities/MainActivity.java | 24 +++++++++++++------ .../flocke/andotp/Database/Entry.java | 1 + .../flocke/andotp/View/TagsAdapter.java | 8 +++++++ 3 files changed, 26 insertions(+), 7 deletions(-) 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 1eaab2a8..f2de988f 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 @@ -582,7 +582,7 @@ public class MainActivity extends BaseActivity getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); - DrawerLayout tagsDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); + final DrawerLayout tagsDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); tagsToggle = new ActionBarDrawerToggle(this, tagsDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override @@ -604,7 +604,7 @@ public class MainActivity extends BaseActivity tagsDrawerLayout.addDrawerListener(tagsToggle); final CheckedTextView noTagsButton = (CheckedTextView)findViewById(R.id.no_tags_entries); - CheckedTextView allTagsButton = (CheckedTextView)findViewById(R.id.all_tags_in_drawer); + final CheckedTextView allTagsButton = (CheckedTextView)findViewById(R.id.all_tags_in_drawer); allTagsButton.setOnClickListener(new View.OnClickListener() { @Override @@ -617,12 +617,12 @@ public class MainActivity extends BaseActivity for(int i = 0; i < tagsDrawerListView.getChildCount(); i++) { CheckedTextView childCheckBox = (CheckedTextView)tagsDrawerListView.getChildAt(i); childCheckBox.setChecked(checkedTextView.isChecked()); + tagsDrawerAdapter.setTagState(childCheckBox.getText().toString(), childCheckBox.isChecked()); + settings.setTagToggle(childCheckBox.getText().toString(), childCheckBox.isChecked()); } - noTagsButton.setChecked(checkedTextView.isChecked()); - settings.setNoTagsToggle(noTagsButton.isChecked()); if(checkedTextView.isChecked()) { - adapter.filterByTags(adapter.getTags()); + adapter.filterByTags(tagsDrawerAdapter.getActiveTags()); } else { adapter.filterByTags(new ArrayList()); } @@ -637,13 +637,12 @@ public class MainActivity extends BaseActivity checkedTextView.setChecked(!checkedTextView.isChecked()); settings.setNoTagsToggle(checkedTextView.isChecked()); - adapter.filterByTags(adapter.getTags()); + adapter.filterByTags(tagsDrawerAdapter.getActiveTags()); } }); noTagsButton.setChecked(settings.getNoTagsToggle()); tagsDrawerListView.setAdapter(tagsDrawerAdapter); - tagsDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -652,6 +651,17 @@ public class MainActivity extends BaseActivity settings.setTagToggle(checkedTextView.getText().toString(), checkedTextView.isChecked()); tagsDrawerAdapter.setTagState(checkedTextView.getText().toString(), checkedTextView.isChecked()); + + if (! checkedTextView.isChecked()) { + allTagsButton.setChecked(false); + settings.setAllTagsToggle(false); + } + + if (tagsDrawerAdapter.allTagsActive()) { + allTagsButton.setChecked(true); + settings.setAllTagsToggle(true); + } + adapter.filterByTags(tagsDrawerAdapter.getActiveTags()); } }); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Database/Entry.java b/app/src/main/java/org/shadowice/flocke/andotp/Database/Entry.java index 52c20566..b1cda863 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Database/Entry.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Database/Entry.java @@ -161,6 +161,7 @@ public class Entry { this.tags.add(tagsArray.getString(i)); } } catch (JSONException e) { + e.printStackTrace(); } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java index 76960d11..5529bf84 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java @@ -69,6 +69,14 @@ public class TagsAdapter extends ArrayAdapter { return tagsList; } + public boolean allTagsActive() { + for (String key : tagsState.keySet()) + if (! tagsState.get(key)) + return false; + + return true; + } + public HashMap getTagsWithState() { return new HashMap(tagsState); }