Skip to content

Commit

Permalink
reduce lint, delete unused translations
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 30, 2024
1 parent 976cd47 commit 2734f9d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.nextcloud.client.jobs.notification.WorkerNotificationManager
import com.nextcloud.utils.numberFormatter.NumberFormatter
import com.owncloud.android.R
import com.owncloud.android.operations.DownloadFileOperation
import com.owncloud.android.utils.theme.ViewThemeUtils
Expand Down Expand Up @@ -46,7 +47,8 @@ class DownloadNotificationManager(

@Suppress("MagicNumber")
fun updateDownloadProgress(percent: Int, totalToTransfer: Long) {
setProgress(percent, R.string.downloader_notification_manager_in_progress_text, totalToTransfer < 0)
val progressText = NumberFormatter.getPercentageText(percent)
setProgress(percent, progressText, totalToTransfer < 0)
showNotification()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ open class WorkerNotificationManager(
}

@Suppress("MagicNumber")
fun setProgress(percent: Int, progressTextId: Int, indeterminate: Boolean) {
val progressText = String.format(
context.getString(progressTextId),
percent
)

fun setProgress(percent: Int, progressText: String?, indeterminate: Boolean) {
notificationBuilder.run {
setProgress(100, percent, indeterminate)
setContentTitle(currentOperationTitle)
setContentText(progressText)

progressText?.let {
setContentText(progressText)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.app.PendingIntent
import android.content.Context
import com.nextcloud.client.jobs.notification.WorkerNotificationManager
import com.nextcloud.utils.extensions.isFileSpecificError
import com.nextcloud.utils.numberFormatter.NumberFormatter
import com.owncloud.android.R
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.operations.UploadFileOperation
Expand Down Expand Up @@ -43,10 +44,7 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
uploadFileOperation.fileName
}

val progressText = String.format(
context.getString(R.string.upload_notification_manager_upload_in_progress_text),
0
)
val progressText = NumberFormatter.getPercentageText(0)

notificationBuilder.run {
setProgress(100, 0, false)
Expand All @@ -71,7 +69,8 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi

@Suppress("MagicNumber")
fun updateUploadProgress(percent: Int, currentOperation: UploadFileOperation?) {
setProgress(percent, R.string.upload_notification_manager_upload_in_progress_text, false)
val progressText = NumberFormatter.getPercentageText(percent)
setProgress(percent, progressText, false)
showNotification()
dismissOldErrorNotification(currentOperation)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.nextcloud.utils.numberFormatter

import java.text.NumberFormat
import java.util.Locale

object NumberFormatter {
fun getPercentageText(percent: Int): String {
val formatter = NumberFormat.getPercentInstance(Locale.getDefault())
formatter.maximumFractionDigits = 0
return formatter.format(percent / 100.0)
}
}
4 changes: 0 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@
<string name="uploader_info_dirname">Folder name</string>

<string name="upload_notification_manager_start_text">%1$d / %2$d - %3$s</string>
<string name="upload_notification_manager_upload_in_progress_text" translatable="false">%1$d%%</string>

<string name="uploader_upload_in_progress_ticker">Uploading…</string>
<string name="uploader_upload_in_progress_content">%1$d%% Uploading %2$s</string>
Expand Down Expand Up @@ -262,9 +261,6 @@
<string name="uploads_view_later_waiting_to_upload">Waiting to upload</string>
<string name="uploads_view_group_header" translatable="false">%1$s (%2$d)</string>

<string name="downloader_notification_manager_download_text" translatable="false">%1$d / %2$d - %3$s</string>
<string name="downloader_notification_manager_in_progress_text" translatable="false">%1$d%%</string>

<string name="downloader_download_in_progress_ticker">Downloading…</string>
<string name="downloader_download_in_progress_content">%1$d%% Downloading %2$s</string>
<string name="downloader_download_succeeded_ticker">Downloaded</string>
Expand Down

0 comments on commit 2734f9d

Please sign in to comment.