Changing ost layout in AccountSavedThingActivity is available.

This commit is contained in:
Alex Ning 2020-07-02 09:52:19 +08:00
parent eff385ccd6
commit 2fbc4d02c8
2 changed files with 33 additions and 1 deletions

View File

@ -34,6 +34,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
@ -47,7 +48,8 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface {
public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
@ -75,6 +77,9 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("post_layout")
SharedPreferences mPostLayoutSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
private SectionsPagerAdapter sectionsPagerAdapter;
private SlidrInterface mSlidrInterface;
@ -84,6 +89,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
private String mAccessToken;
private String mAccountName;
private boolean isInLazyMode = false;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -122,6 +128,8 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
@ -252,6 +260,9 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
}
return true;
case R.id.action_change_post_layout_account_saved_thing_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
return false;
}
@ -300,6 +311,14 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
}
@Override
public void postLayoutSelected(int postLayout) {
if (sectionsPagerAdapter != null) {
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + mAccountName, postLayout).apply();
sectionsPagerAdapter.changePostLayout(postLayout);
}
}
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
private CommentsListingFragment commentsListingFragment;
@ -409,6 +428,13 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
}
public void changePostLayout(int postLayout) {
if (postFragment != null) {
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
public void goBackToTop() {
if (viewPager.getCurrentItem() == 0) {
postFragment.goBackToTop();

View File

@ -13,4 +13,10 @@
android:orderInCategory="2"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item
android:id="@+id/action_change_post_layout_account_saved_thing_activity"
android:orderInCategory="3"
android:title="@string/action_change_post_layout"
app:showAsAction="never" />
</menu>