Fix ViewPager2 swipe sensitivity in other activites.

This commit is contained in:
Alex Ning 2020-11-06 12:12:07 +08:00
parent 4d1668d0a8
commit 50f5612a14
6 changed files with 30 additions and 12 deletions

View File

@ -221,6 +221,8 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
}
});
fixViewPager2Sensitivity(viewPager2);
}
@Override

View File

@ -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) {}
}
}

View File

@ -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();

View File

@ -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);

View File

@ -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) {

View File

@ -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