mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Improved current implementation
This commit is contained in:
parent
b8723ad5af
commit
5b57c25110
8 changed files with 44 additions and 40 deletions
|
|
@ -47,17 +47,17 @@ public abstract class ContributionDao {
|
|||
@Delete
|
||||
public abstract void deleteSynchronous(Contribution contribution);
|
||||
|
||||
@Delete
|
||||
public abstract void deleteContributionsSynchronous(List<Contribution> contributions);
|
||||
@Query("DELETE FROM contribution WHERE state IN (:states)")
|
||||
public abstract void deleteContributionsWithStatesSynchronous(List<Integer> states) throws SQLiteException;
|
||||
|
||||
public Completable delete(final Contribution contribution) {
|
||||
return Completable
|
||||
.fromAction(() -> deleteSynchronous(contribution));
|
||||
}
|
||||
|
||||
public Completable deleteContributions(final List<Contribution> contributions) {
|
||||
public Completable deleteContributionsWithStates(List<Integer> states) {
|
||||
return Completable
|
||||
.fromAction(() -> deleteContributionsSynchronous(contributions));
|
||||
.fromAction(() -> deleteContributionsWithStatesSynchronous(states));
|
||||
}
|
||||
|
||||
@Query("SELECT * from contribution WHERE media_filename=:fileName")
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ class ContributionsLocalDataSource {
|
|||
return contributionDao.delete(contribution);
|
||||
}
|
||||
|
||||
public Completable deleteContributions(final List<Contribution> contributions) {
|
||||
return contributionDao.deleteContributions(contributions);
|
||||
public Completable deleteContributionsWithStates(List<Integer> states) {
|
||||
return contributionDao.deleteContributionsWithStates(states);
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> getContributions() {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ public class ContributionsRepository {
|
|||
return localDataSource.deleteContribution(contribution);
|
||||
}
|
||||
|
||||
public Completable deleteContributionsFromDB(List<Contribution> contributions) {
|
||||
return localDataSource.deleteContributions(contributions);
|
||||
public Completable deleteContributionsFromDBWithStates(List<Integer> states) {
|
||||
return localDataSource.deleteContributionsWithStates(states);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCont
|
|||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||
uploadProgressActivity.hidePendingIcons()
|
||||
pendingUploadsPresenter.deleteUploads(
|
||||
contributionsList,
|
||||
listOf(Contribution.STATE_FAILED),
|
||||
this.requireContext().applicationContext
|
||||
)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ class PendingUploadsAdapter(private val callback: Callback) :
|
|||
}
|
||||
|
||||
fun bindState(state: Int) {
|
||||
Timber.tag("PRINT").e("State is: "+state)
|
||||
if (state == Contribution.STATE_QUEUED || state == Contribution.STATE_PAUSED) {
|
||||
errorTextView.text = "Queued"
|
||||
errorTextView.visibility = View.VISIBLE
|
||||
|
|
@ -98,7 +97,6 @@ class PendingUploadsAdapter(private val callback: Callback) :
|
|||
}
|
||||
|
||||
fun bindProgress(transferred: Long, total: Long, state: Int) {
|
||||
Timber.tag("PRINT").e("State is2: "+state)
|
||||
if (transferred == 0L) {
|
||||
errorTextView.text = "Queued"
|
||||
errorTextView.visibility = View.VISIBLE
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||
uploadProgressActivity.hidePendingIcons()
|
||||
pendingUploadsPresenter.deleteUploads(
|
||||
contributionsList,
|
||||
listOf(Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS, Contribution.STATE_PAUSED),
|
||||
this.requireContext().applicationContext
|
||||
)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -136,9 +136,9 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
));
|
||||
}
|
||||
|
||||
public void deleteUploads(List<Contribution> contributionList, Context context) {
|
||||
public void deleteUploads(List<Integer> states, Context context) {
|
||||
compositeDisposable.add(repository
|
||||
.deleteContributionsFromDB(contributionList)
|
||||
.deleteContributionsFromDBWithStates(states)
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.subscribe(() ->
|
||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||
|
|
|
|||
|
|
@ -177,6 +177,8 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
CommonsApplication.NOTIFICATION_CHANNEL_ID_ALL
|
||||
)!!
|
||||
withContext(Dispatchers.IO) {
|
||||
|
||||
//TODO: Implement Worker Flags
|
||||
/*
|
||||
queuedContributions receives the results from a one-shot query.
|
||||
This means that once the list has been fetched from the database,
|
||||
|
|
@ -187,46 +189,50 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
https://github.com/commons-app/apps-android-commons/issues/5136
|
||||
https://github.com/commons-app/apps-android-commons/issues/5346
|
||||
*/
|
||||
val queuedContributions = contributionDao.getContribution(statesToProcess)
|
||||
.blockingGet()
|
||||
//Showing initial notification for the number of uploads being processed
|
||||
while (contributionDao.getContribution(statesToProcess)
|
||||
.blockingGet().size > 0
|
||||
) {
|
||||
val queuedContributions = contributionDao.getContribution(statesToProcess)
|
||||
.blockingGet()
|
||||
//Showing initial notification for the number of uploads being processed
|
||||
|
||||
processingUploads.setContentTitle(appContext.getString(R.string.starting_uploads))
|
||||
processingUploads.setContentText(
|
||||
appContext.resources.getQuantityString(
|
||||
processingUploads.setContentTitle(appContext.getString(R.string.starting_uploads))
|
||||
processingUploads.setContentText(
|
||||
appContext.resources.getQuantityString(
|
||||
R.plurals.starting_multiple_uploads,
|
||||
queuedContributions.size,
|
||||
queuedContributions.size
|
||||
)
|
||||
)
|
||||
notificationManager?.notify(
|
||||
PROCESSING_UPLOADS_NOTIFICATION_TAG,
|
||||
PROCESSING_UPLOADS_NOTIFICATION_ID,
|
||||
processingUploads.build()
|
||||
)
|
||||
)
|
||||
notificationManager?.notify(
|
||||
PROCESSING_UPLOADS_NOTIFICATION_TAG,
|
||||
PROCESSING_UPLOADS_NOTIFICATION_ID,
|
||||
processingUploads.build()
|
||||
)
|
||||
|
||||
val sortedQueuedContributionsList: List<Contribution> = queuedContributions.sortedBy { it.dateUploadStartedInMillis() }
|
||||
val sortedQueuedContributionsList: List<Contribution> =
|
||||
queuedContributions.sortedBy { it.dateUploadStartedInMillis() }
|
||||
|
||||
/**
|
||||
* To avoid race condition when multiple of these workers are working, assign this state
|
||||
so that the next one does not process these contribution again
|
||||
*/
|
||||
/**
|
||||
* To avoid race condition when multiple of these workers are working, assign this state
|
||||
so that the next one does not process these contribution again
|
||||
*/
|
||||
// sortedQueuedContributionsList.forEach {
|
||||
// it.state = Contribution.STATE_IN_PROGRESS
|
||||
// contributionDao.saveSynchronous(it)
|
||||
// }
|
||||
|
||||
var contribution = sortedQueuedContributionsList.first()
|
||||
var contribution = sortedQueuedContributionsList.first()
|
||||
|
||||
if (contributionDao.getContribution(contribution.pageId) != null) {
|
||||
contribution.transferred = 0
|
||||
contribution.state = Contribution.STATE_IN_PROGRESS
|
||||
contributionDao.saveSynchronous(contribution)
|
||||
setProgressAsync(Data.Builder().putInt("progress", countUpload).build())
|
||||
countUpload++
|
||||
uploadContribution(contribution = contribution)
|
||||
if (contributionDao.getContribution(contribution.pageId) != null) {
|
||||
contribution.transferred = 0
|
||||
contribution.state = Contribution.STATE_IN_PROGRESS
|
||||
contributionDao.saveSynchronous(contribution)
|
||||
setProgressAsync(Data.Builder().putInt("progress", countUpload).build())
|
||||
countUpload++
|
||||
uploadContribution(contribution = contribution)
|
||||
}
|
||||
}
|
||||
|
||||
//Dismiss the global notification
|
||||
notificationManager?.cancel(
|
||||
PROCESSING_UPLOADS_NOTIFICATION_TAG,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue