aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-10-22 02:48:44 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-10-22 02:48:44 +0000
commit2afbba4b682eade2cf1b999309a760cab5afd5aa (patch)
tree2baf907b12f5beebdf7db5358eaa7a69252b7bae /app
parent3d4bb32cbf55440e249c5c335131aeacb4067d19 (diff)
downloadinfinity-for-reddit-2afbba4b682eade2cf1b999309a760cab5afd5aa.tar
infinity-for-reddit-2afbba4b682eade2cf1b999309a760cab5afd5aa.tar.gz
infinity-for-reddit-2afbba4b682eade2cf1b999309a760cab5afd5aa.tar.bz2
infinity-for-reddit-2afbba4b682eade2cf1b999309a760cab5afd5aa.tar.lz
infinity-for-reddit-2afbba4b682eade2cf1b999309a760cab5afd5aa.tar.xz
infinity-for-reddit-2afbba4b682eade2cf1b999309a760cab5afd5aa.tar.zst
infinity-for-reddit-2afbba4b682eade2cf1b999309a760cab5afd5aa.zip
Add "exclude users" entry in CustomizeCommentFilterActivity.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java45
-rw-r--r--app/src/main/res/layout/activity_customize_comment_filter.xml39
-rw-r--r--app/src/main/res/values/strings.xml1
3 files changed, 83 insertions, 2 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java
index 6a3e0644..ce612cde 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeCommentFilterActivity.java
@@ -1,8 +1,10 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
@@ -15,11 +17,15 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
+import androidx.core.content.ContextCompat;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.concurrent.Executor;
import java.util.regex.PatternSyntaxException;
@@ -33,6 +39,7 @@ import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter;
import ml.docilealligator.infinityforreddit.commentfilter.SaveCommentFilter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.databinding.ActivityCustomizeCommentFilterBinding;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class CustomizeCommentFilterActivity extends BaseActivity {
@@ -79,6 +86,35 @@ public class CustomizeCommentFilterActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(binding.toolbarCustomizeCommentFilterActivity);
+ ActivityResultLauncher<Intent> requestAddUsersLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
+ Intent data = result.getData();
+ if (data == null) {
+ return;
+ }
+
+ ArrayList<String> usernames = data.getStringArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_USERNAMES);
+ String currentUsers = binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.getText().toString().trim();
+ if (usernames != null && !usernames.isEmpty()) {
+ if (!currentUsers.isEmpty() && currentUsers.charAt(currentUsers.length() - 1) != ',') {
+ String newString = currentUsers + ",";
+ binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setText(newString);
+ }
+ StringBuilder stringBuilder = new StringBuilder();
+ for (String s : usernames) {
+ stringBuilder.append(s).append(",");
+ }
+ stringBuilder.deleteCharAt(stringBuilder.length() - 1);
+ binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.append(stringBuilder.toString());
+ }
+ });
+
+ binding.addUsersImageViewCustomizeCommentFilterActivity.setOnClickListener(view -> {
+ Intent intent = new Intent(this, SearchActivity.class);
+ intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true);
+ intent.putExtra(SearchActivity.EXTRA_IS_MULTI_SELECTION, true);
+ requestAddUsersLauncher.launch(intent);
+ });
+
fromSettings = getIntent().getBooleanExtra(EXTRA_FROM_SETTINGS, false);
if (savedInstanceState != null) {
@@ -103,6 +139,7 @@ public class CustomizeCommentFilterActivity extends BaseActivity {
private void bindView() {
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.name);
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.excludeStrings);
+ binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.excludeUsers);
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setText(Integer.toString(commentFilter.minVote));
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setText(Integer.toString(commentFilter.maxVote));
}
@@ -130,6 +167,9 @@ public class CustomizeCommentFilterActivity extends BaseActivity {
binding.excludeStringsTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.excludeStringsTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
+ binding.excludeUsersTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
+ binding.addUsersImageViewCustomizeCommentFilterActivity.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
binding.minVoteTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.minVoteTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
@@ -140,11 +180,13 @@ public class CustomizeCommentFilterActivity extends BaseActivity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
+ binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
} else {
setCursorDrawableColor(binding.nameTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
+ setCursorDrawableColor(binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.minVoteTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
}
@@ -242,9 +284,10 @@ public class CustomizeCommentFilterActivity extends BaseActivity {
private void constructCommentFilter() throws PatternSyntaxException {
commentFilter.name = binding.nameTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
+ commentFilter.excludeStrings = binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
+ commentFilter.excludeUsers = binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
commentFilter.maxVote = binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText() == null || binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString().equals("") ? -1 : Integer.parseInt(binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString());
commentFilter.minVote = binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText() == null || binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString().equals("") ? -1 : Integer.parseInt(binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString());
- commentFilter.excludeStrings = binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
}
@Override
diff --git a/app/src/main/res/layout/activity_customize_comment_filter.xml b/app/src/main/res/layout/activity_customize_comment_filter.xml
index 32022e92..9153e01a 100644
--- a/app/src/main/res/layout/activity_customize_comment_filter.xml
+++ b/app/src/main/res/layout/activity_customize_comment_filter.xml
@@ -78,11 +78,48 @@
android:layout_height="wrap_content"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
- android:hint="@string/title_excludes_strings_hint"
+ android:hint="@string/excludes_strings_hint"
android:maxLines="10" />
</com.google.android.material.textfield.TextInputLayout>
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/exclude_users_text_input_layout_customize_comment_filter_activity"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:layout_marginStart="16dp"
+ style="@style/Widget.Material3.TextInputLayout.OutlinedBox">
+
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/exclude_users_text_input_edit_text_customize_comment_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"
+ android:maxLines="10" />
+
+ </com.google.android.material.textfield.TextInputLayout>
+
+ <ImageView
+ android:id="@+id/add_users_image_view_customize_comment_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
android:id="@+id/min_vote_text_input_layout_customize_comment_filter_activity"
android:layout_width="match_parent"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6f97b59f..915535ce 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1162,6 +1162,7 @@
<string name="click_to_apply_post_filter">Click here to apply it to some post feeds</string>
<string name="post_filter_usage_embedded_more_count">and %1$d more</string>
+ <string name="excludes_strings_hint">Exclude keywords (key1,key2)</string>
<string name="comment_filter_name_hint">Comment Filter Name</string>
<string name="comment_filter_requires_a_name">What is the name of this comment filter?</string>
<string name="duplicate_comment_filter_dialog_title">\'%1$s\' Already Exists</string>