mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-29 04:17:12 +01:00
Merge pull request #573 from scria1000/patch-3
Fix observer being triggered twice on SubredditDetail
This commit is contained in:
commit
99c096e111
@ -142,7 +142,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
||||||
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
||||||
private static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 1;
|
private static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 1;
|
||||||
|
public SubredditViewModel mSubredditViewModel;
|
||||||
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity)
|
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@BindView(R.id.view_pager_view_subreddit_detail_activity)
|
@BindView(R.id.view_pager_view_subreddit_detail_activity)
|
||||||
@ -219,7 +219,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
public SubredditViewModel mSubredditViewModel;
|
|
||||||
private FragmentManager fragmentManager;
|
private FragmentManager fragmentManager;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private Call<String> subredditAutocompleteCall;
|
private Call<String> subredditAutocompleteCall;
|
||||||
@ -248,6 +247,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
private int fabOption;
|
private int fabOption;
|
||||||
private SlidrInterface mSlidrInterface;
|
private SlidrInterface mSlidrInterface;
|
||||||
private MaterialAlertDialogBuilder nsfwWarningBuilder;
|
private MaterialAlertDialogBuilder nsfwWarningBuilder;
|
||||||
|
private boolean isOnCreateActivity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -370,6 +370,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
|
|
||||||
checkNewAccountAndBindView();
|
checkNewAccountAndBindView();
|
||||||
|
|
||||||
|
isOnCreateActivity = true;
|
||||||
fetchSubredditData();
|
fetchSubredditData();
|
||||||
|
|
||||||
String title = "r/" + subredditName;
|
String title = "r/" + subredditName;
|
||||||
@ -590,9 +591,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||||
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
|
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
|
||||||
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers));
|
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers));
|
||||||
|
if (isOnCreateActivity) {
|
||||||
|
mFetchSubredditInfoSuccess = true;
|
||||||
|
isOnCreateActivity = false;
|
||||||
|
} else {
|
||||||
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||||
subredditData, () -> mFetchSubredditInfoSuccess = true);
|
subredditData, () -> mFetchSubredditInfoSuccess = true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||||
@ -633,7 +639,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
}
|
}
|
||||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH: {
|
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH: {
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
sectionsPagerAdapter.refresh();
|
sectionsPagerAdapter.refresh(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -878,7 +884,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
switch (fabOption) {
|
switch (fabOption) {
|
||||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: {
|
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: {
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
sectionsPagerAdapter.refresh();
|
sectionsPagerAdapter.refresh(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1105,9 +1111,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_refresh_view_subreddit_detail_activity) {
|
} else if (itemId == R.id.action_refresh_view_subreddit_detail_activity) {
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
sectionsPagerAdapter.refresh();
|
sectionsPagerAdapter.refresh(true);
|
||||||
mFetchSubredditInfoSuccess = false;
|
|
||||||
fetchSubredditData();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_change_post_layout_view_subreddit_detail_activity) {
|
} else if (itemId == R.id.action_change_post_layout_view_subreddit_detail_activity) {
|
||||||
@ -1333,7 +1337,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
break;
|
break;
|
||||||
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH:
|
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH:
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
sectionsPagerAdapter.refresh();
|
sectionsPagerAdapter.refresh(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE:
|
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE:
|
||||||
@ -1541,6 +1545,18 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void lockSwipeRightToGoBack() {
|
||||||
|
if (mSlidrInterface != null) {
|
||||||
|
mSlidrInterface.lock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unlockSwipeRightToGoBack() {
|
||||||
|
if (mSlidrInterface != null) {
|
||||||
|
mSlidrInterface.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class SectionsPagerAdapter extends FragmentStateAdapter {
|
private class SectionsPagerAdapter extends FragmentStateAdapter {
|
||||||
|
|
||||||
SectionsPagerAdapter(FragmentActivity fa) {
|
SectionsPagerAdapter(FragmentActivity fa) {
|
||||||
@ -1585,10 +1601,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh(boolean refreshSubredditData) {
|
||||||
Fragment fragment = getCurrentFragment();
|
Fragment fragment = getCurrentFragment();
|
||||||
if (fragment instanceof PostFragment) {
|
if (fragment instanceof PostFragment) {
|
||||||
((PostFragment) fragment).refresh();
|
((PostFragment) fragment).refresh();
|
||||||
|
if (refreshSubredditData) {
|
||||||
|
mFetchSubredditInfoSuccess = false;
|
||||||
|
fetchSubredditData();
|
||||||
|
}
|
||||||
} else if (fragment instanceof SidebarFragment) {
|
} else if (fragment instanceof SidebarFragment) {
|
||||||
((SidebarFragment) fragment).fetchSubredditData();
|
((SidebarFragment) fragment).fetchSubredditData();
|
||||||
}
|
}
|
||||||
@ -1658,16 +1678,4 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lockSwipeRightToGoBack() {
|
|
||||||
if (mSlidrInterface != null) {
|
|
||||||
mSlidrInterface.lock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void unlockSwipeRightToGoBack() {
|
|
||||||
if (mSlidrInterface != null) {
|
|
||||||
mSlidrInterface.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user