mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Improved pause feature
This commit is contained in:
parent
a6c97521a1
commit
d825cd76fa
3 changed files with 48 additions and 14 deletions
|
|
@ -203,22 +203,14 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
}
|
||||
|
||||
fun restartUploads() {
|
||||
// TODO make the restart as in queue
|
||||
var contribution = l.get(0)
|
||||
contribution.state = Contribution.STATE_QUEUED
|
||||
pendingUploadsPresenter.saveContribution(contribution, this.requireContext().applicationContext)
|
||||
Timber.d("Restarting for %s", contribution.toString())
|
||||
if (l != null){
|
||||
pendingUploadsPresenter.restartUploads(l, 0 , this.requireContext().applicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
fun pauseUploads() {
|
||||
if (l != null){
|
||||
l.forEach {
|
||||
//Pause the upload in the global singleton
|
||||
CommonsApplication.pauseUploads[it.pageId] = true
|
||||
//Retain the paused state in DB
|
||||
it.state = Contribution.STATE_PAUSED
|
||||
pendingUploadsPresenter.saveContribution(it, this.requireContext().applicationContext)
|
||||
}
|
||||
pendingUploadsPresenter.pauseUploads(l, 0, this.requireContext().applicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import androidx.paging.DataSource.Factory;
|
|||
import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.work.ExistingWorkPolicy;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.contributions.ContributionBoundaryCallback;
|
||||
import fr.free.nrw.commons.contributions.ContributionsRemoteDataSource;
|
||||
|
|
@ -19,8 +20,10 @@ import fr.free.nrw.commons.upload.PendingUploadsContract.View;
|
|||
import fr.free.nrw.commons.upload.worker.WorkRequestHelper;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* The presenter class for Contributions
|
||||
|
|
@ -119,7 +122,48 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
.subscribe(() ->
|
||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||
context, ExistingWorkPolicy.KEEP)
|
||||
));
|
||||
}
|
||||
|
||||
public void pauseUploads(List<Contribution> l, int index, Context context) {
|
||||
Timber.tag("PRINT").e(CommonsApplication.pauseUploads.toString());
|
||||
if (index >= l.size()) {
|
||||
return;
|
||||
}
|
||||
Contribution it = l.get(index);
|
||||
CommonsApplication.pauseUploads.put(it.getPageId().toString(), true);
|
||||
//Retain the paused state in DB
|
||||
it.setState(Contribution.STATE_PAUSED);
|
||||
compositeDisposable.add(repository
|
||||
.save(it)
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.doOnComplete(() -> {
|
||||
pauseUploads(l, index + 1, context);
|
||||
}
|
||||
)
|
||||
.subscribe( () ->
|
||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||
context, ExistingWorkPolicy.KEEP)
|
||||
));
|
||||
}
|
||||
|
||||
public void restartUploads(List<Contribution> l, int index, Context context) {
|
||||
if (index >= l.size()) {
|
||||
return;
|
||||
}
|
||||
Contribution it = l.get(index);
|
||||
it.setState(Contribution.STATE_QUEUED);
|
||||
compositeDisposable.add(repository
|
||||
.save(it)
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.doOnComplete(() -> {
|
||||
CommonsApplication.pauseUploads.put(it.getPageId().toString(), false);
|
||||
restartUploads(l, index + 1, context);
|
||||
}
|
||||
)
|
||||
.subscribe(() ->
|
||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||
context, ExistingWorkPolicy.KEEP)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,8 +58,6 @@ class UploadClient @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
contribution.unpause()
|
||||
|
||||
val file = contribution.localUriPath
|
||||
val fileChunks = fileUtilsWrapper.getFileChunks(file, CHUNK_SIZE)
|
||||
val mediaType = fileUtilsWrapper.getMimeType(file).toMediaTypeOrNull()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue