Give back lazy mode control to PostFragment instead of activities.

This commit is contained in:
Alex Ning 2021-09-29 20:34:37 +08:00
parent 5b5bc1c5b8
commit bac1dca855
16 changed files with 83 additions and 454 deletions

View File

@ -46,7 +46,6 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
static final String EXTRA_USER_WHERE = "EUW"; static final String EXTRA_USER_WHERE = "EUW";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
private static final String FRAGMENT_OUT_STATE = "FOS"; private static final String FRAGMENT_OUT_STATE = "FOS";
@BindView(R.id.coordinator_layout_account_posts_activity) @BindView(R.id.coordinator_layout_account_posts_activity)
@ -68,13 +67,10 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
SharedPreferences mCurrentAccountSharedPreferences; SharedPreferences mCurrentAccountSharedPreferences;
@Inject @Inject
CustomThemeWrapper mCustomThemeWrapper; CustomThemeWrapper mCustomThemeWrapper;
private boolean isInLazyMode = false;
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
private String mUserWhere; private String mUserWhere;
private Fragment mFragment; private Fragment mFragment;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@Override @Override
@ -129,16 +125,12 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar); setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
if (savedInstanceState != null) { if (savedInstanceState != null) {
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit();
} else { } else {
@ -188,52 +180,21 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.account_posts_activity, menu); getMenuInflater().inflate(R.menu.account_posts_activity, menu);
applyMenuItemTheme(menu); applyMenuItemTheme(menu);
mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_account_posts_activity);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
}
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.action_refresh_account_posts_activity: if (itemId == R.id.action_refresh_account_posts_activity) {
if (mMenu != null) {
mMenu.findItem(R.id.action_lazy_mode_account_posts_activity).setTitle(R.string.action_start_lazy_mode);
}
if (mFragment != null) { if (mFragment != null) {
((PostFragment) mFragment).refresh(); ((PostFragment) mFragment).refresh();
} }
return true; return true;
case R.id.action_lazy_mode_account_posts_activity: } else if (itemId == R.id.action_change_post_layout_account_posts_activity) {
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_account_posts_activity);
if (isInLazyMode) {
((FragmentCommunicator) mFragment).stopLazyMode();
isInLazyMode = false;
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
} else {
if (((FragmentCommunicator) mFragment).startLazyMode()) {
isInLazyMode = true;
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
}
}
return true;
case R.id.action_change_post_layout_account_posts_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true; return true;
case android.R.id.home: } else if (itemId == android.R.id.home) {
finish(); finish();
return true; return true;
} }
@ -244,7 +205,6 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment); getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
} }
@Override @Override

View File

@ -38,7 +38,6 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
@ -58,8 +57,6 @@ import retrofit2.Retrofit;
public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface, public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, MarkPostAsReadInterface { PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, MarkPostAsReadInterface {
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
@BindView(R.id.coordinator_layout_account_saved_thing_activity) @BindView(R.id.coordinator_layout_account_saved_thing_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@BindView(R.id.collapsing_toolbar_layout_account_saved_thing_activity) @BindView(R.id.collapsing_toolbar_layout_account_saved_thing_activity)
@ -93,11 +90,8 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
private FragmentManager fragmentManager; private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
private SlidrInterface mSlidrInterface; private SlidrInterface mSlidrInterface;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
private boolean isInLazyMode = false;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@Override @Override
@ -141,8 +135,6 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar); setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
fragmentManager = getSupportFragmentManager(); fragmentManager = getSupportFragmentManager();
@ -150,9 +142,6 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
if (savedInstanceState != null) {
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
}
initializeViewPager(); initializeViewPager();
} }
@ -216,66 +205,25 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.account_saved_thing_activity, menu); getMenuInflater().inflate(R.menu.account_saved_thing_activity, menu);
applyMenuItemTheme(menu); applyMenuItemTheme(menu);
mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_account_saved_thing_activity);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
}
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case android.R.id.home: if (itemId == android.R.id.home) {
finish(); finish();
return true; return true;
case R.id.action_refresh_account_saved_thing_activity: } else if (itemId == R.id.action_refresh_account_saved_thing_activity) {
if (mMenu != null) {
mMenu.findItem(R.id.action_lazy_mode_account_saved_thing_activity).setTitle(R.string.action_start_lazy_mode);
}
sectionsPagerAdapter.refresh(); sectionsPagerAdapter.refresh();
return true; return true;
case R.id.action_lazy_mode_account_saved_thing_activity: } else if (itemId == R.id.action_change_post_layout_account_saved_thing_activity) {
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_account_saved_thing_activity);
if (isInLazyMode) {
isInLazyMode = false;
sectionsPagerAdapter.stopLazyMode();
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = true;
if (sectionsPagerAdapter.startLazyMode()) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
appBarLayout.setExpanded(false);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = false;
}
}
return true;
case R.id.action_change_post_layout_account_saved_thing_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true; return true;
} }
return false; return false;
} }
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -382,21 +330,6 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
} }
} }
boolean startLazyMode() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof FragmentCommunicator) {
return ((FragmentCommunicator) fragment).startLazyMode();
}
return false;
}
void stopLazyMode() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof FragmentCommunicator) {
((FragmentCommunicator) fragment).stopLazyMode();
}
}
public void changeNSFW(boolean nsfw) { public void changeNSFW(boolean nsfw) {
Fragment fragment = getCurrentFragment(); Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) { if (fragment instanceof PostFragment) {

View File

@ -68,7 +68,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
public static final String EXTRA_POST_TYPE = "EPT"; public static final String EXTRA_POST_TYPE = "EPT";
public static final String EXTRA_USER_WHERE = "EUW"; public static final String EXTRA_USER_WHERE = "EUW";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
private static final String FRAGMENT_OUT_STATE = "FOS"; private static final String FRAGMENT_OUT_STATE = "FOS";
private static final int CUSTOMIZE_POST_FILTER_ACTIVITY_REQUEST_CODE = 1000; private static final int CUSTOMIZE_POST_FILTER_ACTIVITY_REQUEST_CODE = 1000;
@ -97,7 +96,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
CustomThemeWrapper mCustomThemeWrapper; CustomThemeWrapper mCustomThemeWrapper;
@Inject @Inject
Executor mExecutor; Executor mExecutor;
private boolean isInLazyMode = false;
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
private String name; private String name;
@ -105,7 +103,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
private int postType; private int postType;
private PostFragment mFragment; private PostFragment mFragment;
private Menu mMenu; private Menu mMenu;
private AppBarLayout.LayoutParams params;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -155,8 +152,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar); setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
name = getIntent().getStringExtra(EXTRA_NAME); name = getIntent().getStringExtra(EXTRA_NAME);
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE); postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
int filter = getIntent().getIntExtra(EXTRA_FILTER, -1000); int filter = getIntent().getIntExtra(EXTRA_FILTER, -1000);
@ -231,7 +226,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
if (savedInstanceState != null) { if (savedInstanceState != null) {
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mFragment = (PostFragment) getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); mFragment = (PostFragment) getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
bindView(postFilter, false); bindView(postFilter, false);
@ -342,17 +336,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
getMenuInflater().inflate(R.menu.filtered_posts_activity, menu); getMenuInflater().inflate(R.menu.filtered_posts_activity, menu);
applyMenuItemTheme(menu); applyMenuItemTheme(menu);
mMenu = menu; mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
}
if (userWhere != null && !PostPagingSource.USER_WHERE_SUBMITTED.equals(userWhere)) { if (userWhere != null && !PostPagingSource.USER_WHERE_SUBMITTED.equals(userWhere)) {
mMenu.findItem(R.id.action_sort_filtered_thing_activity).setVisible(false); mMenu.findItem(R.id.action_sort_filtered_thing_activity).setVisible(false);
} }
@ -408,30 +391,10 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
} }
return true; return true;
} else if (itemId == R.id.action_refresh_filtered_thing_activity) { } else if (itemId == R.id.action_refresh_filtered_thing_activity) {
if (mMenu != null) {
mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity).setTitle(R.string.action_start_lazy_mode);
}
if (mFragment != null) { if (mFragment != null) {
((FragmentCommunicator) mFragment).refresh(); ((FragmentCommunicator) mFragment).refresh();
} }
return true; return true;
} else if (itemId == R.id.action_lazy_mode_filtered_thing_activity) {
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity);
if (isInLazyMode) {
((FragmentCommunicator) mFragment).stopLazyMode();
isInLazyMode = false;
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
} else {
if (((FragmentCommunicator) mFragment).startLazyMode()) {
isInLazyMode = true;
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
}
}
return true;
} else if (itemId == R.id.action_change_post_layout_filtered_post_activity) { } else if (itemId == R.id.action_change_post_layout_filtered_post_activity) {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
@ -454,7 +417,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment); getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
} }
@Override @Override

View File

@ -140,7 +140,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private static final String FETCH_USER_INFO_STATE = "FUIS"; private static final String FETCH_USER_INFO_STATE = "FUIS";
private static final String FETCH_SUBSCRIPTIONS_STATE = "FSS"; private static final String FETCH_SUBSCRIPTIONS_STATE = "FSS";
private static final String DRAWER_ON_ACCOUNT_SWITCH_STATE = "DOASS"; private static final String DRAWER_ON_ACCOUNT_SWITCH_STATE = "DOASS";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
private static final String ACCESS_TOKEN_STATE = "ATS"; private static final String ACCESS_TOKEN_STATE = "ATS";
private static final String ACCOUNT_NAME_STATE = "ANS"; private static final String ACCOUNT_NAME_STATE = "ANS";
private static final String MESSAGE_FULLNAME_STATE = "MFS"; private static final String MESSAGE_FULLNAME_STATE = "MFS";
@ -222,7 +221,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
Executor mExecutor; Executor mExecutor;
private FragmentManager fragmentManager; private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
private AppBarLayout.LayoutParams params;
private NavigationDrawerRecyclerViewAdapter adapter; private NavigationDrawerRecyclerViewAdapter adapter;
private Call<String> subredditAutocompleteCall; private Call<String> subredditAutocompleteCall;
private String mAccessToken; private String mAccessToken;
@ -232,8 +230,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private boolean mDrawerOnAccountSwitch = false; private boolean mDrawerOnAccountSwitch = false;
private String mMessageFullname; private String mMessageFullname;
private String mNewAccountName; private String mNewAccountName;
private Menu mMenu;
private boolean isInLazyMode = false;
private boolean showBottomAppBar; private boolean showBottomAppBar;
private boolean mConfirmToExit; private boolean mConfirmToExit;
private boolean mLockBottomAppBar; private boolean mLockBottomAppBar;
@ -315,8 +311,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}); });
toggle.syncState(); toggle.syncState();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, true); showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, true);
mConfirmToExit = mSharedPreferences.getBoolean(SharedPreferencesUtils.CONFIRM_TO_EXIT, false); mConfirmToExit = mSharedPreferences.getBoolean(SharedPreferencesUtils.CONFIRM_TO_EXIT, false);
mLockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); mLockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
@ -331,7 +325,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE); mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE); mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE);
mDrawerOnAccountSwitch = savedInstanceState.getBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE); mDrawerOnAccountSwitch = savedInstanceState.getBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE);
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE); mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE); mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
inboxCount = savedInstanceState.getInt(INBOX_COUNT_STATE); inboxCount = savedInstanceState.getInt(INBOX_COUNT_STATE);
@ -1086,19 +1079,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity, menu); getMenuInflater().inflate(R.menu.main_activity, menu);
applyMenuItemTheme(menu); applyMenuItemTheme(menu);
mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
}
return true; return true;
} }
@ -1122,30 +1102,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
changeSortType(); changeSortType();
return true; return true;
} else if (itemId == R.id.action_refresh_main_activity) { } else if (itemId == R.id.action_refresh_main_activity) {
if (mMenu != null) {
mMenu.findItem(R.id.action_lazy_mode_main_activity).setTitle(R.string.action_start_lazy_mode);
}
sectionsPagerAdapter.refresh(); sectionsPagerAdapter.refresh();
mFetchUserInfoSuccess = false; mFetchUserInfoSuccess = false;
loadUserData(); loadUserData();
return true; return true;
} else if (itemId == R.id.action_lazy_mode_main_activity) {
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity);
if (isInLazyMode) {
sectionsPagerAdapter.stopLazyMode();
isInLazyMode = false;
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
} else {
if (sectionsPagerAdapter.startLazyMode()) {
isInLazyMode = true;
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
}
}
return true;
} else if (itemId == R.id.action_change_post_layout_main_activity) { } else if (itemId == R.id.action_change_post_layout_main_activity) {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
@ -1187,7 +1147,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess); outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
outState.putBoolean(FETCH_SUBSCRIPTIONS_STATE, mFetchSubscriptionsSuccess); outState.putBoolean(FETCH_SUBSCRIPTIONS_STATE, mFetchSubscriptionsSuccess);
outState.putBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE, mDrawerOnAccountSwitch); outState.putBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE, mDrawerOnAccountSwitch);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
outState.putString(ACCESS_TOKEN_STATE, mAccessToken); outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
outState.putString(ACCOUNT_NAME_STATE, mAccountName); outState.putString(ACCOUNT_NAME_STATE, mAccountName);
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname); outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
@ -1806,24 +1765,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
return false; return false;
} }
boolean startLazyMode() {
PostFragment currentFragment = getCurrentFragment();
if (currentFragment != null) {
return currentFragment.startLazyMode();
}
return false;
}
void stopLazyMode() {
for (int i = 0; i < getItemCount(); i++) {
Fragment fragment = fragmentManager.findFragmentByTag("f" + i);
if (fragment instanceof PostFragment && ((PostFragment) fragment).isInLazyMode()) {
((PostFragment) fragment).stopLazyMode();
}
}
}
int getCurrentPostType() { int getCurrentPostType() {
PostFragment currentFragment = getCurrentFragment(); PostFragment currentFragment = getCurrentFragment();
if (currentFragment != null) { if (currentFragment != null) {

View File

@ -62,7 +62,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
public static final String EXTRA_MULTIREDDIT_PATH = "EMP"; public static final String EXTRA_MULTIREDDIT_PATH = "EMP";
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK"; private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
@BindView(R.id.coordinator_layout_view_multi_reddit_detail_activity) @BindView(R.id.coordinator_layout_view_multi_reddit_detail_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@ -99,10 +98,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
private String multiPath; private String multiPath;
private boolean isInLazyMode = false;
private Fragment mFragment; private Fragment mFragment;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment; private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@ -163,8 +159,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-");
if (savedInstanceState != null) { if (savedInstanceState != null) {
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit();
} else { } else {
@ -179,8 +173,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
} }
private void initializeFragment() { private void initializeFragment() {
@ -198,17 +190,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_multi_reddit_detail_activity, menu); getMenuInflater().inflate(R.menu.view_multi_reddit_detail_activity, menu);
applyMenuItemTheme(menu); applyMenuItemTheme(menu);
mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_multi_reddit_detail_activity);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
}
return true; return true;
} }
@ -226,33 +207,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
startActivity(intent); startActivity(intent);
return true; return true;
} else if (itemId == R.id.action_refresh_view_multi_reddit_detail_activity) { } else if (itemId == R.id.action_refresh_view_multi_reddit_detail_activity) {
if (mMenu != null) {
mMenu.findItem(R.id.action_lazy_mode_view_multi_reddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
}
if (mFragment instanceof FragmentCommunicator) { if (mFragment instanceof FragmentCommunicator) {
((FragmentCommunicator) mFragment).refresh(); ((FragmentCommunicator) mFragment).refresh();
} }
return true; return true;
} else if (itemId == R.id.action_lazy_mode_view_multi_reddit_detail_activity) {
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_multi_reddit_detail_activity);
if (isInLazyMode) {
isInLazyMode = false;
((FragmentCommunicator) mFragment).stopLazyMode();
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = true;
if (((FragmentCommunicator) mFragment).startLazyMode()) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
appBarLayout.setExpanded(false);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = false;
}
}
return true;
} else if (itemId == R.id.action_change_post_layout_view_multi_reddit_detail_activity) { } else if (itemId == R.id.action_change_post_layout_view_multi_reddit_detail_activity) {
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true; return true;
@ -302,7 +260,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
@Override @Override
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment); getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
} }

View File

@ -135,7 +135,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS"; private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS";
private static final String CURRENT_ONLINE_SUBSCRIBERS_STATE = "COSS"; private static final String CURRENT_ONLINE_SUBSCRIBERS_STATE = "COSS";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
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;
@ -228,15 +227,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private int mNCurrentOnlineSubscribers = 0; private int mNCurrentOnlineSubscribers = 0;
private boolean isNsfwSubreddit = false; private boolean isNsfwSubreddit = false;
private boolean subscriptionReady = false; private boolean subscriptionReady = false;
private boolean isInLazyMode = false;
private boolean showToast = false; private boolean showToast = false;
private boolean showBottomAppBar; private boolean showBottomAppBar;
private boolean lockBottomAppBar; private boolean lockBottomAppBar;
private String mMessageFullname; private String mMessageFullname;
private String mNewAccountName; private String mNewAccountName;
private RequestManager glide; private RequestManager glide;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private int expandedTabTextColor; private int expandedTabTextColor;
private int expandedTabBackgroundColor; private int expandedTabBackgroundColor;
private int expandedTabIndicatorColor; private int expandedTabIndicatorColor;
@ -359,7 +355,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} else { } else {
mFetchSubredditInfoSuccess = savedInstanceState.getBoolean(FETCH_SUBREDDIT_INFO_STATE); mFetchSubredditInfoSuccess = savedInstanceState.getBoolean(FETCH_SUBREDDIT_INFO_STATE);
mNCurrentOnlineSubscribers = savedInstanceState.getInt(CURRENT_ONLINE_SUBSCRIBERS_STATE); mNCurrentOnlineSubscribers = savedInstanceState.getInt(CURRENT_ONLINE_SUBSCRIBERS_STATE);
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE); mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE); mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
@ -372,8 +367,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
fetchSubredditData(); fetchSubredditData();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
String title = "r/" + subredditName; String title = "r/" + subredditName;
subredditNameTextView.setText(title); subredditNameTextView.setText(title);
@ -1091,18 +1084,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_subreddit_detail_activity, menu); getMenuInflater().inflate(R.menu.view_subreddit_detail_activity, menu);
applyMenuItemTheme(menu); applyMenuItemTheme(menu);
mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
}
return true; return true;
} }
@ -1121,38 +1102,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
startActivity(intent); startActivity(intent);
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 (mMenu != null) {
mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
}
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.refresh(); sectionsPagerAdapter.refresh();
mFetchSubredditInfoSuccess = false; mFetchSubredditInfoSuccess = false;
fetchSubredditData(); fetchSubredditData();
} }
return true; return true;
} else if (itemId == R.id.action_lazy_mode_view_subreddit_detail_activity) {
if (sectionsPagerAdapter != null) {
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
if (isInLazyMode) {
isInLazyMode = false;
sectionsPagerAdapter.stopLazyMode();
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = true;
if (sectionsPagerAdapter.startLazyMode()) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
appBarLayout.setExpanded(false);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = false;
}
}
}
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) {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
@ -1231,7 +1186,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess); outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess);
outState.putInt(CURRENT_ONLINE_SUBSCRIBERS_STATE, mNCurrentOnlineSubscribers); outState.putInt(CURRENT_ONLINE_SUBSCRIBERS_STATE, mNCurrentOnlineSubscribers);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname); outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName); outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
} }
@ -1637,21 +1591,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
} }
boolean startLazyMode() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof FragmentCommunicator) {
return ((FragmentCommunicator) fragment).startLazyMode();
}
return false;
}
void stopLazyMode() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof FragmentCommunicator) {
((FragmentCommunicator) fragment).stopLazyMode();
}
}
public void changeSortType(SortType sortType) { public void changeSortType(SortType sortType) {
Fragment fragment = getCurrentFragment(); Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) { if (fragment instanceof PostFragment) {

View File

@ -131,7 +131,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
public static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 400; public static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 400;
private static final String FETCH_USER_INFO_STATE = "FSIS"; private static final String FETCH_USER_INFO_STATE = "FSIS";
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
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";
@ -211,8 +210,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private FragmentManager fragmentManager; private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
private RequestManager glide; private RequestManager glide;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@ -222,7 +219,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private String username; private String username;
private boolean subscriptionReady = false; private boolean subscriptionReady = false;
private boolean mFetchUserInfoSuccess = false; private boolean mFetchUserInfoSuccess = false;
private boolean isInLazyMode = false;
private int expandedTabTextColor; private int expandedTabTextColor;
private int expandedTabBackgroundColor; private int expandedTabBackgroundColor;
private int expandedTabIndicatorColor; private int expandedTabIndicatorColor;
@ -271,7 +267,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
} else { } else {
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE); mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE); mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE); mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
} }
@ -280,8 +275,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
fetchUserInfo(); fetchUserInfo();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
Resources resources = getResources(); Resources resources = getResources();
adjustToolbar(toolbar); adjustToolbar(toolbar);
@ -923,19 +916,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_user_detail_activity, menu); getMenuInflater().inflate(R.menu.view_user_detail_activity, menu);
applyMenuItemTheme(menu); applyMenuItemTheme(menu);
mMenu = menu;
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
}
return true; return true;
} }
@ -955,34 +935,10 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
startActivity(intent); startActivity(intent);
return true; return true;
} else if (itemId == R.id.action_refresh_view_user_detail_activity) { } else if (itemId == R.id.action_refresh_view_user_detail_activity) {
if (mMenu != null) {
mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity).setTitle(R.string.action_start_lazy_mode);
}
sectionsPagerAdapter.refresh(); sectionsPagerAdapter.refresh();
mFetchUserInfoSuccess = false; mFetchUserInfoSuccess = false;
fetchUserInfo(); fetchUserInfo();
return true; return true;
} else if (itemId == R.id.action_lazy_mode_view_user_detail_activity) {
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity);
if (isInLazyMode) {
isInLazyMode = false;
sectionsPagerAdapter.stopLazyMode();
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = true;
if (sectionsPagerAdapter.startLazyMode()) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
appBarLayout.setExpanded(false);
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
isInLazyMode = false;
}
}
return true;
} else if (itemId == R.id.action_change_post_layout_view_user_detail_activity) { } else if (itemId == R.id.action_change_post_layout_view_user_detail_activity) {
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true; return true;
@ -1100,7 +1056,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess); outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname); outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName); outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
} }
@ -1528,21 +1483,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
} }
} }
boolean startLazyMode() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof FragmentCommunicator) {
return ((FragmentCommunicator) fragment).startLazyMode();
}
return false;
}
void stopLazyMode() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof FragmentCommunicator) {
((FragmentCommunicator) fragment).stopLazyMode();
}
}
public void changeSortType(SortType sortType) { public void changeSortType(SortType sortType) {
Fragment fragment = getCurrentFragment(); Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) { if (fragment instanceof PostFragment) {

View File

@ -18,10 +18,12 @@ import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
@ -211,12 +213,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private AppCompatActivity activity; private AppCompatActivity activity;
private LinearLayoutManagerBugFixed mLinearLayoutManager; private LinearLayoutManagerBugFixed mLinearLayoutManager;
private StaggeredGridLayoutManager mStaggeredGridLayoutManager; private StaggeredGridLayoutManager mStaggeredGridLayoutManager;
private MenuItem lazyModeItem;
private long postFragmentId; private long postFragmentId;
private int postType; private int postType;
private boolean isInLazyMode = false; private boolean isInLazyMode = false;
private boolean isLazyModePaused = false; private boolean isLazyModePaused = false;
private boolean hasPost = false; private boolean hasPost = false;
private boolean isShown = false;
private boolean savePostFeedScrolledPosition; private boolean savePostFeedScrolledPosition;
private boolean rememberMutingOptionInPostFeed; private boolean rememberMutingOptionInPostFeed;
private Boolean masterMutingOption; private Boolean masterMutingOption;
@ -259,7 +261,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
isShown = true;
if (mAdapter != null) { if (mAdapter != null) {
mAdapter.setCanStartActivity(true); mAdapter.setCanStartActivity(true);
} }
@ -306,6 +307,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
unbinder = ButterKnife.bind(this, rootView); unbinder = ButterKnife.bind(this, rootView);
setHasOptionsMenu(true);
EventBus.getDefault().register(this); EventBus.getDefault().register(this);
applyTheme(); applyTheme();
@ -1275,6 +1278,31 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
view -> mAdapter.retry()))); view -> mAdapter.retry())));
} }
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.post_fragment, menu);
lazyModeItem = menu.findItem(R.id.action_lazy_mode_post_fragment);
if (isInLazyMode) {
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
} else {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
}
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_lazy_mode_post_fragment) {
if (isInLazyMode) {
stopLazyMode();
} else {
startLazyMode();
}
return true;
}
return false;
}
private void noPostFound() { private void noPostFound() {
hasPost = false; hasPost = false;
if (isInLazyMode) { if (isInLazyMode) {
@ -1434,6 +1462,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return false; return false;
} }
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
if (mAdapter != null && mAdapter.isAutoplay()) { if (mAdapter != null && mAdapter.isAutoplay()) {
mAdapter.setAutoplay(false); mAdapter.setAutoplay(false);
refreshAdapter(); refreshAdapter();
@ -1453,6 +1483,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override @Override
public void stopLazyMode() { public void stopLazyMode() {
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
if (mAdapter != null) { if (mAdapter != null) {
String autoplayString = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER); String autoplayString = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON) || if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON) ||

View File

@ -7,15 +7,9 @@
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_account_posts_activity"
android:orderInCategory="2"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item <item
android:id="@+id/action_change_post_layout_account_posts_activity" android:id="@+id/action_change_post_layout_account_posts_activity"
android:orderInCategory="3" android:orderInCategory="2"
android:title="@string/action_change_post_layout" android:title="@string/action_change_post_layout"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@ -8,15 +8,9 @@
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_account_saved_thing_activity"
android:orderInCategory="2"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item <item
android:id="@+id/action_change_post_layout_account_saved_thing_activity" android:id="@+id/action_change_post_layout_account_saved_thing_activity"
android:orderInCategory="3" android:orderInCategory="2"
android:title="@string/action_change_post_layout" android:title="@string/action_change_post_layout"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@ -15,15 +15,9 @@
android:icon="@drawable/ic_search_toolbar_24dp" android:icon="@drawable/ic_search_toolbar_24dp"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_filtered_thing_activity"
android:orderInCategory="3"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item <item
android:id="@+id/action_change_post_layout_filtered_post_activity" android:id="@+id/action_change_post_layout_filtered_post_activity"
android:orderInCategory="4" android:orderInCategory="3"
android:title="@string/action_change_post_layout" android:title="@string/action_change_post_layout"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@ -24,12 +24,6 @@
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_main_activity"
android:orderInCategory="4"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item <item
android:id="@+id/action_change_post_layout_main_activity" android:id="@+id/action_change_post_layout_main_activity"
android:orderInCategory="5" android:orderInCategory="5"

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_lazy_mode_post_fragment"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>

View File

@ -22,27 +22,21 @@
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_view_multi_reddit_detail_activity"
android:orderInCategory="4"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item <item
android:id="@+id/action_change_post_layout_view_multi_reddit_detail_activity" android:id="@+id/action_change_post_layout_view_multi_reddit_detail_activity"
android:orderInCategory="5" android:orderInCategory="4"
android:title="@string/action_change_post_layout" android:title="@string/action_change_post_layout"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_edit_view_multi_reddit_detail_activity" android:id="@+id/action_edit_view_multi_reddit_detail_activity"
android:orderInCategory="6" android:orderInCategory="5"
android:title="@string/action_edit_multi_reddit" android:title="@string/action_edit_multi_reddit"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_delete_view_multi_reddit_detail_activity" android:id="@+id/action_delete_view_multi_reddit_detail_activity"
android:orderInCategory="7" android:orderInCategory="6"
android:title="@string/action_delete_multi_reddit" android:title="@string/action_delete_multi_reddit"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@ -23,45 +23,39 @@
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_view_subreddit_detail_activity"
android:orderInCategory="4"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item <item
android:id="@+id/action_change_post_layout_view_subreddit_detail_activity" android:id="@+id/action_change_post_layout_view_subreddit_detail_activity"
android:orderInCategory="5" android:orderInCategory="4"
android:title="@string/action_change_post_layout" android:title="@string/action_change_post_layout"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_select_user_flair_view_subreddit_detail_activity" android:id="@+id/action_select_user_flair_view_subreddit_detail_activity"
android:orderInCategory="6" android:orderInCategory="5"
android:title="@string/action_select_user_flair" android:title="@string/action_select_user_flair"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_add_to_multireddit_view_subreddit_detail_activity" android:id="@+id/action_add_to_multireddit_view_subreddit_detail_activity"
android:orderInCategory="7" android:orderInCategory="6"
android:title="@string/action_add_to_multireddit" android:title="@string/action_add_to_multireddit"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_add_to_post_filter_view_subreddit_detail_activity" android:id="@+id/action_add_to_post_filter_view_subreddit_detail_activity"
android:orderInCategory="8" android:orderInCategory="7"
android:title="@string/action_add_to_post_filter" android:title="@string/action_add_to_post_filter"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_share_view_subreddit_detail_activity" android:id="@+id/action_share_view_subreddit_detail_activity"
android:orderInCategory="9" android:orderInCategory="8"
android:title="@string/action_share" android:title="@string/action_share"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_go_to_wiki_activity" android:id="@+id/action_go_to_wiki_activity"
android:orderInCategory="10" android:orderInCategory="9"
android:title="@string/action_go_to_wiki" android:title="@string/action_go_to_wiki"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@ -20,49 +20,43 @@
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_view_user_detail_activity"
android:orderInCategory="4"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item <item
android:id="@+id/action_change_post_layout_view_user_detail_activity" android:id="@+id/action_change_post_layout_view_user_detail_activity"
android:orderInCategory="5" android:orderInCategory="4"
android:title="@string/action_change_post_layout" android:title="@string/action_change_post_layout"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_send_private_message_view_user_detail_activity" android:id="@+id/action_send_private_message_view_user_detail_activity"
android:orderInCategory="6" android:orderInCategory="5"
android:title="@string/action_send_private_message" android:title="@string/action_send_private_message"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_share_view_user_detail_activity" android:id="@+id/action_share_view_user_detail_activity"
android:orderInCategory="7" android:orderInCategory="6"
android:title="@string/action_share" android:title="@string/action_share"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_add_to_multireddit_view_user_detail_activity" android:id="@+id/action_add_to_multireddit_view_user_detail_activity"
android:orderInCategory="8" android:orderInCategory="7"
android:title="@string/action_add_to_multireddit" android:title="@string/action_add_to_multireddit"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_add_to_post_filter_view_user_detail_activity" android:id="@+id/action_add_to_post_filter_view_user_detail_activity"
android:orderInCategory="9" android:orderInCategory="8"
android:title="@string/action_add_to_post_filter" android:title="@string/action_add_to_post_filter"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/action_report_view_user_detail_activity" android:id="@+id/action_report_view_user_detail_activity"
android:orderInCategory="10" android:orderInCategory="9"
android:title="@string/action_report" /> android:title="@string/action_report" />
<item <item
android:id="@+id/action_block_user_view_user_detail_activity" android:id="@+id/action_block_user_view_user_detail_activity"
android:orderInCategory="11" android:orderInCategory="10"
android:title="@string/action_block_user" /> android:title="@string/action_block_user" />
</menu> </menu>