From 2fbc4d02c863bad0426eece6fb7bcc02dc8ac193 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 2 Jul 2020 09:52:19 +0800 Subject: Changing ost layout in AccountSavedThingActivity is available. --- .../Activity/AccountSavedThingActivity.java | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/ml') 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 36a61624..1641c449 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -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(); -- cgit v1.2.3