mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix issue where upload notification shows up on app start (#4099)
This commit is contained in:
parent
0415a57d34
commit
5c6e777b37
2 changed files with 25 additions and 10 deletions
|
|
@ -68,6 +68,9 @@ public abstract class ContributionDao {
|
|||
@Query("UPDATE contribution SET state=:state WHERE state in (:toUpdateStates)")
|
||||
public abstract Single<Integer> updateStates(int state, int[] toUpdateStates);
|
||||
|
||||
@Query("SELECT COUNT(*) from contribution WHERE state in (:toUpdateStates)")
|
||||
public abstract Single<Integer> getPendingUploads(int[] toUpdateStates);
|
||||
|
||||
@Query("Delete FROM contribution")
|
||||
public abstract void deleteAll() throws SQLiteException;
|
||||
|
||||
|
|
|
|||
|
|
@ -224,8 +224,7 @@ public class UploadService extends CommonsDaggerService {
|
|||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS,
|
||||
curNotification.setContentText(getText(R.string.starting_uploads)).build());
|
||||
showUploadNotification();
|
||||
if (ACTION_START_SERVICE.equals(intent.getAction()) && freshStart) {
|
||||
compositeDisposable.add(contributionDao.updateStates(Contribution.STATE_FAILED,
|
||||
new int[]{Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS})
|
||||
|
|
@ -234,19 +233,32 @@ public class UploadService extends CommonsDaggerService {
|
|||
.subscribe());
|
||||
freshStart = false;
|
||||
} else if (PROCESS_PENDING_LIMITED_CONNECTION_MODE_UPLOADS.equals(intent.getAction())) {
|
||||
contributionDao.getContribution(Contribution.STATE_QUEUED_LIMITED_CONNECTION_MODE)
|
||||
.flatMapObservable(
|
||||
(Function<List<Contribution>, ObservableSource<Contribution>>) contributions -> Observable.fromIterable(contributions))
|
||||
.concatMapCompletable(contribution -> Completable.fromAction(() -> queue(contribution)))
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.subscribe();
|
||||
}
|
||||
contributionDao.getContribution(Contribution.STATE_QUEUED_LIMITED_CONNECTION_MODE)
|
||||
.flatMapObservable(
|
||||
(Function<List<Contribution>, ObservableSource<Contribution>>) contributions -> Observable
|
||||
.fromIterable(contributions))
|
||||
.concatMapCompletable(contribution -> Completable.fromAction(() -> queue(contribution)))
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.subscribe();
|
||||
}
|
||||
return START_REDELIVER_INTENT;
|
||||
}
|
||||
|
||||
private void showUploadNotification() {
|
||||
compositeDisposable.add(contributionDao
|
||||
.getPendingUploads(new int[]{Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED})
|
||||
.subscribe(count -> {
|
||||
if (count > 0) {
|
||||
startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS,
|
||||
curNotification.setContentText(getText(R.string.starting_uploads)).build());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
private NotificationCompat.Builder getNotificationBuilder(String channelId) {
|
||||
return new NotificationCompat.Builder(this, channelId).setAutoCancel(true)
|
||||
return new NotificationCompat.Builder(this, channelId)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
|
||||
.setAutoCancel(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue