aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-11-15 09:23:59 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-11-15 09:23:59 +0000
commite0a9a02157153cbfd27ad6dacbfbabba158a278d (patch)
treed8356015ae1e4eb271e1271a584791192f98d378
parent3233ca6471af3f966b3f6dee5497421442893ff7 (diff)
downloadinfinity-for-reddit-e0a9a02157153cbfd27ad6dacbfbabba158a278d.tar
infinity-for-reddit-e0a9a02157153cbfd27ad6dacbfbabba158a278d.tar.gz
infinity-for-reddit-e0a9a02157153cbfd27ad6dacbfbabba158a278d.tar.bz2
infinity-for-reddit-e0a9a02157153cbfd27ad6dacbfbabba158a278d.tar.lz
infinity-for-reddit-e0a9a02157153cbfd27ad6dacbfbabba158a278d.tar.xz
infinity-for-reddit-e0a9a02157153cbfd27ad6dacbfbabba158a278d.tar.zst
infinity-for-reddit-e0a9a02157153cbfd27ad6dacbfbabba158a278d.zip
Swiping to refresh posts is now available.
-rw-r--r--app/build.gradle1
-rw-r--r--app/src/main/AndroidManifest.xml2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java43
-rw-r--r--app/src/main/res/layout/fragment_post.xml25
-rw-r--r--app/src/main/res/values/styles.xml5
7 files changed, 60 insertions, 38 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 3d3cf668..6a5610ba 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -81,4 +81,5 @@ dependencies {
implementation 'androidx.preference:preference:1.1.0'
implementation 'com.nex3z:flow-layout:1.3.0'
implementation 'com.github.thunder413:DateTimeUtils:3.0'
+ implementation 'com.r0adkll:slidableactivity:2.1.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c7883829..3ddc6003 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -238,7 +238,7 @@
<activity
android:name=".Activity.ViewPostDetailActivity"
android:parentActivityName=".Activity.MainActivity"
- android:theme="@style/AppTheme.NoActionBar" />
+ android:theme="@style/AppTheme.NoActionBarWithTransparentBackground" />
<activity
android:name=".Activity.ViewSubredditDetailActivity"
android:parentActivityName=".Activity.MainActivity"
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index 42824df6..4b38e45b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -4,6 +4,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
@@ -32,6 +33,10 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.livefront.bridge.Bridge;
+import com.r0adkll.slidr.Slidr;
+import com.r0adkll.slidr.model.SlidrConfig;
+import com.r0adkll.slidr.model.SlidrListener;
+import com.r0adkll.slidr.model.SlidrPosition;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -71,11 +76,11 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditAPI;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import ml.docilealligator.infinityforreddit.SaveThing;
-import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
+import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -181,6 +186,17 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
EventBus.getDefault().register(this);
+ SlidrConfig config = new SlidrConfig.Builder()
+ .sensitivity(1f)
+ .scrimColor(Color.BLACK)
+ .scrimStartAlpha(0.8f)
+ .scrimEndAlpha(0f)
+ .velocityThreshold(2400)
+ .distanceThreshold(0.25f)
+ .build();
+
+ Slidr.attach(this);
+
Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
index 4c50c45c..5a8cbaff 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -58,13 +58,13 @@ import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import ml.docilealligator.infinityforreddit.SubredditSubscription;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index 214f77cb..eba9f607 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -32,10 +32,10 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
-import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -62,8 +62,8 @@ import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.PostViewModel;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@@ -84,10 +84,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
private static final String RECYCLER_VIEW_POSITION_STATE = "RVPS";
+ @BindView(R.id.swipe_refresh_layout_post_fragment)
+ SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recycler_view_post_fragment)
RecyclerView mPostRecyclerView;
- @BindView(R.id.progress_bar_post_fragment)
- CircleProgressBar mProgressBar;
@BindView(R.id.fetch_post_info_linear_layout_post_fragment)
LinearLayout mFetchPostInfoLinearLayout;
@BindView(R.id.fetch_post_info_image_view_post_fragment)
@@ -131,6 +131,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (mPostRecyclerView.getAdapter() != null) {
((PostRecyclerViewAdapter) mPostRecyclerView.getAdapter()).setCanStartActivity(true);
}
+ if (isInLazyMode && isLazyModePaused) {
+ resumeLazyMode(false);
+ }
}
@Override
@@ -226,6 +229,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
};
+ mSwipeRefreshLayout.setOnRefreshListener(() -> {
+ mPostViewModel.refresh();
+ });
+
+ mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
+
if (savedInstanceState != null) {
int recyclerViewPosition = savedInstanceState.getInt(RECYCLER_VIEW_POSITION_STATE);
if (recyclerViewPosition > 0) {
@@ -465,11 +474,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostRecyclerView.setAdapter(mAdapter);
mPostViewModel = new ViewModelProvider(this, factory).get(PostViewModel.class);
- mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts));
+ mPostViewModel.getPosts().observe(this, posts -> {
+ mAdapter.submitList(posts);
+ });
mPostViewModel.hasPost().observe(this, hasPost -> {
this.hasPost = hasPost;
- mProgressBar.setVisibility(View.GONE);
+ mSwipeRefreshLayout.setRefreshing(false);
if (hasPost) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
} else {
@@ -485,13 +496,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel.getInitialLoadingState().observe(this, networkState -> {
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
- mProgressBar.setVisibility(View.GONE);
+ mSwipeRefreshLayout.setRefreshing(false);
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
- mProgressBar.setVisibility(View.GONE);
+ mSwipeRefreshLayout.setRefreshing(false);
mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh());
showErrorView(R.string.load_posts_error);
} else {
- mProgressBar.setVisibility(View.VISIBLE);
+ mSwipeRefreshLayout.setRefreshing(true);
}
});
@@ -541,7 +552,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private void showErrorView(int stringResId) {
if (activity != null && isAdded()) {
- mProgressBar.setVisibility(View.GONE);
+ mSwipeRefreshLayout.setRefreshing(false);
mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchPostInfoTextView.setText(stringResId);
mGlide.load(R.drawable.error_image).into(mFetchPostInfoImageView);
@@ -689,16 +700,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
@Override
- public void onStart() {
- super.onStart();
- if (isInLazyMode && isLazyModePaused) {
- resumeLazyMode(false);
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
+ public void onPause() {
+ super.onPause();
if (isInLazyMode) {
pauseLazyMode(false);
}
diff --git a/app/src/main/res/layout/fragment_post.xml b/app/src/main/res/layout/fragment_post.xml
index 56a9290f..263929d6 100644
--- a/app/src/main/res/layout/fragment_post.xml
+++ b/app/src/main/res/layout/fragment_post.xml
@@ -5,22 +5,19 @@
android:layout_height="match_parent"
tools:application="ml.docilealligator.infinityforreddit.Fragment.PostFragment">
- <com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
- android:id="@+id/progress_bar_post_fragment"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dp"
- android:layout_marginBottom="16dp"
- app:mlpb_progress_stoke_width="3dp"
- app:mlpb_progress_color="@color/colorAccent"
- app:mlpb_background_color="?attr/circularProgressBarBackground"
- android:layout_gravity="center_horizontal"/>
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/recycler_view_post_fragment"
+ <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+ android:id="@+id/swipe_refresh_layout_post_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:clipToPadding="false" />
+ android:background="@color/backgroundColor">
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/recycler_view_post_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:clipToPadding="false" />
+
+ </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/fetch_post_info_linear_layout_post_fragment"
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 57a528fd..3248cfd4 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -27,6 +27,11 @@
<item name="android:windowTranslucentStatus">true</item>
</style>
+ <style name="AppTheme.NoActionBarWithTransparentBackground" parent="AppTheme.NoActionBar">
+ <item name="android:windowIsTranslucent">true</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ </style>
+
<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
<item name="android:windowBackground">@android:color/black</item>
<item name="android:windowTranslucentStatus">true</item>