diff --git a/next/src/main/kotlin/org/fdroid/repo/RepoUpdateManager.kt b/next/src/main/kotlin/org/fdroid/repo/RepoUpdateManager.kt index 3932076f2..06206aa4d 100644 --- a/next/src/main/kotlin/org/fdroid/repo/RepoUpdateManager.kt +++ b/next/src/main/kotlin/org/fdroid/repo/RepoUpdateManager.kt @@ -2,11 +2,11 @@ package org.fdroid.repo import android.content.Context import android.text.format.Formatter -import android.util.Log import androidx.annotation.FloatRange import androidx.annotation.IntRange import androidx.annotation.VisibleForTesting import androidx.annotation.WorkerThread +import androidx.core.os.LocaleListCompat import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.ensureActive @@ -27,6 +27,7 @@ import org.fdroid.index.IndexUpdateResult import org.fdroid.index.RepoManager import org.fdroid.index.RepoUpdater import org.fdroid.settings.SettingsManager +import org.fdroid.ui.utils.addressForUi import org.fdroid.updates.UpdatesManager import javax.inject.Inject import javax.inject.Singleton @@ -121,11 +122,13 @@ class RepoUpdateManager @VisibleForTesting internal constructor( currentCoroutineContext().ensureActive() // show notification - val msg = context.getString(R.string.status_connecting_to_repo, repo.address) + val repoName = repo.getName(LocaleListCompat.getDefault()) + val msg = context.getString(R.string.notification_repo_update_default, repoName) notificationManager.showUpdateRepoNotification(msg, throttle = false) // update repo val result = repoUpdater.update(repo) log.info { "Update repo result: $result" } + repoUpdateListener.onUpdateFinished() if (result is IndexUpdateResult.Processed) reposUpdated = true else if (result is IndexUpdateResult.Error) { log.error(result.e) { "Error updating repository ${repo.address} " } @@ -155,11 +158,13 @@ class RepoUpdateManager @VisibleForTesting internal constructor( _isUpdating.value = true return try { // show notification - val msg = context.getString(R.string.status_connecting_to_repo, repo.address) + val repoName = repo.getName(LocaleListCompat.getDefault()) + val msg = context.getString(R.string.notification_repo_update_default, repoName) notificationManager.showUpdateRepoNotification(msg, throttle = false) // update repo val result = repoUpdater.update(repo) log.info { "Update repo result: $result" } + repoUpdateListener.onUpdateFinished() if (result is IndexUpdateResult.Processed) { updatesManager.loadUpdates() } else if (result is IndexUpdateResult.Error) { @@ -180,22 +185,24 @@ internal class RepoUpdateListener( private val notificationManager: NotificationManager, ) : IndexUpdateListener { + private val log = KotlinLogging.logger { } private val _updateState = MutableStateFlow(null) val updateState = _updateState.asStateFlow() private var lastUpdateProgress = 0L override fun onDownloadProgress(repo: Repository, bytesRead: Long, totalBytes: Long) { - Log.d(TAG, "Downloading ${repo.address} ($bytesRead/$totalBytes)") + log.debug { "Downloading ${repo.address} ($bytesRead/$totalBytes)" } val percent = getPercent(bytesRead, totalBytes) val size = Formatter.formatFileSize(context, bytesRead) - val message: String = if (totalBytes == -1L) { - context.getString(R.string.status_download_unknown_size, repo.address, size) - } else { - val totalSize = Formatter.formatFileSize(context, totalBytes) - context.getString(R.string.status_download, repo.address, size, totalSize, percent) - } - notificationManager.showUpdateRepoNotification(msg = message, progress = percent) + notificationManager.showUpdateRepoNotification( + msg = context.getString( + R.string.notification_repo_update_downloading, + size, repo.addressForUi + ), + throttle = bytesRead != totalBytes, + progress = percent, + ) _updateState.update { RepoUpdateState(repo.repoId, true, percent) } } @@ -212,29 +219,33 @@ internal class RepoUpdateListener( if (System.currentTimeMillis() - lastUpdateProgress < 1000 && appsProcessed != totalApps) { return } - Log.d(TAG, "Committing ${repo.address} ($appsProcessed/$totalApps)") + log.debug { "Committing ${repo.address} ($appsProcessed/$totalApps)" } + val repoName = repo.getName(LocaleListCompat.getDefault()) + val msg = context.resources.getQuantityString( + R.plurals.notification_repo_update_saving, + appsProcessed, + appsProcessed, repoName, + ) if (totalApps > 0) { val percent = getPercent(appsProcessed.toLong(), totalApps.toLong()) notificationManager.showUpdateRepoNotification( - msg = context.getString( - R.string.status_inserting_x_apps, - appsProcessed, - totalApps, - repo.address, - ), - progress = percent + msg = msg, + throttle = appsProcessed != totalApps, + progress = percent, ) _updateState.update { RepoUpdateState(repo.repoId, false, percent) } } else { - notificationManager.showUpdateRepoNotification( - msg = context.getString(R.string.status_inserting_apps), - ) + notificationManager.showUpdateRepoNotification(msg) _updateState.update { RepoUpdateState(repo.repoId, false, 0f) } } lastUpdateProgress = System.currentTimeMillis() } + fun onUpdateFinished() { + _updateState.update { null } + } + private fun getPercent(current: Long, total: Long): Int { if (total <= 0) return 0 return (100L * current / total).toInt() diff --git a/next/src/main/kotlin/org/fdroid/ui/repositories/details/RepoDetailsHeader.kt b/next/src/main/kotlin/org/fdroid/ui/repositories/details/RepoDetailsHeader.kt index 23d4e02b6..fbfc82078 100644 --- a/next/src/main/kotlin/org/fdroid/ui/repositories/details/RepoDetailsHeader.kt +++ b/next/src/main/kotlin/org/fdroid/ui/repositories/details/RepoDetailsHeader.kt @@ -32,6 +32,7 @@ import org.fdroid.database.Repository import org.fdroid.ui.FDroidContent import org.fdroid.ui.repositories.RepoIcon import org.fdroid.ui.utils.FDroidOutlineButton +import org.fdroid.ui.utils.addressForUi import org.fdroid.ui.utils.asRelativeTimeString import org.fdroid.ui.utils.getRepository @@ -76,9 +77,7 @@ fun RepoDetailsHeader( style = MaterialTheme.typography.headlineMediumEmphasized, ) Text( - text = repo.address - .replaceFirst("https://", "") - .replaceFirst("/repo", ""), + text = repo.addressForUi, style = MaterialTheme.typography.bodyMedium, ) if (numberOfApps != null) Text( diff --git a/next/src/main/kotlin/org/fdroid/ui/utils/UiUtils.kt b/next/src/main/kotlin/org/fdroid/ui/utils/UiUtils.kt index f84009734..32e1b1d6e 100644 --- a/next/src/main/kotlin/org/fdroid/ui/utils/UiUtils.kt +++ b/next/src/main/kotlin/org/fdroid/ui/utils/UiUtils.kt @@ -19,6 +19,7 @@ import com.google.zxing.BarcodeFormat import com.google.zxing.qrcode.QRCodeWriter import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.fdroid.database.Repository import java.text.Normalizer import java.text.Normalizer.Form.NFKD @@ -106,6 +107,10 @@ val String.flagEmoji: String? return flagEmoji } +val Repository.addressForUi: String + get() = address.replaceFirst("https://", "") + .replaceFirst("/repo", "") + fun canStartForegroundService(context: Context): Boolean { val powerManager = ContextCompat.getSystemService(context, PowerManager::class.java) ?: return false diff --git a/next/src/main/res/values/strings-next.xml b/next/src/main/res/values/strings-next.xml index 6c0dfc357..bf2c7b25c 100644 --- a/next/src/main/res/values/strings-next.xml +++ b/next/src/main/res/values/strings-next.xml @@ -101,6 +101,13 @@ Displays a notification after apps were installed automatically. Available app updates Displays a notification after repositories were updated and app updates were found. + + Connecting to %1$s… + Downloaded %1$s from %2$s + + Saved %1$d app from %2$s + Saved %1$d apps from %2$s + Installing %1$d app… Installing %1$d apps…