-
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.
- Loading branch information
Showing
46 changed files
with
696 additions
and
11 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
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
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
42 changes: 42 additions & 0 deletions
42
app/src/main/java/team/aliens/dms/android/app/service/DmsMessagingService.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,42 @@ | ||
package team.aliens.dms.android.app.service | ||
|
||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import team.aliens.dms.android.core.notification.DeviceTokenManager | ||
import team.aliens.dms.android.core.notification.NotificationManager | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class DmsMessagingService : FirebaseMessagingService() { | ||
|
||
@Inject | ||
lateinit var deviceTokenManager: DeviceTokenManager | ||
|
||
private val notificationManager: NotificationManager by lazy { | ||
NotificationManager(context = this) | ||
} | ||
|
||
override fun onNewToken(deviceToken: String) { | ||
super.onNewToken(deviceToken) | ||
CoroutineScope(Dispatchers.IO).launch { | ||
deviceTokenManager.saveDeviceToken(deviceToken = deviceToken) | ||
} | ||
} | ||
|
||
override fun onMessageReceived(message: RemoteMessage) { | ||
super.onMessageReceived(message) | ||
message.notification?.run { | ||
notificationManager.setNotificationContent( | ||
title = title, | ||
body = body, | ||
) | ||
} | ||
notificationManager.sendNotification() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name" translatable="false">DMS</string> | ||
<string name="default_notification_channel_id">team.aliens.dms.android</string> | ||
</resources> |
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
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
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,53 @@ | ||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
alias(libs.plugins.hilt) | ||
alias(libs.plugins.ksp) | ||
} | ||
|
||
android { | ||
namespace = "team.aliens.dms.android.core.device" | ||
compileSdk = libs.versions.compileSdk.get().toInt() | ||
|
||
defaultConfig { | ||
minSdk = libs.versions.minSdk.get().toInt() | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = Versions.java | ||
targetCompatibility = Versions.java | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = Versions.java.toString() | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(ProjectPaths.Core.DATASTORE)) | ||
|
||
implementation(libs.androidx.core) | ||
implementation(libs.androidx.appcompat) | ||
implementation(libs.material) | ||
testImplementation(libs.junit) | ||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso) | ||
|
||
implementation(libs.androidx.datastore.preferences) | ||
|
||
implementation(libs.hilt) | ||
ksp(libs.hilt.compiler) | ||
} |
Empty file.
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 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
...evice/src/androidTest/java/team/aliens/dms/android/core/device/ExampleInstrumentedTest.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,24 @@ | ||
package team.aliens.dms.android.core.device | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("team.aliens.dms.android.core.device.test", appContext.packageName) | ||
} | ||
} |
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 xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
11 changes: 11 additions & 0 deletions
11
.../src/main/java/team/aliens/dms/android/core/device/datastore/DeviceDataStoreDataSource.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,11 @@ | ||
package team.aliens.dms.android.core.device.datastore | ||
|
||
abstract class DeviceDataStoreDataSource { | ||
|
||
abstract fun loadDeviceToken(): String | ||
|
||
abstract suspend fun storeDeviceToken(deviceToken: String) | ||
|
||
abstract suspend fun clearDeviceToken() | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
.../main/java/team/aliens/dms/android/core/device/datastore/DeviceDataStoreDataSourceImpl.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 team.aliens.dms.android.core.device.datastore | ||
|
||
import team.aliens.dms.android.core.device.datastore.store.DeviceStore | ||
import javax.inject.Inject | ||
|
||
internal class DeviceDataStoreDataSourceImpl @Inject constructor( | ||
private val deviceStore: DeviceStore, | ||
) : DeviceDataStoreDataSource() { | ||
override fun loadDeviceToken(): String = deviceStore.loadDeviceToken() | ||
|
||
override suspend fun storeDeviceToken(deviceToken: String) { | ||
deviceStore.storeDeviceToken(deviceToken) | ||
} | ||
|
||
override suspend fun clearDeviceToken() { | ||
deviceStore.clearDeviceToken() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
core/device/src/main/java/team/aliens/dms/android/core/device/datastore/store/DeviceStore.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,10 @@ | ||
package team.aliens.dms.android.core.device.datastore.store | ||
|
||
internal abstract class DeviceStore { | ||
|
||
abstract fun loadDeviceToken(): String | ||
|
||
abstract suspend fun storeDeviceToken(deviceToken: String) | ||
|
||
abstract suspend fun clearDeviceToken() | ||
} |
45 changes: 45 additions & 0 deletions
45
...vice/src/main/java/team/aliens/dms/android/core/device/datastore/store/DeviceStoreImpl.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,45 @@ | ||
package team.aliens.dms.android.core.device.datastore.store | ||
|
||
import android.util.Log | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.runBlocking | ||
import team.aliens.dms.android.core.datastore.PreferencesDataStore | ||
import team.aliens.dms.android.core.datastore.util.transform | ||
import team.aliens.dms.android.core.device.datastore.store.exception.CannotStoreDeviceTokenException | ||
import team.aliens.dms.android.core.device.datastore.store.exception.DeviceTokenNotFoundException | ||
import javax.inject.Inject | ||
|
||
internal class DeviceStoreImpl @Inject constructor( | ||
private val preferencesDataStore: PreferencesDataStore, | ||
) : DeviceStore() { | ||
override fun loadDeviceToken(): String = runBlocking { | ||
preferencesDataStore.data.map { preferences -> | ||
Log.d("TEST2",preferences[DEVICE_TOKEN].toString()) | ||
preferences[DEVICE_TOKEN] ?: throw DeviceTokenNotFoundException() | ||
}.first() | ||
} | ||
|
||
override suspend fun storeDeviceToken(deviceToken: String) { | ||
transform( | ||
onFailure = { throw CannotStoreDeviceTokenException() }, | ||
) { | ||
Log.d("TEST1",deviceToken) | ||
preferencesDataStore.edit { preferences -> | ||
preferences[DEVICE_TOKEN] = deviceToken | ||
} | ||
} | ||
} | ||
|
||
override suspend fun clearDeviceToken() { | ||
transform { | ||
preferencesDataStore.edit { preferences -> preferences.clear() } | ||
} | ||
} | ||
|
||
private companion object { | ||
val DEVICE_TOKEN = stringPreferencesKey("device-token") | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...iens/dms/android/core/device/datastore/store/exception/CannotStoreDeviceTokenException.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,5 @@ | ||
package team.aliens.dms.android.core.device.datastore.store.exception | ||
|
||
import team.aliens.dms.android.core.datastore.exception.TransformFailureException | ||
|
||
class CannotStoreDeviceTokenException : TransformFailureException("Cannot store deviceToken") |
7 changes: 7 additions & 0 deletions
7
...a/team/aliens/dms/android/core/device/datastore/store/exception/TokenNotFoundException.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 team.aliens.dms.android.core.device.datastore.store.exception | ||
|
||
import team.aliens.dms.android.core.datastore.exception.LoadFailureException | ||
|
||
sealed class TokenNotFoundException(message: String?) : LoadFailureException(message) | ||
|
||
class DeviceTokenNotFoundException : TokenNotFoundException("Device token not found") |
18 changes: 18 additions & 0 deletions
18
core/device/src/main/java/team/aliens/dms/android/core/device/di/DataSourceModule.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 team.aliens.dms.android.core.device.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import team.aliens.dms.android.core.device.datastore.DeviceDataStoreDataSource | ||
import team.aliens.dms.android.core.device.datastore.DeviceDataStoreDataSourceImpl | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal abstract class DataSourceModule { | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindDeviceDataStoreDataSource(impl: DeviceDataStoreDataSourceImpl): DeviceDataStoreDataSource | ||
} |
Oops, something went wrong.