Add two buttons to add subreddits and users in CustomizePostFilterActivity. Show search users and search subreddits when searching them.

This commit is contained in:
Alex Ning 2021-01-06 16:40:27 +08:00
parent b3da83e373
commit 99129a2b14
5 changed files with 143 additions and 47 deletions

View File

@ -9,11 +9,13 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
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;
@ -25,6 +27,7 @@ import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.inject.Inject; import javax.inject.Inject;
@ -39,6 +42,7 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
import ml.docilealligator.infinityforreddit.postfilter.SavePostFilter; import ml.docilealligator.infinityforreddit.postfilter.SavePostFilter;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class CustomizePostFilterActivity extends BaseActivity { public class CustomizePostFilterActivity extends BaseActivity {
@ -46,6 +50,8 @@ public class CustomizePostFilterActivity extends BaseActivity {
public static final String EXTRA_FROM_SETTINGS = "EFS"; public static final String EXTRA_FROM_SETTINGS = "EFS";
public static final String RETURN_EXTRA_POST_FILTER = "REPF"; public static final String RETURN_EXTRA_POST_FILTER = "REPF";
private static final String POST_FILTER_STATE = "PFS"; private static final String POST_FILTER_STATE = "PFS";
private static final int ADD_SUBREDDITS_REQUEST_CODE = 1;
private static final int ADD_USERS_REQUEST_CODE = 2;
@BindView(R.id.coordinator_layout_customize_post_filter_activity) @BindView(R.id.coordinator_layout_customize_post_filter_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@ -119,10 +125,14 @@ public class CustomizePostFilterActivity extends BaseActivity {
TextInputLayout excludesSubredditsTextInputLayout; TextInputLayout excludesSubredditsTextInputLayout;
@BindView(R.id.excludes_subreddits_text_input_edit_text_customize_post_filter_activity) @BindView(R.id.excludes_subreddits_text_input_edit_text_customize_post_filter_activity)
TextInputEditText excludesSubredditsTextInputEditText; TextInputEditText excludesSubredditsTextInputEditText;
@BindView(R.id.add_subreddits_image_view_customize_post_filter_activity)
ImageView addSubredditsImageView;
@BindView(R.id.excludes_users_text_input_layout_customize_post_filter_activity) @BindView(R.id.excludes_users_text_input_layout_customize_post_filter_activity)
TextInputLayout excludesUsersTextInputLayout; TextInputLayout excludesUsersTextInputLayout;
@BindView(R.id.excludes_users_text_input_edit_text_customize_post_filter_activity) @BindView(R.id.excludes_users_text_input_edit_text_customize_post_filter_activity)
TextInputEditText excludesUsersTextInputEditText; TextInputEditText excludesUsersTextInputEditText;
@BindView(R.id.add_users_image_view_customize_post_filter_activity)
ImageView addUsersImageView;
@BindView(R.id.excludes_flairs_text_input_layout_customize_post_filter_activity) @BindView(R.id.excludes_flairs_text_input_layout_customize_post_filter_activity)
TextInputLayout excludesFlairsTextInputLayout; TextInputLayout excludesFlairsTextInputLayout;
@BindView(R.id.excludes_flairs_text_input_edit_text_customize_post_filter_activity) @BindView(R.id.excludes_flairs_text_input_edit_text_customize_post_filter_activity)
@ -226,6 +236,17 @@ public class CustomizePostFilterActivity extends BaseActivity {
onlySpoilerSwitch.performClick(); onlySpoilerSwitch.performClick();
}); });
addSubredditsImageView.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditMultiselectionActivity.class);
startActivityForResult(intent, ADD_SUBREDDITS_REQUEST_CODE);
});
addUsersImageView.setOnClickListener(view -> {
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true);
startActivityForResult(intent, ADD_USERS_REQUEST_CODE);
});
if (savedInstanceState != null) { if (savedInstanceState != null) {
postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE); postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE);
} else { } else {
@ -276,6 +297,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
int primaryIconColor = mCustomThemeWrapper.getPrimaryIconColor();
nameTextInputLayout.setBoxStrokeColor(primaryTextColor); nameTextInputLayout.setBoxStrokeColor(primaryTextColor);
nameTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); nameTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
nameTextInputEditText.setTextColor(primaryTextColor); nameTextInputEditText.setTextColor(primaryTextColor);
@ -296,9 +318,11 @@ public class CustomizePostFilterActivity extends BaseActivity {
excludesSubredditsTextInputLayout.setBoxStrokeColor(primaryTextColor); excludesSubredditsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesSubredditsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); excludesSubredditsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesSubredditsTextInputEditText.setTextColor(primaryTextColor); excludesSubredditsTextInputEditText.setTextColor(primaryTextColor);
addSubredditsImageView.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
excludesUsersTextInputLayout.setBoxStrokeColor(primaryTextColor); excludesUsersTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesUsersTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); excludesUsersTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesUsersTextInputEditText.setTextColor(primaryTextColor); excludesUsersTextInputEditText.setTextColor(primaryTextColor);
addUsersImageView.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
excludesFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor); excludesFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); excludesFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesFlairsTextInputEditText.setTextColor(primaryTextColor); excludesFlairsTextInputEditText.setTextColor(primaryTextColor);
@ -366,6 +390,37 @@ public class CustomizePostFilterActivity extends BaseActivity {
return false; return false;
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && data != null) {
if (requestCode == ADD_SUBREDDITS_REQUEST_CODE) {
ArrayList<String> subreddits = data.getStringArrayListExtra(SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS);
String currentSubreddits = excludesSubredditsTextInputEditText.getText().toString().trim();
if (!currentSubreddits.isEmpty() && currentSubreddits.charAt(currentSubreddits.length() - 1) != ',') {
String newString = currentSubreddits + ",";
excludesSubredditsTextInputEditText.setText(newString);
}
if (subreddits != null) {
StringBuilder stringBuilder = new StringBuilder();
for (String s : subreddits) {
stringBuilder.append(s).append(",");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
excludesSubredditsTextInputEditText.append(stringBuilder.toString());
}
} else if (requestCode == ADD_USERS_REQUEST_CODE) {
String username = data.getStringExtra(SearchActivity.EXTRA_RETURN_USER_NAME);
String currentUsers = excludesSubredditsTextInputEditText.getText().toString().trim();
if (!currentUsers.isEmpty() && currentUsers.charAt(currentUsers.length() - 1) != ',') {
String newString = currentUsers + ",";
excludesSubredditsTextInputEditText.setText(newString);
}
excludesUsersTextInputEditText.append(username);
}
}
}
private void constructPostFilter() { private void constructPostFilter() {
postFilter.name = nameTextInputEditText.getText().toString(); postFilter.name = nameTextInputEditText.getText().toString();
postFilter.maxVote = maxVoteTextInputEditText.getText() == null || maxVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString()); postFilter.maxVote = maxVoteTextInputEditText.getText() == null || maxVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString());

View File

@ -133,6 +133,12 @@ public class SearchActivity extends BaseActivity {
searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false); searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false); searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false);
if (searchOnlySubreddits) {
simpleSearchView.setHint(getText(R.string.search_only_subreddits_hint));
} else if (searchOnlyUsers) {
simpleSearchView.setHint(getText(R.string.search_only_users_hint));
}
simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() { simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
@Override @Override
public void onSearchViewShown() { public void onSearchViewShown() {

View File

@ -201,23 +201,23 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
@Override @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case android.R.id.home: if (itemId == android.R.id.home) {
finish(); finish();
return true; return true;
case R.id.action_save_subreddit_multiselection_activity: } else if (itemId == R.id.action_save_subreddit_multiselection_activity) {
if (mAdapter != null) { if (mAdapter != null) {
Intent returnIntent = new Intent(); Intent returnIntent = new Intent();
returnIntent.putStringArrayListExtra(EXTRA_RETURN_SELECTED_SUBREDDITS, returnIntent.putStringArrayListExtra(EXTRA_RETURN_SELECTED_SUBREDDITS,
mAdapter.getAllSelectedSubreddits()); mAdapter.getAllSelectedSubreddits());
setResult(RESULT_OK, returnIntent); setResult(RESULT_OK, returnIntent);
} }
finish(); finish();
return true; return true;
case R.id.action_search_subreddit_multiselection_activity: } else if (itemId == R.id.action_search_subreddit_multiselection_activity) {
Intent intent = new Intent(this, SearchActivity.class); Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true); intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true);
startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE); startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
} }
return false; return false;

View File

@ -343,45 +343,78 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <LinearLayout
android:id="@+id/excludes_subreddits_text_input_layout_customize_post_filter_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputLayout
android:id="@+id/excludes_subreddits_text_input_edit_text_customize_post_filter_activity" android:id="@+id/excludes_subreddits_text_input_layout_customize_post_filter_activity"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="?attr/font_family" android:layout_weight="1"
android:textSize="?attr/font_default" android:paddingTop="8dp"
android:hint="@string/exclude_subreddits_hint" /> android:paddingBottom="8dp"
android:layout_marginStart="16dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
</com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputEditText
android:id="@+id/excludes_subreddits_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/exclude_subreddits_hint" />
<com.google.android.material.textfield.TextInputLayout </com.google.android.material.textfield.TextInputLayout>
android:id="@+id/excludes_users_text_input_layout_customize_post_filter_activity"
<ImageView
android:id="@+id/add_subreddits_image_view_customize_post_filter_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="16dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputLayout
android:id="@+id/excludes_users_text_input_edit_text_customize_post_filter_activity" android:id="@+id/excludes_users_text_input_layout_customize_post_filter_activity"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="?attr/font_family" android:layout_weight="1"
android:textSize="?attr/font_default" android:paddingTop="8dp"
android:hint="@string/exclude_users_hint" /> android:paddingBottom="8dp"
android:layout_marginStart="16dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
</com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputEditText
android:id="@+id/excludes_users_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/exclude_users_hint" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/add_users_image_view_customize_post_filter_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="16dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/excludes_flairs_text_input_layout_customize_post_filter_activity" android:id="@+id/excludes_flairs_text_input_layout_customize_post_filter_activity"

View File

@ -150,6 +150,8 @@
<string name="app_label">Infinity</string> <string name="app_label">Infinity</string>
<string name="search_hint">Search anything</string> <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="no_posts_no_lazy_mode">No posts available</string> <string name="no_posts_no_lazy_mode">No posts available</string>
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string> <string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>