diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-09-06 13:22:27 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-09-06 13:22:27 +0000 |
commit | 1f02fcd0dabc7a08877e2769357565a2296d0006 (patch) | |
tree | dc86f0a83dad19454cb68efc9f7096bab5b144ff /app | |
parent | 09e1711e7851f86c193a7ad33d011b68490634cc (diff) | |
download | infinity-for-reddit-1f02fcd0dabc7a08877e2769357565a2296d0006.tar infinity-for-reddit-1f02fcd0dabc7a08877e2769357565a2296d0006.tar.gz infinity-for-reddit-1f02fcd0dabc7a08877e2769357565a2296d0006.tar.bz2 infinity-for-reddit-1f02fcd0dabc7a08877e2769357565a2296d0006.tar.lz infinity-for-reddit-1f02fcd0dabc7a08877e2769357565a2296d0006.tar.xz infinity-for-reddit-1f02fcd0dabc7a08877e2769357565a2296d0006.tar.zst infinity-for-reddit-1f02fcd0dabc7a08877e2769357565a2296d0006.zip |
Remove PostPaging3Repository.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java | 151 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java | 135 |
2 files changed, 112 insertions, 174 deletions
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 9ef8828d..3d28320a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/NewPostViewModel.java @@ -25,17 +25,41 @@ import ml.docilealligator.infinityforreddit.readpost.ReadPost; import retrofit2.Retrofit; public class NewPostViewModel extends ViewModel { - private PostPaging3Repository repository; + private Executor executor; + private Retrofit retrofit; + private String accessToken; + private String accountName; + private SharedPreferences sharedPreferences; + private SharedPreferences postFeedScrolledPositionSharedPreferences; + private String name; + private String query; + private String trendingSource; + private int postType; + private SortType sortType; + private PostFilter postFilter; + private String userWhere; + private List<ReadPost> readPostList; + private LiveData<PagingData<Post>> posts; - private PostPaging3PagingSource paging3PagingSource; private MutableLiveData<SortType> sortTypeLiveData; private MutableLiveData<PostFilter> postFilterLiveData; private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData; public NewPostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, - SharedPreferences sharedPreferences, SharedPreferences cache, int postType, + SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) { + 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; + sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); postFilterLiveData = new MutableLiveData<>(); @@ -43,23 +67,31 @@ public class NewPostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - repository = new PostPaging3Repository(executor, retrofit, accessToken, accountName, - sharedPreferences, cache, postType, sortType, postFilter, readPostList); - paging3PagingSource = repository.returnPagingSoruce(); Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { - repository.changeSortTypeAndPostFilter( + 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, - SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName, - int postType, SortType sortType, PostFilter postFilter, - List<ReadPost> readPostList) { + SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, + String subredditName, int postType, SortType sortType, PostFilter postFilter, + List<ReadPost> readPostList) { + 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 = subredditName; + sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); postFilterLiveData = new MutableLiveData<>(); @@ -67,23 +99,33 @@ public class NewPostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - repository = new PostPaging3Repository(executor, retrofit, accessToken, accountName, - sharedPreferences, cache, subredditName, postType, sortType, postFilter, readPostList); - paging3PagingSource = repository.returnPagingSoruce(); Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { - repository.changeSortTypeAndPostFilter( + 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, - SharedPreferences sharedPreferences, SharedPreferences cache, String username, - int postType, SortType sortType, PostFilter postFilter, String where, - List<ReadPost> readPostList) { + SharedPreferences sharedPreferences, + SharedPreferences postFeedScrolledPositionSharedPreferences, String username, + int postType, SortType sortType, PostFilter postFilter, String userWhere, + List<ReadPost> readPostList) { + 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 = username; + this.userWhere = userWhere; + sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); postFilterLiveData = new MutableLiveData<>(); @@ -91,23 +133,33 @@ public class NewPostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - repository = new PostPaging3Repository(executor, retrofit, accessToken, accountName, - sharedPreferences, cache, username, postType, sortType, postFilter, where, readPostList); - paging3PagingSource = repository.returnPagingSoruce(); Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { - repository.changeSortTypeAndPostFilter( + 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, - SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName, - String query, String trendingSource, int postType, SortType sortType, - PostFilter postFilter, List<ReadPost> readPostList) { + SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, + String subredditName, String query, String trendingSource, int postType, SortType sortType, + PostFilter postFilter, List<ReadPost> readPostList) { + 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 = subredditName; + this.query = query; + this.trendingSource = trendingSource; + sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); postFilterLiveData = new MutableLiveData<>(); @@ -115,26 +167,51 @@ public class NewPostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - repository = new PostPaging3Repository(executor, retrofit, accessToken, accountName, - sharedPreferences, cache, subredditName, query, trendingSource, postType, sortType, postFilter, - readPostList); - paging3PagingSource = repository.returnPagingSoruce(); Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { - repository.changeSortTypeAndPostFilter( + 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() { return posts; } - private PostPaging3PagingSource returnPagingSoruce() { - return repository.returnPagingSoruce(); + public PostPaging3PagingSource returnPagingSoruce() { + PostPaging3PagingSource paging3PagingSource; + switch (postType) { + case PostDataSource.TYPE_FRONT_PAGE: + paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName, + sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType, + postFilter, readPostList); + break; + case PostDataSource.TYPE_SUBREDDIT: + case PostDataSource.TYPE_MULTI_REDDIT: + case PostDataSource.TYPE_ANONYMOUS_FRONT_PAGE: + paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName, + sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType, + sortType, postFilter, readPostList); + break; + case PostDataSource.TYPE_SEARCH: + paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName, + sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource, + postType, sortType, postFilter, readPostList); + default: + //User + paging3PagingSource = new PostPaging3PagingSource(executor, retrofit, accessToken, accountName, + sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType, + sortType, postFilter, userWhere, readPostList); + break; + } + return paging3PagingSource; + } + + private void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) { + this.sortType = sortType; + this.postFilter = postFilter; } public void changeSortType(SortType sortType) { @@ -145,10 +222,6 @@ public class NewPostViewModel extends ViewModel { postFilterLiveData.postValue(postFilter); } - public void refresh() { - - } - public void retryLoadingMore() { } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java deleted file mode 100644 index 1f24730a..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPaging3Repository.java +++ /dev/null @@ -1,135 +0,0 @@ -package ml.docilealligator.infinityforreddit.post; - -import android.content.SharedPreferences; - -import java.util.List; -import java.util.concurrent.Executor; - -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.postfilter.PostFilter; -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) { - 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) { - 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) { - 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) { - 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; - } -} |