diff options
Diffstat (limited to 'app/src/main/java')
4 files changed, 124 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 4eb10c4a..0f7cbe75 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -354,6 +354,9 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { database.execSQL("ALTER TABLE recent_search_queries ADD COLUMN time INTEGER DEFAULT 0 NOT NULL"); database.execSQL("ALTER TABLE custom_themes ADD COLUMN media_indicator_icon_color INTEGER DEFAULT " + Color.parseColor("#FFFFFF") + " NOT NULL"); database.execSQL("ALTER TABLE custom_themes ADD COLUMN media_indicator_background_color INTEGER DEFAULT " + Color.parseColor("#000000") + " NOT NULL"); + database.execSQL("ALTER TABLE post_filter ADD COLUMN post_title_contains_strings TEXT"); + database.execSQL("ALTER TABLE post_filter ADD COLUMN post_title_contains_regex TEXT"); + database.execSQL("ALTER TABLE post_filter ADD COLUMN contain_domains TEXT"); } }; } 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 862a5603..37194312 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -59,6 +59,7 @@ public class CustomizePostFilterActivity extends BaseActivity { public static final String EXTRA_EXCLUDE_FLAIR = "EEF"; public static final String EXTRA_CONTAIN_FLAIR = "ECF"; public static final String EXTRA_EXCLUDE_DOMAIN = "EED"; + public static final String EXTRA_CONTAIN_DOMAIN = "ECD"; public static final String RETURN_EXTRA_POST_FILTER = "REPF"; private static final String POST_FILTER_STATE = "PFS"; private static final String ORIGINAL_NAME_STATE = "ONS"; @@ -130,10 +131,18 @@ public class CustomizePostFilterActivity extends BaseActivity { TextInputLayout titleExcludesStringsTextInputLayout; @BindView(R.id.title_excludes_strings_text_input_edit_text_customize_post_filter_activity) TextInputEditText titleExcludesStringsTextInputEditText; + @BindView(R.id.title_contains_strings_text_input_layout_customize_post_filter_activity) + TextInputLayout titleContainsStringsTextInputLayout; + @BindView(R.id.title_contains_strings_text_input_edit_text_customize_post_filter_activity) + TextInputEditText titleContainsStringsTextInputEditText; @BindView(R.id.title_excludes_regex_text_input_layout_customize_post_filter_activity) TextInputLayout titleExcludesRegexTextInputLayout; @BindView(R.id.title_excludes_regex_text_input_edit_text_customize_post_filter_activity) TextInputEditText titleExcludesRegexTextInputEditText; + @BindView(R.id.title_contains_regex_text_input_layout_customize_post_filter_activity) + TextInputLayout titleContainsRegexTextInputLayout; + @BindView(R.id.title_contains_regex_text_input_edit_text_customize_post_filter_activity) + TextInputEditText titleContainsRegexTextInputEditText; @BindView(R.id.excludes_subreddits_text_input_layout_customize_post_filter_activity) TextInputLayout excludesSubredditsTextInputLayout; @BindView(R.id.excludes_subreddits_text_input_edit_text_customize_post_filter_activity) @@ -154,10 +163,14 @@ public class CustomizePostFilterActivity extends BaseActivity { TextInputLayout containsFlairsTextInputLayout; @BindView(R.id.contains_flairs_text_input_edit_text_customize_post_filter_activity) TextInputEditText containsFlairsTextInputEditText; - @BindView(R.id.excludes_domains_text_input_layout_customize_post_filter_activity) - TextInputLayout excludesDomainsTextInputLayout; - @BindView(R.id.excludes_domains_text_input_edit_text_customize_post_filter_activity) - TextInputEditText excludesDomainsTextInputEditText; + @BindView(R.id.exclude_domains_text_input_layout_customize_post_filter_activity) + TextInputLayout excludeDomainsTextInputLayout; + @BindView(R.id.exclude_domains_text_input_edit_text_customize_post_filter_activity) + TextInputEditText excludeDomainsTextInputEditText; + @BindView(R.id.contain_domains_text_input_layout_customize_post_filter_activity) + TextInputLayout containDomainsTextInputLayout; + @BindView(R.id.contain_domains_text_input_edit_text_customize_post_filter_activity) + TextInputEditText containDomainsTextInputEditText; @BindView(R.id.min_vote_text_input_layout_customize_post_filter_activity) TextInputLayout minVoteTextInputLayout; @BindView(R.id.min_vote_text_input_edit_text_customize_post_filter_activity) @@ -307,12 +320,15 @@ public class CustomizePostFilterActivity extends BaseActivity { onlyNSFWSwitch.setChecked(postFilter.onlyNSFW); onlySpoilerSwitch.setChecked(postFilter.onlySpoiler); titleExcludesStringsTextInputEditText.setText(postFilter.postTitleExcludesStrings); + titleContainsStringsTextInputEditText.setText(postFilter.postTitleContainsStrings); titleExcludesRegexTextInputEditText.setText(postFilter.postTitleExcludesRegex); + titleContainsRegexTextInputEditText.setText(postFilter.postTitleContainsRegex); excludesSubredditsTextInputEditText.setText(postFilter.excludeSubreddits); excludesUsersTextInputEditText.setText(postFilter.excludeUsers); excludesFlairsTextInputEditText.setText(postFilter.excludeFlairs); containsFlairsTextInputEditText.setText(postFilter.containFlairs); - excludesDomainsTextInputEditText.setText(postFilter.excludeDomains); + excludeDomainsTextInputEditText.setText(postFilter.excludeDomains); + containDomainsTextInputEditText.setText(postFilter.containDomains); minVoteTextInputEditText.setText(Integer.toString(postFilter.minVote)); maxVoteTextInputEditText.setText(Integer.toString(postFilter.maxVote)); minCommentsTextInputEditText.setText(Integer.toString(postFilter.minComments)); @@ -326,6 +342,7 @@ public class CustomizePostFilterActivity extends BaseActivity { String excludeFlair = intent.getStringExtra(EXTRA_EXCLUDE_FLAIR); String containFlair = intent.getStringExtra(EXTRA_CONTAIN_FLAIR); String excludeDomain = intent.getStringExtra(EXTRA_EXCLUDE_DOMAIN); + String containDomain = intent.getStringExtra(EXTRA_CONTAIN_DOMAIN); if (excludeSubreddit != null && !excludeSubreddit.equals("")) { if (!excludesSubredditsTextInputEditText.getText().toString().equals("")) { @@ -352,10 +369,16 @@ public class CustomizePostFilterActivity extends BaseActivity { containsFlairsTextInputEditText.append(containFlair); } if (excludeDomain != null && !excludeDomain.equals("")) { - if (!excludesDomainsTextInputEditText.getText().toString().equals("")) { - excludesDomainsTextInputEditText.append(","); + if (!excludeDomainsTextInputEditText.getText().toString().equals("")) { + excludeDomainsTextInputEditText.append(","); } - excludesDomainsTextInputEditText.append(Uri.parse(excludeDomain).getHost()); + excludeDomainsTextInputEditText.append(Uri.parse(excludeDomain).getHost()); + } + if (containDomain != null && !containDomain.equals("")) { + if (!containDomainsTextInputEditText.getText().toString().equals("")) { + containDomainsTextInputEditText.append(","); + } + containDomainsTextInputEditText.append(Uri.parse(containDomain).getHost()); } } @@ -390,9 +413,15 @@ public class CustomizePostFilterActivity extends BaseActivity { titleExcludesStringsTextInputLayout.setBoxStrokeColor(primaryTextColor); titleExcludesStringsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); titleExcludesStringsTextInputEditText.setTextColor(primaryTextColor); + titleContainsStringsTextInputLayout.setBoxStrokeColor(primaryTextColor); + titleContainsStringsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); + titleContainsStringsTextInputEditText.setTextColor(primaryTextColor); titleExcludesRegexTextInputLayout.setBoxStrokeColor(primaryTextColor); titleExcludesRegexTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); titleExcludesRegexTextInputEditText.setTextColor(primaryTextColor); + titleContainsRegexTextInputLayout.setBoxStrokeColor(primaryTextColor); + titleContainsRegexTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); + titleContainsRegexTextInputEditText.setTextColor(primaryTextColor); excludesSubredditsTextInputLayout.setBoxStrokeColor(primaryTextColor); excludesSubredditsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); excludesSubredditsTextInputEditText.setTextColor(primaryTextColor); @@ -407,9 +436,12 @@ public class CustomizePostFilterActivity extends BaseActivity { containsFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor); containsFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); containsFlairsTextInputEditText.setTextColor(primaryTextColor); - excludesDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor); - excludesDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); - excludesDomainsTextInputEditText.setTextColor(primaryTextColor); + excludeDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor); + excludeDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); + excludeDomainsTextInputEditText.setTextColor(primaryTextColor); + containDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor); + containDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); + containDomainsTextInputEditText.setTextColor(primaryTextColor); minVoteTextInputLayout.setBoxStrokeColor(primaryTextColor); minVoteTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); minVoteTextInputEditText.setTextColor(primaryTextColor); @@ -432,12 +464,15 @@ public class CustomizePostFilterActivity extends BaseActivity { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { nameTextInputEditText.setTextCursorDrawable(cursorDrawable); titleExcludesStringsTextInputEditText.setTextCursorDrawable(cursorDrawable); + titleContainsStringsTextInputEditText.setTextCursorDrawable(cursorDrawable); titleExcludesRegexTextInputEditText.setTextCursorDrawable(cursorDrawable); + titleContainsRegexTextInputEditText.setTextCursorDrawable(cursorDrawable); excludesSubredditsTextInputEditText.setTextCursorDrawable(cursorDrawable); excludesUsersTextInputEditText.setTextCursorDrawable(cursorDrawable); excludesFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable); containsFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable); - excludesDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable); + excludeDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable); + containDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable); minVoteTextInputEditText.setTextCursorDrawable(cursorDrawable); maxVoteTextInputEditText.setTextCursorDrawable(cursorDrawable); minCommentsTextInputEditText.setTextCursorDrawable(cursorDrawable); @@ -447,12 +482,15 @@ public class CustomizePostFilterActivity extends BaseActivity { } else { setCursorDrawableColor(nameTextInputEditText, primaryTextColor); setCursorDrawableColor(titleExcludesStringsTextInputEditText, primaryTextColor); + setCursorDrawableColor(titleContainsStringsTextInputEditText, primaryTextColor); setCursorDrawableColor(titleExcludesRegexTextInputEditText, primaryTextColor); + setCursorDrawableColor(titleContainsRegexTextInputEditText, primaryTextColor); setCursorDrawableColor(excludesSubredditsTextInputEditText, primaryTextColor); setCursorDrawableColor(excludesUsersTextInputEditText, primaryTextColor); setCursorDrawableColor(excludesFlairsTextInputEditText, primaryTextColor); setCursorDrawableColor(containsFlairsTextInputEditText, primaryTextColor); - setCursorDrawableColor(excludesDomainsTextInputEditText, primaryTextColor); + setCursorDrawableColor(excludeDomainsTextInputEditText, primaryTextColor); + setCursorDrawableColor(containDomainsTextInputEditText, primaryTextColor); setCursorDrawableColor(minVoteTextInputEditText, primaryTextColor); setCursorDrawableColor(maxVoteTextInputEditText, primaryTextColor); setCursorDrawableColor(minCommentsTextInputEditText, primaryTextColor); @@ -594,12 +632,15 @@ public class CustomizePostFilterActivity extends BaseActivity { postFilter.maxAwards = maxAwardsTextInputEditText.getText() == null || maxAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxAwardsTextInputEditText.getText().toString()); postFilter.minAwards = minAwardsTextInputEditText.getText() == null || minAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minAwardsTextInputEditText.getText().toString()); postFilter.postTitleExcludesRegex = titleExcludesRegexTextInputEditText.getText().toString(); + postFilter.postTitleContainsRegex = titleContainsRegexTextInputEditText.getText().toString(); postFilter.postTitleExcludesStrings = titleExcludesStringsTextInputEditText.getText().toString(); + postFilter.postTitleContainsStrings = titleContainsStringsTextInputEditText.getText().toString(); postFilter.excludeSubreddits = excludesSubredditsTextInputEditText.getText().toString(); postFilter.excludeUsers = excludesUsersTextInputEditText.getText().toString(); postFilter.excludeFlairs = excludesFlairsTextInputEditText.getText().toString(); postFilter.containFlairs = containsFlairsTextInputEditText.getText().toString(); - postFilter.excludeDomains = excludesDomainsTextInputEditText.getText().toString(); + postFilter.excludeDomains = excludeDomainsTextInputEditText.getText().toString(); + postFilter.containDomains = containDomainsTextInputEditText.getText().toString(); postFilter.containTextType = postTypeTextCheckBox.isChecked(); postFilter.containLinkType = postTypeLinkCheckBox.isChecked(); postFilter.containImageType = postTypeImageCheckBox.isChecked(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java index 4ed7534d..d8c89639 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java @@ -121,7 +121,7 @@ public class PostFilterPreferenceActivity extends BaseActivity { public void showPostFilterOptions(Post post, PostFilter postFilter) { String[] options = getResources().getStringArray(R.array.add_to_post_filter_options); - boolean[] selectedOptions = new boolean[]{false, false, false, false, false}; + boolean[] selectedOptions = new boolean[]{false, false, false, false, false, false}; new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) .setTitle(R.string.select) .setMultiChoiceItems(options, selectedOptions, (dialogInterface, i, b) -> selectedOptions[i] = b) @@ -149,6 +149,9 @@ public class PostFilterPreferenceActivity extends BaseActivity { case 4: intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_DOMAIN, post.getUrl()); break; + case 5: + intent.putExtra(CustomizePostFilterActivity.EXTRA_CONTAIN_DOMAIN, post.getUrl()); + break; } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java index 9cc0987f..833cd5a8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java @@ -41,8 +41,12 @@ public class PostFilter implements Parcelable { public boolean onlySpoiler; @ColumnInfo(name = "post_title_excludes_regex") public String postTitleExcludesRegex; + @ColumnInfo(name = "post_title_contains_regex") + public String postTitleContainsRegex; @ColumnInfo(name = "post_title_excludes_strings") public String postTitleExcludesStrings; + @ColumnInfo(name = "post_title_contains_strings") + public String postTitleContainsStrings; @ColumnInfo(name = "exclude_subreddits") public String excludeSubreddits; @ColumnInfo(name = "exclude_users") @@ -53,6 +57,8 @@ public class PostFilter implements Parcelable { public String excludeFlairs; @ColumnInfo(name = "exclude_domains") public String excludeDomains; + @ColumnInfo(name = "contain_domains") + public String containDomains; @ColumnInfo(name = "contain_text_type") public boolean containTextType = true; @ColumnInfo(name = "contain_link_type") @@ -82,12 +88,15 @@ public class PostFilter implements Parcelable { onlyNSFW = in.readByte() != 0; onlySpoiler = in.readByte() != 0; postTitleExcludesRegex = in.readString(); + postTitleContainsRegex = in.readString(); postTitleExcludesStrings = in.readString(); + postTitleContainsStrings = in.readString(); excludeSubreddits = in.readString(); excludeUsers = in.readString(); containFlairs = in.readString(); excludeFlairs = in.readString(); excludeDomains = in.readString(); + containDomains = in.readString(); containTextType = in.readByte() != 0; containLinkType = in.readByte() != 0; containImageType = in.readByte() != 0; @@ -170,6 +179,13 @@ public class PostFilter implements Parcelable { return false; } } + if (postFilter.postTitleContainsRegex != null && !postFilter.postTitleContainsRegex.equals("")) { + Pattern pattern = Pattern.compile(postFilter.postTitleContainsRegex); + Matcher matcher = pattern.matcher(post.getTitle()); + if (!matcher.find()) { + return false; + } + } if (postFilter.postTitleExcludesStrings != null && !postFilter.postTitleExcludesStrings.equals("")) { String[] titles = postFilter.postTitleExcludesStrings.split(",", 0); for (String t : titles) { @@ -178,6 +194,19 @@ public class PostFilter implements Parcelable { } } } + if (postFilter.postTitleContainsStrings != null && !postFilter.postTitleContainsStrings.equals("")) { + String[] titles = postFilter.postTitleContainsStrings.split(",", 0); + boolean hasRequiredString = false; + for (String t : titles) { + if (post.getTitle().toLowerCase().contains(t.toLowerCase().trim())) { + hasRequiredString = true; + break; + } + } + if (!hasRequiredString) { + return false; + } + } if (postFilter.excludeSubreddits != null && !postFilter.excludeSubreddits.equals("")) { String[] subreddits = postFilter.excludeSubreddits.split(",", 0); for (String s : subreddits) { @@ -211,6 +240,20 @@ public class PostFilter implements Parcelable { } } } + if (post.getUrl() != null && postFilter.containDomains != null && !postFilter.containDomains.equals("")) { + String[] domains = postFilter.containDomains.split(",", 0); + String url = post.getUrl().toLowerCase(); + boolean hasRequiredDomain = false; + for (String f : domains) { + if (url.contains(f.trim().toLowerCase())) { + hasRequiredDomain = true; + break; + } + } + if (!hasRequiredDomain) { + return false; + } + } if (postFilter.containFlairs != null && !postFilter.containFlairs.equals("")) { String[] flairs = postFilter.containFlairs.split(",", 0); if (flairs.length > 0) { @@ -255,12 +298,22 @@ public class PostFilter implements Parcelable { postFilter.postTitleExcludesRegex = p.postTitleExcludesRegex; } + if (p.postTitleContainsRegex != null && !p.postTitleContainsRegex.equals("")) { + postFilter.postTitleContainsRegex = p.postTitleContainsRegex; + } + if (p.postTitleExcludesStrings != null && !p.postTitleExcludesStrings.equals("")) { stringBuilder = new StringBuilder(postFilter.postTitleExcludesStrings == null ? "" : postFilter.postTitleExcludesStrings); stringBuilder.append(",").append(p.postTitleExcludesStrings); postFilter.postTitleExcludesStrings = stringBuilder.toString(); } + if (p.postTitleContainsStrings != null && !p.postTitleContainsStrings.equals("")) { + stringBuilder = new StringBuilder(postFilter.postTitleContainsStrings == null ? "" : postFilter.postTitleContainsStrings); + stringBuilder.append(",").append(p.postTitleContainsStrings); + postFilter.postTitleContainsStrings = stringBuilder.toString(); + } + if (p.excludeSubreddits != null && !p.excludeSubreddits.equals("")) { stringBuilder = new StringBuilder(postFilter.excludeSubreddits == null ? "" : postFilter.excludeSubreddits); stringBuilder.append(",").append(p.excludeSubreddits); @@ -291,6 +344,12 @@ public class PostFilter implements Parcelable { postFilter.excludeDomains = stringBuilder.toString(); } + if (p.containDomains != null && !p.containDomains.equals("")) { + stringBuilder = new StringBuilder(postFilter.containDomains == null ? "" : postFilter.containDomains); + stringBuilder.append(",").append(p.containDomains); + postFilter.containDomains = stringBuilder.toString(); + } + postFilter.containTextType = p.containTextType || postFilter.containTextType; postFilter.containLinkType = p.containLinkType || postFilter.containLinkType; postFilter.containImageType = p.containImageType || postFilter.containImageType; @@ -320,12 +379,15 @@ public class PostFilter implements Parcelable { parcel.writeByte((byte) (onlyNSFW ? 1 : 0)); parcel.writeByte((byte) (onlySpoiler ? 1 : 0)); parcel.writeString(postTitleExcludesRegex); + parcel.writeString(postTitleContainsRegex); parcel.writeString(postTitleExcludesStrings); + parcel.writeString(postTitleContainsStrings); parcel.writeString(excludeSubreddits); parcel.writeString(excludeUsers); parcel.writeString(containFlairs); parcel.writeString(excludeFlairs); parcel.writeString(excludeDomains); + parcel.writeString(containDomains); parcel.writeByte((byte) (containTextType ? 1 : 0)); parcel.writeByte((byte) (containLinkType ? 1 : 0)); parcel.writeByte((byte) (containImageType ? 1 : 0)); |