diff --git a/README.md b/README.md index e8f7c31..ae48450 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,11 @@ dependencies { smallIcon = smallIcon, //It is required showSpeed = true, //Default: true showSize = true, //Default: true - showTime = true //Default: true + showTime = true, //Default: true + showCancelAction = true, //Default: true + showPauseAction = true, //Default: true + showResumeAction = true, //Default: true + showRetryAction= true, //Default: true ) ).build(this) ``` diff --git a/app/src/main/java/com/khush/sample/MainFragment.kt b/app/src/main/java/com/khush/sample/MainFragment.kt index 3d2ae31..ae5b660 100644 --- a/app/src/main/java/com/khush/sample/MainFragment.kt +++ b/app/src/main/java/com/khush/sample/MainFragment.kt @@ -142,7 +142,8 @@ class MainFragment : Fragment() { path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path, fileName = "Sample_Video_1.mp4", tag = "Video", - metaData = "158" + metaData = "158", + customTitle = "Video 1 File" ) } @@ -232,7 +233,7 @@ class MainFragment : Fragment() { path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path, fileName = "Sample_Pdf_1.pdf", tag = "Document", - metaData = "5" + metaData = "5", ) } } diff --git a/ketch/src/main/java/com/ketch/DownloadModel.kt b/ketch/src/main/java/com/ketch/DownloadModel.kt index 91c2381..a98efe6 100644 --- a/ketch/src/main/java/com/ketch/DownloadModel.kt +++ b/ketch/src/main/java/com/ketch/DownloadModel.kt @@ -35,5 +35,5 @@ data class DownloadModel( val lastModified: Long, val eTag: String, val metaData: String, - val failureReason: String + val failureReason: String, ) diff --git a/ketch/src/main/java/com/ketch/Ketch.kt b/ketch/src/main/java/com/ketch/Ketch.kt index c18d63b..f3b5ee8 100644 --- a/ketch/src/main/java/com/ketch/Ketch.kt +++ b/ketch/src/main/java/com/ketch/Ketch.kt @@ -142,8 +142,14 @@ class Ketch private constructor( if (!::okHttpClient.isInitialized) { okHttpClient = OkHttpClient .Builder() - .connectTimeout(downloadConfig.connectTimeOutInMs, TimeUnit.MILLISECONDS) - .readTimeout(downloadConfig.readTimeOutInMs, TimeUnit.MILLISECONDS) + .connectTimeout( + downloadConfig.connectTimeOutInMs, + TimeUnit.MILLISECONDS + ) + .readTimeout( + downloadConfig.readTimeOutInMs, + TimeUnit.MILLISECONDS + ) .build() } @@ -183,6 +189,7 @@ class Ketch private constructor( * @param metaData Optional metaData set for adding any extra download info * @param headers Optional headers sent when making api call for file download * @param supportPauseResume Optional flag to enable pause and resume functionality + * @param customTitle Name of the tile that show in notification progress * @return Unique Download ID associated with current download */ fun download( @@ -193,6 +200,7 @@ class Ketch private constructor( metaData: String = "", headers: HashMap = hashMapOf(), supportPauseResume: Boolean = true, + customTitle: String? = null, ): Int { val downloadRequest = prepareDownloadRequest( url = url, @@ -202,6 +210,7 @@ class Ketch private constructor( headers = headers, metaData = metaData, supportPauseResume = supportPauseResume, + customTitle = customTitle ) downloadManager.downloadAsync(downloadRequest) return downloadRequest.id @@ -226,6 +235,7 @@ class Ketch private constructor( metaData: String = "", headers: HashMap = hashMapOf(), supportPauseResume: Boolean = true, + customTitle: String? ): Int { val downloadRequest = mutex.withLock { prepareDownloadRequest( @@ -236,6 +246,7 @@ class Ketch private constructor( headers = headers, metaData = metaData, supportPauseResume = supportPauseResume, + customTitle = customTitle ) } downloadManager.download(downloadRequest) @@ -517,7 +528,8 @@ class Ketch private constructor( * @param status * @return [DownloadModel] if present else null */ - suspend fun getDownloadModelByStatus(status: Status) = downloadManager.getDownloadModelByStatus(status) + suspend fun getDownloadModelByStatus(status: Status) = + downloadManager.getDownloadModelByStatus(status) /** * Suspend function to get download model by list of tags @@ -525,7 +537,8 @@ class Ketch private constructor( * @param tags * @return List of [DownloadModel] */ - suspend fun getDownloadModelByTags(tags: List) = downloadManager.getDownloadModelByTags(tags) + suspend fun getDownloadModelByTags(tags: List) = + downloadManager.getDownloadModelByTags(tags) /** * Suspend function to get download model by list of ids @@ -541,7 +554,8 @@ class Ketch private constructor( * @param statuses * @return List of [DownloadModel] */ - suspend fun getDownloadModelByStatuses(statuses: List) = downloadManager.getDownloadModelByStatuses(statuses) + suspend fun getDownloadModelByStatuses(statuses: List) = + downloadManager.getDownloadModelByStatuses(statuses) private fun prepareDownloadRequest( url: String, @@ -551,6 +565,7 @@ class Ketch private constructor( headers: HashMap, metaData: String, supportPauseResume: Boolean, + customTitle: String?, ): DownloadRequest { require(url.isNotEmpty() && path.isNotEmpty() && fileName.isNotEmpty()) { "Missing ${if (url.isEmpty()) "url" else if (path.isEmpty()) "path" else "fileName"}" @@ -569,6 +584,7 @@ class Ketch private constructor( headers = headers, metaData = metaData, supportPauseResume = supportPauseResume, + customTitle = customTitle ) return downloadRequest diff --git a/ketch/src/main/java/com/ketch/NotificationConfig.kt b/ketch/src/main/java/com/ketch/NotificationConfig.kt index c8c454f..a285d4b 100644 --- a/ketch/src/main/java/com/ketch/NotificationConfig.kt +++ b/ketch/src/main/java/com/ketch/NotificationConfig.kt @@ -12,5 +12,9 @@ data class NotificationConfig( val showSpeed: Boolean = true, val showSize: Boolean = true, val showTime: Boolean = true, - val smallIcon: Int + val smallIcon: Int, + val showCancelAction: Boolean = true, + val showPauseAction: Boolean = true, + val showResumeAction: Boolean = true, + val showRetryAction: Boolean = true, ) diff --git a/ketch/src/main/java/com/ketch/internal/database/DownloadDatabase.kt b/ketch/src/main/java/com/ketch/internal/database/DownloadDatabase.kt index f8ffffe..7f92020 100644 --- a/ketch/src/main/java/com/ketch/internal/database/DownloadDatabase.kt +++ b/ketch/src/main/java/com/ketch/internal/database/DownloadDatabase.kt @@ -3,7 +3,7 @@ package com.ketch.internal.database import androidx.room.Database import androidx.room.RoomDatabase -@Database(entities = [DownloadEntity::class], version = 1) +@Database(entities = [DownloadEntity::class], version = 2) internal abstract class DownloadDatabase : RoomDatabase() { abstract fun downloadDao(): DownloadDao } diff --git a/ketch/src/main/java/com/ketch/internal/database/DownloadEntity.kt b/ketch/src/main/java/com/ketch/internal/database/DownloadEntity.kt index e64a0bd..3a37b0d 100644 --- a/ketch/src/main/java/com/ketch/internal/database/DownloadEntity.kt +++ b/ketch/src/main/java/com/ketch/internal/database/DownloadEntity.kt @@ -26,5 +26,6 @@ internal data class DownloadEntity( var eTag: String = "", var userAction: String = UserAction.DEFAULT.toString(), var metaData: String = "", - var failureReason: String = "" + var failureReason: String = "", + var customTitle: String?, ) diff --git a/ketch/src/main/java/com/ketch/internal/download/DownloadManager.kt b/ketch/src/main/java/com/ketch/internal/download/DownloadManager.kt index 4992fca..6310dfb 100644 --- a/ketch/src/main/java/com/ketch/internal/download/DownloadManager.kt +++ b/ketch/src/main/java/com/ketch/internal/download/DownloadManager.kt @@ -83,11 +83,13 @@ internal class DownloadManager( msg = "Download in Progress. FileName: ${downloadEntity?.fileName}, " + "ID: ${downloadEntity?.id}, " + "Size in bytes: ${downloadEntity?.totalBytes}, " + - "downloadPercent: ${if (downloadEntity != null && downloadEntity.totalBytes.toInt() != 0) { - ((downloadEntity.downloadedBytes * 100) / downloadEntity.totalBytes).toInt() - } else { - 0 - }}%, " + + "downloadPercent: ${ + if (downloadEntity != null && downloadEntity.totalBytes.toInt() != 0) { + ((downloadEntity.downloadedBytes * 100) / downloadEntity.totalBytes).toInt() + } else { + 0 + } + }%, " + "downloadSpeedInBytesPerMilliSeconds: ${downloadEntity?.speedInBytePerMs} b/ms" ) @@ -190,7 +192,8 @@ internal class DownloadManager( uuid = downloadWorkRequest.id.toString(), lastModified = System.currentTimeMillis(), userAction = UserAction.START.toString(), - metaData = downloadRequest.metaData + metaData = downloadRequest.metaData, + customTitle = downloadRequest.customTitle ) ) } @@ -219,7 +222,8 @@ internal class DownloadManager( tag = downloadEntity.tag, id = downloadEntity.id, headers = WorkUtil.jsonToHashMap(downloadEntity.headersJson), - metaData = downloadEntity.metaData + metaData = downloadEntity.metaData, + customTitle = downloadEntity.customTitle, ) ) } @@ -247,7 +251,8 @@ internal class DownloadManager( context = context, notificationConfig = notificationConfig, requestId = id, - fileName = downloadEntity.fileName + fileName = downloadEntity.fileName, + customTitle = downloadEntity.customTitle ).sendDownloadCancelledNotification() } } @@ -284,7 +289,8 @@ internal class DownloadManager( tag = downloadEntity.tag, id = downloadEntity.id, headers = WorkUtil.jsonToHashMap(downloadEntity.headersJson), - metaData = downloadEntity.metaData + metaData = downloadEntity.metaData, + customTitle = downloadEntity.customTitle ) ) } @@ -417,7 +423,10 @@ internal class DownloadManager( } downloadDao.remove(it.id) removeNotification(context, it.id) // In progress notification - removeNotification(context, it.id + 1) // Cancelled, Paused, Failed, Success notification + removeNotification( + context, + it.id + 1 + ) // Cancelled, Paused, Failed, Success notification } } } @@ -433,7 +442,10 @@ internal class DownloadManager( deleteFileIfExists(path, fileName) } removeNotification(context, it.id) // In progress notification - removeNotification(context, it.id + 1) // Cancelled, Paused, Failed, Success notification + removeNotification( + context, + it.id + 1 + ) // Cancelled, Paused, Failed, Success notification } downloadDao.deleteAll() } @@ -451,7 +463,10 @@ internal class DownloadManager( } downloadDao.remove(it.id) removeNotification(context, it.id) // In progress notification - removeNotification(context, it.id + 1) // Cancelled, Paused, Failed, Success notification + removeNotification( + context, + it.id + 1 + ) // Cancelled, Paused, Failed, Success notification } } } @@ -485,11 +500,12 @@ internal class DownloadManager( } fun observeDownloadsByStatus(status: Status): Flow> { - return downloadDao.getAllEntityByStatusFlow(status.name).distinctUntilChanged().map { entityList -> - entityList.map { entity -> - entity.toDownloadModel() + return downloadDao.getAllEntityByStatusFlow(status.name).distinctUntilChanged() + .map { entityList -> + entityList.map { entity -> + entity.toDownloadModel() + } } - } } fun observeDownloadsByIds(ids: List): Flow> { diff --git a/ketch/src/main/java/com/ketch/internal/download/DownloadRequest.kt b/ketch/src/main/java/com/ketch/internal/download/DownloadRequest.kt index 7cdebd6..b8bcced 100644 --- a/ketch/src/main/java/com/ketch/internal/download/DownloadRequest.kt +++ b/ketch/src/main/java/com/ketch/internal/download/DownloadRequest.kt @@ -8,6 +8,7 @@ internal data class DownloadRequest( val url: String, val path: String, val fileName: String, + val customTitle: String?, val tag: String, val id: Int = getUniqueId(url, path, fileName), val headers: HashMap = hashMapOf(), diff --git a/ketch/src/main/java/com/ketch/internal/notification/DownloadNotificationManager.kt b/ketch/src/main/java/com/ketch/internal/notification/DownloadNotificationManager.kt index 0bed409..9d551d3 100644 --- a/ketch/src/main/java/com/ketch/internal/notification/DownloadNotificationManager.kt +++ b/ketch/src/main/java/com/ketch/internal/notification/DownloadNotificationManager.kt @@ -34,7 +34,8 @@ internal class DownloadNotificationManager( private val context: Context, private val notificationConfig: NotificationConfig, private val requestId: Int, - private val fileName: String + private val fileName: String, + private val customTitle: String? ) { private var foregroundInfo: ForegroundInfo? = null @@ -66,7 +67,11 @@ internal class DownloadNotificationManager( if (update) { var nb = notificationBuilder - .setProgress(DownloadConst.MAX_VALUE_PROGRESS, progress, if (length == 0L) true else false) + .setProgress( + DownloadConst.MAX_VALUE_PROGRESS, + progress, + if (length == 0L) true else false + ) if (length != 0L) { nb = nb.setContentText( @@ -86,7 +91,10 @@ internal class DownloadNotificationManager( } else { // Remove any previous notification removeNotification(context, requestId) // In progress notification - removeNotification(context, requestId + 1) // Cancelled, Paused, Failed, Success notification + removeNotification( + context, + requestId + 1 + ) // Cancelled, Paused, Failed, Success notification // Open Application (Send the unique download request id in intent) val intentOpen = context.packageManager.getLaunchIntentForPackage(context.packageName) @@ -140,20 +148,33 @@ internal class DownloadNotificationManager( var nb = notificationBuilder .setSmallIcon(notificationConfig.smallIcon) - .setContentTitle("Downloading $fileName") + .setContentTitle(customTitle ?: "Downloading $fileName") .setContentIntent(pendingIntentOpen) - .setProgress(DownloadConst.MAX_VALUE_PROGRESS, progress, if (length == 0L) true else false) + .setProgress( + DownloadConst.MAX_VALUE_PROGRESS, + progress, + if (length == 0L) true else false + ) .setOnlyAlertOnce(true) .setOngoing(true) if (length != 0L) { - nb = nb.addAction(-1, NotificationConst.PAUSE_BUTTON_TEXT, pendingIntentPause) + nb = nb.apply { + if (notificationConfig.showPauseAction) { + addAction(-1, NotificationConst.PAUSE_BUTTON_TEXT, pendingIntentPause) + } + + } } foregroundInfo = ForegroundInfo( notificationId, - nb.addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel) - .setDeleteIntent(pendingIntentDismiss) + nb.apply { + if (notificationConfig.showCancelAction) { + addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel) + } + setDeleteIntent(pendingIntentDismiss) + } .build(), if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { FOREGROUND_SERVICE_TYPE_DATA_SYNC @@ -223,10 +244,31 @@ internal class DownloadNotificationManager( NotificationConst.KEY_NOTIFICATION_SMALL_ICON, notificationConfig.smallIcon ) - putExtra(DownloadConst.KEY_FILE_NAME, fileName) + customTitle?.let { + putExtra(DownloadConst.KEY_FILE_NAME, it) + } ?: run { + putExtra(DownloadConst.KEY_FILE_NAME, fileName) + } + putExtra(DownloadConst.KEY_LENGTH, totalLength) putExtra(DownloadConst.KEY_REQUEST_ID, requestId) putExtra(NotificationConst.KEY_NOTIFICATION_ID, notificationId) + putExtra( + NotificationConst.KEY_NOTIFICATION_CANCEL_ACTION, + notificationConfig.showCancelAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RESUME_ACTION, + notificationConfig.showResumeAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RETRY_ACTION, + notificationConfig.showRetryAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_PAUSE_ACTION, + notificationConfig.showPauseAction + ) action = NotificationConst.ACTION_DOWNLOAD_COMPLETED } ) @@ -256,10 +298,30 @@ internal class DownloadNotificationManager( NotificationConst.KEY_NOTIFICATION_SMALL_ICON, notificationConfig.smallIcon ) - putExtra(DownloadConst.KEY_FILE_NAME, fileName) + customTitle?.let { + putExtra(DownloadConst.KEY_FILE_NAME, it) + } ?: run { + putExtra(DownloadConst.KEY_FILE_NAME, fileName) + } putExtra(DownloadConst.KEY_REQUEST_ID, requestId) putExtra(NotificationConst.KEY_NOTIFICATION_ID, notificationId) putExtra(DownloadConst.KEY_PROGRESS, currentProgress) + putExtra( + NotificationConst.KEY_NOTIFICATION_CANCEL_ACTION, + notificationConfig.showCancelAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RESUME_ACTION, + notificationConfig.showResumeAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RETRY_ACTION, + notificationConfig.showRetryAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_PAUSE_ACTION, + notificationConfig.showPauseAction + ) action = NotificationConst.ACTION_DOWNLOAD_FAILED } ) @@ -288,9 +350,29 @@ internal class DownloadNotificationManager( NotificationConst.KEY_NOTIFICATION_SMALL_ICON, notificationConfig.smallIcon ) - putExtra(DownloadConst.KEY_FILE_NAME, fileName) + customTitle?.let { + putExtra(DownloadConst.KEY_FILE_NAME, it) + } ?: run { + putExtra(DownloadConst.KEY_FILE_NAME, fileName) + } putExtra(DownloadConst.KEY_REQUEST_ID, requestId) putExtra(NotificationConst.KEY_NOTIFICATION_ID, notificationId) + putExtra( + NotificationConst.KEY_NOTIFICATION_CANCEL_ACTION, + notificationConfig.showCancelAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RESUME_ACTION, + notificationConfig.showResumeAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RETRY_ACTION, + notificationConfig.showRetryAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_PAUSE_ACTION, + notificationConfig.showPauseAction + ) action = NotificationConst.ACTION_DOWNLOAD_CANCELLED } ) @@ -320,10 +402,30 @@ internal class DownloadNotificationManager( NotificationConst.KEY_NOTIFICATION_SMALL_ICON, notificationConfig.smallIcon ) - putExtra(DownloadConst.KEY_FILE_NAME, fileName) + customTitle?.let { + putExtra(DownloadConst.KEY_FILE_NAME, it) + } ?: run { + putExtra(DownloadConst.KEY_FILE_NAME, fileName) + } putExtra(DownloadConst.KEY_PROGRESS, currentProgress) putExtra(DownloadConst.KEY_REQUEST_ID, requestId) putExtra(NotificationConst.KEY_NOTIFICATION_ID, notificationId) + putExtra( + NotificationConst.KEY_NOTIFICATION_CANCEL_ACTION, + notificationConfig.showCancelAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RESUME_ACTION, + notificationConfig.showResumeAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_RETRY_ACTION, + notificationConfig.showRetryAction + ) + putExtra( + NotificationConst.KEY_NOTIFICATION_PAUSE_ACTION, + notificationConfig.showPauseAction + ) action = NotificationConst.ACTION_DOWNLOAD_PAUSED } ) diff --git a/ketch/src/main/java/com/ketch/internal/notification/NotificationReceiver.kt b/ketch/src/main/java/com/ketch/internal/notification/NotificationReceiver.kt index c5b1404..88b3c48 100644 --- a/ketch/src/main/java/com/ketch/internal/notification/NotificationReceiver.kt +++ b/ketch/src/main/java/com/ketch/internal/notification/NotificationReceiver.kt @@ -89,6 +89,19 @@ internal class NotificationReceiver : BroadcastReceiver() { ) if (intent.action in notificationActionList) { + + val notificationCancelActionEnable = + intent.extras?.getBoolean(NotificationConst.KEY_NOTIFICATION_CANCEL_ACTION) + ?: NotificationConst.DEFAULT_VALUE_ACTION_ENABLE + val notificationRetryActionEnable = + intent.extras?.getBoolean(NotificationConst.KEY_NOTIFICATION_RETRY_ACTION) + ?: NotificationConst.DEFAULT_VALUE_ACTION_ENABLE + val notificationResumeActionEnable = + intent.extras?.getBoolean(NotificationConst.KEY_NOTIFICATION_RESUME_ACTION) + ?: NotificationConst.DEFAULT_VALUE_ACTION_ENABLE + val notificationPauseActionEnable = + intent.extras?.getBoolean(NotificationConst.KEY_NOTIFICATION_PAUSE_ACTION) + ?: NotificationConst.DEFAULT_VALUE_ACTION_ENABLE val notificationChannelName = intent.extras?.getString(NotificationConst.KEY_NOTIFICATION_CHANNEL_NAME) ?: NotificationConst.DEFAULT_VALUE_NOTIFICATION_CHANNEL_NAME @@ -196,25 +209,38 @@ internal class NotificationReceiver : BroadcastReceiver() { // add retry and cancel button for failed download if (intent.action == NotificationConst.ACTION_DOWNLOAD_FAILED) { - notificationBuilder = notificationBuilder.addAction( - -1, - NotificationConst.RETRY_BUTTON_TEXT, - pendingIntentRetry - ) - .setProgress(DownloadConst.MAX_VALUE_PROGRESS, currentProgress, false) - .addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel) - .setSubText("$currentProgress%") + notificationBuilder = notificationBuilder.apply { + if (notificationRetryActionEnable) { + addAction( + -1, + NotificationConst.RETRY_BUTTON_TEXT, + pendingIntentRetry + ) + } + if (notificationCancelActionEnable) { + addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel) + } + setProgress(DownloadConst.MAX_VALUE_PROGRESS, currentProgress, false) + setSubText("$currentProgress%") + } } // add resume and cancel button for paused download if (intent.action == NotificationConst.ACTION_DOWNLOAD_PAUSED) { - notificationBuilder = notificationBuilder.addAction( - -1, - NotificationConst.RESUME_BUTTON_TEXT, - pendingIntentResume - ) - .setProgress(DownloadConst.MAX_VALUE_PROGRESS, currentProgress, false) - .addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel) - .setSubText("$currentProgress%") + notificationBuilder = notificationBuilder.apply { + if (notificationResumeActionEnable) { + addAction( + -1, + NotificationConst.RESUME_BUTTON_TEXT, + pendingIntentResume + ) + } + + if (notificationCancelActionEnable) { + addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel) + } + setProgress(DownloadConst.MAX_VALUE_PROGRESS, currentProgress, false) + setSubText("$currentProgress%") + } } val notification = notificationBuilder diff --git a/ketch/src/main/java/com/ketch/internal/utils/MapperUtil.kt b/ketch/src/main/java/com/ketch/internal/utils/MapperUtil.kt index cf7289b..b80d6e0 100644 --- a/ketch/src/main/java/com/ketch/internal/utils/MapperUtil.kt +++ b/ketch/src/main/java/com/ketch/internal/utils/MapperUtil.kt @@ -21,5 +21,5 @@ internal fun DownloadEntity.toDownloadModel() = lastModified = lastModified, eTag = eTag, metaData = metaData, - failureReason = failureReason + failureReason = failureReason, ) diff --git a/ketch/src/main/java/com/ketch/internal/utils/NotificationConst.kt b/ketch/src/main/java/com/ketch/internal/utils/NotificationConst.kt index bd3df3f..cfb5606 100644 --- a/ketch/src/main/java/com/ketch/internal/utils/NotificationConst.kt +++ b/ketch/src/main/java/com/ketch/internal/utils/NotificationConst.kt @@ -12,6 +12,11 @@ internal object NotificationConst { const val KEY_NOTIFICATION_SMALL_ICON = "key_small_notification_icon" const val DEFAULT_VALUE_NOTIFICATION_SMALL_ICON = -1 const val KEY_NOTIFICATION_ID = "key_notification_id" + const val KEY_NOTIFICATION_CANCEL_ACTION = "key_notification_cancel_action" + const val DEFAULT_VALUE_ACTION_ENABLE = true + const val KEY_NOTIFICATION_PAUSE_ACTION = "key_notification_pause_action" + const val KEY_NOTIFICATION_RESUME_ACTION = "key_notification_resume_action" + const val KEY_NOTIFICATION_RETRY_ACTION = "key_notification_retry_action" // Actions const val ACTION_NOTIFICATION_DISMISSED = "ACTION_NOTIFICATION_DISMISSED" diff --git a/ketch/src/main/java/com/ketch/internal/utils/TextUtil.kt b/ketch/src/main/java/com/ketch/internal/utils/TextUtil.kt index 586b3d5..6c6945c 100644 --- a/ketch/src/main/java/com/ketch/internal/utils/TextUtil.kt +++ b/ketch/src/main/java/com/ketch/internal/utils/TextUtil.kt @@ -30,7 +30,7 @@ internal object TextUtil { fun getSpeedText(speedInBPerMs: Float): String { var value = speedInBPerMs * SEC_IN_MILLIS - val units = arrayOf("b/s", "kb/s", "mb/s", "gb/s") + val units = arrayOf("b/s", "KB/s", "MB/s", "GB/s") var unitIndex = 0 while (value >= VALUE_500 && unitIndex < units.size - 1) { @@ -43,7 +43,7 @@ internal object TextUtil { fun getTotalLengthText(lengthInBytes: Long): String { var value = lengthInBytes.toFloat() - val units = arrayOf("b", "kb", "mb", "gb") + val units = arrayOf("b", "KB", "MB", "GB") var unitIndex = 0 while (value >= VALUE_500 && unitIndex < units.size - 1) { diff --git a/ketch/src/main/java/com/ketch/internal/worker/DownloadWorker.kt b/ketch/src/main/java/com/ketch/internal/worker/DownloadWorker.kt index 5d51a9a..6e46834 100644 --- a/ketch/src/main/java/com/ketch/internal/worker/DownloadWorker.kt +++ b/ketch/src/main/java/com/ketch/internal/worker/DownloadWorker.kt @@ -6,8 +6,8 @@ import androidx.work.WorkerParameters import androidx.work.workDataOf import com.ketch.Status import com.ketch.internal.database.DatabaseInstance -import com.ketch.internal.download.DownloadTask import com.ketch.internal.download.ApiResponseHeaderChecker +import com.ketch.internal.download.DownloadTask import com.ketch.internal.network.RetrofitInstance import com.ketch.internal.notification.DownloadNotificationManager import com.ketch.internal.utils.DownloadConst @@ -51,6 +51,7 @@ internal class DownloadWorker( val id = downloadRequest.id val url = downloadRequest.url val dirPath = downloadRequest.path + val customTitle = downloadRequest.customTitle val fileName = downloadRequest.fileName val headers = downloadRequest.headers val supportPauseResume = downloadRequest.supportPauseResume // in case of false, we will not store total length info in DB @@ -60,7 +61,8 @@ internal class DownloadWorker( context = context, notificationConfig = notificationConfig, requestId = id, - fileName = fileName + fileName = fileName, + customTitle = customTitle, ) } @@ -194,7 +196,6 @@ internal class DownloadWorker( } } else { - downloadDao.find(id)?.copy( status = Status.FAILED.toString(), failureReason = e.message ?: "",