diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-11-06 04:12:07 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-11-06 04:12:07 +0000 |
commit | 50f5612a1451391d490bc3f8223619220c3a060c (patch) | |
tree | 22952f74e3ba0546aa3b4ffa348cdc43bd1d7ff2 /app/src | |
parent | 4d1668d0a8fc107e1b460be7f1b249de9beaac96 (diff) | |
download | infinity-for-reddit-50f5612a1451391d490bc3f8223619220c3a060c.tar infinity-for-reddit-50f5612a1451391d490bc3f8223619220c3a060c.tar.gz infinity-for-reddit-50f5612a1451391d490bc3f8223619220c3a060c.tar.bz2 infinity-for-reddit-50f5612a1451391d490bc3f8223619220c3a060c.tar.lz infinity-for-reddit-50f5612a1451391d490bc3f8223619220c3a060c.tar.xz infinity-for-reddit-50f5612a1451391d490bc3f8223619220c3a060c.tar.zst infinity-for-reddit-50f5612a1451391d490bc3f8223619220c3a060c.zip |
Fix ViewPager2 swipe sensitivity in other activites.
Diffstat (limited to '')
6 files changed, 30 insertions, 12 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java index 6da1325d..d278848c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -221,6 +221,8 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT } } }); + + fixViewPager2Sensitivity(viewPager2); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java index 17e3eebe..478a717c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java @@ -21,11 +21,15 @@ import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.view.menu.MenuItemImpl; import androidx.appcompat.widget.Toolbar; import androidx.core.graphics.drawable.DrawableCompat; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager2.widget.ViewPager2; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; +import java.lang.reflect.Field; + import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; @@ -301,4 +305,22 @@ public abstract class BaseActivity extends AppCompatActivity { fab.setBackgroundTintList(ColorStateList.valueOf(customThemeWrapper.getColorPrimaryLightTheme())); fab.setImageTintList(ColorStateList.valueOf(customThemeWrapper.getFABIconColor())); } + + protected void fixViewPager2Sensitivity(ViewPager2 viewPager2) { + try { + Field recyclerViewField = ViewPager2.class.getDeclaredField("mRecyclerView"); + recyclerViewField.setAccessible(true); + + RecyclerView recyclerView = (RecyclerView) recyclerViewField.get(viewPager2); + + Field touchSlopField = RecyclerView.class.getDeclaredField("mTouchSlop"); + touchSlopField.setAccessible(true); + + Object touchSlopBox = touchSlopField.get(recyclerView); + if (touchSlopBox != null) { + int touchSlop = (int) touchSlopBox; + touchSlopField.set(recyclerView, touchSlop * 4); + } + } catch (NoSuchFieldException | IllegalAccessException ignore) {} + } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 0826ce6d..bf354c21 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -815,18 +815,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } }); - try { - Field recyclerViewField = ViewPager2.class.getDeclaredField("mRecyclerView"); - recyclerViewField.setAccessible(true); - - RecyclerView recyclerView = (RecyclerView) recyclerViewField.get(viewPager2); - - Field touchSlopField = RecyclerView.class.getDeclaredField("mTouchSlop"); - touchSlopField.setAccessible(true); - - int touchSlop = (int) touchSlopField.get(recyclerView); - touchSlopField.set(recyclerView, touchSlop * 4); - } catch (NoSuchFieldException | IllegalAccessException ignore) {} + fixViewPager2Sensitivity(viewPager2); loadSubscriptions(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java index bd6cd543..89d2faf3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -249,6 +249,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect break; } }).attach(); + fixViewPager2Sensitivity(viewPager2); + if (mAccountName != null && !mInsertSearchQuerySuccess && mQuery != null) { InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountName, mQuery, () -> mInsertSearchQuerySuccess = true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index 2492b7ef..b5310569 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -838,6 +838,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp tab.setText(R.string.sidebar); } }).attach(); + fixViewPager2Sensitivity(viewPager2); boolean viewSidebar = getIntent().getBooleanExtra(EXTRA_VIEW_SIDEBAR, false); if (viewSidebar) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index c309e899..f365dda4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -562,6 +562,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } }); + fixViewPager2Sensitivity(viewPager2); + if (mAccessToken != null && mMessageFullname != null) { ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { @Override |