aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java52
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java105
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java42
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java19
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java9
-rw-r--r--app/src/main/res/values/strings.xml1
13 files changed, 205 insertions, 102 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java
new file mode 100644
index 00000000..a663f36f
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java
@@ -0,0 +1,7 @@
+package ml.docilealligator.infinityforreddit;
+
+public class SelectThingReturnKey {
+ public static final String RETURN_EXTRA_SUBREDDIT_OR_USER_NAME = "RESOUN";
+ public static final String RETURN_EXTRA_SUBREDDIT_OR_USER_ICON = "RESOUI";
+ public static final String RETURN_EXTRA_IS_USER = "REIU";
+}
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 4505a355..ec18a167 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
@@ -16,6 +16,8 @@ import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.inputmethod.EditorInfoCompat;
@@ -39,6 +41,7 @@ import javax.inject.Named;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SelectThingReturnKey;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.adapters.SearchActivityRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter;
@@ -66,6 +69,7 @@ public class SearchActivity extends BaseActivity {
public static final String EXTRA_SEARCH_IN_SUBREDDIT_IS_USER = "ESISIU";
public static final String EXTRA_SEARCH_ONLY_SUBREDDITS = "ESOS";
public static final String EXTRA_SEARCH_ONLY_USERS = "ESOU";
+ public static final String EXTRA_SEARCH_SUBREDDITS_AND_USERS = "ESSAU";
public static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
public static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIU";
public static final String RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES = "RESSN";
@@ -105,12 +109,14 @@ public class SearchActivity extends BaseActivity {
private boolean searchInIsUser;
private boolean searchOnlySubreddits;
private boolean searchOnlyUsers;
+ private boolean searchSubredditsAndUsers;
private SearchActivityRecyclerViewAdapter adapter;
private SubredditAutocompleteRecyclerViewAdapter subredditAutocompleteRecyclerViewAdapter;
private Handler handler;
private Runnable autoCompleteRunnable;
private Call<String> subredditAutocompleteCall;
RecentSearchQueryViewModel mRecentSearchQueryViewModel;
+ private ActivityResultLauncher<Intent> requestThingSelectionLauncher;
private ActivitySearchBinding binding;
@Override
@@ -139,18 +145,21 @@ public class SearchActivity extends BaseActivity {
searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false);
+ searchSubredditsAndUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_SUBREDDITS_AND_USERS, false);
if (searchOnlySubreddits) {
- binding.searchEditTextSearchActivity.setHint(getText(R.string.search_only_subreddits_hint));
+ binding.searchEditTextSearchActivity.setHint(R.string.search_only_subreddits_hint);
} else if (searchOnlyUsers) {
- binding.searchEditTextSearchActivity.setHint(getText(R.string.search_only_users_hint));
+ binding.searchEditTextSearchActivity.setHint(R.string.search_only_users_hint);
+ } else {
+ binding.searchEditTextSearchActivity.setHint(R.string.search_subreddits_and_users_hint);
}
boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
subredditAutocompleteRecyclerViewAdapter = new SubredditAutocompleteRecyclerViewAdapter(this,
mCustomThemeWrapper, subredditData -> {
- if (searchOnlySubreddits) {
+ if (searchOnlySubreddits || searchSubredditsAndUsers) {
Intent returnIntent = new Intent();
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
ArrayList<String> subredditNameList = new ArrayList<>();
@@ -300,13 +309,29 @@ public class SearchActivity extends BaseActivity {
}
bindView();
- if (searchOnlySubreddits || searchOnlyUsers) {
+ requestThingSelectionLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
+ Intent returnIntent = result.getData();
+ if (returnIntent == null) {
+ return;
+ }
+
+ searchInSubredditOrUserName = returnIntent.getStringExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME);
+ searchInIsUser = returnIntent.getBooleanExtra(SelectThingReturnKey.RETURN_EXTRA_IS_USER, false);
+
+ if (searchInSubredditOrUserName == null) {
+ binding.subredditNameTextViewSearchActivity.setText(R.string.all_subreddits);
+ } else {
+ binding.subredditNameTextViewSearchActivity.setText(searchInSubredditOrUserName);
+ }
+ });
+
+ if (searchOnlySubreddits || searchOnlyUsers || searchSubredditsAndUsers) {
binding.subredditNameRelativeLayoutSearchActivity.setVisibility(View.GONE);
} else {
binding.subredditNameRelativeLayoutSearchActivity.setOnClickListener(view -> {
- Intent intent = new Intent(this, SubredditSelectionActivity.class);
- intent.putExtra(SubredditSelectionActivity.EXTRA_EXTRA_CLEAR_SELECTION, true);
- startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
+ Intent intent = new Intent(this, SubscribedThingListingActivity.class);
+ intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
+ requestThingSelectionLauncher.launch(intent);
});
}
@@ -409,6 +434,11 @@ public class SearchActivity extends BaseActivity {
intent.putExtra(SearchUsersResultActivity.EXTRA_QUERY, query);
intent.putExtra(SearchUsersResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
startActivityForResult(intent, USER_SEARCH_REQUEST_CODE);
+ } else if (searchSubredditsAndUsers) {
+ 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);
} else {
Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
intent.putExtra(SearchResultActivity.EXTRA_QUERY, query);
@@ -491,8 +521,8 @@ public class SearchActivity extends BaseActivity {
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, data.getStringArrayListExtra(SearchSubredditsResultActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES));
} else {
- String name = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME);
- String iconUrl = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
+ String name = data.getStringExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME);
+ String iconUrl = data.getStringExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_ICON);
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
}
@@ -503,8 +533,8 @@ public class SearchActivity extends BaseActivity {
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_USERNAMES, data.getStringArrayListExtra(SearchUsersResultActivity.RETURN_EXTRA_SELECTED_USERNAMES));
} else {
- String username = data.getStringExtra(SearchUsersResultActivity.EXTRA_RETURN_USER_NAME);
- String iconUrl = data.getStringExtra(SearchUsersResultActivity.EXTRA_RETURN_USER_ICON_URL);
+ String username = data.getStringExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME);
+ String iconUrl = data.getStringExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_ICON);
returnIntent.putExtra(EXTRA_RETURN_USER_NAME, username);
returnIntent.putExtra(EXTRA_RETURN_USER_ICON_URL, iconUrl);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
index 6e2d9024..62e33ac3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
@@ -81,9 +81,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, RandomBottomSheetFragment.RandomOptionSelectionCallback,
PostTypeBottomSheetFragment.PostTypeSelectionCallback, RecyclerViewContentScrollingInterface {
- static final String EXTRA_QUERY = "EQ";
- static final String EXTRA_TRENDING_SOURCE = "ETS";
- static final String EXTRA_SEARCH_IN_SUBREDDIT_OR_USER_NAME = "ESISOUN";
+ public static final String EXTRA_QUERY = "EQ";
+ public static final String EXTRA_TRENDING_SOURCE = "ETS";
+ public static final String EXTRA_SEARCH_IN_SUBREDDIT_OR_USER_NAME = "ESISOUN";
+ public static final String EXTRA_SHOULD_RETURN_SUBREDDIT_AND_USER_NAME = "ESRSAUN";
public static final String EXTRA_SEARCH_IN_SUBREDDIT_IS_USER = "ESISIU";
private static final String INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
@@ -121,6 +122,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
private String mSearchInSubredditOrUserName;
private boolean mSearchInIsUser;
private boolean mInsertSearchQuerySuccess;
+ private boolean mReturnSubredditAndUserName;
private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter;
private int fabOption;
@@ -178,6 +180,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
mSearchInSubredditOrUserName = intent.getStringExtra(EXTRA_SEARCH_IN_SUBREDDIT_OR_USER_NAME);
mSearchInIsUser = intent.getBooleanExtra(EXTRA_SEARCH_IN_SUBREDDIT_IS_USER, false);
+ mReturnSubredditAndUserName = intent.getBooleanExtra(EXTRA_SHOULD_RETURN_SUBREDDIT_AND_USER_NAME, false);
if (query != null) {
mQuery = query;
@@ -241,16 +244,24 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
});
new TabLayoutMediator(binding.tabLayoutSearchResultActivity, binding.viewPagerSearchResultActivity, (tab, position) -> {
- switch (position) {
- case 0:
- Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.posts));
- break;
- case 1:
+ if (mReturnSubredditAndUserName) {
+ if (position == 0) {
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.subreddits));
- break;
- case 2:
+ } else {
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.users));
- break;
+ }
+ } else {
+ switch (position) {
+ case 0:
+ Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.posts));
+ break;
+ case 1:
+ Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.subreddits));
+ break;
+ case 2:
+ Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.users));
+ break;
+ }
}
}).attach();
fixViewPager2Sensitivity(binding.viewPagerSearchResultActivity);
@@ -767,36 +778,55 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
@NonNull
@Override
public Fragment createFragment(int position) {
- switch (position) {
- case 0: {
- PostFragment mFragment = new PostFragment();
- Bundle bundle = new Bundle();
- bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
- bundle.putString(PostFragment.EXTRA_NAME, mSearchInIsUser ? "u_" + mSearchInSubredditOrUserName : mSearchInSubredditOrUserName);
- bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
- bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
- mFragment.setArguments(bundle);
- return mFragment;
- }
- case 1: {
- SubredditListingFragment mFragment = new SubredditListingFragment();
- Bundle bundle = new Bundle();
- bundle.putString(SubredditListingFragment.EXTRA_QUERY, mQuery);
- bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, false);
- mFragment.setArguments(bundle);
- return mFragment;
+ if (mReturnSubredditAndUserName) {
+ if (position == 0) {
+ return createSubredditListingFragment(true);
}
- default: {
- UserListingFragment mFragment = new UserListingFragment();
- Bundle bundle = new Bundle();
- bundle.putString(UserListingFragment.EXTRA_QUERY, mQuery);
- bundle.putBoolean(UserListingFragment.EXTRA_IS_GETTING_USER_INFO, false);
- mFragment.setArguments(bundle);
- return mFragment;
+ return createUserListingFragment(true);
+ } else {
+ switch (position) {
+ case 0: {
+ return createPostFragment();
+ }
+ case 1: {
+ return createSubredditListingFragment(false);
+ }
+ default: {
+ return createUserListingFragment(false);
+ }
}
}
}
+ private Fragment createPostFragment() {
+ PostFragment mFragment = new PostFragment();
+ Bundle bundle = new Bundle();
+ bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
+ bundle.putString(PostFragment.EXTRA_NAME, mSearchInIsUser ? "u_" + mSearchInSubredditOrUserName : mSearchInSubredditOrUserName);
+ bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
+ bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
+ mFragment.setArguments(bundle);
+ return mFragment;
+ }
+
+ private Fragment createSubredditListingFragment(boolean returnSubredditName) {
+ SubredditListingFragment mFragment = new SubredditListingFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(SubredditListingFragment.EXTRA_QUERY, mQuery);
+ bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, returnSubredditName);
+ mFragment.setArguments(bundle);
+ return mFragment;
+ }
+
+ private Fragment createUserListingFragment(boolean returnUsername) {
+ UserListingFragment mFragment = new UserListingFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(UserListingFragment.EXTRA_QUERY, mQuery);
+ bundle.putBoolean(UserListingFragment.EXTRA_IS_GETTING_USER_INFO, returnUsername);
+ mFragment.setArguments(bundle);
+ return mFragment;
+ }
+
@Nullable
private Fragment getCurrentFragment() {
if (fragmentManager == null) {
@@ -896,6 +926,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
@Override
public int getItemCount() {
+ if (mReturnSubredditAndUserName) {
+ return 2;
+ }
return 3;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java
index 0e75c367..c96de881 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java
@@ -34,8 +34,6 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class SearchSubredditsResultActivity extends BaseActivity implements ActivityToolbarInterface {
static final String EXTRA_QUERY = "EQ";
- static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
- static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIU";
static final String EXTRA_IS_MULTI_SELECTION = "EIMS";
static final String RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES = "RESS";
@@ -128,14 +126,6 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutSearchSubredditsResultActivity, null, binding.toolbarSearchSubredditsResultActivity);
}
- public void getSelectedSubreddit(String name, String iconUrl) {
- Intent returnIntent = new Intent();
- returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
- returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
- setResult(Activity.RESULT_OK, returnIntent);
- finish();
- }
-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java
index 78c9b003..a24acc0f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java
@@ -35,8 +35,6 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT
static final String EXTRA_QUERY = "EQ";
static final String EXTRA_IS_MULTI_SELECTION = "EIMS";
- static final String EXTRA_RETURN_USER_NAME = "ERUN";
- static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
static final String RETURN_EXTRA_SELECTED_USERNAMES = "RESU";
private static final String FRAGMENT_OUT_STATE = "FOS";
@@ -129,14 +127,6 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT
null, binding.toolbarSearchUsersResultActivity);
}
- public void getSelectedUser(String name, String iconUrl) {
- Intent returnIntent = new Intent();
- returnIntent.putExtra(EXTRA_RETURN_USER_NAME, name);
- returnIntent.putExtra(EXTRA_RETURN_USER_ICON_URL, iconUrl);
- setResult(Activity.RESULT_OK, returnIntent);
- finish();
- }
-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
index af3c5cde..d1a540f9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
@@ -245,15 +245,6 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
return false;
}
- public void getSelectedSubreddit(String name, String iconUrl, boolean subredditIsUser) {
- Intent returnIntent = new Intent();
- returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
- returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
- returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_IS_USER, subredditIsUser);
- setResult(Activity.RESULT_OK, returnIntent);
- finish();
- }
-
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
index 4b8d1a93..750f049f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
@@ -17,6 +17,8 @@ import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.inputmethod.EditorInfoCompat;
@@ -68,6 +70,7 @@ import retrofit2.Retrofit;
public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface {
public static final String EXTRA_SHOW_MULTIREDDITS = "ESM";
+ public static final String EXTRA_THING_SELECTION_MODE = "ETSM";
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
private static final String INSERT_MULTIREDDIT_STATE = "IMS";
@@ -86,11 +89,13 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
- private boolean mInsertSuccess = false;
- private boolean mInsertMultiredditSuccess = false;
- private boolean showMultiReddits = false;
+ private boolean mInsertSuccess;
+ private boolean mInsertMultiredditSuccess;
+ private boolean showMultiReddits;
+ private boolean isThingSelectionMode;
private SectionsPagerAdapter sectionsPagerAdapter;
private Menu mMenu;
+ private ActivityResultLauncher<Intent> requestSearchThingLauncher;
private ActivitySubscribedThingListingBinding binding;
@Override
@@ -145,6 +150,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false);
}
+ isThingSelectionMode = getIntent().getBooleanExtra(EXTRA_THING_SELECTION_MODE, false);
+
if (accountName.equals(Account.ANONYMOUS_ACCOUNT) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.searchEditTextSubscribedThingListingActivity.setImeOptions(binding.searchEditTextSubscribedThingListingActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
}
@@ -165,6 +172,12 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
sectionsPagerAdapter.changeSearchQuery(editable.toString());
}
});
+
+ requestSearchThingLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
+ setResult(RESULT_OK, result.getData());
+ finish();
+ });
+
initializeViewPagerAndLoadSubscriptions();
}
@@ -241,6 +254,13 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_search_subscribed_thing_listing_activity) {
+ if (isThingSelectionMode) {
+ Intent intent = new Intent(this, SearchActivity.class);
+ intent.putExtra(SearchActivity.EXTRA_SEARCH_SUBREDDITS_AND_USERS, true);
+ requestSearchThingLauncher.launch(intent);
+ return true;
+ }
+
item.setVisible(false);
binding.searchEditTextSubscribedThingListingActivity.setVisibility(View.VISIBLE);
binding.searchEditTextSubscribedThingListingActivity.requestFocus();
@@ -454,27 +474,29 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment();
Bundle bundle = new Bundle();
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, false);
+ bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, isThingSelectionMode);
+ bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_EXTRA_CLEAR_SELECTION, isThingSelectionMode);
fragment.setArguments(bundle);
return fragment;
}
case 1: {
FollowedUsersListingFragment fragment = new FollowedUsersListingFragment();
Bundle bundle = new Bundle();
- fragment.setArguments(bundle);
- return fragment;
- }
- default: {
- MultiRedditListingFragment fragment = new MultiRedditListingFragment();
- Bundle bundle = new Bundle();
+ bundle.putBoolean(FollowedUsersListingFragment.EXTRA_IS_USER_SELECTION, isThingSelectionMode);
fragment.setArguments(bundle);
return fragment;
}
}
+
+ MultiRedditListingFragment fragment = new MultiRedditListingFragment();
+ Bundle bundle = new Bundle();
+ fragment.setArguments(bundle);
+ return fragment;
}
@Override
public int getCount() {
- return 3;
+ return isThingSelectionMode && Account.ANONYMOUS_ACCOUNT.equals(accountName) ? 2 : 3;
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
index 008944e2..61e237d1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
@@ -1,6 +1,5 @@
package ml.docilealligator.infinityforreddit.adapters;
-import android.content.Intent;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
@@ -24,7 +23,6 @@ import ml.docilealligator.infinityforreddit.FavoriteThing;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
-import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.databinding.ItemFavoriteThingDividerBinding;
import ml.docilealligator.infinityforreddit.databinding.ItemSubscribedThingBinding;
@@ -48,11 +46,13 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
private final RequestManager glide;
private final int mPrimaryTextColor;
private final int mSecondaryTextColor;
+ private final ItemOnClickListener itemOnClickListener;
public FollowedUsersRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper,
- @Nullable String accessToken, @NonNull String accountName) {
+ @Nullable String accessToken, @NonNull String accountName,
+ ItemOnClickListener itemOnClickListener) {
mActivity = activity;
mExecutor = executor;
mOauthRetrofit = oauthRetrofit;
@@ -62,6 +62,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
glide = Glide.with(activity);
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
+ this.itemOnClickListener = itemOnClickListener;
}
@Override
@@ -205,9 +206,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
itemView.setOnClickListener(view -> {
int position = getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
- Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
- intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mFavoriteSubscribedUserData.get(position).getName());
- mActivity.startActivity(intent);
+ itemOnClickListener.onClick(mFavoriteSubscribedUserData.get(position));
}
});
@@ -288,9 +287,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
mFavoriteSubscribedUserData.size() + 2 : 0;
int position = getBindingAdapterPosition() - offset;
if(position >= 0 && mSubscribedUserData.size() > position) {
- Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
- intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mSubscribedUserData.get(position).getName());
- mActivity.startActivity(intent);
+ itemOnClickListener.onClick(mSubscribedUserData.get(position));
}
});
@@ -385,4 +382,8 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
binding.dividerTextViewItemFavoriteThingDivider.setTextColor(mSecondaryTextColor);
}
}
+
+ public interface ItemOnClickListener {
+ void onClick(SubscribedUserData subscribedUserData);
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
index c1486d2c..3f51bcaf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
@@ -1,7 +1,9 @@
package ml.docilealligator.infinityforreddit.fragments;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
@@ -27,9 +29,11 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SelectThingReturnKey;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
+import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.adapters.FollowedUsersRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
@@ -44,6 +48,8 @@ import retrofit2.Retrofit;
*/
public class FollowedUsersListingFragment extends Fragment implements FragmentCommunicator {
+ public static final String EXTRA_IS_USER_SELECTION = "EIUS";
+
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@@ -95,7 +101,20 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
binding.recyclerViewFollowedUsersListingFragment.setLayoutManager(mLinearLayoutManager);
FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity,
- mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, mActivity.accessToken, mActivity.accountName);
+ mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, mActivity.accessToken,
+ mActivity.accountName, subscribedUserData -> {
+ if (getArguments().getBoolean(EXTRA_IS_USER_SELECTION)) {
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME, subscribedUserData.getName());
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_IS_USER, true);
+ mActivity.setResult(Activity.RESULT_OK, returnIntent);
+ mActivity.finish();
+ } else {
+ Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, subscribedUserData.getName());
+ mActivity.startActivity(intent);
+ }
+ });
binding.recyclerViewFollowedUsersListingFragment.setAdapter(adapter);
new FastScrollerBuilder(binding.recyclerViewFollowedUsersListingFragment).useMd2Style().build();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
index ca7255f5..f168cd3d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit.fragments;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -32,10 +33,10 @@ import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SelectThingReturnKey;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
-import ml.docilealligator.infinityforreddit.activities.SearchSubredditsResultActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.adapters.SubredditListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
@@ -133,7 +134,11 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
@Override
public void subredditSelected(String subredditName, String iconUrl) {
if (isGettingSubredditInfo) {
- ((SearchSubredditsResultActivity) mActivity).getSelectedSubreddit(subredditName, iconUrl);
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME, subredditName);
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_ICON, iconUrl);
+ mActivity.setResult(Activity.RESULT_OK, returnIntent);
+ mActivity.finish();
} else {
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
index 33f15adc..7eb624f7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
@@ -1,7 +1,9 @@
package ml.docilealligator.infinityforreddit.fragments;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
@@ -27,9 +29,9 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SelectThingReturnKey;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
-import ml.docilealligator.infinityforreddit.activities.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.adapters.SubscribedSubredditsRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
@@ -104,7 +106,14 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) {
adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase,
mCustomThemeWrapper, mActivity.accessToken, mActivity.accountName, getArguments().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION),
- (name, iconUrl, subredditIsUser) -> ((SubredditSelectionActivity) mActivity).getSelectedSubreddit(name, iconUrl, subredditIsUser));
+ (name, iconUrl, subredditIsUser) -> {
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME, name);
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_ICON, iconUrl);
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_IS_USER, subredditIsUser);
+ mActivity.setResult(Activity.RESULT_OK, returnIntent);
+ mActivity.finish();
+ });
} else {
adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase,
mCustomThemeWrapper, mActivity.accessToken, mActivity.accountName);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java
index ba556f84..7fb40b34 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit.fragments;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -31,10 +32,10 @@ import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.SelectThingReturnKey;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
-import ml.docilealligator.infinityforreddit.activities.SearchUsersResultActivity;
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.adapters.UserListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
@@ -132,7 +133,11 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
@Override
public void userSelected(String username, String iconUrl) {
if (isGettingUserInfo) {
- ((SearchUsersResultActivity) mActivity).getSelectedUser(username, iconUrl);
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_NAME, username);
+ returnIntent.putExtra(SelectThingReturnKey.RETURN_EXTRA_SUBREDDIT_OR_USER_ICON, iconUrl);
+ mActivity.setResult(Activity.RESULT_OK, returnIntent);
+ mActivity.finish();
} else {
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, username);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1b50d61e..ad3098b7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -172,6 +172,7 @@
<string name="search_hint">Search anything</string>
<string name="search_only_subreddits_hint">Search subreddits</string>
<string name="search_only_users_hint">Search users</string>
+ <string name="search_subreddits_and_users_hint">Search subreddits and users</string>
<string name="no_posts_no_lazy_mode">No posts available</string>
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>