diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-12-09 07:01:17 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-12-09 07:01:17 +0000 |
commit | fa5008ea5e304693423ce4850234aea51faca15b (patch) | |
tree | b3dd3f8c73ac383252fa3c5268870ba717cc3021 /app/src/main/java | |
parent | 459f75b749865ed8501b22dcb5f9a600fb9ad950 (diff) | |
download | infinity-for-reddit-fa5008ea5e304693423ce4850234aea51faca15b.tar infinity-for-reddit-fa5008ea5e304693423ce4850234aea51faca15b.tar.gz infinity-for-reddit-fa5008ea5e304693423ce4850234aea51faca15b.tar.bz2 infinity-for-reddit-fa5008ea5e304693423ce4850234aea51faca15b.tar.lz infinity-for-reddit-fa5008ea5e304693423ce4850234aea51faca15b.tar.xz infinity-for-reddit-fa5008ea5e304693423ce4850234aea51faca15b.tar.zst infinity-for-reddit-fa5008ea5e304693423ce4850234aea51faca15b.zip |
Hide read posts in FilteredThingActivity. Prepare to add support for filters.
Diffstat (limited to 'app/src/main/java')
3 files changed, 124 insertions, 6 deletions
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); |