From 06d1d028ebd482607762cdf87f958710d773eec1 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 11 Dec 2020 19:37:45 +0800 Subject: Prepare to add post filter. --- app/src/main/AndroidManifest.xml | 8 +- .../infinityforreddit/AppComponent.java | 3 + .../infinityforreddit/PostFilter.java | 21 ++ .../activities/CustomizePostFilterActivity.java | 161 +++++++++ .../activities/FilteredThingActivity.java | 4 +- .../res/layout/activity_customize_post_filter.xml | 390 +++++++++++++++++++++ .../res/menu/customize_post_filter_activity.xml | 10 + app/src/main/res/values/strings.xml | 16 +- 8 files changed, 609 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java create mode 100644 app/src/main/res/layout/activity_customize_post_filter.xml create mode 100644 app/src/main/res/menu/customize_post_filter_activity.xml (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d3ad80b3..68bdf08c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,13 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true" tools:replace="android:label"> - + postTitleExcludesStrings; + public ArrayList excludesSubreddits; + public ArrayList excludesUsers; + public ArrayList containsFlairs; + public ArrayList excludesFlairs; + public ArrayList containsPostTypes; +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java new file mode 100644 index 00000000..9ad3cac7 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -0,0 +1,161 @@ +package ml.docilealligator.infinityforreddit.activities; + +import android.content.SharedPreferences; +import android.os.Build; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.checkbox.MaterialCheckBox; +import com.google.android.material.textfield.TextInputEditText; +import com.r0adkll.slidr.Slidr; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; + +public class CustomizePostFilterActivity extends BaseActivity { + + @BindView(R.id.coordinator_layout_customize_post_filter_activity) + CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_customize_post_filter_activity) + AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_customize_post_filter_activity) + CollapsingToolbarLayout collapsingToolbarLayout; + @BindView(R.id.toolbar_customize_post_filter_activity) + Toolbar toolbar; + @BindView(R.id.post_type_text_linear_layout_customize_post_filter_activity) + LinearLayout postTypeTextLinearLayout; + @BindView(R.id.post_type_text_text_view_customize_post_filter_activity) + TextView postTypeTextTextView; + @BindView(R.id.post_type_text_check_box_customize_post_filter_activity) + MaterialCheckBox postTypeTextCheckBox; + @BindView(R.id.post_type_link_linear_layout_customize_post_filter_activity) + LinearLayout postTypeLinkLinearLayout; + @BindView(R.id.post_type_link_text_view_customize_post_filter_activity) + TextView postTypeLinkTextView; + @BindView(R.id.post_type_link_check_box_customize_post_filter_activity) + MaterialCheckBox postTypeLinkCheckBox; + @BindView(R.id.post_type_image_linear_layout_customize_post_filter_activity) + LinearLayout postTypeImageLinearLayout; + @BindView(R.id.post_type_image_text_view_customize_post_filter_activity) + TextView postTypeImageTextView; + @BindView(R.id.post_type_image_check_box_customize_post_filter_activity) + MaterialCheckBox postTypeImageCheckBox; + @BindView(R.id.post_type_video_linear_layout_customize_post_filter_activity) + LinearLayout postTypeVideoLinearLayout; + @BindView(R.id.post_type_video_text_view_customize_post_filter_activity) + TextView postTypeVideoTextView; + @BindView(R.id.post_type_video_check_box_customize_post_filter_activity) + MaterialCheckBox postTypeVideoCheckBox; + @BindView(R.id.title_excludes_strings_text_input_edit_text_customize_post_filter_activity) + TextInputEditText titleExcludesStringsTextInputEditText; + @BindView(R.id.title_excludes_regex_text_input_edit_text_customize_post_filter_activity) + TextInputEditText titleExcludesRegexTextInputEditText; + @BindView(R.id.excludes_subreddits_text_input_edit_text_customize_post_filter_activity) + TextInputEditText excludesSubredditsTextInputEditText; + @BindView(R.id.excludes_users_text_input_edit_text_customize_post_filter_activity) + TextInputEditText excludesUsersTextInputEditText; + @BindView(R.id.excludes_flairs_text_input_edit_text_customize_post_filter_activity) + TextInputEditText excludesFlairsTextInputEditText; + @BindView(R.id.contains_flairs_text_input_edit_text_customize_post_filter_activity) + TextInputEditText containsFlairsTextInputEditText; + @BindView(R.id.min_vote_text_input_edit_text_customize_post_filter_activity) + TextInputEditText minVoteTextInputEditText; + @BindView(R.id.max_vote_text_input_edit_text_customize_post_filter_activity) + TextInputEditText maxVoteTextInputEditText; + @BindView(R.id.min_comments_text_input_edit_text_customize_post_filter_activity) + TextInputEditText minCommentsTextInputEditText; + @BindView(R.id.max_comments_text_input_edit_text_customize_post_filter_activity) + TextInputEditText maxCommentsTextInputEditText; + @BindView(R.id.min_awards_text_input_edit_text_customize_post_filter_activity) + TextInputEditText minAwardsTextInputEditText; + @BindView(R.id.max_awards_text_input_edit_text_customize_post_filter_activity) + TextInputEditText maxAwardsTextInputEditText; + @Inject + RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject + CustomThemeWrapper mCustomThemeWrapper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + ((Infinity) getApplication()).getAppComponent().inject(this); + + setImmersiveModeNotApplicable(); + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_customize_post_filter); + + ButterKnife.bind(this); + + applyCustomTheme(); + + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { + Slidr.attach(this); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + setToolbarGoToTop(toolbar); + + + } + + @Override + protected SharedPreferences getDefaultSharedPreferences() { + return mSharedPreferences; + } + + @Override + protected CustomThemeWrapper getCustomThemeWrapper() { + return mCustomThemeWrapper; + } + + @Override + protected void applyCustomTheme() { + coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + titleExcludesStringsTextInputEditText.setTextColor(primaryTextColor); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.customize_post_filter_activity, menu); + applyMenuItemTheme(menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } else if (item.getItemId() == R.id.action_save_customize_post_filter_activity) { + + } + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java index 1fa98963..a8775ea7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.activities; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; @@ -329,7 +330,8 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec } fab.setOnClickListener(view -> { - + Intent intent = new Intent(this, CustomizePostFilterActivity.class); + startActivity(intent); }); if (mAccessToken != null) { diff --git a/app/src/main/res/layout/activity_customize_post_filter.xml b/app/src/main/res/layout/activity_customize_post_filter.xml new file mode 100644 index 00000000..084f83d7 --- /dev/null +++ b/app/src/main/res/layout/activity_customize_post_filter.xml @@ -0,0 +1,390 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/customize_post_filter_activity.xml b/app/src/main/res/menu/customize_post_filter_activity.xml new file mode 100644 index 00000000..87b5521a --- /dev/null +++ b/app/src/main/res/menu/customize_post_filter_activity.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7e7ed640..baa52b3f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,6 +34,7 @@ Crosspost Give Award r/all and r/popular + Post Filter Open navigation drawer Close navigation drawer @@ -950,7 +951,18 @@ Select Video Quality Hide Read Posts - - Hello blank fragment + + Title: excludes keywords + Title: excludes regex + Excludes subreddits + Excludes users + Exclude flairs + Contains flairs + Min vote + Max vote + Min comments + Max comments + Min awards + Max awards -- cgit v1.2.3