From c1472403845b4f2250ffd19c3fd12639038e0061 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 26 Nov 2022 18:28:00 +0100 Subject: [PATCH] Fix issue #544 - Jump in profiles --- .../android/activities/HashTagActivity.java | 60 ++++++++++++++----- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/HashTagActivity.java b/app/src/main/java/app/fedilab/android/activities/HashTagActivity.java index 14008d15..e5d8a1fe 100644 --- a/app/src/main/java/app/fedilab/android/activities/HashTagActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/HashTagActivity.java @@ -80,7 +80,7 @@ public class HashTagActivity extends BaseActivity { finish(); pinnedTag = false; followedTag = false; - mutedTag = true; + mutedTag = false; setSupportActionBar(binding.toolbar); ActionBar actionBar = getSupportActionBar(); //Remove title @@ -221,26 +221,56 @@ public class HashTagActivity extends BaseActivity { } }); } else if (item.getItemId() == R.id.action_mute) { - Filter.FilterParams filterParams = new Filter.FilterParams(); - filterParams.id = fedilabFilter.id; - filterParams.keywords = new ArrayList<>(); - Filter.KeywordsParams keywordsParams = new Filter.KeywordsParams(); - keywordsParams.whole_word = true; - keywordsParams.keyword = tag.startsWith("#") ? tag : "#" + tag; - filterParams.keywords.add(keywordsParams); - filterParams.context = fedilabFilter.context; - FiltersVM filtersVM = new ViewModelProvider(HashTagActivity.this).get(FiltersVM.class); - filtersVM.editFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filterParams) - .observe(HashTagActivity.this, filter -> { - mutedTag = true; - invalidateOptionsMenu(); - }); + + if (MainActivity.mainFilters == null || fedilabFilter == null) { + MainActivity.mainFilters = new ArrayList<>(); + Filter.FilterParams filterParams = new Filter.FilterParams(); + filterParams.title = Helper.FEDILAB_MUTED_HASHTAGS; + filterParams.filter_action = "hide"; + filterParams.context = new ArrayList<>(); + filterParams.context.add("home"); + filterParams.context.add("public"); + filterParams.context.add("thread"); + filterParams.context.add("account"); + String finalTag = tag; + FiltersVM filtersVM = new ViewModelProvider(HashTagActivity.this).get(FiltersVM.class); + filtersVM.addFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filterParams) + .observe(HashTagActivity.this, filter -> { + if (filter != null) { + MainActivity.mainFilters.add(filter); + mutedTag = false; + fedilabFilter = filter; + muteTags(); + invalidateOptionsMenu(); + } + }); + } else { + muteTags(); + } + } return super.onOptionsItemSelected(item); } + private void muteTags() { + Filter.FilterParams filterParams = new Filter.FilterParams(); + filterParams.id = fedilabFilter.id; + filterParams.keywords = new ArrayList<>(); + Filter.KeywordsParams keywordsParams = new Filter.KeywordsParams(); + keywordsParams.whole_word = true; + keywordsParams.keyword = tag.startsWith("#") ? tag : "#" + tag; + filterParams.keywords.add(keywordsParams); + filterParams.context = fedilabFilter.context; + FiltersVM filtersVM = new ViewModelProvider(HashTagActivity.this).get(FiltersVM.class); + filtersVM.editFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filterParams) + .observe(HashTagActivity.this, filter -> { + mutedTag = true; + invalidateOptionsMenu(); + }); + } + @Override public boolean onCreateOptionsMenu(@NonNull Menu menu) { getMenuInflater().inflate(R.menu.menu_hashtag, menu);