Skip to content

Commit

Permalink
Publish 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
limsaehyun authored Jan 9, 2023
2 parents 599ff0d + 8b1b748 commit 48293d5
Show file tree
Hide file tree
Showing 41 changed files with 1,389 additions and 125 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ dependencies {

implementation(Dependency.Hilt.HILT_ANDROID)
kapt(Dependency.Hilt.HILT_ANDROID_COMPILER)
implementation(Dependency.Compose.COMPOSE_HILT_NAV)

implementation(platform(Dependency.FIREBASE.FIREBASE_BOM))
implementation(Dependency.FIREBASE.FIREBASE_MESSAGING)
implementation(Dependency.FIREBASE.FIREBASE_CRASHLYTICS)
implementation(Dependency.FIREBASE.FIREBASE_ANALYTICS)

Expand Down
13 changes: 11 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
<service
android:name=".firebase.FCMManager"
android:enabled="true"
android:exported="true"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
71 changes: 71 additions & 0 deletions app/src/main/java/com/comit/simtong/firebase/FCMManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@file:Suppress(
"MissingFirebaseInstanceTokenRefresh",
"MagicNumber",
)

package com.comit.simtong.firebase

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.os.Build
import androidx.core.app.NotificationCompat
import com.comit.simtong.R
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

class FCMManager : FirebaseMessagingService() {

private companion object Channel {
const val CHANNEL_ID = "simtong_fcm"
const val CHANNEL_NAME = "SimTong"
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
if (remoteMessage.data.isNotEmpty()) {
sendNotification(remoteMessage)
}
}

private fun sendNotification(remoteMessage: RemoteMessage) {
val title = remoteMessage.data["title"]
val message = remoteMessage.data["message"]

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val channelMessage = NotificationChannel(
CHANNEL_ID, CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT
)

channelMessage.apply {
enableLights(true)
enableVibration(true)
setShowBadge(false)
vibrationPattern = longArrayOf(100, 200, 100, 200)
}
notificationChannel.createNotificationChannel(channelMessage)

val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(title)
.setContentText(message)
.setChannelId(CHANNEL_ID)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND or Notification.DEFAULT_VIBRATE)
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager

notificationManager.notify(9999, notificationBuilder.build())
} else {
val notificationBuilder = NotificationCompat.Builder(this, "")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND or Notification.DEFAULT_VIBRATE)
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(9999, notificationBuilder.build())
}
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/comit/simtong/firebase/firebase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.comit.simtong.firebase

import com.comit.domain.exception.UnknownException
import com.google.firebase.messaging.FirebaseMessaging

/**
* FCM 에서 사용되는 DeviceToken 을 불러오는 함수
*
* @return 디바이스 토큰
* @throws UnknownException DeviceToken 을 불러오지 못한 경우 발생
*/
internal fun getDeviceToken(): String =
FirebaseMessaging.getInstance().token.result
?: throw UnknownException("디바이스 토큰 발급에 실패했습니다.\n잠시 후 다시 시도해주세요.")
8 changes: 8 additions & 0 deletions app/src/main/java/com/comit/simtong/root/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.graphics.toArgb
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import com.comit.common.systemBarPadding
Expand All @@ -32,6 +33,7 @@ class MainActivity : ComponentActivity() {

setContent {
setWindowInset()
saveDeviceToken(hiltViewModel())

val navController = rememberNavController()

Expand Down Expand Up @@ -85,4 +87,10 @@ class MainActivity : ComponentActivity() {
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
}

private fun saveDeviceToken(
vm: MainViewModel,
) {
vm.saveDeviceToken()
}
}
33 changes: 33 additions & 0 deletions app/src/main/java/com/comit/simtong/root/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.comit.simtong.root

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.comit.domain.usecase.users.SaveDeviceTokenUseCase
import com.google.firebase.messaging.FirebaseMessaging
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
* TODO(limsaehyun)
*
* Device 토큰을 google-service 가 위치한 app 에서 추출하여 저장하기 위해
* MainViewModel 이 존재함
* app 모듈에 viewModel 이 존재해도 될까? app 모듈의 범위에 대해서 고민한 필요가 있음
*/
@HiltViewModel
class MainViewModel @Inject constructor(
private val saveDeviceTokenUseCase: SaveDeviceTokenUseCase,
) : ViewModel() {

fun saveDeviceToken() {
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
val token = task.result
viewModelScope.launch {
saveDeviceTokenUseCase(
token = token
)
}
}
}
}
2 changes: 2 additions & 0 deletions buildSrc/src/main/java/Dependency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ object Dependency {
}

object FIREBASE {
const val FIREBASE_BOM = "com.google.firebase:firebase-bom:${Versions.FIREBASE_BOM}"
const val FIREBASE_CRASHLYTICS = "com.google.firebase:firebase-crashlytics-ktx:${Versions.FIREBASE_CRASHLYTICS}"
const val FIREBASE_ANALYTICS = "com.google.firebase:firebase-analytics-ktx:${Versions.FIREBASE_ANALYTICS}"
const val FIREBASE_MESSAGING = "com.google.firebase:firebase-messaging-ktx"
}

object Kotlin {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/ProjectProperties.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import org.gradle.api.JavaVersion

object ProjectProperties{
const val VERSION_CODE = 6
const val VERSION_NAME = "1.0.3"
const val VERSION_CODE = 7
const val VERSION_NAME = "1.0.4"

const val APPLICATION_ID = "com.comit.simtong"

Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ object Versions {
const val GRADLE_FIREBASE_CRASHLYTICS = "2.9.2"
const val FIREBASE_CRASHLYTICS = "18.3.2"
const val FIREBASE_ANALYTICS = "21.2.0"
const val FIREBASE_BOM = "31.1.1"

const val KT_LINT = "10.2.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ class SimTongIcon private constructor(
@Stable
val Logo = SimTongIcon(
drawableId = R.drawable.ic_logo,
contentDescription = "logo icon"
contentDescription = "logo icon",
)

@Stable
val Profile_Big = SimTongIcon(
drawableId = R.drawable.ic_profile_big,
contentDescription = "profile big"
contentDescription = "profile big",
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions core-design-system/src/main/res/drawable/ic_logo.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ interface LocalAuthDataSource {
suspend fun saveAccessToken(token: String)
suspend fun saveRefreshToken(token: String)
suspend fun saveExpiredAt(expiredAt: LocalDateTime)

suspend fun saveToken(token: Token)

suspend fun clearToken()

suspend fun fetchDeviceToken(): Flow<String>
suspend fun saveDeviceToken(token: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface RemoteAuthDataSource {
suspend fun signIn(
employeeNumber: Int,
password: String,
deviceToken: String,
): Token

suspend fun verificationEmployee(
Expand All @@ -23,6 +24,7 @@ interface RemoteAuthDataSource {
password: String,
nickname: String?,
profileImagePath: String?,
deviceToken: String,
): Token

suspend fun checkNicknameDuplication(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("TooManyFunctions")

package com.comit.data.repository

import com.comit.data.datasource.LocalAuthDataSource
Expand All @@ -6,6 +8,7 @@ import com.comit.data.datasource.RemoteFileDataSource
import com.comit.data.util.FormDataUtil
import com.comit.domain.repository.AuthRepository
import com.comit.model.User
import kotlinx.coroutines.flow.first
import java.io.File
import java.util.UUID
import javax.inject.Inject
Expand All @@ -23,6 +26,7 @@ class AuthRepositoryImpl @Inject constructor(
remoteAuthDataSource.signIn(
employeeNumber = employeeNumber,
password = password,
deviceToken = getDeviceToken(),
).also {
localAuthDataSource.saveToken(it)
}
Expand All @@ -44,7 +48,7 @@ class AuthRepositoryImpl @Inject constructor(
email: String,
password: String,
nickname: String?,
profileImage: File?
profileImage: File?,
) {
val profileImagePath = profileImage?.let {
getImagePathByFile(
Expand All @@ -59,6 +63,7 @@ class AuthRepositoryImpl @Inject constructor(
password = password,
nickname = nickname,
profileImagePath = profileImagePath,
deviceToken = getDeviceToken(),
).also {
localAuthDataSource.saveToken(it)
}
Expand Down Expand Up @@ -108,6 +113,20 @@ class AuthRepositoryImpl @Inject constructor(
return remoteAuthDataSource.fetchUserInformation()
}

override suspend fun saveDeviceToken(token: String) {
localAuthDataSource.saveDeviceToken(
token = token,
)
}

override suspend fun clearToken() {
localAuthDataSource.clearToken()
}

private suspend fun getDeviceToken(): String {
return localAuthDataSource.fetchDeviceToken().first()
}

private suspend fun getImagePathByFile(
file: File,
): String {
Expand Down
2 changes: 2 additions & 0 deletions detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ complexity:
ignoreAnnotated: [ 'Composable' ]
LongParameterList:
active: false
TooManyFunctions:
active: false

performance:
SpreadOperator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ interface AuthRepository {
)

suspend fun fetchUserInformation(): User

suspend fun saveDeviceToken(token: String)

suspend fun clearToken()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.comit.domain.usecase.users

import com.comit.domain.repository.AuthRepository
import javax.inject.Inject

class ClearTokenUseCase @Inject constructor(
private val authRepository: AuthRepository,
) {

suspend operator fun invoke() = kotlin.runCatching {
authRepository.clearToken()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.comit.domain.usecase.users

import com.comit.domain.repository.AuthRepository
import javax.inject.Inject

class SaveDeviceTokenUseCase @Inject constructor(
private val repository: AuthRepository,
) {

suspend operator fun invoke(token: String) = kotlin.runCatching {
repository.saveDeviceToken(
token = token,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -248,6 +249,9 @@ private fun HomeBottomIconLayout(
color = SimTongColor.White,
shape = RoundedCornerShape(16.dp),
)
.clip(
shape = RoundedCornerShape(16.dp)
)
.simClickable {
onClick()
}
Expand Down
Loading

0 comments on commit 48293d5

Please sign in to comment.