Fix options in Post History not hidden in anonymous mode. Fix memory leak in ViewSubredditDetailActivity related to bottom sheet fragmnets.

This commit is contained in:
Alex Ning 2021-01-04 15:17:02 +08:00
parent 9830db0303
commit 9589ec5192
2 changed files with 20 additions and 19 deletions

View File

@ -209,11 +209,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private RequestManager glide; private RequestManager glide;
private Menu mMenu; private Menu mMenu;
private AppBarLayout.LayoutParams params; private AppBarLayout.LayoutParams params;
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
private FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment;
private int expandedTabTextColor; private int expandedTabTextColor;
private int expandedTabBackgroundColor; private int expandedTabBackgroundColor;
private int expandedTabIndicatorColor; private int expandedTabIndicatorColor;
@ -354,17 +349,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
fetchSubredditData(); fetchSubredditData();
postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
Bundle bottomSheetBundle = new Bundle();
bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
sortTypeBottomSheetFragment.setArguments(bottomSheetBundle);
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
String title = "r/" + subredditName; String title = "r/" + subredditName;
@ -734,10 +718,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
break; break;
} }
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: { case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: {
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); displaySortTypeBottomSheetFragment();
break; break;
} }
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: { case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
break; break;
} }
@ -767,11 +752,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
break; break;
default: default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
break; break;
} }
}); });
fab.setOnLongClickListener(view -> { fab.setOnLongClickListener(view -> {
FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null);
fabMoreOptionsBottomSheetFragment.setArguments(bundle); fabMoreOptionsBottomSheetFragment.setArguments(bundle);
@ -885,6 +872,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
} }
private void displaySortTypeBottomSheetFragment() {
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
Bundle bottomSheetBundle = new Bundle();
bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
sortTypeBottomSheetFragment.setArguments(bottomSheetBundle);
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
}
@Override @Override
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);
@ -911,7 +906,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
finish(); finish();
return true; return true;
case R.id.action_sort_view_subreddit_detail_activity: case R.id.action_sort_view_subreddit_detail_activity:
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); displaySortTypeBottomSheetFragment();
return true; return true;
case R.id.action_search_view_subreddit_detail_activity: case R.id.action_search_view_subreddit_detail_activity:
Intent intent = new Intent(this, SearchActivity.class); Intent intent = new Intent(this, SearchActivity.class);
@ -952,6 +947,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
return true; return true;
case R.id.action_change_post_layout_view_subreddit_detail_activity: case R.id.action_change_post_layout_view_subreddit_detail_activity:
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true; return true;
case R.id.action_select_user_flair_view_subreddit_detail_activity: case R.id.action_select_user_flair_view_subreddit_detail_activity:
@ -1018,6 +1014,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
@Override @Override
public void sortTypeSelected(String sortType) { public void sortTypeSelected(String sortType) {
SortTimeBottomSheetFragment sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType); bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType);
sortTimeBottomSheetFragment.setArguments(bundle); sortTimeBottomSheetFragment.setArguments(bundle);
@ -1115,6 +1112,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public void fabOptionSelected(int option) { public void fabOptionSelected(int option) {
switch (option) { switch (option) {
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SUBMIT_POST: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SUBMIT_POST:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
break; break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH:
@ -1123,9 +1121,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
break; break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE:
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); displaySortTypeBottomSheetFragment();
break; break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT:
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
break; break;
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH: case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH:

View File

@ -71,6 +71,8 @@ public class PostHistoryFragment extends Fragment {
infoTextView.setText(R.string.only_for_logged_in_user); infoTextView.setText(R.string.only_for_logged_in_user);
markPostsAsReadLinearLayout.setVisibility(View.GONE); markPostsAsReadLinearLayout.setVisibility(View.GONE);
markPostsAsReadAfterVotingLinearLayout.setVisibility(View.GONE); markPostsAsReadAfterVotingLinearLayout.setVisibility(View.GONE);
markPostsAsReadOnScrollLinearLayout.setVisibility(View.GONE);
hideReadPostsAutomaticallyLinearLayout.setVisibility(View.GONE);
return rootView; return rootView;
} }