Try fixing IllegalArgumentException at androidx.viewpager.widget.ViewPager.onInterceptTouchEvent.

This commit is contained in:
Alex Ning 2021-08-19 21:50:36 +08:00
parent b3eb20862a
commit 54785beede
10 changed files with 63 additions and 23 deletions

View File

@ -1,5 +1,10 @@
package ml.docilealligator.infinityforreddit.activities;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
@ -43,22 +48,18 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeSettingsItem;
import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontStyle;
import ml.docilealligator.infinityforreddit.font.TitleFontStyle;
import ml.docilealligator.infinityforreddit.fragments.ThemePreviewCommentsFragment;
import ml.docilealligator.infinityforreddit.fragments.ThemePreviewPostsFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
public class CustomThemePreviewActivity extends AppCompatActivity {
public static final String EXTRA_CUSTOM_THEME_SETTINGS_ITEMS = "ECTSI";
@ -66,7 +67,7 @@ public class CustomThemePreviewActivity extends AppCompatActivity {
@BindView(R.id.coordinator_layout_theme_preview_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.view_pager_theme_preview_activity)
ViewPager viewPager;
ViewPagerBugFixed viewPager;
@BindView(R.id.appbar_layout_theme_preview_activity)
AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_theme_preview_activity)

View File

@ -47,6 +47,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent;
import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
@ -77,7 +78,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
@BindView(R.id.tab_layout_subscribed_thing_listing_activity)
TabLayout tabLayout;
@BindView(R.id.view_pager_subscribed_thing_listing_activity)
ViewPager viewPager;
ViewPagerBugFixed viewPager;
@BindView(R.id.fab_subscribed_thing_listing_activity)
FloatingActionButton fab;
@Inject

View File

@ -36,7 +36,13 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ImgurMedia;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
import ml.docilealligator.infinityforreddit.WallpaperSetter;
import ml.docilealligator.infinityforreddit.apis.ImgurAPI;
import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontFamily;
@ -45,14 +51,9 @@ import ml.docilealligator.infinityforreddit.font.TitleFontFamily;
import ml.docilealligator.infinityforreddit.font.TitleFontStyle;
import ml.docilealligator.infinityforreddit.fragments.ViewImgurImageFragment;
import ml.docilealligator.infinityforreddit.fragments.ViewImgurVideoFragment;
import ml.docilealligator.infinityforreddit.ImgurMedia;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.WallpaperSetter;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@ -72,7 +73,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
@BindView(R.id.progress_bar_view_imgur_media_activity)
ProgressBar progressBar;
@BindView(R.id.view_pager_view_imgur_media_activity)
ViewPager viewPager;
ViewPagerBugFixed viewPager;
@BindView(R.id.load_image_error_linear_layout_view_imgur_media_activity)
LinearLayout errorLinearLayout;
private SectionsPagerAdapter sectionsPagerAdapter;

View File

@ -28,6 +28,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontFamily;
@ -51,7 +52,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
@BindView(R.id.hauler_view_view_reddit_gallery_activity)
HaulerView haulerView;
@BindView(R.id.view_pager_view_reddit_gallery_activity)
ViewPager viewPager;
ViewPagerBugFixed viewPager;
private SectionsPagerAdapter sectionsPagerAdapter;
private ArrayList<Post.Gallery> gallery;
private String subredditName;

View File

@ -0,0 +1,37 @@
package ml.docilealligator.infinityforreddit.customviews;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
public class ViewPagerBugFixed extends ViewPager {
public ViewPagerBugFixed(@NonNull Context context) {
super(context);
}
public ViewPagerBugFixed(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException ignore) {}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException ignore) {}
return false;
}
}

View File

@ -6,7 +6,6 @@ import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;

View File

@ -45,7 +45,7 @@
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
<ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed
android:id="@+id/view_pager_subscribed_thing_listing_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -7,7 +7,7 @@
android:id="@+id/coordinator_layout_theme_preview_activity"
tools:context=".activities.CustomThemePreviewActivity">
<androidx.viewpager.widget.ViewPager
<ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed
android:id="@+id/view_pager_theme_preview_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -23,10 +23,10 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<androidx.viewpager.widget.ViewPager
<ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed
android:id="@+id/view_pager_view_imgur_media_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/view_pager_view_imgur_media_activity" />
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/load_image_error_linear_layout_view_imgur_media_activity"

View File

@ -13,7 +13,7 @@
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.viewpager.widget.ViewPager
<ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed
android:id="@+id/view_pager_view_reddit_gallery_activity"
android:layout_width="match_parent"
android:layout_height="match_parent" />