Improved current implementation

This commit is contained in:
Kanahia 2024-07-21 21:18:51 +05:30
parent b8723ad5af
commit 5b57c25110
8 changed files with 44 additions and 40 deletions

View file

@ -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")

View file

@ -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() {

View file

@ -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);
}
/**

View file

@ -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
)
},

View file

@ -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

View file

@ -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
)
},

View file

@ -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(

View file

@ -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,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/5346
*/
while (contributionDao.getContribution(statesToProcess)
.blockingGet().size > 0
) {
val queuedContributions = contributionDao.getContribution(statesToProcess)
.blockingGet()
//Showing initial notification for the number of uploads being processed
@ -205,7 +210,8 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
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
@ -226,7 +232,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
countUpload++
uploadContribution(contribution = contribution)
}
}
//Dismiss the global notification
notificationManager?.cancel(
PROCESSING_UPLOADS_NOTIFICATION_TAG,