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)")
|
@Query("UPDATE contribution SET state=:state WHERE state in (:toUpdateStates)")
|
||||||
public abstract Single<Integer> updateStates(int state, int[] 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")
|
@Query("Delete FROM contribution")
|
||||||
public abstract void deleteAll() throws SQLiteException;
|
public abstract void deleteAll() throws SQLiteException;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -224,8 +224,7 @@ public class UploadService extends CommonsDaggerService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS,
|
showUploadNotification();
|
||||||
curNotification.setContentText(getText(R.string.starting_uploads)).build());
|
|
||||||
if (ACTION_START_SERVICE.equals(intent.getAction()) && freshStart) {
|
if (ACTION_START_SERVICE.equals(intent.getAction()) && freshStart) {
|
||||||
compositeDisposable.add(contributionDao.updateStates(Contribution.STATE_FAILED,
|
compositeDisposable.add(contributionDao.updateStates(Contribution.STATE_FAILED,
|
||||||
new int[]{Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS})
|
new int[]{Contribution.STATE_QUEUED, Contribution.STATE_IN_PROGRESS})
|
||||||
|
|
@ -234,19 +233,32 @@ public class UploadService extends CommonsDaggerService {
|
||||||
.subscribe());
|
.subscribe());
|
||||||
freshStart = false;
|
freshStart = false;
|
||||||
} else if (PROCESS_PENDING_LIMITED_CONNECTION_MODE_UPLOADS.equals(intent.getAction())) {
|
} else if (PROCESS_PENDING_LIMITED_CONNECTION_MODE_UPLOADS.equals(intent.getAction())) {
|
||||||
contributionDao.getContribution(Contribution.STATE_QUEUED_LIMITED_CONNECTION_MODE)
|
contributionDao.getContribution(Contribution.STATE_QUEUED_LIMITED_CONNECTION_MODE)
|
||||||
.flatMapObservable(
|
.flatMapObservable(
|
||||||
(Function<List<Contribution>, ObservableSource<Contribution>>) contributions -> Observable.fromIterable(contributions))
|
(Function<List<Contribution>, ObservableSource<Contribution>>) contributions -> Observable
|
||||||
.concatMapCompletable(contribution -> Completable.fromAction(() -> queue(contribution)))
|
.fromIterable(contributions))
|
||||||
.subscribeOn(ioThreadScheduler)
|
.concatMapCompletable(contribution -> Completable.fromAction(() -> queue(contribution)))
|
||||||
.subscribe();
|
.subscribeOn(ioThreadScheduler)
|
||||||
}
|
.subscribe();
|
||||||
|
}
|
||||||
return START_REDELIVER_INTENT;
|
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")
|
@SuppressLint("StringFormatInvalid")
|
||||||
private NotificationCompat.Builder getNotificationBuilder(String channelId) {
|
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)
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
|
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue