Lazy mode in ViewUserDetailActivity. Fixed follow chip background color in dark mode in ViewUserDetailActivity. Fixed force stop after orientation change in ViewUserDetailActivity.

This commit is contained in:
Alex Ning 2019-06-11 11:21:56 +08:00
parent 076607a7ca
commit 22ec85b3dd
8 changed files with 115 additions and 23 deletions

View File

@ -8,9 +8,9 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
@ -45,7 +45,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK"; private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.coordinator_layout_view_subreddit_detail_activity) CoordinatorLayout coordinatorLayout;
@BindView(R.id.banner_image_view_view_subreddit_detail_activity) ImageView bannerImageView; @BindView(R.id.banner_image_view_view_subreddit_detail_activity) GifImageView bannerImageView;
@BindView(R.id.icon_gif_image_view_view_subreddit_detail_activity) GifImageView iconGifImageView; @BindView(R.id.icon_gif_image_view_view_subreddit_detail_activity) GifImageView iconGifImageView;
@BindView(R.id.subscribe_subreddit_chip_view_subreddit_detail_activity) Chip subscribeSubredditChip; @BindView(R.id.subscribe_subreddit_chip_view_subreddit_detail_activity) Chip subscribeSubredditChip;
@BindView(R.id.subreddit_name_text_view_view_subreddit_detail_activity) TextView subredditNameTextView; @BindView(R.id.subreddit_name_text_view_view_subreddit_detail_activity) TextView subredditNameTextView;
@ -238,6 +238,13 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
} else { } else {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
if(mFragment == null) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putString(PostFragment.NAME_KEY, subredditName);
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_SUBREDDIT);
mFragment.setArguments(bundle);
}
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
} }
} }
@ -263,11 +270,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
if(mFragment != null) { getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
}
} }
private void makeSnackbar(int resId) { private void makeSnackbar(int resId) {

View File

@ -4,12 +4,13 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
@ -19,6 +20,8 @@ import androidx.lifecycle.ViewModelProviders;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.chip.Chip; import com.google.android.material.chip.Chip;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -42,9 +45,12 @@ public class ViewUserDetailActivity extends AppCompatActivity {
static final String EXTRA_USER_NAME_KEY = "EUNK"; static final String EXTRA_USER_NAME_KEY = "EUNK";
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_user_detail_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.coordinator_layout_view_user_detail_activity) CoordinatorLayout coordinatorLayout;
@BindView(R.id.banner_image_view_view_user_detail_activity) ImageView bannerImageView; @BindView(R.id.appbar_layout_view_user_detail) AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_view_user_detail_activity) CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.banner_image_view_view_user_detail_activity) GifImageView bannerImageView;
@BindView(R.id.icon_gif_image_view_view_user_detail_activity) GifImageView iconGifImageView; @BindView(R.id.icon_gif_image_view_view_user_detail_activity) GifImageView iconGifImageView;
@BindView(R.id.user_name_text_view_view_user_detail_activity) TextView userNameTextView; @BindView(R.id.user_name_text_view_view_user_detail_activity) TextView userNameTextView;
@BindView(R.id.subscribe_user_chip_view_user_detail_activity) Chip subscribeUserChip; @BindView(R.id.subscribe_user_chip_view_user_detail_activity) Chip subscribeUserChip;
@ -54,8 +60,11 @@ public class ViewUserDetailActivity extends AppCompatActivity {
private SubscribedUserDao subscribedUserDao; private SubscribedUserDao subscribedUserDao;
private RequestManager glide; private RequestManager glide;
private UserViewModel userViewModel; private UserViewModel userViewModel;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private boolean subscriptionReady = false; private boolean subscriptionReady = false;
private boolean isInLazyMode = false;
@Inject @Inject
@Named("no_oauth") @Named("no_oauth")
@ -78,6 +87,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
((Infinity) getApplication()).getmAppComponent().inject(this); ((Infinity) getApplication()).getmAppComponent().inject(this);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
//Get status bar height //Get status bar height
int statusBarHeight = 0; int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
@ -93,6 +104,10 @@ public class ViewUserDetailActivity extends AppCompatActivity {
toolbar.setTitle(title); toolbar.setTitle(title);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
if(savedInstanceState != null) {
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
}
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = statusBarHeight; params.topMargin = statusBarHeight;
@ -169,7 +184,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
@Override @Override
public void onUserFollowingSuccess() { public void onUserFollowingSuccess() {
subscribeUserChip.setText(R.string.follow); subscribeUserChip.setText(R.string.follow);
subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorPrimaryDark)); subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.textColorPrimaryDark));
makeSnackbar(R.string.unfollowed); makeSnackbar(R.string.unfollowed);
subscriptionReady = true; subscriptionReady = true;
} }
@ -195,7 +210,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
@Override @Override
public void isNotSubscribed() { public void isNotSubscribed() {
subscribeUserChip.setText(R.string.follow); subscribeUserChip.setText(R.string.follow);
subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorPrimaryDark)); subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.textColorPrimaryDark));
subscriptionReady = true; subscriptionReady = true;
} }
}).execute(); }).execute();
@ -231,20 +246,77 @@ public class ViewUserDetailActivity extends AppCompatActivity {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit();
} else { } else {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
if(mFragment == null) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putString(PostFragment.NAME_KEY, userName);
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_USER);
mFragment.setArguments(bundle);
}
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit();
} }
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_user_detail_activity, 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;
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
finish(); finish();
return true; return true;
case R.id.action_refresh_view_user_detail_activity:
if (mFragment instanceof FragmentCommunicator) {
((FragmentCommunicator) mFragment).refresh();
return true;
}
break;
case 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;
((FragmentCommunicator) mFragment).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;
((FragmentCommunicator) mFragment).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);
}
return true;
} }
return false; return false;
} }
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
}
private void makeSnackbar(int resId) { private void makeSnackbar(int resId) {
Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show(); Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
} }

View File

@ -24,7 +24,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ImageView <pl.droidsonroids.gif.GifImageView
android:id="@+id/banner_image_view_view_subreddit_detail_activity" android:id="@+id/banner_image_view_view_subreddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"

View File

@ -8,11 +8,13 @@
tools:context=".ViewUserDetailActivity"> tools:context=".ViewUserDetailActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout_view_user_detail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout <com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout_view_user_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:titleEnabled="false" app:titleEnabled="false"
@ -24,7 +26,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ImageView <pl.droidsonroids.gif.GifImageView
android:id="@+id/banner_image_view_view_user_detail_activity" android:id="@+id/banner_image_view_view_user_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"

View File

@ -29,7 +29,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" /> app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.ferfalk.simplesearchview.SimpleSearchView <com.ferfalk.simplesearchview.SimpleSearchView

View File

@ -1,10 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="ml.docilealligator.infinityforreddit.ViewUserDetailActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>

View File

@ -9,4 +9,10 @@
android:title="@string/action_refresh" android:title="@string/action_refresh"
android:icon="@drawable/ic_refresh_white_24dp" android:icon="@drawable/ic_refresh_white_24dp"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_view_subreddit_detail_activity"
android:orderInCategory="2"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
</menu> </menu>

View File

@ -0,0 +1,17 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="ml.docilealligator.infinityforreddit.ViewUserDetailActivity">
<item
android:id="@+id/action_refresh_view_user_detail_activity"
android:orderInCategory="1"
android:title="@string/action_refresh"
android:icon="@drawable/ic_refresh_white_24dp"
app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_view_user_detail_activity"
android:orderInCategory="2"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
</menu>