aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java80
-rw-r--r--app/src/main/res/layout/activity_view_subreddit_detail.xml2
-rw-r--r--app/src/main/res/layout/activity_view_user_detail.xml4
-rw-r--r--app/src/main/res/layout/app_bar_main.xml2
-rw-r--r--app/src/main/res/menu/menu_view_user_detail.xml10
-rw-r--r--app/src/main/res/menu/view_subreddit_detail_activity.xml6
-rw-r--r--app/src/main/res/menu/view_user_detail_activity.xml17
8 files changed, 115 insertions, 23 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();
}
diff --git a/app/src/main/res/layout/activity_view_subreddit_detail.xml b/app/src/main/res/layout/activity_view_subreddit_detail.xml
index ac76d15b..24bff22c 100644
--- a/app/src/main/res/layout/activity_view_subreddit_detail.xml
+++ b/app/src/main/res/layout/activity_view_subreddit_detail.xml
@@ -24,7 +24,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <ImageView
+ <pl.droidsonroids.gif.GifImageView
android:id="@+id/banner_image_view_view_subreddit_detail_activity"
android:layout_width="match_parent"
android:scaleType="centerCrop"
diff --git a/app/src/main/res/layout/activity_view_user_detail.xml b/app/src/main/res/layout/activity_view_user_detail.xml
index 70b225f8..fac8a2ca 100644
--- a/app/src/main/res/layout/activity_view_user_detail.xml
+++ b/app/src/main/res/layout/activity_view_user_detail.xml
@@ -8,11 +8,13 @@
tools:context=".ViewUserDetailActivity">
<com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar_layout_view_user_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
+ android:id="@+id/collapsing_toolbar_layout_view_user_detail_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:titleEnabled="false"
@@ -24,7 +26,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <ImageView
+ <pl.droidsonroids.gif.GifImageView
android:id="@+id/banner_image_view_view_user_detail_activity"
android:layout_width="match_parent"
android:scaleType="centerCrop"
diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml
index f7efde6c..1407326c 100644
--- a/app/src/main/res/layout/app_bar_main.xml
+++ b/app/src/main/res/layout/app_bar_main.xml
@@ -29,7 +29,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
- app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
+ app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.ferfalk.simplesearchview.SimpleSearchView
diff --git a/app/src/main/res/menu/menu_view_user_detail.xml b/app/src/main/res/menu/menu_view_user_detail.xml
deleted file mode 100644
index ec7d65b8..00000000
--- a/app/src/main/res/menu/menu_view_user_detail.xml
+++ /dev/null
@@ -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>
diff --git a/app/src/main/res/menu/view_subreddit_detail_activity.xml b/app/src/main/res/menu/view_subreddit_detail_activity.xml
index d9b85107..ede3e6b9 100644
--- a/app/src/main/res/menu/view_subreddit_detail_activity.xml
+++ b/app/src/main/res/menu/view_subreddit_detail_activity.xml
@@ -9,4 +9,10 @@
android:title="@string/action_refresh"
android:icon="@drawable/ic_refresh_white_24dp"
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> \ No newline at end of file
diff --git a/app/src/main/res/menu/view_user_detail_activity.xml b/app/src/main/res/menu/view_user_detail_activity.xml
new file mode 100644
index 00000000..6f550333
--- /dev/null
+++ b/app/src/main/res/menu/view_user_detail_activity.xml
@@ -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>