Fixed constantly failing uploads

This commit is contained in:
Kanahia 2024-07-18 20:07:22 +05:30
parent 926ef27e5e
commit ea693b3ddc
3 changed files with 15 additions and 37 deletions

View file

@ -100,7 +100,7 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCont
fun initRecyclerView() {
binding.failedUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context))
binding.failedUploadsRecyclerView.adapter = adapter
pendingUploadsPresenter!!.getFailedContributions(userName)
pendingUploadsPresenter!!.getFailedContributions()
pendingUploadsPresenter!!.failedContributionList.observe(
viewLifecycleOwner
) { list: PagedList<Contribution?> ->

View file

@ -108,10 +108,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
fun initRecyclerView() {
binding.pendingUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context))
binding.pendingUploadsRecyclerView.adapter = adapter
pendingUploadsPresenter!!.setup(
userName,
sessionManager!!.userName == userName
)
pendingUploadsPresenter!!.setup()
pendingUploadsPresenter!!.totalContributionList.observe(
viewLifecycleOwner
) { list: PagedList<Contribution?> ->

View file

@ -60,58 +60,31 @@ public class PendingUploadsPresenter implements UserActionListener {
* the live data object. This method can be tweaked to update the lazy loading behavior of the
* contributions list
*/
void setup(String userName, boolean isSelf) {
void setup() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
boolean shouldSetBoundaryCallback;
if (!isSelf) {
//We don't want to persist contributions for other user's, therefore
// creating a new DataSource for them
contributionsRemoteDataSource.setUserName(userName);
factory = new Factory<Integer, Contribution>() {
@NonNull
@Override
public DataSource<Integer, Contribution> create() {
return contributionsRemoteDataSource;
}
};
shouldSetBoundaryCallback = false;
} else {
contributionBoundaryCallback.setUserName(userName);
shouldSetBoundaryCallback = true;
factory = repository.fetchContributionsWithStates(
Arrays.asList(Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS,
Contribution.STATE_PAUSED));
}
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
if (shouldSetBoundaryCallback) {
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
}
totalContributionList = livePagedListBuilder.build();
}
void getFailedContributions(String userName) {
void getFailedContributions() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
boolean shouldSetBoundaryCallback;
contributionBoundaryCallback.setUserName(userName);
shouldSetBoundaryCallback = true;
factory = repository.fetchContributionsWithStates(
Collections.singletonList(Contribution.STATE_FAILED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
if (shouldSetBoundaryCallback) {
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
}
failedContributionList = livePagedListBuilder.build();
}
@ -186,6 +159,10 @@ public class PendingUploadsPresenter implements UserActionListener {
}
Contribution it = contributionList.get(index);
it.setState(Contribution.STATE_QUEUED);
if (it.getErrorInfo() == null){
it.setChunkInfo(null);
it.setTransferred(0);
}
compositeDisposable.add(repository
.save(it)
.subscribeOn(ioThreadScheduler)
@ -205,6 +182,10 @@ public class PendingUploadsPresenter implements UserActionListener {
return;
}
Contribution it = contributionList.get(index);
if (it.getErrorInfo() == null){
it.setChunkInfo(null);
it.setTransferred(0);
}
it.setState(Contribution.STATE_QUEUED);
compositeDisposable.add(repository
.save(it)