mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Minor fixes
This commit is contained in:
parent
1e032e6bdf
commit
04c102d641
9 changed files with 61 additions and 66 deletions
|
|
@ -20,15 +20,6 @@ public abstract class ContributionDao {
|
|||
@Query("SELECT * FROM contribution order by media_dateUploaded DESC")
|
||||
abstract DataSource.Factory<Integer, Contribution> fetchContributions();
|
||||
|
||||
@Query("SELECT * FROM contribution WHERE state = -1 ORDER BY media_dateUploaded DESC")
|
||||
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateCompleted();
|
||||
|
||||
@Query("SELECT * FROM contribution WHERE state IN (2, 3, 4) ORDER BY media_dateUploaded DESC")
|
||||
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateInProgress();
|
||||
|
||||
@Query("SELECT * FROM contribution WHERE state = 1 ORDER BY media_dateUploaded DESC")
|
||||
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateFailed();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract void saveSynchronous(Contribution contribution);
|
||||
|
||||
|
|
@ -67,6 +58,9 @@ public abstract class ContributionDao {
|
|||
@Query("SELECT * from contribution WHERE state IN (:states) order by media_dateUploaded DESC")
|
||||
public abstract Single<List<Contribution>> getContribution(List<Integer> states);
|
||||
|
||||
@Query("SELECT * from contribution WHERE state IN (:states) order by media_dateUploaded DESC")
|
||||
public abstract DataSource.Factory<Integer, Contribution> getContributions(List<Integer> states);
|
||||
|
||||
@Query("SELECT COUNT(*) from contribution WHERE state in (:toUpdateStates)")
|
||||
public abstract Single<Integer> getPendingUploads(int[] toUpdateStates);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import fr.free.nrw.commons.contributions.ContributionsListContract.UserActionLis
|
|||
import fr.free.nrw.commons.di.CommonsApplicationModule;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
|
|
@ -38,7 +40,7 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
this.contributionBoundaryCallback = contributionBoundaryCallback;
|
||||
this.repository = repository;
|
||||
this.ioThreadScheduler = ioThreadScheduler;
|
||||
this.contributionsRemoteDataSource=contributionsRemoteDataSource;
|
||||
this.contributionsRemoteDataSource = contributionsRemoteDataSource;
|
||||
compositeDisposable = new CompositeDisposable();
|
||||
}
|
||||
|
||||
|
|
@ -73,10 +75,12 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
} else {
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchCompletedContributions();
|
||||
factory = repository.fetchContributionsWithStates(
|
||||
Collections.singletonList(Contribution.STATE_COMPLETED));
|
||||
}
|
||||
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, pagedListConfig);
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||
}
|
||||
|
|
@ -100,7 +104,11 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
boolean shouldSetBoundaryCallback;
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchInProgressContributions();
|
||||
|
||||
factory = repository.fetchContributionsWithStates(
|
||||
Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
|
||||
Contribution.STATE_PAUSED));
|
||||
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
|
|
@ -118,7 +126,8 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
boolean shouldSetBoundaryCallback;
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchFailedContributions();
|
||||
factory = repository.fetchContributionsWithStates(
|
||||
Collections.singletonList(Contribution.STATE_FAILED));
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
|
|
|
|||
|
|
@ -67,16 +67,8 @@ class ContributionsLocalDataSource {
|
|||
return contributionDao.fetchContributions();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> getCompletedContributions() {
|
||||
return contributionDao.fetchContributionsWithStateCompleted();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> getInProgressContributions() {
|
||||
return contributionDao.fetchContributionsWithStateInProgress();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> getFailedContributions() {
|
||||
return contributionDao.fetchContributionsWithStateFailed();
|
||||
public Factory<Integer, Contribution> getContributionsWithStates(List<Integer> states) {
|
||||
return contributionDao.getContributions(states);
|
||||
}
|
||||
|
||||
public Single<List<Long>> saveContributions(final List<Contribution> contributions) {
|
||||
|
|
|
|||
|
|
@ -49,16 +49,8 @@ public class ContributionsRepository {
|
|||
return localDataSource.getContributions();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> fetchCompletedContributions() {
|
||||
return localDataSource.getCompletedContributions();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> fetchInProgressContributions() {
|
||||
return localDataSource.getInProgressContributions();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> fetchFailedContributions() {
|
||||
return localDataSource.getFailedContributions();
|
||||
public Factory<Integer, Contribution> fetchContributionsWithStates(List<Integer> states) {
|
||||
return localDataSource.getContributionsWithStates(states);
|
||||
}
|
||||
|
||||
public Single<List<Long>> save(List<Contribution> contributions) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ class PendingUploadsAdapter(items: List<Contribution>, callback: Callback) :
|
|||
holder.itemImage.setImageRequest(imageRequest)
|
||||
}
|
||||
}
|
||||
Timber.tag("PRINT").e(item.state.toString() + " " + item)
|
||||
if (item.state == Contribution.STATE_QUEUED || item.state == Contribution.STATE_PAUSED) {
|
||||
holder.errorTextView.setText("Queued")
|
||||
holder.errorTextView.visibility = View.VISIBLE
|
||||
|
|
|
|||
|
|
@ -261,9 +261,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
*/
|
||||
fun retryUpload(contribution: Contribution) {
|
||||
if (NetworkUtils.isInternetConnectionEstablished(context)) {
|
||||
if (contribution.state == Contribution.STATE_PAUSED
|
||||
|| contribution.state == Contribution.STATE_QUEUED_LIMITED_CONNECTION_MODE
|
||||
) {
|
||||
if (contribution.state == Contribution.STATE_PAUSED) {
|
||||
restartUpload(contribution)
|
||||
} else if (contribution.state == Contribution.STATE_FAILED) {
|
||||
val retries = contribution.retries
|
||||
|
|
|
|||
|
|
@ -15,16 +15,16 @@ import fr.free.nrw.commons.contributions.ContributionBoundaryCallback;
|
|||
import fr.free.nrw.commons.contributions.ContributionsRemoteDataSource;
|
||||
import fr.free.nrw.commons.contributions.ContributionsRepository;
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule;
|
||||
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
|
||||
import fr.free.nrw.commons.upload.PendingUploadsContract.UserActionListener;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* The presenter class for Contributions
|
||||
|
|
@ -50,7 +50,7 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
this.contributionBoundaryCallback = contributionBoundaryCallback;
|
||||
this.repository = repository;
|
||||
this.ioThreadScheduler = ioThreadScheduler;
|
||||
this.contributionsRemoteDataSource=contributionsRemoteDataSource;
|
||||
this.contributionsRemoteDataSource = contributionsRemoteDataSource;
|
||||
compositeDisposable = new CompositeDisposable();
|
||||
}
|
||||
|
||||
|
|
@ -82,10 +82,13 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
} else {
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchInProgressContributions();
|
||||
factory = repository.fetchContributionsWithStates(
|
||||
Arrays.asList(Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS,
|
||||
Contribution.STATE_PAUSED));
|
||||
}
|
||||
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, pagedListConfig);
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||
}
|
||||
|
|
@ -102,7 +105,8 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
boolean shouldSetBoundaryCallback;
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchFailedContributions();
|
||||
factory = repository.fetchContributionsWithStates(
|
||||
Collections.singletonList(Contribution.STATE_FAILED));
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
|
|
@ -137,11 +141,11 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
));
|
||||
}
|
||||
|
||||
public void pauseUploads(List<Contribution> l, int index, Context context) {
|
||||
if (index >= l.size()) {
|
||||
public void pauseUploads(List<Contribution> contributionList, int index, Context context) {
|
||||
if (index >= contributionList.size()) {
|
||||
return;
|
||||
}
|
||||
Contribution it = l.get(index);
|
||||
Contribution it = contributionList.get(index);
|
||||
CommonsApplication.pauseUploads.put(it.getPageId().toString(), true);
|
||||
//Retain the paused state in DB
|
||||
it.setState(Contribution.STATE_PAUSED);
|
||||
|
|
@ -149,26 +153,26 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
.save(it)
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.doOnComplete(() -> {
|
||||
pauseUploads(l, index + 1, context);
|
||||
pauseUploads(contributionList, index + 1, context);
|
||||
}
|
||||
)
|
||||
.subscribe( () ->
|
||||
.subscribe(() ->
|
||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||
context, ExistingWorkPolicy.KEEP)
|
||||
));
|
||||
}
|
||||
|
||||
public void deleteUploads(List<Contribution> l, int index, Context context) {
|
||||
if (index >= l.size()) {
|
||||
public void deleteUploads(List<Contribution> contributionList, int index, Context context) {
|
||||
if (index >= contributionList.size()) {
|
||||
return;
|
||||
}
|
||||
Contribution it = l.get(index);
|
||||
Contribution it = contributionList.get(index);
|
||||
compositeDisposable.add(repository
|
||||
.deleteContributionFromDB(it)
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.doOnComplete(() -> {
|
||||
CommonsApplication.cancelledUploads.add(it.getPageId());
|
||||
deleteUploads(l, index + 1, context);
|
||||
deleteUploads(contributionList, index + 1, context);
|
||||
}
|
||||
)
|
||||
.subscribe(() ->
|
||||
|
|
@ -177,18 +181,18 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
));
|
||||
}
|
||||
|
||||
public void restartUploads(List<Contribution> l, int index, Context context) {
|
||||
if (index >= l.size()) {
|
||||
public void restartUploads(List<Contribution> contributionList, int index, Context context) {
|
||||
if (index >= contributionList.size()) {
|
||||
return;
|
||||
}
|
||||
Contribution it = l.get(index);
|
||||
Contribution it = contributionList.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);
|
||||
CommonsApplication.pauseUploads.put(it.getPageId().toString(), false);
|
||||
restartUploads(contributionList, index + 1, context);
|
||||
}
|
||||
)
|
||||
.subscribe(() ->
|
||||
|
|
@ -197,11 +201,11 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
));
|
||||
}
|
||||
|
||||
public void restartUpload(List<Contribution> l, int index, Context context) {
|
||||
if (index >= l.size()) {
|
||||
public void restartUpload(List<Contribution> contributionList, int index, Context context) {
|
||||
if (index >= contributionList.size()) {
|
||||
return;
|
||||
}
|
||||
Contribution it = l.get(index);
|
||||
Contribution it = contributionList.get(index);
|
||||
it.setState(Contribution.STATE_QUEUED);
|
||||
compositeDisposable.add(repository
|
||||
.save(it)
|
||||
|
|
|
|||
|
|
@ -81,10 +81,19 @@ class UploadClient @Inject constructor(
|
|||
if (CommonsApplication.cancelledUploads.contains(contribution.pageId)) {
|
||||
compositeDisposable.clear()
|
||||
return@forEach
|
||||
}else{
|
||||
} else {
|
||||
processChunk(
|
||||
filename, contribution, notificationUpdater, chunkFile,
|
||||
failures, chunkInfo, index, errorMessage, mediaType!!, file!!, fileChunks.size
|
||||
filename,
|
||||
contribution,
|
||||
notificationUpdater,
|
||||
chunkFile,
|
||||
failures,
|
||||
chunkInfo,
|
||||
index,
|
||||
errorMessage,
|
||||
mediaType!!,
|
||||
file!!,
|
||||
fileChunks.size
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,8 +189,6 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
.blockingGet()
|
||||
//Showing initial notification for the number of uploads being processed
|
||||
|
||||
Timber.tag("PRINT").e("Queued Contributions: " + queuedContributions.size)
|
||||
|
||||
processingUploads.setContentTitle(appContext.getString(R.string.starting_uploads))
|
||||
processingUploads.setContentText(
|
||||
appContext.resources.getQuantityString(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue