From 4c40d645ab99a28fc32b0273c74d087c994d6649 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:50:24 -0400 Subject: Pass data back to the original SearchActivity after selecting a subreddit or user in SearchResultActivity. --- .../infinityforreddit/activities/SearchActivity.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 ec18a167..d9c02988 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -116,7 +116,8 @@ public class SearchActivity extends BaseActivity { private Runnable autoCompleteRunnable; private Call subredditAutocompleteCall; RecentSearchQueryViewModel mRecentSearchQueryViewModel; - private ActivityResultLauncher requestThingSelectionLauncher; + private ActivityResultLauncher requestThingSelectionForCurrentActivityLauncher; + private ActivityResultLauncher requestThingSelectionForOtherActivityLauncher; private ActivitySearchBinding binding; @Override @@ -151,7 +152,7 @@ public class SearchActivity extends BaseActivity { binding.searchEditTextSearchActivity.setHint(R.string.search_only_subreddits_hint); } else if (searchOnlyUsers) { binding.searchEditTextSearchActivity.setHint(R.string.search_only_users_hint); - } else { + } else if (searchSubredditsAndUsers) { binding.searchEditTextSearchActivity.setHint(R.string.search_subreddits_and_users_hint); } @@ -309,7 +310,7 @@ public class SearchActivity extends BaseActivity { } bindView(); - requestThingSelectionLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { + requestThingSelectionForCurrentActivityLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { Intent returnIntent = result.getData(); if (returnIntent == null) { return; @@ -325,13 +326,18 @@ public class SearchActivity extends BaseActivity { } }); + requestThingSelectionForOtherActivityLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { + setResult(RESULT_OK, result.getData()); + finish(); + }); + if (searchOnlySubreddits || searchOnlyUsers || searchSubredditsAndUsers) { binding.subredditNameRelativeLayoutSearchActivity.setVisibility(View.GONE); } else { binding.subredditNameRelativeLayoutSearchActivity.setOnClickListener(view -> { Intent intent = new Intent(this, SubscribedThingListingActivity.class); intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true); - requestThingSelectionLauncher.launch(intent); + requestThingSelectionForCurrentActivityLauncher.launch(intent); }); } @@ -438,7 +444,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); - startActivity(intent); + requestThingSelectionForOtherActivityLauncher.launch(intent); } else { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra(SearchResultActivity.EXTRA_QUERY, query); -- cgit v1.2.3