From 5663d33ed3da5c43424774e9ec5700465c49eece Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:45:29 -0400 Subject: Select multireddit in SearchActivity. --- .../activities/SearchActivity.java | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index de0b643f..87c791fd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -120,7 +120,7 @@ public class SearchActivity extends BaseActivity { private Call subredditAutocompleteCall; RecentSearchQueryViewModel mRecentSearchQueryViewModel; private ActivityResultLauncher requestThingSelectionForCurrentActivityLauncher; - private ActivityResultLauncher requestThingSelectionForOtherActivityLauncher; + private ActivityResultLauncher requestThingSelectionForAnotherActivityLauncher; private ActivitySearchBinding binding; @Override @@ -315,21 +315,30 @@ public class SearchActivity extends BaseActivity { requestThingSelectionForCurrentActivityLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { Intent returnIntent = result.getData(); - if (returnIntent == null) { + if (returnIntent == null || returnIntent.getExtras() == null) { return; } searchInSubredditOrUserName = returnIntent.getStringExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME); searchInThingType = returnIntent.getIntExtra(SelectThingReturnKey.RETURN_EXTRA_THING_TYPE, SelectThingReturnKey.THING_TYPE.SUBREDDIT); + searchInMultiReddit = returnIntent.getExtras().getParcelable(SelectThingReturnKey.RETRUN_EXTRA_MULTIREDDIT); + + switch (searchInThingType) { + case SelectThingReturnKey.THING_TYPE.SUBREDDIT: + case SelectThingReturnKey.THING_TYPE.USER: + if (searchInSubredditOrUserName == null) { + binding.subredditNameTextViewSearchActivity.setText(R.string.all_subreddits); + } else { + binding.subredditNameTextViewSearchActivity.setText(searchInSubredditOrUserName); + } + break; + case SelectThingReturnKey.THING_TYPE.MULTIREDDIT: + binding.subredditNameTextViewSearchActivity.setText(searchInMultiReddit.getDisplayName()); - if (searchInSubredditOrUserName == null) { - binding.subredditNameTextViewSearchActivity.setText(R.string.all_subreddits); - } else { - binding.subredditNameTextViewSearchActivity.setText(searchInSubredditOrUserName); } }); - requestThingSelectionForOtherActivityLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { + requestThingSelectionForAnotherActivityLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { setResult(RESULT_OK, result.getData()); finish(); }); @@ -447,7 +456,7 @@ public class SearchActivity extends BaseActivity { Intent intent = new Intent(this, SearchResultActivity.class); intent.putExtra(SearchResultActivity.EXTRA_QUERY, query); intent.putExtra(SearchResultActivity.EXTRA_SHOULD_RETURN_SUBREDDIT_AND_USER_NAME, true); - requestThingSelectionForOtherActivityLauncher.launch(intent); + requestThingSelectionForAnotherActivityLauncher.launch(intent); } else { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra(SearchResultActivity.EXTRA_QUERY, query); -- cgit v1.2.3