Check if PostFragment is detached before initializing PostViewModel.

This commit is contained in:
Docile-Alligator 2022-03-17 14:23:06 +08:00
parent 7405e19c2e
commit b4915859da

View File

@ -911,7 +911,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (postFilter == null) { if (postFilter == null) {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> { new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
initializeAndBindPostViewModel(accessToken); initializeAndBindPostViewModel(accessToken);
@ -923,7 +923,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else { } else {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
new Handler(), accountName, usage, nameOfUsage, (postFilter, readPostList) -> { new Handler(), accountName, usage, nameOfUsage, (postFilter, readPostList) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
if (this.postFilter == null) { if (this.postFilter == null) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
@ -937,7 +937,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (postFilter == null) { if (postFilter == null) {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> { new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
initializeAndBindPostViewModel(accessToken); initializeAndBindPostViewModel(accessToken);
@ -953,7 +953,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (concatenatedSubredditNames == null) { if (concatenatedSubredditNames == null) {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage,
(postFilter, concatenatedSubredditNames) -> { (postFilter, concatenatedSubredditNames) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
this.concatenatedSubredditNames = concatenatedSubredditNames; this.concatenatedSubredditNames = concatenatedSubredditNames;
@ -971,7 +971,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (concatenatedSubredditNames == null) { if (concatenatedSubredditNames == null) {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), multiRedditPath, usage, nameOfUsage, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), multiRedditPath, usage, nameOfUsage,
(postFilter, concatenatedSubredditNames) -> { (postFilter, concatenatedSubredditNames) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
this.concatenatedSubredditNames = concatenatedSubredditNames; this.concatenatedSubredditNames = concatenatedSubredditNames;
@ -988,7 +988,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else { } else {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor,
new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> { new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
initializeAndBindPostViewModelForAnonymous(null); initializeAndBindPostViewModelForAnonymous(null);
@ -1000,7 +1000,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (concatenatedSubredditNames == null) { if (concatenatedSubredditNames == null) {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), usage, nameOfUsage,
(postFilter, concatenatedSubredditNames) -> { (postFilter, concatenatedSubredditNames) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
this.concatenatedSubredditNames = concatenatedSubredditNames; this.concatenatedSubredditNames = concatenatedSubredditNames;
@ -1018,7 +1018,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (concatenatedSubredditNames == null) { if (concatenatedSubredditNames == null) {
FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), multiRedditPath, usage, nameOfUsage, FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndConcatenatedSubredditNames(mRedditDataRoomDatabase, mExecutor, new Handler(), multiRedditPath, usage, nameOfUsage,
(postFilter, concatenatedSubredditNames) -> { (postFilter, concatenatedSubredditNames) -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
this.postFilter = postFilter; this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false); postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
this.concatenatedSubredditNames = concatenatedSubredditNames; this.concatenatedSubredditNames = concatenatedSubredditNames;