Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sh text eol=lf
*.bat text eol=crlf
2 changes: 1 addition & 1 deletion app/src/main/java/com/khush/sample/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MainApplication : Application() {
.setNotificationConfig(
NotificationConfig(
true,
smallIcon = R.drawable.ic_launcher_foreground
smallIcon = R.drawable.ic_notif_android
)
)
.enableLogs(true)
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_notif_android.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="#fff"
android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z" />

</vector>
178 changes: 89 additions & 89 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ketch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
androidResources {
resourcePrefix = "ketch_"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.work.ForegroundInfo
import com.ketch.NotificationConfig
import com.ketch.R
import com.ketch.internal.utils.DownloadConst
import com.ketch.internal.utils.NotificationConst
import com.ketch.internal.utils.TextUtil
Expand Down Expand Up @@ -138,7 +139,7 @@ internal class DownloadNotificationManager(
PendingIntent.FLAG_IMMUTABLE
)

var nb = notificationBuilder
val nb = notificationBuilder
.setSmallIcon(notificationConfig.smallIcon)
.setContentTitle("Downloading $fileName")
.setContentIntent(pendingIntentOpen)
Expand All @@ -147,12 +148,22 @@ internal class DownloadNotificationManager(
.setOngoing(true)

if (length != 0L) {
nb = nb.addAction(-1, NotificationConst.PAUSE_BUTTON_TEXT, pendingIntentPause)
nb
.addAction(
R.drawable.ketch_ic_notif_pause,
NotificationConst.PAUSE_BUTTON_TEXT,
pendingIntentPause
)
}

foregroundInfo = ForegroundInfo(
notificationId,
nb.addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel)
nb
.addAction(
R.drawable.ketch_ic_notif_cancel,
NotificationConst.CANCEL_BUTTON_TEXT,
pendingIntentCancel
)
.setDeleteIntent(pendingIntentDismiss)
.build(),
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.ketch.Ketch
import com.ketch.R
import com.ketch.internal.utils.DownloadConst
import com.ketch.internal.utils.NotificationConst
import com.ketch.internal.utils.TextUtil
Expand Down Expand Up @@ -93,13 +94,19 @@ internal class NotificationReceiver : BroadcastReceiver() {
intent.extras?.getString(NotificationConst.KEY_NOTIFICATION_CHANNEL_NAME)
?: NotificationConst.DEFAULT_VALUE_NOTIFICATION_CHANNEL_NAME
val notificationImportance =
intent.extras?.getInt(NotificationConst.KEY_NOTIFICATION_CHANNEL_IMPORTANCE)
intent.extras?.getInt(
NotificationConst.KEY_NOTIFICATION_CHANNEL_IMPORTANCE,
NotificationConst.DEFAULT_VALUE_NOTIFICATION_CHANNEL_IMPORTANCE
)
?: NotificationConst.DEFAULT_VALUE_NOTIFICATION_CHANNEL_IMPORTANCE
val notificationChannelDescription =
intent.extras?.getString(NotificationConst.KEY_NOTIFICATION_CHANNEL_DESCRIPTION)
?: NotificationConst.DEFAULT_VALUE_NOTIFICATION_CHANNEL_DESCRIPTION
val notificationSmallIcon =
intent.extras?.getInt(NotificationConst.KEY_NOTIFICATION_SMALL_ICON)
intent.extras?.getInt(
NotificationConst.KEY_NOTIFICATION_SMALL_ICON,
NotificationConst.DEFAULT_VALUE_NOTIFICATION_SMALL_ICON
)
?: NotificationConst.DEFAULT_VALUE_NOTIFICATION_SMALL_ICON
val fileName = intent.extras?.getString(DownloadConst.KEY_FILE_NAME) ?: ""
val currentProgress = intent.extras?.getInt(DownloadConst.KEY_PROGRESS) ?: 0
Expand Down Expand Up @@ -171,7 +178,7 @@ internal class NotificationReceiver : BroadcastReceiver() {
PendingIntent.FLAG_IMMUTABLE
)

var notificationBuilder =
val notificationBuilder =
NotificationCompat.Builder(context, NotificationConst.NOTIFICATION_CHANNEL_ID)
.setSmallIcon(notificationSmallIcon)
.setContentText(
Expand All @@ -196,24 +203,34 @@ 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
)
notificationBuilder
.addAction(
R.drawable.ketch_ic_notif_retry,
NotificationConst.RETRY_BUTTON_TEXT,
pendingIntentRetry
)
.setProgress(DownloadConst.MAX_VALUE_PROGRESS, currentProgress, false)
.addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel)
.addAction(
R.drawable.ketch_ic_notif_cancel,
NotificationConst.CANCEL_BUTTON_TEXT,
pendingIntentCancel
)
.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
)
notificationBuilder
.addAction(
R.drawable.ketch_ic_notif_resume,
NotificationConst.RESUME_BUTTON_TEXT,
pendingIntentResume
)
.setProgress(DownloadConst.MAX_VALUE_PROGRESS, currentProgress, false)
.addAction(-1, NotificationConst.CANCEL_BUTTON_TEXT, pendingIntentCancel)
.addAction(
R.drawable.ketch_ic_notif_cancel,
NotificationConst.CANCEL_BUTTON_TEXT,
pendingIntentCancel
)
.setSubText("$currentProgress%")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal object NotificationConst {
const val KEY_NOTIFICATION_CHANNEL_IMPORTANCE = "key_notification_channel_importance"
const val DEFAULT_VALUE_NOTIFICATION_CHANNEL_IMPORTANCE = 2 // LOW
const val KEY_NOTIFICATION_SMALL_ICON = "key_small_notification_icon"
const val DEFAULT_VALUE_NOTIFICATION_SMALL_ICON = -1
const val DEFAULT_VALUE_NOTIFICATION_SMALL_ICON = 0
const val KEY_NOTIFICATION_ID = "key_notification_id"

// Actions
Expand Down
11 changes: 11 additions & 0 deletions ketch/src/main/res/drawable/ketch_ic_notif_cancel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<!-- close -->
<path
android:fillColor="#fff"
android:pathData="M256,760L200,704L424,480L200,256L256,200L480,424L704,200L760,256L536,480L760,704L704,760L480,536L256,760Z" />

</vector>
11 changes: 11 additions & 0 deletions ketch/src/main/res/drawable/ketch_ic_notif_pause.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<!-- pause -->
<path
android:fillColor="#fff"
android:pathData="M560,760L560,200L720,200L720,760L560,760ZM240,760L240,200L400,200L400,760L240,760Z" />

</vector>
11 changes: 11 additions & 0 deletions ketch/src/main/res/drawable/ketch_ic_notif_resume.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<!-- resume -->
<path
android:fillColor="#fff"
android:pathData="M240,720L240,240L320,240L320,720L240,720ZM400,720L800,480L400,240L400,720Z" />

</vector>
11 changes: 11 additions & 0 deletions ketch/src/main/res/drawable/ketch_ic_notif_retry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<!-- refresh -->
<path
android:fillColor="#fff"
android:pathData="M480,800Q346,800 253,707Q160,614 160,480Q160,346 253,253Q346,160 480,160Q549,160 612,188.5Q675,217 720,270L720,160L800,160L800,440L520,440L520,360L688,360Q656,304 600.5,272Q545,240 480,240Q380,240 310,310Q240,380 240,480Q240,580 310,650Q380,720 480,720Q557,720 619,676Q681,632 706,560L790,560Q762,666 676,733Q590,800 480,800Z" />

</vector>