Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ class DownloadMonitorService : Service() {
* until there are no active downloads, at which point the service is stopped.
*/
private fun showDownloadServiceForegroundNotification() {
// Start the foreground service immediately before going to background.
downloadNotificationChannel()
startForeground(DOWNLOAD_SERVICE_NOTIFICATION_ID, buildForegroundNotification())
fetch.getDownloadsWithStatus(
listOf(Status.NONE, Status.ADDED, Status.QUEUED, Status.DOWNLOADING, Status.PAUSED)
) { activeDownloads ->
if (activeDownloads.isNotEmpty()) {
downloadNotificationChannel()
startForeground(DOWNLOAD_SERVICE_NOTIFICATION_ID, buildForegroundNotification())
// Update the notification.
notificationManager.notify(DOWNLOAD_SERVICE_NOTIFICATION_ID, buildForegroundNotification())
} else {
// Stop the foreground service if no active downloads.
stopForegroundServiceForDownloads()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,14 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
super.onStart()
externalLinkOpener.setAlertDialogShower(alertDialogShower)
rateDialogHandler.setAlertDialogShower(alertDialogShower)
rateDialogHandler.checkForRateDialog(getIconResId())
}

override fun onResume() {
super.onResume()
// Resume in-app download monitoring now that the app is visible again.
downloadMonitor.startMonitoringDownload()
stopDownloadServiceIfRunning()
rateDialogHandler.checkForRateDialog(getIconResId())
}

/**
Expand All @@ -276,10 +281,12 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
}
}

override fun onStop() {
override fun onPause() {
// Start the DownloadService as the app is about to enter the background,
// so downloads can continue even if the app is no longer in the foreground.
startMonitoringDownloads()
downloadMonitor.stopListeningDownloads()
super.onStop()
super.onPause()
}

/**
Expand Down
Loading