mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Add an option to disable swiping between tabs in MainActivity.
This commit is contained in:
parent
8ce4a0ef6b
commit
7c23be5d2f
@ -72,6 +72,7 @@ import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSh
|
||||
import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTypeBottomSheetFragment;
|
||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeConfirmToExitEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDisableSwipingBetweenTabsEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeLockBottomAppBarEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
|
||||
@ -199,6 +200,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
private boolean showBottomAppBar;
|
||||
private boolean mConfirmToExit;
|
||||
private boolean mLockBottomAppBar;
|
||||
private boolean mDisableSwipingBetweenTabs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -265,6 +267,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false);
|
||||
mConfirmToExit = mSharedPreferences.getBoolean(SharedPreferencesUtils.CONFIRM_TO_EXIT, false);
|
||||
mLockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
|
||||
mDisableSwipingBetweenTabs = mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
||||
@ -585,7 +588,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle());
|
||||
viewPager2.setAdapter(sectionsPagerAdapter);
|
||||
viewPager2.setOffscreenPageLimit(3);
|
||||
viewPager2.requestDisallowInterceptTouchEvent(true);
|
||||
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
|
||||
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
|
||||
if (mAccessToken == null) {
|
||||
switch (position) {
|
||||
@ -963,6 +966,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
mLockBottomAppBar = changeLockBottomAppBarEvent.lockBottomAppBar;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChangeDisableSwipingBetweenTabsEvent(ChangeDisableSwipingBetweenTabsEvent changeDisableSwipingBetweenTabsEvent) {
|
||||
mDisableSwipingBetweenTabs = changeDisableSwipingBetweenTabsEvent.disableSwipingBetweenTabs;
|
||||
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress() {
|
||||
if (sectionsPagerAdapter != null) {
|
||||
|
@ -0,0 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit.Event;
|
||||
|
||||
public class ChangeDisableSwipingBetweenTabsEvent {
|
||||
public boolean disableSwipingBetweenTabs;
|
||||
|
||||
public ChangeDisableSwipingBetweenTabsEvent(boolean disableSwipingBetweenTabs) {
|
||||
this.disableSwipingBetweenTabs = disableSwipingBetweenTabs;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeDisableSwipingBetweenTabsEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
@ -18,6 +19,7 @@ public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat {
|
||||
setPreferencesFromResource(R.xml.swipe_action_preferences, rootKey);
|
||||
|
||||
SwitchPreference vibrateWhenActionTriggeredSwitch = findPreference(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED);
|
||||
SwitchPreference disableSwipingBetweenTabsSwitch = findPreference(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS);
|
||||
|
||||
if (vibrateWhenActionTriggeredSwitch != null) {
|
||||
vibrateWhenActionTriggeredSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
@ -25,5 +27,12 @@ public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (disableSwipingBetweenTabsSwitch != null) {
|
||||
disableSwipingBetweenTabsSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
EventBus.getDefault().post(new ChangeDisableSwipingBetweenTabsEvent((Boolean) newValue));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -120,6 +120,7 @@ public class SharedPreferencesUtils {
|
||||
public static final String VIDEO_DOWNLOAD_LOCATION = "video_download_location";
|
||||
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 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";
|
||||
|
@ -480,6 +480,7 @@
|
||||
<string name="settings_separate_folder_for_each_subreddit">Separate Folder for Each Subreddit</string>
|
||||
<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="no_link_available">Cannot get the link</string>
|
||||
|
||||
|
@ -6,4 +6,9 @@
|
||||
app:key="vibrate_when_action_triggered"
|
||||
app:title="@string/settings_vibrate_when_action_triggered_title" />
|
||||
|
||||
<SwitchPreference
|
||||
app:defaultValue="false"
|
||||
app:key="disable_swiping_between_tabs"
|
||||
app:title="@string/settings_disable_swiping_between_tabs_title" />
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user