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