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() { fun initRecyclerView() {
binding.failedUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context)) binding.failedUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context))
binding.failedUploadsRecyclerView.adapter = adapter binding.failedUploadsRecyclerView.adapter = adapter
pendingUploadsPresenter!!.getFailedContributions(userName) pendingUploadsPresenter!!.getFailedContributions()
pendingUploadsPresenter!!.failedContributionList.observe( pendingUploadsPresenter!!.failedContributionList.observe(
viewLifecycleOwner viewLifecycleOwner
) { list: PagedList<Contribution?> -> ) { list: PagedList<Contribution?> ->

View file

@ -108,10 +108,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
fun initRecyclerView() { fun initRecyclerView() {
binding.pendingUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context)) binding.pendingUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context))
binding.pendingUploadsRecyclerView.adapter = adapter binding.pendingUploadsRecyclerView.adapter = adapter
pendingUploadsPresenter!!.setup( pendingUploadsPresenter!!.setup()
userName,
sessionManager!!.userName == userName
)
pendingUploadsPresenter!!.totalContributionList.observe( pendingUploadsPresenter!!.totalContributionList.observe(
viewLifecycleOwner viewLifecycleOwner
) { list: PagedList<Contribution?> -> ) { 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 * the live data object. This method can be tweaked to update the lazy loading behavior of the
* contributions list * contributions list
*/ */
void setup(String userName, boolean isSelf) { void setup() {
final PagedList.Config pagedListConfig = final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
.setPrefetchDistance(50) .setPrefetchDistance(50)
.setPageSize(10).build(); .setPageSize(10).build();
Factory<Integer, Contribution> factory; 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));
}
factory = repository.fetchContributionsWithStates(
Arrays.asList(Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS,
Contribution.STATE_PAUSED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig); pagedListConfig);
if (shouldSetBoundaryCallback) {
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
}
totalContributionList = livePagedListBuilder.build(); totalContributionList = livePagedListBuilder.build();
} }
void getFailedContributions(String userName) { void getFailedContributions() {
final PagedList.Config pagedListConfig = final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
.setPrefetchDistance(50) .setPrefetchDistance(50)
.setPageSize(10).build(); .setPageSize(10).build();
Factory<Integer, Contribution> factory; Factory<Integer, Contribution> factory;
boolean shouldSetBoundaryCallback;
contributionBoundaryCallback.setUserName(userName);
shouldSetBoundaryCallback = true;
factory = repository.fetchContributionsWithStates( factory = repository.fetchContributionsWithStates(
Collections.singletonList(Contribution.STATE_FAILED)); Collections.singletonList(Contribution.STATE_FAILED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig); pagedListConfig);
if (shouldSetBoundaryCallback) {
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
}
failedContributionList = livePagedListBuilder.build(); failedContributionList = livePagedListBuilder.build();
} }
@ -186,6 +159,10 @@ public class PendingUploadsPresenter implements UserActionListener {
} }
Contribution it = contributionList.get(index); Contribution it = contributionList.get(index);
it.setState(Contribution.STATE_QUEUED); it.setState(Contribution.STATE_QUEUED);
if (it.getErrorInfo() == null){
it.setChunkInfo(null);
it.setTransferred(0);
}
compositeDisposable.add(repository compositeDisposable.add(repository
.save(it) .save(it)
.subscribeOn(ioThreadScheduler) .subscribeOn(ioThreadScheduler)
@ -205,6 +182,10 @@ public class PendingUploadsPresenter implements UserActionListener {
return; return;
} }
Contribution it = contributionList.get(index); Contribution it = contributionList.get(index);
if (it.getErrorInfo() == null){
it.setChunkInfo(null);
it.setTransferred(0);
}
it.setState(Contribution.STATE_QUEUED); it.setState(Contribution.STATE_QUEUED);
compositeDisposable.add(repository compositeDisposable.add(repository
.save(it) .save(it)