Fix issue where upload notification shows up on app start (#4099)

This commit is contained in:
Vivek Maskara 2020-12-14 05:55:17 -07:00 committed by GitHub
parent 0415a57d34
commit 5c6e777b37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 10 deletions

View file

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

View file

@ -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})
@ -236,7 +235,8 @@ public class UploadService extends CommonsDaggerService {
} 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))
(Function<List<Contribution>, ObservableSource<Contribution>>) contributions -> Observable
.fromIterable(contributions))
.concatMapCompletable(contribution -> Completable.fromAction(() -> queue(contribution)))
.subscribeOn(ioThreadScheduler)
.subscribe();
@ -244,9 +244,21 @@ public class UploadService extends CommonsDaggerService {
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)