mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-30 11:34:43 +01:00
Refreshing, changing sort type and post filter are now working in PostFragment.
This commit is contained in:
parent
ba2c12d45d
commit
09e1711e78
@ -1329,7 +1329,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
if (mPostViewModel != null) {
|
||||
mAdapter.removeFooter();
|
||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||
hasPost = false;
|
||||
@ -1337,10 +1336,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
stopLazyMode();
|
||||
}
|
||||
saveCache();
|
||||
mPostViewModel.refresh();
|
||||
} else {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
mAdapter.refresh();
|
||||
}
|
||||
|
||||
private void showErrorView(int stringResId) {
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
|
||||
public PostPaging3PagingSource returnPagingSoruce() {
|
||||
return paging3PagingSource;
|
||||
}
|
||||
|
||||
void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) {
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user