Searching subreddits in SubredditFilterPopularAndAllActivity is available.

This commit is contained in:
Alex Ning 2020-11-09 12:17:32 +08:00
parent b39f90e275
commit 252412d8ce
3 changed files with 24 additions and 8 deletions

View File

@ -86,6 +86,9 @@ public class CreateMultiRedditActivity extends BaseActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_multi_reddit); setContentView(R.layout.activity_create_multi_reddit);

View File

@ -1,7 +1,7 @@
package ml.docilealligator.infinityforreddit.Activity; package ml.docilealligator.infinityforreddit.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
@ -9,6 +9,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
@ -36,6 +37,7 @@ import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilterViewM
public class SubredditFilterPopularAndAllActivity extends BaseActivity { 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) @BindView(R.id.coordinator_layout_subreddit_filter_popular_and_all_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_subreddit_filter_popular_and_all_activity) @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) .setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.search, new DialogInterface.OnClickListener() { .setNeutralButton(R.string.search, (dialogInterface, i) -> {
@Override if (imm != null) {
public void onClick(DialogInterface dialogInterface, int i) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
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 -> { .setOnDismissListener(dialogInterface -> {
if (imm != null) { if (imm != null) {
@ -138,6 +141,16 @@ public class SubredditFilterPopularAndAllActivity extends BaseActivity {
return false; 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 @Override
protected SharedPreferences getDefaultSharedPreferences() { protected SharedPreferences getDefaultSharedPreferences() {
return sharedPreferences; return sharedPreferences;

View File

@ -222,7 +222,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, 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(); Intent returnIntent = new Intent();
ArrayList<String> selectedSubreddits = mAdapter.getAllSelectedSubreddits(); ArrayList<String> selectedSubreddits = mAdapter.getAllSelectedSubreddits();
selectedSubreddits.add(data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME)); selectedSubreddits.add(data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME));