Automatically switch to tabs when searching

auto_cache_home
Thomas 2 years ago
parent d9e92b13b6
commit 44676707f0

@ -70,6 +70,7 @@ public class SearchResultTabActivity extends BaseBarActivity {
private String search; private String search;
private ActivitySearchResultTabsBinding binding; private ActivitySearchResultTabsBinding binding;
private TabLayout.Tab initial; private TabLayout.Tab initial;
public Boolean tagEmpty, accountEmpty;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -277,9 +278,17 @@ public class SearchResultTabActivity extends BaseBarActivity {
public void moveToAccount() { public void moveToAccount() {
tagEmpty = null;
accountEmpty = null;
binding.searchViewpager.setCurrentItem(1); binding.searchViewpager.setCurrentItem(1);
} }
public void moveToMessage() {
tagEmpty = null;
accountEmpty = null;
binding.searchViewpager.setCurrentItem(2);
}
/** /**
* Pager adapter for the 4 fragments * Pager adapter for the 4 fragments
*/ */

@ -36,6 +36,7 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.FragmentPaginationBinding; 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.Account;
import app.fedilab.android.mastodon.client.entities.api.Accounts; import app.fedilab.android.mastodon.client.entities.api.Accounts;
import app.fedilab.android.mastodon.client.entities.api.Pagination; import app.fedilab.android.mastodon.client.entities.api.Pagination;
@ -223,10 +224,25 @@ public class FragmentMastodonAccount extends Fragment {
router(true); router(true);
}); });
if (accounts == null || accounts.accounts == null || accounts.accounts.size() == 0) { 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.noAction.setVisibility(View.VISIBLE);
binding.noActionText.setText(R.string.no_accounts); binding.noActionText.setText(R.string.no_accounts);
return; return;
} }
if (requireActivity() instanceof SearchResultTabActivity) {
if (((SearchResultTabActivity) requireActivity()).tagEmpty != null) {
if (((SearchResultTabActivity) requireActivity()).tagEmpty) {
((SearchResultTabActivity) requireActivity()).moveToAccount();
}
}
}
binding.recyclerView.setVisibility(View.VISIBLE); binding.recyclerView.setVisibility(View.VISIBLE);
if (accountAdapter != null && this.accounts != null) { if (accountAdapter != null && this.accounts != null) {
int size = this.accounts.size(); int size = this.accounts.size();

@ -146,8 +146,16 @@ public class FragmentMastodonTag extends Fragment {
}); });
if (tags == null || tags.size() == 0) { if (tags == null || tags.size() == 0) {
if (requireActivity() instanceof SearchResultTabActivity) { if (requireActivity() instanceof SearchResultTabActivity) {
((SearchResultTabActivity) requireActivity()).tagEmpty = true;
if (((SearchResultTabActivity) requireActivity()).accountEmpty != null) {
if (((SearchResultTabActivity) requireActivity()).accountEmpty) {
((SearchResultTabActivity) requireActivity()).moveToMessage();
} else {
((SearchResultTabActivity) requireActivity()).moveToAccount(); ((SearchResultTabActivity) requireActivity()).moveToAccount();
} }
}
}
binding.recyclerView.setVisibility(View.GONE); binding.recyclerView.setVisibility(View.GONE);
binding.noAction.setVisibility(View.VISIBLE); binding.noAction.setVisibility(View.VISIBLE);
binding.noActionText.setText(R.string.no_tags); binding.noActionText.setText(R.string.no_tags);

Loading…
Cancel
Save