-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from toquete/notification_module
Creating notification module
- Loading branch information
Showing
11 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id("boxbox.android.library") | ||
id("boxbox.android.hilt") | ||
} | ||
|
||
android { | ||
namespace = "com.toquete.boxbox.core.notification" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest> | ||
|
||
</manifest> |
32 changes: 32 additions & 0 deletions
32
...ification/src/main/java/com/toquete/boxbox/core/notification/DefaultNotificationHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.toquete.boxbox.core.notification | ||
|
||
import android.app.NotificationChannel | ||
import android.os.Build | ||
import androidx.core.app.NotificationManagerCompat | ||
import com.toquete.boxbox.core.notification.model.Notification | ||
import javax.inject.Inject | ||
|
||
internal class DefaultNotificationHelper @Inject constructor( | ||
private val notificationManager: NotificationManagerCompat | ||
) : NotificationHelper { | ||
|
||
override fun notify(notification: Notification) { | ||
createNotificationChannel(notification) | ||
|
||
if (notificationManager.areNotificationsEnabled()) { | ||
notificationManager.notify(notification.id, notification.notification) | ||
} | ||
} | ||
|
||
private fun createNotificationChannel(notification: Notification) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val channel = notification.channel | ||
NotificationChannel(channel.id, channel.channelName, channel.importance).apply { | ||
description = channel.description | ||
enableLights(channel.enableLights) | ||
enableVibration(channel.enableVibration) | ||
notificationManager.createNotificationChannel(this) | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/notification/src/main/java/com/toquete/boxbox/core/notification/NotificationHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.toquete.boxbox.core.notification | ||
|
||
import com.toquete.boxbox.core.notification.model.Notification | ||
|
||
interface NotificationHelper { | ||
fun notify(notification: Notification) | ||
} |
18 changes: 18 additions & 0 deletions
18
...ication/src/main/java/com/toquete/boxbox/core/notification/di/NotificationHelperModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.toquete.boxbox.core.notification.di | ||
|
||
import com.toquete.boxbox.core.notification.DefaultNotificationHelper | ||
import com.toquete.boxbox.core.notification.NotificationHelper | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal abstract class NotificationHelperModule { | ||
|
||
@Binds | ||
abstract fun bindsNotificationHelper( | ||
defaultNotificationHelper: DefaultNotificationHelper | ||
): NotificationHelper | ||
} |
23 changes: 23 additions & 0 deletions
23
.../notification/src/main/java/com/toquete/boxbox/core/notification/di/NotificationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.toquete.boxbox.core.notification.di | ||
|
||
import android.content.Context | ||
import androidx.core.app.NotificationManagerCompat | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object NotificationModule { | ||
|
||
@Singleton | ||
@Provides | ||
fun providesNotificationManager( | ||
@ApplicationContext context: Context | ||
): NotificationManagerCompat { | ||
return NotificationManagerCompat.from(context) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core/notification/src/main/java/com/toquete/boxbox/core/notification/model/Channel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.toquete.boxbox.core.notification.model | ||
|
||
import android.app.NotificationManager | ||
|
||
enum class Channel( | ||
val id: String, | ||
val channelName: String, | ||
val description: String, | ||
val importance: Int, | ||
val enableLights: Boolean, | ||
val enableVibration: Boolean | ||
) { | ||
EVENTS( | ||
id = "EVENTS_CHANNEL_ID", | ||
channelName = "Events", | ||
description = "Events notifications", | ||
importance = NotificationManager.IMPORTANCE_DEFAULT, | ||
enableLights = true, | ||
enableVibration = true | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
core/notification/src/main/java/com/toquete/boxbox/core/notification/model/Notification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.toquete.boxbox.core.notification.model | ||
|
||
import android.app.Notification as AndroidNotification | ||
|
||
data class Notification( | ||
val id: Int, | ||
val channel: Channel, | ||
val notification: AndroidNotification | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="540" | ||
android:viewportHeight="540" | ||
tools:ignore="all"> | ||
<group android:scaleX="0.5" | ||
android:scaleY="0.5" | ||
android:translateX="135" | ||
android:translateY="135"> | ||
<path | ||
android:pathData="m270,0a270,270 0,0 0,-270 270,270 270,0 0,0 270,270 270,270 0,0 0,270 -270,270 270,0 0,0 -270,-270zM270,154.78a115.22,115.22 0,0 1,115.22 115.22,115.22 115.22,0 0,1 -115.22,115.22 115.22,115.22 0,0 1,-115.22 -115.22,115.22 115.22,0 0,1 115.22,-115.22z" | ||
android:fillColor="#333"/> | ||
<path | ||
android:pathData="m400.87,87.21 l-10.63,17.01a205,205 0,0 1,84.76 165.78,205 205,0 0,1 -34.22,113.16l15.84,12.38a225,225 0,0 0,38.37 -125.53,225 225,0 0,0 -94.13,-182.79z" | ||
android:fillColor="#ff2d2c"/> | ||
<path | ||
android:pathData="m139.11,87.33a225,225 0,0 0,-94.11 182.67,225 225,0 0,0 38.65,125.74l16.98,-10.59a205,205 0,0 1,-35.63 -115.15,205 205,0 0,1 84.72,-165.69z" | ||
android:fillColor="#ff2d2c"/> | ||
<path | ||
android:pathData="m270,120a150,150 0,0 0,-150 150,150 150,0 0,0 150,150 150,150 0,0 0,150 -150,150 150,0 0,0 -150,-150zM270,154.78a115.22,115.22 0,0 1,115.22 115.22,115.22 115.22,0 0,1 -115.22,115.22 115.22,115.22 0,0 1,-115.22 -115.22,115.22 115.22,0 0,1 115.22,-115.22z" | ||
android:fillColor="#a8a8a8"/> | ||
<path | ||
android:pathData="m270,145a125,125 0,0 0,-125 125,125 125,0 0,0 125,125 125,125 0,0 0,125 -125,125 125,0 0,0 -125,-125zM261,162.94v63.02a45,45 0,0 0,-9.6 3.13l-37.02,-50.96a107.5,107.5 0,0 1,46.62 -15.19zM279,162.95a107.5,107.5 0,0 1,46.6 15.2l-37,50.92a45,45 0,0 0,-9.6 -3.16v-62.96zM340.21,188.67a107.5,107.5 0,0 1,28.79 39.7l-59.9,19.46a45,45 0,0 0,-5.93 -8.18l37.04,-50.98zM199.83,188.73 L236.83,239.66a45,45 0,0 0,-5.96 8.16l-59.96,-19.48a107.5,107.5 0,0 1,28.92 -39.61zM270,240a30,30 0,0 1,30 30,30 30,0 0,1 -30,30 30,30 0,0 1,-30 -30,30 30,0 0,1 30,-30zM165.45,245.49 L225.31,264.94a45,45 0,0 0,-0.31 5.06,45 45,0 0,0 0.34,5.05l-59.88,19.45a107.5,107.5 0,0 1,-2.96 -24.5,107.5 107.5,0 0,1 2.95,-24.51zM374.54,245.5a107.5,107.5 0,0 1,2.96 24.5,107.5 107.5,0 0,1 -2.95,24.51l-59.86,-19.45a45,45 0,0 0,0.31 -5.06,45 45,0 0,0 -0.34,-5.05l59.88,-19.45zM230.91,292.17a45,45 0,0 0,5.93 8.17l-37.04,50.99a107.5,107.5 0,0 1,-28.78 -39.69l59.9,-19.46zM309.13,292.18 L369.09,311.66a107.5,107.5 0,0 1,-28.92 39.61l-37.01,-50.93a45,45 0,0 0,5.96 -8.16zM288.61,310.91 L325.63,361.87a107.5,107.5 0,0 1,-46.62 15.19v-63.02a45,45 0,0 0,9.6 -3.13zM251.39,310.92a45,45 0,0 0,9.61 3.17v62.96a107.5,107.5 0,0 1,-46.61 -15.2l37,-50.92z" | ||
android:fillColor="#7f7f7f"/> | ||
<path | ||
android:pathData="m165.3,435.72a9.85,9.85 0,0 1,2.87 2.74,6.52 6.52,0 0,1 1.06,2.87 6.66,6.66 0,0 1,-0.36 2.85,12.1 12.1,0 0,1 -1.33,2.64l-0.12,0.19 -17.42,13.85a14.86,14.86 0,0 1,-3.63 1.17,20.38 20.38,0 0,1 -4.16,0.38 17.92,17.92 0,0 1,-4.2 -0.55,11.71 11.71,0 0,1 -3.71,-1.63l-15.68,-10.49a7.21,7.21 0,0 1,-2.3 -2.4,8.67 8.67,0 0,1 -1.11,-3 8.44,8.44 0,0 1,0 -3.09,7.69 7.69,0 0,1 1.13,-2.78l17.5,-13.94a15.28,15.28 0,0 1,3.75 -1.09,22.23 22.23,0 0,1 4.25,-0.31 19.31,19.31 0,0 1,4.19 0.54,10.63 10.63,0 0,1 3.5,1.49zM159.64,444.48a2.56,2.56 0,0 0,0.89 -0.91,2.68 2.68,0 0,0 0.26,-2.64 6.11,6.11 0,0 0,-2.42 -2.64l-11.7,-7.84a9,9 0,0 0,-2.09 -1,8.92 8.92,0 0,0 -2.33,-0.46 7.92,7.92 0,0 0,-2.29 0.18,5.28 5.28,0 0,0 -1.96,0.83l-13.85,11 -0.36,0.38 -0.21,0.27a3,3 0,0 0,-0.26 2.84,5.35 5.35,0 0,0 2.18,2.7l11.7,7.83a7.12,7.12 0,0 0,2.16 0.93,12 12,0 0,0 2.49,0.36 10,10 0,0 0,2.31 -0.17,3.21 3.21,0 0,0 1.62,-0.73zM203.43,470 L203.36,470.22 202.83,470.77a0.46,0.46 0,0 1,-0.45 0.19h-0.56l-7.29,-2.27a7.82,7.82 0,0 0,-2.29 -0.33,10.44 10.44,0 0,0 -2.44,0.29 8.87,8.87 0,0 0,-2.17 0.81,4.44 4.44,0 0,0 -1.5,1.27l-3.35,4.8 -0.2,0.48a3.49,3.49 0,0 0,-0.13 1.36,3.81 3.81,0 0,0 0.43,1.48 4.69,4.69 0,0 0,1.08 1.32,5 5,0 0,0 1.8,0.95l13.66,4.26a1.48,1.48 0,0 0,0.73 0,5 5,0 0,0 0.69,-0.17l18,-25.67a2,2 0,0 1,0.73 -0.61,1.2 1.2,0 0,1 0.93,-0.12l5,1.56c0.4,0.12 0.53,0.42 0.38,0.89 -0.08,0.26 -0.14,0.4 -0.19,0.42l-21.16,30.12a2.41,2.41 0,0 1,-0.92 0.67,1.5 1.5,0 0,1 -1.06,0.15l-22.7,-7.08a8.58,8.58 0,0 1,-2.85 -1.54,8.07 8.07,0 0,1 -2,-2.31 7.46,7.46 0,0 1,-0.92 -2.8,6.61 6.61,0 0,1 0.25,-2.9l0.27,-0.7 5.14,-7.29a9.24,9.24 0,0 1,2.84 -2.61,18.28 18.28,0 0,1 4,-1.81 21.81,21.81 0,0 1,4.43 -0.92,15 15,0 0,1 4,0.08l-0.74,-10.62a0.69,0.69 0,0 0,0 -0.2,0.68 0.68,0 0,1 0,-0.19l0.17,-0.37a1,1 0,0 1,0.68 -0.44l6.31,2c0.55,0.17 0.81,0.47 0.8,0.91zM263.24,478.45a1,1 0,0 0,0.76 -0.34,3.11 3.11,0 0,0 0.54,-0.69l2.14,-5.84v-0.29a0.8,0.8 0,0 0,-0.12 -0.49c-0.09,-0.14 -0.29,-0.21 -0.59,-0.22l-20.27,-0.89a2.17,2.17 0,0 1,-0.85 -0.2c-0.26,-0.13 -0.39,-0.29 -0.38,-0.48l1.62,-4.49a1.37,1.37 0,0 1,0.68 -0.54,2.39 2.39,0 0,1 1.07,-0.18l27.28,1.2a0.79,0.79 0,0 1,0.64 0.37,1.35 1.35,0 0,1 0.23,0.81l-12.75,34.59a2.46,2.46 0,0 1,-0.72 0.88,1.53 1.53,0 0,1 -1,0.42l-27.39,-1.19c-0.76,0 -1.13,-0.28 -1.11,-0.74l1.62,-4.43a1,1 0,0 1,0.68 -0.54,2.6 2.6,0 0,1 1,-0.19l20.27,0.88a1.41,1.41 0,0 0,0.72 -0.17,4 4,0 0,0 0.61,-0.34l3.63,-9.88a2.55,2.55 0,0 1,0.13 -0.37,1 1,0 0,0 0.07,-0.25c0,-0.31 -0.21,-0.47 -0.67,-0.49l-20.5,-0.89a1.77,1.77 0,0 1,-0.82 -0.23c-0.24,-0.15 -0.35,-0.31 -0.34,-0.51l1.62,-4.43a1.73,1.73 0,0 1,1.68 -0.73zM303.5,493.58a1.13,1.13 0,0 0,-0.14 0.44v0.17c0,0.14 0.14,0.2 0.32,0.16l20.38,-4.35a1.76,1.76 0,0 1,0.82 0c0.29,0.08 0.45,0.21 0.49,0.39l-0.44,4.7a1,1 0,0 1,-0.49 0.69,2.49 2.49,0 0,1 -1,0.45l-29.36,6.35c-0.75,0.16 -1.17,0 -1.26,-0.43l0.42,-4.81a0.7,0.7 0,0 0,0.17 -0.39,1.58 1.58,0 0,1 0.26,-0.58l24.09,-30.46v-0.4c0,-0.22 -0.25,-0.35 -0.58,-0.28l-19.72,4.26a1.89,1.89 0,0 1,-0.82 0c-0.28,-0.05 -0.45,-0.18 -0.49,-0.36l0.43,-4.76a1.33,1.33 0,0 1,0.52 -0.69,2.42 2.42,0 0,1 1,-0.45l29.36,-6.34q1.11,-0.24 1.26,0.42l-0.3,3.51a2.27,2.27 0,0 1,-0.46 1.09zM402.35,429.79c0.65,-0.53 1.12,-0.61 1.4,-0.25l1.65,4.46a1,1 0,0 1,-0.17 0.87,3 3,0 0,1 -0.66,0.82l-5.48,4.38a7.22,7.22 0,0 0,-1.74 2,11.18 11.18,0 0,0 -1.05,2.26 8.32,8.32 0,0 0,-0.42 2.16,4.41 4.41,0 0,0 0.19,1.71l2.11,5.46 0.2,0.39c0,0.09 0.05,0.11 0,0.08l0.32,0.41a3,3 0,0 0,2.47 1.12,5.23 5.23,0 0,0 3.27,-1.33l11.18,-8.93a1.52,1.52 0,0 0,0.43 -0.6,5.1 5.1,0 0,0 0.24,-0.67l-11.16,-29.31a1.87,1.87 0,0 1,-0.1 -0.94,1.26 1.26,0 0,1 0.42,-0.85l4.1,-3.27c0.33,-0.26 0.64,-0.2 0.95,0.19q0.25,0.3 0.24,0.39l13.11,34.4a2.38,2.38 0,0 1,0 1.14,1.51 1.51,0 0,1 -0.47,1l-18.57,14.83a8.38,8.38 0,0 1,-2.92 1.56,7.82 7.82,0 0,1 -3,0.33 7.59,7.59 0,0 1,-2.83 -0.8,6.68 6.68,0 0,1 -2.27,-1.84l-0.42,-0.61 -3.16,-8.34a9,9 0,0 1,-0.6 -4.09,19.12 19.12,0 0,1 0.87,-4.66 20.32,20.32 0,0 1,1.93 -4.39,11.17 11.17,0 0,1 2.58,-3.16z" | ||
android:strokeWidth="5" | ||
android:fillColor="#ff2d2c" | ||
android:strokeColor="#ff2d2c"/> | ||
<path | ||
android:pathData="m251.81,89.83c2.44,-1.1 3.98,-3.56 3.98,-6.41 0,-3.88 -3.05,-7.42 -8.25,-7.42h-24.54v21.56h11.93v-6.96h3.9l3.59,6.96h13.38zM241.73,85.39h-6.8v-4.56l6.8,0.02a2.27,2.27 0,1 1,0 4.54zM263.27,97.57h26.3v-4.82h-14.38v-3.17h14.38v-5.2h-14.38v-3.17h14.38v-5.2h-26.3zM309.63,76.01h-11.93v21.56h24.01v-4.82h-12.08zM337.73,76.01h-11.93v21.56h24v-4.82h-12.08zM361.39,56.34h-186.38v41.13h20.64v-25.84l165.74,0a7.65,7.65 0,1 0,0 -15.3zM338.49,66.42h-142.85v-4.88l142.85,0.01a2.43,2.43 0,1 1,0 4.87zM202.5,97.57h11.93v-21.56h-11.93zM354.78,97.57h11.93v-21.56h-11.93z" | ||
android:strokeWidth="1.0371" | ||
android:fillColor="#ff2d2c" | ||
android:fillType="evenOdd"/> | ||
</group> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters