From 44676707f02129c6a3fcb3f13710f7807094824a Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 31 Jan 2023 18:36:37 +0100 Subject: [PATCH] Automatically switch to tabs when searching --- .../activities/SearchResultTabActivity.java | 9 +++++++++ .../timeline/FragmentMastodonAccount.java | 16 ++++++++++++++++ .../fragment/timeline/FragmentMastodonTag.java | 10 +++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java index 08bb89dc..decb29d7 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java @@ -70,6 +70,7 @@ public class SearchResultTabActivity extends BaseBarActivity { private String search; private ActivitySearchResultTabsBinding binding; private TabLayout.Tab initial; + public Boolean tagEmpty, accountEmpty; @Override protected void onCreate(Bundle savedInstanceState) { @@ -277,9 +278,17 @@ public class SearchResultTabActivity extends BaseBarActivity { public void moveToAccount() { + tagEmpty = null; + accountEmpty = null; binding.searchViewpager.setCurrentItem(1); } + public void moveToMessage() { + tagEmpty = null; + accountEmpty = null; + binding.searchViewpager.setCurrentItem(2); + } + /** * Pager adapter for the 4 fragments */ diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java index d0567bc7..3a38671c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java @@ -36,6 +36,7 @@ import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.activities.MainActivity; import app.fedilab.android.databinding.FragmentPaginationBinding; +import app.fedilab.android.mastodon.activities.SearchResultTabActivity; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Accounts; import app.fedilab.android.mastodon.client.entities.api.Pagination; @@ -223,10 +224,25 @@ public class FragmentMastodonAccount extends Fragment { router(true); }); if (accounts == null || accounts.accounts == null || accounts.accounts.size() == 0) { + if (requireActivity() instanceof SearchResultTabActivity) { + ((SearchResultTabActivity) requireActivity()).accountEmpty = true; + if (((SearchResultTabActivity) requireActivity()).tagEmpty != null) { + if (((SearchResultTabActivity) requireActivity()).tagEmpty) { + ((SearchResultTabActivity) requireActivity()).moveToMessage(); + } + } + } binding.noAction.setVisibility(View.VISIBLE); binding.noActionText.setText(R.string.no_accounts); return; } + if (requireActivity() instanceof SearchResultTabActivity) { + if (((SearchResultTabActivity) requireActivity()).tagEmpty != null) { + if (((SearchResultTabActivity) requireActivity()).tagEmpty) { + ((SearchResultTabActivity) requireActivity()).moveToAccount(); + } + } + } binding.recyclerView.setVisibility(View.VISIBLE); if (accountAdapter != null && this.accounts != null) { int size = this.accounts.size(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTag.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTag.java index 24dcc9ee..13254a16 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTag.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTag.java @@ -146,7 +146,15 @@ public class FragmentMastodonTag extends Fragment { }); if (tags == null || tags.size() == 0) { if (requireActivity() instanceof SearchResultTabActivity) { - ((SearchResultTabActivity) requireActivity()).moveToAccount(); + ((SearchResultTabActivity) requireActivity()).tagEmpty = true; + if (((SearchResultTabActivity) requireActivity()).accountEmpty != null) { + if (((SearchResultTabActivity) requireActivity()).accountEmpty) { + ((SearchResultTabActivity) requireActivity()).moveToMessage(); + } else { + ((SearchResultTabActivity) requireActivity()).moveToAccount(); + } + } + } binding.recyclerView.setVisibility(View.GONE); binding.noAction.setVisibility(View.VISIBLE);