Add an option to enable swipe action. Fix text color in FlairBottomSheetFragment.

This commit is contained in:
Alex Ning 2020-09-15 23:43:26 +08:00
parent 7c23be5d2f
commit 9444599f4b
7 changed files with 44 additions and 4 deletions

View File

@ -26,13 +26,13 @@ import ml.docilealligator.infinityforreddit.R;
public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<FlairBottomSheetRecyclerViewAdapter.FlairViewHolder> {
private Context context;
private ArrayList<Flair> flairs;
private int flairColor;
private int flairTextColor;
private ItemClickListener itemClickListener;
public FlairBottomSheetRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper,
ItemClickListener itemClickListener) {
this.context = context;
flairColor = customThemeWrapper.getFlairBackgroundColor();
flairTextColor = customThemeWrapper.getPrimaryTextColor();
this.itemClickListener = itemClickListener;
}
@ -108,7 +108,7 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<Fl
super(itemView);
ButterKnife.bind(this, itemView);
this.itemView = itemView;
flairTextView.setTextColor(flairColor);
flairTextView.setTextColor(flairTextColor);
}
}
}

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.Event;
public class ChangeEnableSwipeActionSwitchEvent {
public boolean enableSwipeAction;
public ChangeEnableSwipeActionSwitchEvent(boolean enableSwipeAction) {
this.enableSwipeAction = enableSwipeAction;
}
}

View File

@ -69,6 +69,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeMuteNSFWVideoEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
@ -173,6 +174,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private boolean isShown = false;
private boolean savePostFeedScrolledPosition;
private boolean vibrateWhenActionTriggered;
private boolean enableSwipeAction;
private PostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller smoothScroller;
private Window window;
@ -399,6 +401,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true);
enableSwipeAction = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false);
Locale locale = getResources().getConfiguration().locale;
if (postType == PostDataSource.TYPE_SEARCH) {
@ -729,7 +732,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
});
touchHelper.attachToRecyclerView(mPostRecyclerView);
if (enableSwipeAction) {
touchHelper.attachToRecyclerView(mPostRecyclerView);
}
mPostRecyclerView.setAdapter(mAdapter);
mPostRecyclerView.setCacheManager(mAdapter);
mPostRecyclerView.setPlayerInitializer(order -> {
@ -1186,6 +1191,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
vibrateWhenActionTriggered = changeVibrateWhenActionTriggeredEvent.vibrateWhenActionTriggered;
}
@Subscribe
public void onChangeEnableSwipeActionSwitchEvent(ChangeEnableSwipeActionSwitchEvent changeEnableSwipeActionSwitchEvent) {
if (touchHelper != null) {
if (changeEnableSwipeActionSwitchEvent.enableSwipeAction) {
touchHelper.attachToRecyclerView(mPostRecyclerView);
} else {
touchHelper.attachToRecyclerView(null);
}
}
}
private void refreshAdapter() {
int previousPosition = -1;
if (mLinearLayoutManager != null) {

View File

@ -8,6 +8,7 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.Event.ChangeDisableSwipingBetweenTabsEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@ -18,9 +19,16 @@ public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.swipe_action_preferences, rootKey);
SwitchPreference enableSwipeActionSwitch = findPreference(SharedPreferencesUtils.ENABLE_SWIPE_ACTION);
SwitchPreference vibrateWhenActionTriggeredSwitch = findPreference(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED);
SwitchPreference disableSwipingBetweenTabsSwitch = findPreference(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS);
if (enableSwipeActionSwitch != null) {
enableSwipeActionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeEnableSwipeActionSwitchEvent((Boolean) newValue));
return true;
});
}
if (vibrateWhenActionTriggeredSwitch != null) {
vibrateWhenActionTriggeredSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeVibrateWhenActionTriggeredEvent((Boolean) newValue));

View File

@ -121,6 +121,7 @@ public class SharedPreferencesUtils {
public static final String SEPARATE_FOLDER_FOR_EACH_SUBREDDIT = "separate_folder_for_each_subreddit";
public static final String VIBRATE_WHEN_ACTION_TRIGGERED = "vibrate_when_action_triggered";
public static final String DISABLE_SWIPING_BETWEEN_TABS = "disable_swiping_between_tabs";
public static final String ENABLE_SWIPE_ACTION = "enable_swipe_action";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
public static final String MAIN_PAGE_TAB_1_TITLE = "_main_page_tab_1_title";

View File

@ -481,6 +481,7 @@
<string name="settings_swipe_action_title">Swipe Action</string>
<string name="settings_vibrate_when_action_triggered_title">Vibrate the phone when the action is triggered</string>
<string name="settings_disable_swiping_between_tabs_title">Disable Swiping Between Tabs</string>
<string name="settings_enable_swipe_action_title">Enable Swipe Action</string>
<string name="no_link_available">Cannot get the link</string>

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreference
app:defaultValue="false"
app:key="enable_swipe_action"
app:title="@string/settings_enable_swipe_action_title" />
<SwitchPreference
app:defaultValue="true"
app:key="vibrate_when_action_triggered"