mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 02:18:23 +01:00
Swiping to refresh posts is now available.
This commit is contained in:
parent
3233ca6471
commit
e0a9a02157
@ -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'
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -5,16 +5,11 @@
|
||||
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.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipe_refresh_layout_post_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/backgroundColor">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_post_fragment"
|
||||
@ -22,6 +17,8 @@
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false" />
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/fetch_post_info_linear_layout_post_fragment"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user