aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java55
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java34
-rw-r--r--app/src/main/res/layout/activity_customize_post_filter.xml93
-rw-r--r--app/src/main/res/values/strings.xml2
5 files changed, 143 insertions, 47 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
index 04d19eda..b5bbb03a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
@@ -9,11 +9,13 @@ import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
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.r0adkll.slidr.Slidr;
+import java.util.ArrayList;
import java.util.concurrent.Executor;
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.SavePostFilter;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.utils.Utils;
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 RETURN_EXTRA_POST_FILTER = "REPF";
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)
CoordinatorLayout coordinatorLayout;
@@ -119,10 +125,14 @@ public class CustomizePostFilterActivity extends BaseActivity {
TextInputLayout excludesSubredditsTextInputLayout;
@BindView(R.id.excludes_subreddits_text_input_edit_text_customize_post_filter_activity)
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)
TextInputLayout excludesUsersTextInputLayout;
@BindView(R.id.excludes_users_text_input_edit_text_customize_post_filter_activity)
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)
TextInputLayout excludesFlairsTextInputLayout;
@BindView(R.id.excludes_flairs_text_input_edit_text_customize_post_filter_activity)
@@ -226,6 +236,17 @@ public class CustomizePostFilterActivity extends BaseActivity {
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) {
postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE);
} else {
@@ -276,6 +297,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ int primaryIconColor = mCustomThemeWrapper.getPrimaryIconColor();
nameTextInputLayout.setBoxStrokeColor(primaryTextColor);
nameTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
nameTextInputEditText.setTextColor(primaryTextColor);
@@ -296,9 +318,11 @@ public class CustomizePostFilterActivity extends BaseActivity {
excludesSubredditsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesSubredditsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesSubredditsTextInputEditText.setTextColor(primaryTextColor);
+ addSubredditsImageView.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
excludesUsersTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesUsersTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesUsersTextInputEditText.setTextColor(primaryTextColor);
+ addUsersImageView.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
excludesFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesFlairsTextInputEditText.setTextColor(primaryTextColor);
@@ -366,6 +390,37 @@ public class CustomizePostFilterActivity extends BaseActivity {
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() {
postFilter.name = nameTextInputEditText.getText().toString();
postFilter.maxVote = maxVoteTextInputEditText.getText() == null || maxVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString());
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 141d0ffd..72d92738 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
@@ -133,6 +133,12 @@ public class SearchActivity extends BaseActivity {
searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, 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() {
@Override
public void onSearchViewShown() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java
index 98854d1a..74888f2e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java
@@ -201,23 +201,23 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.action_save_subreddit_multiselection_activity:
- if (mAdapter != null) {
- Intent returnIntent = new Intent();
- returnIntent.putStringArrayListExtra(EXTRA_RETURN_SELECTED_SUBREDDITS,
- mAdapter.getAllSelectedSubreddits());
- setResult(RESULT_OK, returnIntent);
- }
- finish();
- return true;
- case R.id.action_search_subreddit_multiselection_activity:
- Intent intent = new Intent(this, SearchActivity.class);
- intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true);
- startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
+ int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ finish();
+ return true;
+ } else if (itemId == R.id.action_save_subreddit_multiselection_activity) {
+ if (mAdapter != null) {
+ Intent returnIntent = new Intent();
+ returnIntent.putStringArrayListExtra(EXTRA_RETURN_SELECTED_SUBREDDITS,
+ mAdapter.getAllSelectedSubreddits());
+ setResult(RESULT_OK, returnIntent);
+ }
+ finish();
+ return true;
+ } else if (itemId == R.id.action_search_subreddit_multiselection_activity) {
+ Intent intent = new Intent(this, SearchActivity.class);
+ intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true);
+ startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
}
return false;
diff --git a/app/src/main/res/layout/activity_customize_post_filter.xml b/app/src/main/res/layout/activity_customize_post_filter.xml
index b7940c7a..7768b75c 100644
--- a/app/src/main/res/layout/activity_customize_post_filter.xml
+++ b/app/src/main/res/layout/activity_customize_post_filter.xml
@@ -343,45 +343,78 @@
</com.google.android.material.textfield.TextInputLayout>
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/excludes_subreddits_text_input_layout_customize_post_filter_activity"
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dp"
- android:paddingBottom="8dp"
- android:paddingStart="16dp"
- android:paddingEnd="16dp"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
+ android:layout_height="wrap_content">
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/excludes_subreddits_text_input_edit_text_customize_post_filter_activity"
- android:layout_width="match_parent"
+ <com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/excludes_subreddits_text_input_layout_customize_post_filter_activity"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
- android:fontFamily="?attr/font_family"
- android:textSize="?attr/font_default"
- android:hint="@string/exclude_subreddits_hint" />
+ android:layout_weight="1"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:layout_marginStart="16dp"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
+
+ <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>
+
+ <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" />
- </com.google.android.material.textfield.TextInputLayout>
+ </LinearLayout>
- <com.google.android.material.textfield.TextInputLayout
- android:id="@+id/excludes_users_text_input_layout_customize_post_filter_activity"
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dp"
- android:paddingBottom="8dp"
- android:paddingStart="16dp"
- android:paddingEnd="16dp"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
+ android:layout_height="wrap_content">
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/excludes_users_text_input_edit_text_customize_post_filter_activity"
- android:layout_width="match_parent"
+ <com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/excludes_users_text_input_layout_customize_post_filter_activity"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
- android:fontFamily="?attr/font_family"
- android:textSize="?attr/font_default"
- android:hint="@string/exclude_users_hint" />
+ android:layout_weight="1"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:layout_marginStart="16dp"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
+
+ <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" />
- </com.google.android.material.textfield.TextInputLayout>
+ </LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/excludes_flairs_text_input_layout_customize_post_filter_activity"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 29d5930c..957b5a48 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -150,6 +150,8 @@
<string name="app_label">Infinity</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="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>