aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostPaginationScrollListener.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java2
5 files changed, 24 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index 511949b2..0b856945 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -41,10 +41,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
static final String SUBREDDIT_NAME_KEY = "SNK";
static final String IS_BEST_POST_KEY = "IBPK";
- private static final String POST_DATA_PARCELABLE_STATE = "PDPS";
private static final String LAST_ITEM_STATE = "LIS";
private static final String LOADING_STATE_STATE = "LSS";
private static final String LOAD_SUCCESS_STATE = "LOSS";
+ private static final String IS_REFRESH_STATE = "IRS";
private CoordinatorLayout mCoordinatorLayout;
private RecyclerView mPostRecyclerView;
@@ -53,7 +53,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private LinearLayout mFetchPostErrorLinearLayout;
private ImageView mFetchPostErrorImageView;
- private ArrayList<Post> mPostData;
private String mLastItem;
private PaginationSynchronizer mPaginationSynchronizer;
@@ -145,11 +144,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel.getPosts().observe(this, new Observer<ArrayList<Post>>() {
@Override
public void onChanged(@Nullable ArrayList<Post> posts) {
- mAdapter.changeDataSet(posts);
if(posts == null) {
Log.i("datachange", Integer.toString(0));
} else {
Log.i("datachange", Integer.toString(posts.size()));
+ mAdapter.changeDataSet(posts);
}
}
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostPaginationScrollListener.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostPaginationScrollListener.java
index 29b1776e..0c11e305 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostPaginationScrollListener.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostPaginationScrollListener.java
@@ -104,11 +104,9 @@ class PostPaginationScrollListener extends RecyclerView.OnScrollListener {
if(response.isSuccessful()) {
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
@Override
- public void onParsePostSuccess(ArrayList<Post> newPostData, String lastItem) {
+ public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
if(mPostViewModel != null) {
- ArrayList<Post> posts = mPostViewModel.getPosts().getValue();
- posts.addAll(newPostData);
- mPostViewModel.setPosts(posts);
+ mPostViewModel.addPosts(newPosts);
mLastItem = lastItem;
mPaginationSynchronizer.notifyLastItemChanged(lastItem);
@@ -154,11 +152,9 @@ class PostPaginationScrollListener extends RecyclerView.OnScrollListener {
if(response.isSuccessful()) {
ParsePost.parsePost(response.body(), locale, new ParsePost.ParsePostListener() {
@Override
- public void onParsePostSuccess(ArrayList<Post> newPostData, String lastItem) {
+ public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
if(mPostViewModel != null) {
- ArrayList<Post> posts = mPostViewModel.getPosts().getValue();
- posts.addAll(newPostData);
- mPostViewModel.setPosts(posts);
+ mPostViewModel.addPosts(newPosts);
mLastItem = lastItem;
mPaginationSynchronizer.notifyLastItemChanged(lastItem);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 9ded7a44..a3a7e504 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -61,6 +61,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
private static final int VIEW_TYPE_DATA = 0;
private static final int VIEW_TYPE_LOADING = 1;
+ private int dataSize;
PostRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, SharedPreferences sharedPreferences, PaginationSynchronizer paginationSynchronizer, boolean hasMultipleSubreddits) {
if(context != null) {
@@ -505,7 +506,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
});
if(post.isNSFW()) {
- imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 2)))
.into(((DataViewHolder) holder).imageView);
} else {
imageRequestBuilder.into(((DataViewHolder) holder).imageView);
@@ -526,7 +527,12 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
void changeDataSet(ArrayList<Post> posts) {
mPostData = posts;
- notifyDataSetChanged();
+ if(dataSize == 0 || posts.size() <= dataSize) {
+ notifyDataSetChanged();
+ } else {
+ notifyItemRangeInserted(dataSize, posts.size() - dataSize);
+ }
+ dataSize = posts.size();
}
class DataViewHolder extends RecyclerView.ViewHolder {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
index f665380f..af6c1f31 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java
@@ -6,7 +6,7 @@ import android.arch.lifecycle.ViewModel;
import java.util.ArrayList;
-class PostViewModel extends ViewModel {
+public class PostViewModel extends ViewModel {
private MutableLiveData<ArrayList<Post>> posts = new MutableLiveData<>();
LiveData<ArrayList<Post>> getPosts() {
@@ -19,4 +19,12 @@ class PostViewModel extends ViewModel {
void setPosts(ArrayList<Post> posts) {
this.posts.postValue(posts);
}
+
+ void addPosts(ArrayList<Post> newPosts) {
+ ArrayList<Post> posts = this.posts.getValue();
+ if(posts != null) {
+ posts.addAll(newPosts);
+ this.posts.postValue(posts);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 427b12ed..27d152d1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -550,7 +550,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
});
if(mPost.isNSFW()) {
- imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 3)))
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 2)))
.into(mImageView);
} else {
imageRequestBuilder.into(mImageView);