aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3PagingSource.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java105
4 files changed, 108 insertions, 34 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 59624b7f..f4ed088a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -1329,18 +1329,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void refresh() {
- if (mPostViewModel != null) {
- mAdapter.removeFooter();
- mFetchPostInfoLinearLayout.setVisibility(View.GONE);
- hasPost = false;
- if (isInLazyMode) {
- stopLazyMode();
- }
- saveCache();
- mPostViewModel.refresh();
- } else {
- mSwipeRefreshLayout.setRefreshing(false);
+ mAdapter.removeFooter();
+ mFetchPostInfoLinearLayout.setVisibility(View.GONE);
+ hasPost = false;
+ if (isInLazyMode) {
+ stopLazyMode();
}
+ saveCache();
+ mAdapter.refresh();
}
private void showErrorView(int stringResId) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java
index 970f380c..9ef8828d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java
@@ -49,10 +49,11 @@ public class NewPostViewModel extends ViewModel {
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
- paging3PagingSource.changeSortTypeAndPostFilter(
+ repository.changeSortTypeAndPostFilter(
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
+ //posts = PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
}
public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
@@ -72,10 +73,11 @@ public class NewPostViewModel extends ViewModel {
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
- paging3PagingSource.changeSortTypeAndPostFilter(
+ repository.changeSortTypeAndPostFilter(
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
+ //posts = PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
}
public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
@@ -95,10 +97,11 @@ public class NewPostViewModel extends ViewModel {
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
- paging3PagingSource.changeSortTypeAndPostFilter(
+ repository.changeSortTypeAndPostFilter(
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
+ //posts = PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
}
public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
@@ -119,10 +122,11 @@ public class NewPostViewModel extends ViewModel {
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
- paging3PagingSource.changeSortTypeAndPostFilter(
+ repository.changeSortTypeAndPostFilter(
sortTypeLiveData.getValue(), postFilterLiveData.getValue());
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
+ //posts = PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
}
public LiveData<PagingData<Post>> getPosts() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3PagingSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3PagingSource.java
index cde59067..dee6edd1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3PagingSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3PagingSource.java
@@ -157,6 +157,7 @@ public class PostPaging3PagingSource extends ListenableFuturePagingSource<String
@Nullable
@Override
public String getRefreshKey(@NonNull PagingState<String, Post> pagingState) {
+ Log.i("asdfad", "asdf " + sortType.getType().value);
return null;
}
@@ -385,10 +386,4 @@ public class PostPaging3PagingSource extends ListenableFuturePagingSource<String
return Futures.catching(partialLoadResultFuture,
IOException.class, LoadResult.Error::new, executor);
}
-
- void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) {
- Log.i("asdasfd", "s6 " + (postFilter == null));
- this.sortType = sortType;
- this.postFilter = postFilter;
- }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java
index 7030f433..1f24730a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java
@@ -11,46 +11,125 @@ import ml.docilealligator.infinityforreddit.readpost.ReadPost;
import retrofit2.Retrofit;
public class PostPaging3Repository {
+ Executor executor;
+ Retrofit retrofit;
+ String accessToken;
+ String accountName;
+ SharedPreferences sharedPreferences;
+ SharedPreferences postFeedScrolledPositionSharedPreferences;
+ int postType;
+ SortType sortType;
+ PostFilter postFilter;
+ List<ReadPost> readPostList;
+ String name;
+ String userWhere;
+ String query;
+ String trendingSource;
+
private PostPaging3PagingSource paging3PagingSource;
+ private int type;
PostPaging3Repository(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences,
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
- paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
- sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
- postFilter, readPostList);
+ type = 1;
+ this.executor = executor;
+ this.retrofit = retrofit;
+ this.accessToken = accessToken;
+ this.accountName = accountName;
+ this.sharedPreferences = sharedPreferences;
+ this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postType = postType;
+ this.sortType = sortType;
+ this.postFilter = postFilter;
+ this.readPostList = readPostList;
}
PostPaging3Repository(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String name, int postType, SortType sortType, PostFilter postFilter,
List<ReadPost> readPostList) {
- paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
- sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
- sortType, postFilter, readPostList);
+ type = 2;
+ this.executor = executor;
+ this.retrofit = retrofit;
+ this.accessToken = accessToken;
+ this.accountName = accountName;
+ this.sharedPreferences = sharedPreferences;
+ this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postType = postType;
+ this.sortType = sortType;
+ this.postFilter = postFilter;
+ this.readPostList = readPostList;
+ this.name = name;
}
PostPaging3Repository(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String name, int postType, SortType sortType, PostFilter postFilter,
String userWhere, List<ReadPost> readPostList) {
-
- paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
- sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
- sortType, postFilter, userWhere, readPostList);
+ type = 3;
+ this.executor = executor;
+ this.retrofit = retrofit;
+ this.accessToken = accessToken;
+ this.accountName = accountName;
+ this.sharedPreferences = sharedPreferences;
+ this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postType = postType;
+ this.sortType = sortType;
+ this.postFilter = postFilter;
+ this.readPostList = readPostList;
+ this.name = name;
+ this.userWhere = userWhere;
}
PostPaging3Repository(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String name, String query, String trendingSource, int postType, SortType sortType,
PostFilter postFilter, List<ReadPost> readPostList) {
- paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
- sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
- postType, sortType, postFilter, readPostList);
+ type = 4;
+ this.executor = executor;
+ this.retrofit = retrofit;
+ this.accessToken = accessToken;
+ this.accountName = accountName;
+ this.sharedPreferences = sharedPreferences;
+ this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postType = postType;
+ this.sortType = sortType;
+ this.postFilter = postFilter;
+ this.readPostList = readPostList;
+ this.name = name;
+ this.query = query;
+ this.trendingSource = trendingSource;
}
public PostPaging3PagingSource returnPagingSoruce() {
+ switch (type) {
+ case 1:
+ paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
+ sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
+ postFilter, readPostList);
+ break;
+ case 2:
+ paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
+ sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
+ sortType, postFilter, readPostList);
+ break;
+ case 3:
+ paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
+ sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
+ sortType, postFilter, userWhere, readPostList);
+ break;
+ default:
+ paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName,
+ sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
+ postType, sortType, postFilter, readPostList);
+ }
return paging3PagingSource;
}
+
+ void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) {
+ this.sortType = sortType;
+ this.postFilter = postFilter;
+ }
}