Skip to content
Merged
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dependencies {

implementation(project(":core:common"))
implementation(project(":core:design-system"))
implementation(project(":core:device"))
implementation(project((":feature:splash")))
implementation(project(":feature:landing"))
implementation(project(":feature:signin"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import team.retum.device.DeviceTokenManager
import team.retum.jobisandroidv2.ui.JobisApp
import team.retum.jobisdesignsystemv2.foundation.JobisDesignSystemV2Theme
import team.retum.jobisdesignsystemv2.toast.JobisToast
import team.retum.notification.util.DeviceTokenManager
import javax.inject.Inject

private const val ANR_TIME = 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import team.retum.notification.util.DeviceTokenManager
import team.retum.notification.util.NotificationManager
import team.retum.device.DeviceTokenManager
import team.retum.device.NotificationManager
import team.retum.jobisandroidv2.MainActivity
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -17,7 +18,10 @@ class JobisMessagingService : FirebaseMessagingService() {
lateinit var deviceTokenManager: DeviceTokenManager

private val notificationManager: NotificationManager by lazy {
NotificationManager(context = this)
NotificationManager(
context = this,
intentClass = MainActivity::class.java,
)
}

override fun onNewToken(token: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ object ResourceKeys {
const val REFRESH_EXPIRES_AT = "refreshExpiresAt"
const val DEVICE_TOKEN = "deviceToken"
const val IMAGE_URL = "https://dsm-s3-bucket-jobis.s3.ap-northeast-2.amazonaws.com/"
const val SHARED_PREFERENCES_NAME = "jobis"
const val USER_SHARED_PREFERENCES_NAME = "user-shared-preferences"
const val DEVICE_SHARED_PREFERENCES_NAME = "device-shared-preferences"
const val BEARER = "Bearer"
const val SIGN_UP = "signUp"
const val COMPANY_ID = "companyId"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.retum.data.repository.user

import team.retum.jobis.local.datasource.device.LocalDeviceDataSource
import team.retum.jobis.local.datasource.user.LocalUserDataSource
import team.retum.network.datasource.user.RemoteUserDataSource
import team.retum.network.model.request.user.SignInRequest
Expand All @@ -9,6 +10,7 @@ import javax.inject.Inject
class UserRepositoryImpl @Inject constructor(
private val remoteUserDataSource: RemoteUserDataSource,
private val localUserDataSource: LocalUserDataSource,
private val localDeviceDataSource: LocalDeviceDataSource,
) : UserRepository {
override suspend fun signIn(signInRequest: SignInRequest): TokenResponse {
val response = remoteUserDataSource.signIn(signInRequest = signInRequest)
Expand Down Expand Up @@ -58,10 +60,10 @@ class UserRepositoryImpl @Inject constructor(
}

override suspend fun saveDeviceToken(deviceToken: String) {
localUserDataSource.saveDeviceToken(deviceToken = deviceToken)
localDeviceDataSource.saveDeviceToken(deviceToken = deviceToken)
}

override suspend fun getDeviceToken(): String {
return localUserDataSource.getDeviceToken()
return localDeviceDataSource.getDeviceToken()
}
}
1 change: 1 addition & 0 deletions core/device/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
26 changes: 26 additions & 0 deletions core/device/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
id(libs.plugins.android.library.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.kotlin.ksp.get().pluginId)
id(libs.plugins.ktlint.gradle.get().pluginId)
}

apply<CommonGradlePlugin>()

dependencies {
implementation(project(":core:design-system"))
implementation(project(":core:domain"))
implementation(project(":core:common"))

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics.ktx)
implementation(libs.firebase.messaging)
}

android {
namespace = "team.retum.device"

kotlinOptions {
jvmTarget = ProjectProperties.JVM_TARGET
}
}
4 changes: 4 additions & 0 deletions core/device/src/main/AndroidManifest.xml
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>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package team.retum.notification.util
package team.retum.device

class DeviceTokenException : RuntimeException("Fetching FCM registration token failed")
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.retum.notification.util
package team.retum.device

import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package team.retum.notification.util
package team.retum.device

import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import team.retum.alarm.R
import team.retum.common.utils.notificationPermissionGranted
import team.retum.jobisdesignsystemv2.foundation.JobisIcon

Expand All @@ -18,7 +19,10 @@ private object Notifications {
const val CHANNEL_DESCRIPTION = "jobis notification channel"
}

class NotificationManager(private val context: Context) {
class NotificationManager(
private val context: Context,
private val intentClass: Class<*>,
) {

init {
createNotificationChannel()
Expand All @@ -27,6 +31,13 @@ class NotificationManager(private val context: Context) {
private val notificationManagerCompat: NotificationManagerCompat by lazy {
NotificationManagerCompat.from(context)
}
private val intent = Intent(context, intentClass)
private val contentPendingIntent = PendingIntent.getActivity(
context,
Notifications.NOTIFICATION_ID,
intent,
PendingIntent.FLAG_IMMUTABLE,
)

private val notificationBuilder: NotificationCompat.Builder by lazy {
NotificationCompat.Builder(context, Notifications.NOTIFICATION_CHANNEL_ID)
Expand All @@ -36,6 +47,7 @@ class NotificationManager(private val context: Context) {
.setPriority(NotificationManager.IMPORTANCE_HIGH)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(contentPendingIntent)
}

fun setNotificationContent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package team.retum.notification.di
package team.retum.device.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import team.retum.notification.util.DeviceTokenManager
import team.retum.device.DeviceTokenManager
import team.retum.usecase.usecase.user.SaveDeviceTokenUseCase
import javax.inject.Singleton

Expand Down
11 changes: 11 additions & 0 deletions core/local/src/main/java/team/retum/jobis/local/Qualifier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.retum.jobis.local

import javax.inject.Qualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class UserDataSource

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class DeviceDataSource
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team.retum.jobis.local.datasource.device

interface LocalDeviceDataSource {
suspend fun saveDeviceToken(deviceToken: String)

suspend fun getDeviceToken(): String

suspend fun clearDeviceToken()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package team.retum.jobis.local.datasource.device

import android.content.SharedPreferences
import androidx.core.content.edit
import team.retum.common.utils.ResourceKeys
import team.retum.jobis.local.DeviceDataSource
import javax.inject.Inject

class LocalDeviceDataSourceImpl @Inject constructor(
@DeviceDataSource private val sharedPreferences: SharedPreferences,
) : LocalDeviceDataSource {
override suspend fun saveDeviceToken(deviceToken: String) {
sharedPreferences.edit {
this.putString(ResourceKeys.DEVICE_TOKEN, deviceToken)
}
}

override suspend fun getDeviceToken(): String {
return sharedPreferences.getString(ResourceKeys.DEVICE_TOKEN, "")
?: throw NullPointerException()
}

override suspend fun clearDeviceToken() {
sharedPreferences.edit {
[email protected]()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ interface LocalUserDataSource {
fun getRefreshExpiresAt(): String

fun clearUserInformation()

suspend fun saveDeviceToken(deviceToken: String)

suspend fun getDeviceToken(): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package team.retum.jobis.local.datasource.user
import android.content.SharedPreferences
import androidx.core.content.edit
import team.retum.common.utils.ResourceKeys
import team.retum.jobis.local.UserDataSource
import javax.inject.Inject

class LocalUserDataSourceImpl @Inject constructor(
private val sharedPreferences: SharedPreferences,
@UserDataSource private val sharedPreferences: SharedPreferences,
) : LocalUserDataSource {
override suspend fun saveAccessToken(accessToken: String) {
sharedPreferences.edit {
Expand Down Expand Up @@ -57,15 +58,4 @@ class LocalUserDataSourceImpl @Inject constructor(
[email protected]()
}
}

override suspend fun saveDeviceToken(deviceToken: String) {
sharedPreferences.edit {
this.putString(ResourceKeys.DEVICE_TOKEN, deviceToken)
}
}

override suspend fun getDeviceToken(): String {
return sharedPreferences.getString(ResourceKeys.DEVICE_TOKEN, "")
?: throw NullPointerException()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import team.retum.jobis.local.datasource.device.LocalDeviceDataSource
import team.retum.jobis.local.datasource.device.LocalDeviceDataSourceImpl
import team.retum.jobis.local.datasource.user.LocalUserDataSource
import team.retum.jobis.local.datasource.user.LocalUserDataSourceImpl
import javax.inject.Singleton
Expand All @@ -14,4 +16,8 @@ abstract class LocalDataSourceModule {
@Binds
@Singleton
abstract fun bindLocalUserDataSource(localUserDataSourceImpl: LocalUserDataSourceImpl): LocalUserDataSource

@Binds
@Singleton
abstract fun bindLocalDeviceDataSource(localDeviceDataSourceImpl: LocalDeviceDataSourceImpl): LocalDeviceDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import team.retum.common.utils.ResourceKeys
import team.retum.jobis.local.DeviceDataSource
import team.retum.jobis.local.UserDataSource
import javax.inject.Singleton

@Module
Expand All @@ -17,9 +19,19 @@ object SharedPreferenceModule {

@Provides
@Singleton
@UserDataSource
fun provideDataStore(
@ApplicationContext context: Context,
): SharedPreferences {
return context.getSharedPreferences(ResourceKeys.SHARED_PREFERENCES_NAME, MODE_PRIVATE)
return context.getSharedPreferences(ResourceKeys.USER_SHARED_PREFERENCES_NAME, MODE_PRIVATE)
}

@Provides
@Singleton
@DeviceDataSource
fun provideDeviceDataStore(
@ApplicationContext context: Context,
): SharedPreferences {
return context.getSharedPreferences(ResourceKeys.DEVICE_SHARED_PREFERENCES_NAME, MODE_PRIVATE)
}
}
4 changes: 0 additions & 4 deletions feature/notification/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,5 @@ android {
}

dependencies {
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics.ktx)
implementation(libs.firebase.messaging)

implementation(libs.kotlinx.collections.immutable)
}
4 changes: 4 additions & 0 deletions feature/signin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ android {
jvmTarget = ProjectProperties.JVM_TARGET
}
}

dependencies {
implementation(project(":core:device"))
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ include(":core:local")
include(":feature:review")
include(":feature:application")
include(":feature:splash")
include(":core:device")