mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +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
|
@Delete
|
||||||
public abstract void deleteSynchronous(Contribution contribution);
|
public abstract void deleteSynchronous(Contribution contribution);
|
||||||
|
|
||||||
@Delete
|
@Query("DELETE FROM contribution WHERE state IN (:states)")
|
||||||
public abstract void deleteContributionsSynchronous(List<Contribution> contributions);
|
public abstract void deleteContributionsWithStatesSynchronous(List<Integer> states) throws SQLiteException;
|
||||||
|
|
||||||
public Completable delete(final Contribution contribution) {
|
public Completable delete(final Contribution contribution) {
|
||||||
return Completable
|
return Completable
|
||||||
.fromAction(() -> deleteSynchronous(contribution));
|
.fromAction(() -> deleteSynchronous(contribution));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Completable deleteContributions(final List<Contribution> contributions) {
|
public Completable deleteContributionsWithStates(List<Integer> states) {
|
||||||
return Completable
|
return Completable
|
||||||
.fromAction(() -> deleteContributionsSynchronous(contributions));
|
.fromAction(() -> deleteContributionsWithStatesSynchronous(states));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query("SELECT * from contribution WHERE media_filename=:fileName")
|
@Query("SELECT * from contribution WHERE media_filename=:fileName")
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,8 @@ class ContributionsLocalDataSource {
|
||||||
return contributionDao.delete(contribution);
|
return contributionDao.delete(contribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Completable deleteContributions(final List<Contribution> contributions) {
|
public Completable deleteContributionsWithStates(List<Integer> states) {
|
||||||
return contributionDao.deleteContributions(contributions);
|
return contributionDao.deleteContributionsWithStates(states);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Factory<Integer, Contribution> getContributions() {
|
public Factory<Integer, Contribution> getContributions() {
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ public class ContributionsRepository {
|
||||||
return localDataSource.deleteContribution(contribution);
|
return localDataSource.deleteContribution(contribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Completable deleteContributionsFromDB(List<Contribution> contributions) {
|
public Completable deleteContributionsFromDBWithStates(List<Integer> states) {
|
||||||
return localDataSource.deleteContributions(contributions);
|
return localDataSource.deleteContributionsWithStates(states);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCont
|
||||||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||||
uploadProgressActivity.hidePendingIcons()
|
uploadProgressActivity.hidePendingIcons()
|
||||||
pendingUploadsPresenter.deleteUploads(
|
pendingUploadsPresenter.deleteUploads(
|
||||||
contributionsList,
|
listOf(Contribution.STATE_FAILED),
|
||||||
this.requireContext().applicationContext
|
this.requireContext().applicationContext
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,6 @@ class PendingUploadsAdapter(private val callback: Callback) :
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bindState(state: Int) {
|
fun bindState(state: Int) {
|
||||||
Timber.tag("PRINT").e("State is: "+state)
|
|
||||||
if (state == Contribution.STATE_QUEUED || state == Contribution.STATE_PAUSED) {
|
if (state == Contribution.STATE_QUEUED || state == Contribution.STATE_PAUSED) {
|
||||||
errorTextView.text = "Queued"
|
errorTextView.text = "Queued"
|
||||||
errorTextView.visibility = View.VISIBLE
|
errorTextView.visibility = View.VISIBLE
|
||||||
|
|
@ -98,7 +97,6 @@ class PendingUploadsAdapter(private val callback: Callback) :
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bindProgress(transferred: Long, total: Long, state: Int) {
|
fun bindProgress(transferred: Long, total: Long, state: Int) {
|
||||||
Timber.tag("PRINT").e("State is2: "+state)
|
|
||||||
if (transferred == 0L) {
|
if (transferred == 0L) {
|
||||||
errorTextView.text = "Queued"
|
errorTextView.text = "Queued"
|
||||||
errorTextView.visibility = View.VISIBLE
|
errorTextView.visibility = View.VISIBLE
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||||
uploadProgressActivity.hidePendingIcons()
|
uploadProgressActivity.hidePendingIcons()
|
||||||
pendingUploadsPresenter.deleteUploads(
|
pendingUploadsPresenter.deleteUploads(
|
||||||
contributionsList,
|
listOf(Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS, Contribution.STATE_PAUSED),
|
||||||
this.requireContext().applicationContext
|
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
|
compositeDisposable.add(repository
|
||||||
.deleteContributionsFromDB(contributionList)
|
.deleteContributionsFromDBWithStates(states)
|
||||||
.subscribeOn(ioThreadScheduler)
|
.subscribeOn(ioThreadScheduler)
|
||||||
.subscribe(() ->
|
.subscribe(() ->
|
||||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,8 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
||||||
CommonsApplication.NOTIFICATION_CHANNEL_ID_ALL
|
CommonsApplication.NOTIFICATION_CHANNEL_ID_ALL
|
||||||
)!!
|
)!!
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
|
||||||
|
//TODO: Implement Worker Flags
|
||||||
/*
|
/*
|
||||||
queuedContributions receives the results from a one-shot query.
|
queuedContributions receives the results from a one-shot query.
|
||||||
This means that once the list has been fetched from the database,
|
This means that once the list has been fetched from the database,
|
||||||
|
|
@ -187,6 +189,9 @@ 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/5136
|
||||||
https://github.com/commons-app/apps-android-commons/issues/5346
|
https://github.com/commons-app/apps-android-commons/issues/5346
|
||||||
*/
|
*/
|
||||||
|
while (contributionDao.getContribution(statesToProcess)
|
||||||
|
.blockingGet().size > 0
|
||||||
|
) {
|
||||||
val queuedContributions = contributionDao.getContribution(statesToProcess)
|
val queuedContributions = contributionDao.getContribution(statesToProcess)
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
//Showing initial notification for the number of uploads being processed
|
//Showing initial notification for the number of uploads being processed
|
||||||
|
|
@ -205,7 +210,8 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
||||||
processingUploads.build()
|
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
|
* To avoid race condition when multiple of these workers are working, assign this state
|
||||||
|
|
@ -226,7 +232,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
||||||
countUpload++
|
countUpload++
|
||||||
uploadContribution(contribution = contribution)
|
uploadContribution(contribution = contribution)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//Dismiss the global notification
|
//Dismiss the global notification
|
||||||
notificationManager?.cancel(
|
notificationManager?.cancel(
|
||||||
PROCESSING_UPLOADS_NOTIFICATION_TAG,
|
PROCESSING_UPLOADS_NOTIFICATION_TAG,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue