New options in post filter: Title: contains keywords, Title: contains regex, Contain domains.

This commit is contained in:
Alex Ning 2021-10-16 15:28:35 +08:00
parent 4395384586
commit 4e2b09b079
7 changed files with 191 additions and 17 deletions

View File

@ -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 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_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 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");
} }
}; };
} }

View File

@ -59,6 +59,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
public static final String EXTRA_EXCLUDE_FLAIR = "EEF"; public static final String EXTRA_EXCLUDE_FLAIR = "EEF";
public static final String EXTRA_CONTAIN_FLAIR = "ECF"; public static final String EXTRA_CONTAIN_FLAIR = "ECF";
public static final String EXTRA_EXCLUDE_DOMAIN = "EED"; 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"; 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 String ORIGINAL_NAME_STATE = "ONS"; private static final String ORIGINAL_NAME_STATE = "ONS";
@ -130,10 +131,18 @@ public class CustomizePostFilterActivity extends BaseActivity {
TextInputLayout titleExcludesStringsTextInputLayout; TextInputLayout titleExcludesStringsTextInputLayout;
@BindView(R.id.title_excludes_strings_text_input_edit_text_customize_post_filter_activity) @BindView(R.id.title_excludes_strings_text_input_edit_text_customize_post_filter_activity)
TextInputEditText titleExcludesStringsTextInputEditText; 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) @BindView(R.id.title_excludes_regex_text_input_layout_customize_post_filter_activity)
TextInputLayout titleExcludesRegexTextInputLayout; TextInputLayout titleExcludesRegexTextInputLayout;
@BindView(R.id.title_excludes_regex_text_input_edit_text_customize_post_filter_activity) @BindView(R.id.title_excludes_regex_text_input_edit_text_customize_post_filter_activity)
TextInputEditText titleExcludesRegexTextInputEditText; 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) @BindView(R.id.excludes_subreddits_text_input_layout_customize_post_filter_activity)
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)
@ -154,10 +163,14 @@ public class CustomizePostFilterActivity extends BaseActivity {
TextInputLayout containsFlairsTextInputLayout; TextInputLayout containsFlairsTextInputLayout;
@BindView(R.id.contains_flairs_text_input_edit_text_customize_post_filter_activity) @BindView(R.id.contains_flairs_text_input_edit_text_customize_post_filter_activity)
TextInputEditText containsFlairsTextInputEditText; TextInputEditText containsFlairsTextInputEditText;
@BindView(R.id.excludes_domains_text_input_layout_customize_post_filter_activity) @BindView(R.id.exclude_domains_text_input_layout_customize_post_filter_activity)
TextInputLayout excludesDomainsTextInputLayout; TextInputLayout excludeDomainsTextInputLayout;
@BindView(R.id.excludes_domains_text_input_edit_text_customize_post_filter_activity) @BindView(R.id.exclude_domains_text_input_edit_text_customize_post_filter_activity)
TextInputEditText excludesDomainsTextInputEditText; 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) @BindView(R.id.min_vote_text_input_layout_customize_post_filter_activity)
TextInputLayout minVoteTextInputLayout; TextInputLayout minVoteTextInputLayout;
@BindView(R.id.min_vote_text_input_edit_text_customize_post_filter_activity) @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); onlyNSFWSwitch.setChecked(postFilter.onlyNSFW);
onlySpoilerSwitch.setChecked(postFilter.onlySpoiler); onlySpoilerSwitch.setChecked(postFilter.onlySpoiler);
titleExcludesStringsTextInputEditText.setText(postFilter.postTitleExcludesStrings); titleExcludesStringsTextInputEditText.setText(postFilter.postTitleExcludesStrings);
titleContainsStringsTextInputEditText.setText(postFilter.postTitleContainsStrings);
titleExcludesRegexTextInputEditText.setText(postFilter.postTitleExcludesRegex); titleExcludesRegexTextInputEditText.setText(postFilter.postTitleExcludesRegex);
titleContainsRegexTextInputEditText.setText(postFilter.postTitleContainsRegex);
excludesSubredditsTextInputEditText.setText(postFilter.excludeSubreddits); excludesSubredditsTextInputEditText.setText(postFilter.excludeSubreddits);
excludesUsersTextInputEditText.setText(postFilter.excludeUsers); excludesUsersTextInputEditText.setText(postFilter.excludeUsers);
excludesFlairsTextInputEditText.setText(postFilter.excludeFlairs); excludesFlairsTextInputEditText.setText(postFilter.excludeFlairs);
containsFlairsTextInputEditText.setText(postFilter.containFlairs); containsFlairsTextInputEditText.setText(postFilter.containFlairs);
excludesDomainsTextInputEditText.setText(postFilter.excludeDomains); excludeDomainsTextInputEditText.setText(postFilter.excludeDomains);
containDomainsTextInputEditText.setText(postFilter.containDomains);
minVoteTextInputEditText.setText(Integer.toString(postFilter.minVote)); minVoteTextInputEditText.setText(Integer.toString(postFilter.minVote));
maxVoteTextInputEditText.setText(Integer.toString(postFilter.maxVote)); maxVoteTextInputEditText.setText(Integer.toString(postFilter.maxVote));
minCommentsTextInputEditText.setText(Integer.toString(postFilter.minComments)); minCommentsTextInputEditText.setText(Integer.toString(postFilter.minComments));
@ -326,6 +342,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
String excludeFlair = intent.getStringExtra(EXTRA_EXCLUDE_FLAIR); String excludeFlair = intent.getStringExtra(EXTRA_EXCLUDE_FLAIR);
String containFlair = intent.getStringExtra(EXTRA_CONTAIN_FLAIR); String containFlair = intent.getStringExtra(EXTRA_CONTAIN_FLAIR);
String excludeDomain = intent.getStringExtra(EXTRA_EXCLUDE_DOMAIN); String excludeDomain = intent.getStringExtra(EXTRA_EXCLUDE_DOMAIN);
String containDomain = intent.getStringExtra(EXTRA_CONTAIN_DOMAIN);
if (excludeSubreddit != null && !excludeSubreddit.equals("")) { if (excludeSubreddit != null && !excludeSubreddit.equals("")) {
if (!excludesSubredditsTextInputEditText.getText().toString().equals("")) { if (!excludesSubredditsTextInputEditText.getText().toString().equals("")) {
@ -352,10 +369,16 @@ public class CustomizePostFilterActivity extends BaseActivity {
containsFlairsTextInputEditText.append(containFlair); containsFlairsTextInputEditText.append(containFlair);
} }
if (excludeDomain != null && !excludeDomain.equals("")) { if (excludeDomain != null && !excludeDomain.equals("")) {
if (!excludesDomainsTextInputEditText.getText().toString().equals("")) { if (!excludeDomainsTextInputEditText.getText().toString().equals("")) {
excludesDomainsTextInputEditText.append(","); 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.setBoxStrokeColor(primaryTextColor);
titleExcludesStringsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); titleExcludesStringsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
titleExcludesStringsTextInputEditText.setTextColor(primaryTextColor); titleExcludesStringsTextInputEditText.setTextColor(primaryTextColor);
titleContainsStringsTextInputLayout.setBoxStrokeColor(primaryTextColor);
titleContainsStringsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
titleContainsStringsTextInputEditText.setTextColor(primaryTextColor);
titleExcludesRegexTextInputLayout.setBoxStrokeColor(primaryTextColor); titleExcludesRegexTextInputLayout.setBoxStrokeColor(primaryTextColor);
titleExcludesRegexTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); titleExcludesRegexTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
titleExcludesRegexTextInputEditText.setTextColor(primaryTextColor); titleExcludesRegexTextInputEditText.setTextColor(primaryTextColor);
titleContainsRegexTextInputLayout.setBoxStrokeColor(primaryTextColor);
titleContainsRegexTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
titleContainsRegexTextInputEditText.setTextColor(primaryTextColor);
excludesSubredditsTextInputLayout.setBoxStrokeColor(primaryTextColor); excludesSubredditsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesSubredditsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); excludesSubredditsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesSubredditsTextInputEditText.setTextColor(primaryTextColor); excludesSubredditsTextInputEditText.setTextColor(primaryTextColor);
@ -407,9 +436,12 @@ public class CustomizePostFilterActivity extends BaseActivity {
containsFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor); containsFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor);
containsFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); containsFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
containsFlairsTextInputEditText.setTextColor(primaryTextColor); containsFlairsTextInputEditText.setTextColor(primaryTextColor);
excludesDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor); excludeDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); excludeDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesDomainsTextInputEditText.setTextColor(primaryTextColor); excludeDomainsTextInputEditText.setTextColor(primaryTextColor);
containDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor);
containDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
containDomainsTextInputEditText.setTextColor(primaryTextColor);
minVoteTextInputLayout.setBoxStrokeColor(primaryTextColor); minVoteTextInputLayout.setBoxStrokeColor(primaryTextColor);
minVoteTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor)); minVoteTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
minVoteTextInputEditText.setTextColor(primaryTextColor); minVoteTextInputEditText.setTextColor(primaryTextColor);
@ -432,12 +464,15 @@ public class CustomizePostFilterActivity extends BaseActivity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
nameTextInputEditText.setTextCursorDrawable(cursorDrawable); nameTextInputEditText.setTextCursorDrawable(cursorDrawable);
titleExcludesStringsTextInputEditText.setTextCursorDrawable(cursorDrawable); titleExcludesStringsTextInputEditText.setTextCursorDrawable(cursorDrawable);
titleContainsStringsTextInputEditText.setTextCursorDrawable(cursorDrawable);
titleExcludesRegexTextInputEditText.setTextCursorDrawable(cursorDrawable); titleExcludesRegexTextInputEditText.setTextCursorDrawable(cursorDrawable);
titleContainsRegexTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludesSubredditsTextInputEditText.setTextCursorDrawable(cursorDrawable); excludesSubredditsTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludesUsersTextInputEditText.setTextCursorDrawable(cursorDrawable); excludesUsersTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludesFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable); excludesFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable);
containsFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable); containsFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludesDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable); excludeDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable);
containDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable);
minVoteTextInputEditText.setTextCursorDrawable(cursorDrawable); minVoteTextInputEditText.setTextCursorDrawable(cursorDrawable);
maxVoteTextInputEditText.setTextCursorDrawable(cursorDrawable); maxVoteTextInputEditText.setTextCursorDrawable(cursorDrawable);
minCommentsTextInputEditText.setTextCursorDrawable(cursorDrawable); minCommentsTextInputEditText.setTextCursorDrawable(cursorDrawable);
@ -447,12 +482,15 @@ public class CustomizePostFilterActivity extends BaseActivity {
} else { } else {
setCursorDrawableColor(nameTextInputEditText, primaryTextColor); setCursorDrawableColor(nameTextInputEditText, primaryTextColor);
setCursorDrawableColor(titleExcludesStringsTextInputEditText, primaryTextColor); setCursorDrawableColor(titleExcludesStringsTextInputEditText, primaryTextColor);
setCursorDrawableColor(titleContainsStringsTextInputEditText, primaryTextColor);
setCursorDrawableColor(titleExcludesRegexTextInputEditText, primaryTextColor); setCursorDrawableColor(titleExcludesRegexTextInputEditText, primaryTextColor);
setCursorDrawableColor(titleContainsRegexTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludesSubredditsTextInputEditText, primaryTextColor); setCursorDrawableColor(excludesSubredditsTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludesUsersTextInputEditText, primaryTextColor); setCursorDrawableColor(excludesUsersTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludesFlairsTextInputEditText, primaryTextColor); setCursorDrawableColor(excludesFlairsTextInputEditText, primaryTextColor);
setCursorDrawableColor(containsFlairsTextInputEditText, primaryTextColor); setCursorDrawableColor(containsFlairsTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludesDomainsTextInputEditText, primaryTextColor); setCursorDrawableColor(excludeDomainsTextInputEditText, primaryTextColor);
setCursorDrawableColor(containDomainsTextInputEditText, primaryTextColor);
setCursorDrawableColor(minVoteTextInputEditText, primaryTextColor); setCursorDrawableColor(minVoteTextInputEditText, primaryTextColor);
setCursorDrawableColor(maxVoteTextInputEditText, primaryTextColor); setCursorDrawableColor(maxVoteTextInputEditText, primaryTextColor);
setCursorDrawableColor(minCommentsTextInputEditText, 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.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.minAwards = minAwardsTextInputEditText.getText() == null || minAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minAwardsTextInputEditText.getText().toString());
postFilter.postTitleExcludesRegex = titleExcludesRegexTextInputEditText.getText().toString(); postFilter.postTitleExcludesRegex = titleExcludesRegexTextInputEditText.getText().toString();
postFilter.postTitleContainsRegex = titleContainsRegexTextInputEditText.getText().toString();
postFilter.postTitleExcludesStrings = titleExcludesStringsTextInputEditText.getText().toString(); postFilter.postTitleExcludesStrings = titleExcludesStringsTextInputEditText.getText().toString();
postFilter.postTitleContainsStrings = titleContainsStringsTextInputEditText.getText().toString();
postFilter.excludeSubreddits = excludesSubredditsTextInputEditText.getText().toString(); postFilter.excludeSubreddits = excludesSubredditsTextInputEditText.getText().toString();
postFilter.excludeUsers = excludesUsersTextInputEditText.getText().toString(); postFilter.excludeUsers = excludesUsersTextInputEditText.getText().toString();
postFilter.excludeFlairs = excludesFlairsTextInputEditText.getText().toString(); postFilter.excludeFlairs = excludesFlairsTextInputEditText.getText().toString();
postFilter.containFlairs = containsFlairsTextInputEditText.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.containTextType = postTypeTextCheckBox.isChecked();
postFilter.containLinkType = postTypeLinkCheckBox.isChecked(); postFilter.containLinkType = postTypeLinkCheckBox.isChecked();
postFilter.containImageType = postTypeImageCheckBox.isChecked(); postFilter.containImageType = postTypeImageCheckBox.isChecked();

View File

@ -121,7 +121,7 @@ public class PostFilterPreferenceActivity extends BaseActivity {
public void showPostFilterOptions(Post post, PostFilter postFilter) { public void showPostFilterOptions(Post post, PostFilter postFilter) {
String[] options = getResources().getStringArray(R.array.add_to_post_filter_options); 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) new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.select) .setTitle(R.string.select)
.setMultiChoiceItems(options, selectedOptions, (dialogInterface, i, b) -> selectedOptions[i] = b) .setMultiChoiceItems(options, selectedOptions, (dialogInterface, i, b) -> selectedOptions[i] = b)
@ -149,6 +149,9 @@ public class PostFilterPreferenceActivity extends BaseActivity {
case 4: case 4:
intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_DOMAIN, post.getUrl()); intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_DOMAIN, post.getUrl());
break; break;
case 5:
intent.putExtra(CustomizePostFilterActivity.EXTRA_CONTAIN_DOMAIN, post.getUrl());
break;
} }
} }
} }

View File

@ -41,8 +41,12 @@ public class PostFilter implements Parcelable {
public boolean onlySpoiler; public boolean onlySpoiler;
@ColumnInfo(name = "post_title_excludes_regex") @ColumnInfo(name = "post_title_excludes_regex")
public String postTitleExcludesRegex; public String postTitleExcludesRegex;
@ColumnInfo(name = "post_title_contains_regex")
public String postTitleContainsRegex;
@ColumnInfo(name = "post_title_excludes_strings") @ColumnInfo(name = "post_title_excludes_strings")
public String postTitleExcludesStrings; public String postTitleExcludesStrings;
@ColumnInfo(name = "post_title_contains_strings")
public String postTitleContainsStrings;
@ColumnInfo(name = "exclude_subreddits") @ColumnInfo(name = "exclude_subreddits")
public String excludeSubreddits; public String excludeSubreddits;
@ColumnInfo(name = "exclude_users") @ColumnInfo(name = "exclude_users")
@ -53,6 +57,8 @@ public class PostFilter implements Parcelable {
public String excludeFlairs; public String excludeFlairs;
@ColumnInfo(name = "exclude_domains") @ColumnInfo(name = "exclude_domains")
public String excludeDomains; public String excludeDomains;
@ColumnInfo(name = "contain_domains")
public String containDomains;
@ColumnInfo(name = "contain_text_type") @ColumnInfo(name = "contain_text_type")
public boolean containTextType = true; public boolean containTextType = true;
@ColumnInfo(name = "contain_link_type") @ColumnInfo(name = "contain_link_type")
@ -82,12 +88,15 @@ public class PostFilter implements Parcelable {
onlyNSFW = in.readByte() != 0; onlyNSFW = in.readByte() != 0;
onlySpoiler = in.readByte() != 0; onlySpoiler = in.readByte() != 0;
postTitleExcludesRegex = in.readString(); postTitleExcludesRegex = in.readString();
postTitleContainsRegex = in.readString();
postTitleExcludesStrings = in.readString(); postTitleExcludesStrings = in.readString();
postTitleContainsStrings = in.readString();
excludeSubreddits = in.readString(); excludeSubreddits = in.readString();
excludeUsers = in.readString(); excludeUsers = in.readString();
containFlairs = in.readString(); containFlairs = in.readString();
excludeFlairs = in.readString(); excludeFlairs = in.readString();
excludeDomains = in.readString(); excludeDomains = in.readString();
containDomains = in.readString();
containTextType = in.readByte() != 0; containTextType = in.readByte() != 0;
containLinkType = in.readByte() != 0; containLinkType = in.readByte() != 0;
containImageType = in.readByte() != 0; containImageType = in.readByte() != 0;
@ -170,6 +179,13 @@ public class PostFilter implements Parcelable {
return false; 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("")) { if (postFilter.postTitleExcludesStrings != null && !postFilter.postTitleExcludesStrings.equals("")) {
String[] titles = postFilter.postTitleExcludesStrings.split(",", 0); String[] titles = postFilter.postTitleExcludesStrings.split(",", 0);
for (String t : titles) { 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("")) { if (postFilter.excludeSubreddits != null && !postFilter.excludeSubreddits.equals("")) {
String[] subreddits = postFilter.excludeSubreddits.split(",", 0); String[] subreddits = postFilter.excludeSubreddits.split(",", 0);
for (String s : subreddits) { 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("")) { if (postFilter.containFlairs != null && !postFilter.containFlairs.equals("")) {
String[] flairs = postFilter.containFlairs.split(",", 0); String[] flairs = postFilter.containFlairs.split(",", 0);
if (flairs.length > 0) { if (flairs.length > 0) {
@ -255,12 +298,22 @@ public class PostFilter implements Parcelable {
postFilter.postTitleExcludesRegex = p.postTitleExcludesRegex; postFilter.postTitleExcludesRegex = p.postTitleExcludesRegex;
} }
if (p.postTitleContainsRegex != null && !p.postTitleContainsRegex.equals("")) {
postFilter.postTitleContainsRegex = p.postTitleContainsRegex;
}
if (p.postTitleExcludesStrings != null && !p.postTitleExcludesStrings.equals("")) { if (p.postTitleExcludesStrings != null && !p.postTitleExcludesStrings.equals("")) {
stringBuilder = new StringBuilder(postFilter.postTitleExcludesStrings == null ? "" : postFilter.postTitleExcludesStrings); stringBuilder = new StringBuilder(postFilter.postTitleExcludesStrings == null ? "" : postFilter.postTitleExcludesStrings);
stringBuilder.append(",").append(p.postTitleExcludesStrings); stringBuilder.append(",").append(p.postTitleExcludesStrings);
postFilter.postTitleExcludesStrings = stringBuilder.toString(); 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("")) { if (p.excludeSubreddits != null && !p.excludeSubreddits.equals("")) {
stringBuilder = new StringBuilder(postFilter.excludeSubreddits == null ? "" : postFilter.excludeSubreddits); stringBuilder = new StringBuilder(postFilter.excludeSubreddits == null ? "" : postFilter.excludeSubreddits);
stringBuilder.append(",").append(p.excludeSubreddits); stringBuilder.append(",").append(p.excludeSubreddits);
@ -291,6 +344,12 @@ public class PostFilter implements Parcelable {
postFilter.excludeDomains = stringBuilder.toString(); 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.containTextType = p.containTextType || postFilter.containTextType;
postFilter.containLinkType = p.containLinkType || postFilter.containLinkType; postFilter.containLinkType = p.containLinkType || postFilter.containLinkType;
postFilter.containImageType = p.containImageType || postFilter.containImageType; postFilter.containImageType = p.containImageType || postFilter.containImageType;
@ -320,12 +379,15 @@ public class PostFilter implements Parcelable {
parcel.writeByte((byte) (onlyNSFW ? 1 : 0)); parcel.writeByte((byte) (onlyNSFW ? 1 : 0));
parcel.writeByte((byte) (onlySpoiler ? 1 : 0)); parcel.writeByte((byte) (onlySpoiler ? 1 : 0));
parcel.writeString(postTitleExcludesRegex); parcel.writeString(postTitleExcludesRegex);
parcel.writeString(postTitleContainsRegex);
parcel.writeString(postTitleExcludesStrings); parcel.writeString(postTitleExcludesStrings);
parcel.writeString(postTitleContainsStrings);
parcel.writeString(excludeSubreddits); parcel.writeString(excludeSubreddits);
parcel.writeString(excludeUsers); parcel.writeString(excludeUsers);
parcel.writeString(containFlairs); parcel.writeString(containFlairs);
parcel.writeString(excludeFlairs); parcel.writeString(excludeFlairs);
parcel.writeString(excludeDomains); parcel.writeString(excludeDomains);
parcel.writeString(containDomains);
parcel.writeByte((byte) (containTextType ? 1 : 0)); parcel.writeByte((byte) (containTextType ? 1 : 0));
parcel.writeByte((byte) (containLinkType ? 1 : 0)); parcel.writeByte((byte) (containLinkType ? 1 : 0));
parcel.writeByte((byte) (containImageType ? 1 : 0)); parcel.writeByte((byte) (containImageType ? 1 : 0));

View File

@ -323,6 +323,26 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/title_contains_strings_text_input_layout_customize_post_filter_activity"
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">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/title_contains_strings_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/title_contains_strings_hint" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/title_excludes_regex_text_input_layout_customize_post_filter_activity" android:id="@+id/title_excludes_regex_text_input_layout_customize_post_filter_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -343,6 +363,26 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/title_contains_regex_text_input_layout_customize_post_filter_activity"
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">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/title_contains_regex_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/title_contains_regex_hint" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -457,7 +497,7 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/excludes_domains_text_input_layout_customize_post_filter_activity" android:id="@+id/exclude_domains_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:paddingTop="8dp"
@ -467,7 +507,7 @@
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"> style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/excludes_domains_text_input_edit_text_customize_post_filter_activity" android:id="@+id/exclude_domains_text_input_edit_text_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:fontFamily="?attr/font_family" android:fontFamily="?attr/font_family"
@ -476,6 +516,26 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/contain_domains_text_input_layout_customize_post_filter_activity"
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">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/contain_domains_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/contain_domains_hint" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/min_vote_text_input_layout_customize_post_filter_activity" android:id="@+id/min_vote_text_input_layout_customize_post_filter_activity"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -546,6 +546,7 @@
<item>@string/exclude_flair</item> <item>@string/exclude_flair</item>
<item>@string/contain_flair</item> <item>@string/contain_flair</item>
<item>@string/exclude_domain</item> <item>@string/exclude_domain</item>
<item>@string/contain_domain</item>
</string-array> </string-array>
<string-array name="settings_app_lock_timeout"> <string-array name="settings_app_lock_timeout">

View File

@ -1077,12 +1077,15 @@
<string name="only_nsfw">Only NSFW</string> <string name="only_nsfw">Only NSFW</string>
<string name="only_spoiler">Only Spoiler</string> <string name="only_spoiler">Only Spoiler</string>
<string name="title_excludes_strings_hint">Title: excludes keywords (key1,key2)</string> <string name="title_excludes_strings_hint">Title: excludes keywords (key1,key2)</string>
<string name="title_contains_strings_hint">Title: contains keywords (key1,key2)</string>
<string name="title_excludes_regex_hint">Title: excludes regex</string> <string name="title_excludes_regex_hint">Title: excludes regex</string>
<string name="title_contains_regex_hint">Title: contains regex</string>
<string name="exclude_subreddits_hint">Exclude subreddits (e.g. funny,AskReddit)</string> <string name="exclude_subreddits_hint">Exclude subreddits (e.g. funny,AskReddit)</string>
<string name="exclude_users_hint">Exclude users (e.g. Hostilenemy,random)</string> <string name="exclude_users_hint">Exclude users (e.g. Hostilenemy,random)</string>
<string name="exclude_flairs_hint">Exclude flairs (e.g. flair1,flair2)</string> <string name="exclude_flairs_hint">Exclude flairs (e.g. flair1,flair2)</string>
<string name="contain_flairs_hint">Contain flairs (e.g. flair1,flair2)</string> <string name="contain_flairs_hint">Contain flairs (e.g. flair1,flair2)</string>
<string name="exclude_domains_hint">Exclude domains</string> <string name="exclude_domains_hint">Exclude domains</string>
<string name="contain_domains_hint">Contain domains</string>
<string name="min_vote_hint">Min vote (-1: no restriction)</string> <string name="min_vote_hint">Min vote (-1: no restriction)</string>
<string name="max_vote_hint">Max vote (-1: no restriction)</string> <string name="max_vote_hint">Max vote (-1: no restriction)</string>
<string name="min_comments_hint">Min comments (-1: no restriction)</string> <string name="min_comments_hint">Min comments (-1: no restriction)</string>
@ -1158,6 +1161,7 @@
<string name="exclude_flair">Exclude this flair</string> <string name="exclude_flair">Exclude this flair</string>
<string name="contain_flair">Contain this flair</string> <string name="contain_flair">Contain this flair</string>
<string name="exclude_domain">Exclude this domain</string> <string name="exclude_domain">Exclude this domain</string>
<string name="contain_domain">Contain this domain</string>
<string name="suggest_title">Suggest Title</string> <string name="suggest_title">Suggest Title</string>
<string name="suggest_title_failed">Failed to suggest a title</string> <string name="suggest_title_failed">Failed to suggest a title</string>