From fa5008ea5e304693423ce4850234aea51faca15b Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 9 Dec 2020 15:01:17 +0800 Subject: Hide read posts in FilteredThingActivity. Prepare to add support for filters. --- .../activities/FilteredThingActivity.java | 56 ++++++++++++++++--- ...eredThingFABMoreOptionsBottomSheetFragment.java | 63 ++++++++++++++++++++++ .../infinityforreddit/fragments/PostFragment.java | 11 ++++ .../main/res/layout/activity_filtered_thing.xml | 8 +++ app/src/main/res/layout/app_bar_main.xml | 1 - ...iltered_thing_fab_more_options_bottom_sheet.xml | 54 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 7 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java create mode 100644 app/src/main/res/layout/fragment_filtered_thing_fab_more_options_bottom_sheet.xml 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 279a8346..1fa98963 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java @@ -13,10 +13,10 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.fragment.app.Fragment; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; @@ -36,6 +36,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.FilteredThingFABMoreOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment; @@ -50,7 +51,8 @@ import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback, - PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, MarkPostAsReadInterface { + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, + MarkPostAsReadInterface, FilteredThingFABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback { public static final String EXTRA_NAME = "ESN"; public static final String EXTRA_QUERY = "EQ"; @@ -72,6 +74,8 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar; + @BindView(R.id.fab_filtered_thing_activity) + FloatingActionButton fab; @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject @@ -89,7 +93,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec private String name; private String userWhere; private int postType; - private Fragment mFragment; + private PostFragment mFragment; private Menu mMenu; private AppBarLayout.LayoutParams params; private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment; @@ -135,6 +139,13 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } adjustToolbar(toolbar); + + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + params.bottomMargin += navBarHeight; + fab.setLayoutParams(params); + } } } @@ -164,7 +175,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec if (!mNullAccessToken && mAccessToken == null) { getCurrentAccountAndBindView(filter); } else { - mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); + mFragment = (PostFragment) getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); bindView(filter, false); } @@ -198,6 +209,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyFABTheme(fab); } private void getCurrentAccountAndBindView(int filter) { @@ -315,6 +327,19 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec mFragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); } + + fab.setOnClickListener(view -> { + + }); + + if (mAccessToken != null) { + fab.setOnLongClickListener(view -> { + FilteredThingFABMoreOptionsBottomSheetFragment filteredThingFABMoreOptionsBottomSheetFragment + = new FilteredThingFABMoreOptionsBottomSheetFragment(); + filteredThingFABMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), filteredThingFABMoreOptionsBottomSheetFragment.getTag()); + return true; + }); + } } @Override @@ -417,7 +442,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec @Override public void sortTypeSelected(SortType sortType) { - ((PostFragment) mFragment).changeSortType(sortType); + mFragment.changeSortType(sortType); } @Override @@ -456,7 +481,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec @Override public void onLongPress() { if (mFragment != null) { - ((PostFragment) mFragment).goBackToTop(); + mFragment.goBackToTop(); } } @@ -464,4 +489,23 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec public void markPostAsRead(Post post) { InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); } + + @Override + public void fabOptionSelected(int option) { + if (option == FilteredThingFABMoreOptionsBottomSheetFragment.FAB_OPTION_FILTER) { + + } else if (option == FilteredThingFABMoreOptionsBottomSheetFragment.FAB_OPTION_HIDE_READ_POSTS) { + if (mFragment != null) { + mFragment.hideReadPosts(); + } + } + } + + public void contentScrollUp() { + fab.show(); + } + + public void contentScrollDown() { + fab.hide(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java new file mode 100644 index 00000000..af70869d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java @@ -0,0 +1,63 @@ +package ml.docilealligator.infinityforreddit.bottomsheetfragments; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; + +public class FilteredThingFABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogFragment { + + public static final int FAB_OPTION_FILTER = 0; + public static final int FAB_OPTION_HIDE_READ_POSTS = 1; + + @BindView(R.id.filter_text_view_filtered_thing_fab_more_options_bottom_sheet_fragment) + TextView filterTextView; + @BindView(R.id.hide_read_posts_text_view_filtered_thing_fab_more_options_bottom_sheet_fragment) + TextView hideReadPostsTextView; + private FABOptionSelectionCallback activity; + + public FilteredThingFABMoreOptionsBottomSheetFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View rootView = inflater.inflate(R.layout.fragment_filtered_thing_fab_more_options_bottom_sheet, container, false); + + ButterKnife.bind(this, rootView); + + filterTextView.setOnClickListener(view -> { + activity.fabOptionSelected(FAB_OPTION_FILTER); + dismiss(); + }); + + hideReadPostsTextView.setOnClickListener(view -> { + activity.fabOptionSelected(FAB_OPTION_HIDE_READ_POSTS); + dismiss(); + }); + + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (FABOptionSelectionCallback) context; + } + + public interface FABOptionSelectionCallback { + void fabOptionSelected(int option); + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 91e2ca0f..0b92bc36 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -426,6 +426,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } }); + } else if (activity instanceof FilteredThingActivity) { + mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + ((FilteredThingActivity) activity).contentScrollDown(); + } else if (dy < 0) { + ((FilteredThingActivity) activity).contentScrollUp(); + } + } + }); } postType = getArguments().getInt(EXTRA_POST_TYPE); diff --git a/app/src/main/res/layout/activity_filtered_thing.xml b/app/src/main/res/layout/activity_filtered_thing.xml index a84e5140..59b857af 100644 --- a/app/src/main/res/layout/activity_filtered_thing.xml +++ b/app/src/main/res/layout/activity_filtered_thing.xml @@ -39,4 +39,12 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 85db79c9..9aef7ff3 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -63,7 +63,6 @@ android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" android:visibility="gone" - app:tint="@android:color/white" app:layout_anchor="@id/bottom_app_bar_bottom_app_bar" /> diff --git a/app/src/main/res/layout/fragment_filtered_thing_fab_more_options_bottom_sheet.xml b/app/src/main/res/layout/fragment_filtered_thing_fab_more_options_bottom_sheet.xml new file mode 100644 index 00000000..c1820f61 --- /dev/null +++ b/app/src/main/res/layout/fragment_filtered_thing_fab_more_options_bottom_sheet.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + \ 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 87b52482..3aa406a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -948,5 +948,7 @@ Select Video Quality Hide Read Posts + + Hello blank fragment -- cgit v1.2.3