From 252412d8ce5cd87e94bceaf30b5108eec63aadb7 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 9 Nov 2020 12:17:32 +0800 Subject: Searching subreddits in SubredditFilterPopularAndAllActivity is available. --- .../Activity/CreateMultiRedditActivity.java | 3 +++ .../SubredditFilterPopularAndAllActivity.java | 27 ++++++++++++++++------ .../Activity/SubredditMultiselectionActivity.java | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java index 3c488a5c..3fff7dae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java @@ -86,6 +86,9 @@ public class CreateMultiRedditActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); + + setImmersiveModeNotApplicable(); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_multi_reddit); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java index 88618b5e..55a62e7f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditFilterPopularAndAllActivity.java @@ -1,7 +1,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Context; -import android.content.DialogInterface; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.view.MenuItem; @@ -9,6 +9,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.lifecycle.ViewModelProvider; @@ -36,6 +37,7 @@ import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilterViewM public class SubredditFilterPopularAndAllActivity extends BaseActivity { + private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 1; @BindView(R.id.coordinator_layout_subreddit_filter_popular_and_all_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_subreddit_filter_popular_and_all_activity) @@ -111,13 +113,14 @@ public class SubredditFilterPopularAndAllActivity extends BaseActivity { () -> {}); }) .setNegativeButton(R.string.cancel, null) - .setNeutralButton(R.string.search, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - if (imm != null) { - imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); - } + .setNeutralButton(R.string.search, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); } + + Intent intent = new Intent(this, SearchActivity.class); + intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true); + startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE); }) .setOnDismissListener(dialogInterface -> { if (imm != null) { @@ -138,6 +141,16 @@ public class SubredditFilterPopularAndAllActivity extends BaseActivity { return false; } + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE && resultCode == RESULT_OK && data != null) { + SubredditFilter subredditFilter = new SubredditFilter(data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME), SubredditFilter.TYPE_POPULAR_AND_ALL); + InsertSubredditFilter.insertSubredditFilter(redditDataRoomDatabase, subredditFilter, + () -> {}); + } + } + @Override protected SharedPreferences getDefaultSharedPreferences() { return sharedPreferences; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java index 1afa6e4b..bf7a739b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java @@ -222,7 +222,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE && resultCode == RESULT_OK && data != null) { + if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE && resultCode == RESULT_OK && data != null && mAdapter != null) { Intent returnIntent = new Intent(); ArrayList selectedSubreddits = mAdapter.getAllSelectedSubreddits(); selectedSubreddits.add(data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME)); -- cgit v1.2.3