Skip to content

Commit

Permalink
[feat]: brand color in notification on older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse205 authored Oct 17, 2023
1 parent c0e06fa commit ee7fc59
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ val isAtLeastAndroid13 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
val gesturesAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
val contrastedNavBarAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1

val notificationsDynamicColorAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val notificationsChannelsAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
val shouldRequestNotificationsPermission = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
val startForegroundServiceAvailable = notificationsChannelsAvailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fun Context.sendErrorNotification(appCrash: AppCrash) = doIfPermitted {
)))
}
.setAutoCancel(true)
.applyPrimaryColorIfNeeded(this@sendErrorNotification)
.addAction(
R.drawable.ic_copy,
getString(android.R.string.copy),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.f0x1d.logfox.extensions.notifications

import android.content.Context
import androidx.core.app.NotificationCompat
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.notificationsDynamicColorAvailable

fun NotificationCompat.Builder.applyPrimaryColorIfNeeded(context: Context): NotificationCompat.Builder {
if (!notificationsDynamicColorAvailable) color = context.getColor(R.color.color_primary)
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fun Context.sendRecordingNotification() = doIfPermitted {
NotificationCompat.Builder(this@sendRecordingNotification, LogFoxApp.RECORDING_STATUS_CHANNEL_ID)
.setContentTitle(getString(R.string.recording))
.setSmallIcon(R.drawable.ic_recording_notification)
.applyPrimaryColorIfNeeded(this@sendRecordingNotification)
.addAction(
R.drawable.ic_pause,
getString(R.string.pause),
Expand All @@ -43,6 +44,7 @@ fun Context.sendRecordingPausedNotification() = doIfPermitted {
NotificationCompat.Builder(this@sendRecordingPausedNotification, LogFoxApp.RECORDING_STATUS_CHANNEL_ID)
.setContentTitle(getString(R.string.recording_paused))
.setSmallIcon(R.drawable.ic_recording_play_notification)
.applyPrimaryColorIfNeeded(this@sendRecordingPausedNotification)
.addAction(
R.drawable.ic_play,
getString(R.string.resume),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/service/LoggingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.f0x1d.logfox.LogFoxApp
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.EXIT_APP_INTENT_ID
import com.f0x1d.logfox.extensions.STOP_LOGGING_SERVICE_INTENT_ID
import com.f0x1d.logfox.extensions.notifications.applyPrimaryColorIfNeeded
import com.f0x1d.logfox.extensions.makeOpenAppPendingIntent
import com.f0x1d.logfox.extensions.makeServicePendingIntent
import com.f0x1d.logfox.repository.logging.LoggingRepository
Expand Down Expand Up @@ -49,6 +50,7 @@ class LoggingService: Service() {
.setContentTitle(getString(R.string.logging))
.setSmallIcon(R.drawable.ic_bug_notification)
.setContentIntent(makeOpenAppPendingIntent())
.applyPrimaryColorIfNeeded(this)
.addAction(R.drawable.ic_stop, getString(R.string.stop_service), makeServicePendingIntent(STOP_LOGGING_SERVICE_INTENT_ID, LoggingService::class.java) {
action = ACTION_STOP_SERVICE
})
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_primary">#F78D1E</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>

<color name="transparent_black">#40000000</color>

<color name="ic_launcher_background">@color/white</color>
<color name="ic_launcher_foreground">#F78D1E</color>
<color name="ic_launcher_foreground">@color/color_primary</color>

<color name="card_stroke_color">#ffdadce0</color>
</resources>

0 comments on commit ee7fc59

Please sign in to comment.