Skip to content

Commit

Permalink
update notification progress- copy/move action
Browse files Browse the repository at this point in the history
  • Loading branch information
WirelessAlien committed Jan 3, 2025
1 parent b90f348 commit 0fc6ac2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CopyMoveService : Service() {
val isCopyAction = intent.getBooleanExtra(EXTRA_IS_COPY_ACTION, true)

createNotificationChannel()
startForeground(NOTIFICATION_ID, createNotification(0, filesToCopyMove.size))
startForeground(NOTIFICATION_ID, createNotification(0, filesToCopyMove.size, isCopyAction))

CoroutineScope(Dispatchers.IO).launch {
copyMoveFiles(filesToCopyMove, destinationPath, isCopyAction)
Expand Down Expand Up @@ -84,7 +84,7 @@ class CopyMoveService : Service() {
file.moveTo(destination, overwrite = true)
}
processedFilesCount++
updateNotification(processedFilesCount, totalFilesCount)
updateNotification(processedFilesCount, totalFilesCount, isCopyAction)
}
}

Expand Down Expand Up @@ -120,18 +120,29 @@ class CopyMoveService : Service() {
}
}

private fun createNotification(progress: Int, total: Int): Notification {
private fun createNotification(progress: Int, total: Int, isCopyAction: Boolean): Notification {
val title = if (isCopyAction) {
getString(R.string.copying_files)
} else {
getString(R.string.moving_files)
}
val contentText = if (isCopyAction) {
getString(R.string.copying_files_progress, progress, total)
} else {
getString(R.string.moving_files_progress, progress, total)
}

return NotificationCompat.Builder(this, COPY_MOVE_NOTIFICATION_CHANNEL_ID)
.setContentTitle(getString(R.string.copying_moving_files))
.setContentText(getString(R.string.copying_moving_files_progress, progress, total))
.setContentTitle(title)
.setContentText(contentText)
.setSmallIcon(R.drawable.ic_notification_icon)
.setProgress(total, progress, false)
.setOngoing(true)
.build()
}

private fun updateNotification(progress: Int, total: Int) {
val notification = createNotification(progress, total)
private fun updateNotification(progress: Int, total: Int, isCopyAction: Boolean) {
val notification = createNotification(progress, total, isCopyAction)
val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager.notify(NOTIFICATION_ID, notification)
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@
<string name="the_file_doesn_t_exist">The file doesn\'t exist: %1$s</string>
<string name="delete_files_notification_name">Delete File</string>
<string name="deleting_files">Deleting files: %1$d/%2$d</string>
<string name="delete_ongoing">Deleting...</string>
<string name="delete_ongoing">Deleting</string>
<string name="copy_move_files_notification_name">Copy/Move Files</string>
<string name="copying_moving_files">Progress...</string>
<string name="copying_moving_files_progress">Progress %1$d/%2$d</string>
<string name="copying_files_progress">Copying files: %1$d/%2$d</string>
<string name="moving_files_progress">Moving files: %1$d/%2$d</string>
<string name="copying_files">Copying…</string>
<string name="moving_files">Moving…</string>
</resources>

0 comments on commit 0fc6ac2

Please sign in to comment.