From 6e211a582135c1d12cd2e7ff036ad6e40c8e82f2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 3 Feb 2020 23:01:03 +0800 Subject: Fix crashes on scrolling posts using volume keys. --- .../infinityforreddit/Activity/AccountPostsActivity.java | 6 +++++- .../infinityforreddit/Activity/AccountSavedThingActivity.java | 6 +++++- .../infinityforreddit/Activity/FilteredThingActivity.java | 6 +++++- .../infinityforreddit/Activity/MainActivity.java | 6 +++++- .../infinityforreddit/Activity/SearchResultActivity.java | 5 ++++- .../infinityforreddit/Activity/ViewPostDetailActivity.java | 8 ++++++-- .../Activity/ViewSubredditDetailActivity.java | 10 ++++++++-- .../infinityforreddit/Activity/ViewUserDetailActivity.java | 6 +++++- 8 files changed, 43 insertions(+), 10 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java index ede80722..e855177d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -161,7 +161,11 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - return ((FragmentCommunicator) mFragment).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + if (mFragment != null) { + return ((FragmentCommunicator) mFragment).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + } + + return super.onKeyDown(keyCode, event); } @Override 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 1e1e7447..7f3f0341 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -154,7 +154,11 @@ public class AccountSavedThingActivity extends BaseActivity { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + if (sectionsPagerAdapter != null) { + return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + } + + return super.onKeyDown(keyCode, event); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index 71123450..bb2e40f6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -180,7 +180,11 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - return ((FragmentCommunicator) mFragment).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + if (mFragment != null) { + return ((FragmentCommunicator) mFragment).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + } + + return super.onKeyDown(keyCode, event); } @Override 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 865525d2..862ab95d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -942,7 +942,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + if (sectionsPagerAdapter != null) { + return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + } + + return super.onKeyDown(keyCode, event); } @Override 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 f077ee54..96685fec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -173,7 +173,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + if (sectionsPagerAdapter != null) { + return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + } + return super.onKeyDown(keyCode, event); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index e516cdfc..63ebd1ce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -1564,10 +1564,14 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } public void lockSwipeRightToGoBack() { - mSlidrInterface.lock(); + if (mSlidrInterface != null) { + mSlidrInterface.lock(); + } } public void unlockSwipeRightToGoBack() { - mSlidrInterface.unlock(); + if (mSlidrInterface != null) { + mSlidrInterface.unlock(); + } } } 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 77cbe4b9..cbec2aba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -336,7 +336,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - return ((FragmentCommunicator)(mFragment)).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + if (mFragment != null) { + return ((FragmentCommunicator)(mFragment)).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + } + + return super.onKeyDown(keyCode, event); } @Override @@ -645,7 +649,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST, sortType.getTime().name()).apply(); } - ((PostFragment) mFragment).changeSortType(sortType); + if (mFragment != null) { + ((PostFragment) mFragment).changeSortType(sortType); + } } @Override 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 90695fde..53eb9720 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -399,7 +399,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + if (sectionsPagerAdapter != null) { + return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event); + } + + return super.onKeyDown(keyCode, event); } @Override -- cgit v1.2.3