aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-06-11 03:21:56 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-06-11 03:21:56 +0000
commit22ec85b3dd2e345b292ab97d9f6de5087f33539d (patch)
tree922b392605cadd02f9ef94c55e735627872cbf71 /app/src/main/java
parent076607a7ca5f23f7a87d032a9b1e80beb218fb27 (diff)
downloadinfinity-for-reddit-22ec85b3dd2e345b292ab97d9f6de5087f33539d.tar
infinity-for-reddit-22ec85b3dd2e345b292ab97d9f6de5087f33539d.tar.gz
infinity-for-reddit-22ec85b3dd2e345b292ab97d9f6de5087f33539d.tar.bz2
infinity-for-reddit-22ec85b3dd2e345b292ab97d9f6de5087f33539d.tar.lz
infinity-for-reddit-22ec85b3dd2e345b292ab97d9f6de5087f33539d.tar.xz
infinity-for-reddit-22ec85b3dd2e345b292ab97d9f6de5087f33539d.tar.zst
infinity-for-reddit-22ec85b3dd2e345b292ab97d9f6de5087f33539d.zip
Lazy mode in ViewUserDetailActivity. Fixed follow chip background color in dark mode in ViewUserDetailActivity. Fixed force stop after orientation change in ViewUserDetailActivity.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java80
2 files changed, 87 insertions, 10 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
index d0e45c08..e10f96cd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
@@ -8,9 +8,9 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ImageView;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -45,7 +45,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
@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.subscribe_subreddit_chip_view_subreddit_detail_activity) Chip subscribeSubredditChip;
@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();
} else {
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();
}
}
@@ -263,11 +270,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
}
@Override
- protected void onSaveInstanceState(Bundle outState) {
+ protected void onSaveInstanceState(@NonNull Bundle 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) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
index a55eb6c0..905144f8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
@@ -4,12 +4,13 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ImageView;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -19,6 +20,8 @@ import androidx.lifecycle.ViewModelProviders;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
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.snackbar.Snackbar;
@@ -42,9 +45,12 @@ public class ViewUserDetailActivity extends AppCompatActivity {
static final String EXTRA_USER_NAME_KEY = "EUNK";
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.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.user_name_text_view_view_user_detail_activity) TextView userNameTextView;
@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 RequestManager glide;
private UserViewModel userViewModel;
+ private Menu mMenu;
+ private AppBarLayout.LayoutParams params;
private boolean subscriptionReady = false;
+ private boolean isInLazyMode = false;
@Inject
@Named("no_oauth")
@@ -78,6 +87,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
((Infinity) getApplication()).getmAppComponent().inject(this);
+ params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
+
//Get status bar height
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
@@ -93,6 +104,10 @@ public class ViewUserDetailActivity extends AppCompatActivity {
toolbar.setTitle(title);
setSupportActionBar(toolbar);
+ if(savedInstanceState != null) {
+ isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
+ }
+
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = statusBarHeight;
@@ -169,7 +184,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
@Override
public void onUserFollowingSuccess() {
subscribeUserChip.setText(R.string.follow);
- subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorPrimaryDark));
+ subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.textColorPrimaryDark));
makeSnackbar(R.string.unfollowed);
subscriptionReady = true;
}
@@ -195,7 +210,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
@Override
public void isNotSubscribed() {
subscribeUserChip.setText(R.string.follow);
- subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorPrimaryDark));
+ subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.textColorPrimaryDark));
subscriptionReady = true;
}
}).execute();
@@ -231,20 +246,77 @@ public class ViewUserDetailActivity extends AppCompatActivity {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit();
} else {
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();
}
}
@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
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
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;
}
+ @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) {
Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
}