New option in fab: go to top.

This commit is contained in:
Docile-Alligator 2022-12-25 16:05:04 -08:00
parent 24b33bb05d
commit b74fc9354c
10 changed files with 132 additions and 46 deletions

View File

@ -697,6 +697,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24);
break;
default:
if (mAccessToken == null) {
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
@ -747,6 +750,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
sectionsPagerAdapter.filterPosts();
}
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
@ -1368,6 +1376,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
break;
}
case FABMoreOptionsBottomSheetFragment.FAB_GO_TO_TOP: {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
}
}
}

View File

@ -298,7 +298,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_hide_read_posts_24dp);
}
@ -306,10 +306,13 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
fab.setImageResource(R.drawable.ic_filter_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
fab.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24);
break;
default:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_add_day_night_24dp);
}
@ -363,6 +366,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
sectionsPagerAdapter.filterPosts();
}
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
@ -561,6 +569,12 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
break;
}
case FABMoreOptionsBottomSheetFragment.FAB_GO_TO_TOP: {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
}
}
}

View File

@ -339,7 +339,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS:
if (mAccessToken == null) {
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_hide_read_posts_24dp);
}
@ -347,10 +347,13 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24);
break;
default:
if (mAccessToken == null) {
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_add_day_night_24dp);
}
@ -396,6 +399,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
((PostFragment) mFragment).filterPosts();
}
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
if (mFragment instanceof PostFragment) {
((PostFragment) mFragment).goBackToTop();
}
break;
default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
@ -964,6 +972,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
}
break;
}
case FABMoreOptionsBottomSheetFragment.FAB_GO_TO_TOP: {
if (mFragment instanceof PostFragment) {
((PostFragment) mFragment).goBackToTop();
}
break;
}
}
}

View File

@ -867,6 +867,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24);
break;
default:
if (mAccessToken == null) {
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
@ -918,6 +921,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
sectionsPagerAdapter.filterPosts();
}
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
@ -1378,6 +1386,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
break;
}
case FABMoreOptionsBottomSheetFragment.FAB_GO_TO_TOP: {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
}
}
}

View File

@ -830,6 +830,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24);
break;
default:
if (mAccessToken == null) {
navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp);
@ -880,6 +883,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
sectionsPagerAdapter.filterPosts();
}
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP:
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
@ -1320,6 +1328,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
break;
}
case FABMoreOptionsBottomSheetFragment.FAB_GO_TO_TOP: {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
break;
}
}
}

View File

@ -6,15 +6,12 @@ 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 butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import ml.docilealligator.infinityforreddit.databinding.FragmentFabMoreOptionsBottomSheetBinding;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class FABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
@ -30,27 +27,8 @@ public class FABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedB
public static final int FAB_RANDOM = 7;
public static final int FAB_HIDE_READ_POSTS = 8;
public static final int FAB_FILTER_POSTS = 9;
public static final int FAB_GO_TO_TOP = 10;
@BindView(R.id.submit_post_text_view_fab_more_options_bottom_sheet_fragment)
TextView submitPostTextView;
@BindView(R.id.refresh_text_view_fab_more_options_bottom_sheet_fragment)
TextView refreshTextView;
@BindView(R.id.change_sort_type_text_view_fab_more_options_bottom_sheet_fragment)
TextView changeSortTypeTextView;
@BindView(R.id.change_post_layout_text_view_fab_more_options_bottom_sheet_fragment)
TextView changePostLayoutTextView;
@BindView(R.id.search_text_view_fab_more_options_bottom_sheet_fragment)
TextView searchTextView;
@BindView(R.id.go_to_subreddit_text_view_fab_more_options_bottom_sheet_fragment)
TextView goToSubredditTextView;
@BindView(R.id.go_to_user_text_view_fab_more_options_bottom_sheet_fragment)
TextView goToUserTextView;
@BindView(R.id.random_text_view_fab_more_options_bottom_sheet_fragment)
TextView randomTextView;
@BindView(R.id.hide_read_posts_text_view_fab_more_options_bottom_sheet_fragment)
TextView hideReadPostsTextView;
@BindView(R.id.filter_posts_text_view_fab_more_options_bottom_sheet_fragment)
TextView filterPostsTextView;
private FABOptionSelectionCallback activity;
public FABMoreOptionsBottomSheetFragment() {
@ -58,76 +36,79 @@ public class FABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedB
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_fab_more_options_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
FragmentFabMoreOptionsBottomSheetBinding binding = FragmentFabMoreOptionsBottomSheetBinding.inflate(inflater, container, false);
if (getArguments() != null && getArguments().getBoolean(EXTRA_ANONYMOUS_MODE, false)) {
submitPostTextView.setVisibility(View.GONE);
hideReadPostsTextView.setVisibility(View.GONE);
binding.submitPostTextViewFabMoreOptionsBottomSheetFragment.setVisibility(View.GONE);
binding.hideReadPostsTextViewFabMoreOptionsBottomSheetFragment.setVisibility(View.GONE);
} else {
submitPostTextView.setOnClickListener(view -> {
binding.submitPostTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_OPTION_SUBMIT_POST);
dismiss();
});
hideReadPostsTextView.setOnClickListener(view -> {
binding.hideReadPostsTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_HIDE_READ_POSTS);
dismiss();
});
}
refreshTextView.setOnClickListener(view -> {
binding.refreshTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_OPTION_REFRESH);
dismiss();
});
changeSortTypeTextView.setOnClickListener(view -> {
binding.changeSortTypeTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_OPTION_CHANGE_SORT_TYPE);
dismiss();
});
changePostLayoutTextView.setOnClickListener(view -> {
binding.changePostLayoutTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_OPTION_CHANGE_POST_LAYOUT);
dismiss();
});
searchTextView.setOnClickListener(view -> {
binding.searchTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_OPTION_SEARCH);
dismiss();
});
goToSubredditTextView.setOnClickListener(view -> {
binding.goToSubredditTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_OPTION_GO_TO_SUBREDDIT);
dismiss();
});
goToUserTextView.setOnClickListener(view -> {
binding.goToUserTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_OPTION_GO_TO_USER);
dismiss();
});
randomTextView.setOnClickListener(view -> {
binding.randomTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_RANDOM);
dismiss();
});
filterPostsTextView.setOnClickListener(view -> {
binding.filterPostsTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_FILTER_POSTS);
dismiss();
});
binding.goToTopTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.fabOptionSelected(FAB_GO_TO_TOP);
dismiss();
});
Activity baseActivity = getActivity();
if (baseActivity instanceof BaseActivity) {
if (((BaseActivity) baseActivity).typeface != null) {
Utils.setFontToAllTextViews(rootView, ((BaseActivity) baseActivity).typeface);
Utils.setFontToAllTextViews(binding.getRoot(), ((BaseActivity) baseActivity).typeface);
}
}
return rootView;
return binding.getRoot();
}
@Override

View File

@ -291,6 +291,7 @@ public class SharedPreferencesUtils {
public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM = 7;
public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS = 8;
public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS = 9;
public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_TOP = 10;
public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME = 0;
public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS = 1;
@ -324,6 +325,7 @@ public class SharedPreferencesUtils {
public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_RANDOM = 7;
public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS = 8;
public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS = 9;
public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_TOP = 10;
public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler";
public static final String NSFW_BASE = "_nsfw";

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,17.59l1.41,1.41l4.59,-4.58l4.59,4.58l1.41,-1.41l-6,-6z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M6,11l1.41,1.41l4.59,-4.58l4.59,4.58l1.41,-1.41l-6,-6z"/>
</vector>

View File

@ -201,6 +201,25 @@
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/go_to_top_text_view_fab_more_options_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/go_to_top"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
app:drawableStartCompat="@drawable/ic_keyboard_double_arrow_up_24"
android:drawablePadding="48dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -400,6 +400,7 @@
<item>@string/random</item>
<item>@string/hide_read_posts</item>
<item>@string/filter_posts</item>
<item>@string/go_to_top</item>
</string-array>
<string-array name="settings_bottom_app_bar_fab_options_anonymous">
@ -411,6 +412,7 @@
<item>@string/go_to_user</item>
<item>@string/random</item>
<item>@string/filter_posts</item>
<item>@string/go_to_top</item>
</string-array>
<string-array name="settings_swipe_action_threshold">