Skip to content

Commit

Permalink
Release v1.3.8
Browse files Browse the repository at this point in the history
Release v1.3.8
  • Loading branch information
parkuiery authored Aug 13, 2024
2 parents 41d2ad1 + 721d32d commit 9af0beb
Show file tree
Hide file tree
Showing 115 changed files with 2,385 additions and 342 deletions.
18 changes: 16 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.googleServices)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
alias(libs.plugins.firebase.crashlytics)
}

android {
Expand All @@ -17,8 +18,8 @@ android {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()

versionCode = 16
versionName = "1.3.7"
versionCode = 17
versionName = "1.3.8"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -66,6 +67,9 @@ dependencies {
implementation(project(ProjectPaths.Core.PROJECT))
implementation(project(ProjectPaths.Core.SCHOOL))
implementation(project(ProjectPaths.Core.UI))
implementation(project(ProjectPaths.Core.NOTIFICATION))
implementation(project(ProjectPaths.Core.DEVICE))
implementation(project(ProjectPaths.Core.WIDGET))

implementation(project(ProjectPaths.DATA))
implementation(project(ProjectPaths.DATABASE))
Expand Down Expand Up @@ -123,4 +127,14 @@ dependencies {
androidTestImplementation(libs.androidx.junit)

implementation(libs.app.update)

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.messaging)
implementation(libs.firebase.analytics)
implementation(libs.firebase.crashlytics)

implementation(libs.androidx.work.runtime.ktx)

implementation(libs.androidx.hilt.work)
ksp(libs.androidx.hilt.compiler)
}
36 changes: 36 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,41 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.DmsMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="om.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_logo_image"/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />

<receiver
android:name="team.aliens.dms.android.core.widget.meal.MealWidgetReceiver"
android:label="@string/today_meal"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/big_meal_widget_provider"/>
</receiver>

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>

</application>
</manifest>
14 changes: 13 additions & 1 deletion app/src/main/java/team/aliens/dms/android/app/DmsApplication.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package team.aliens.dms.android.app

import android.app.Application
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject

@HiltAndroidApp
class DmsApplication : Application()
class DmsApplication : Application(), Configuration.Provider {

@Inject
lateinit var workFactory: HiltWorkerFactory

override val workManagerConfiguration: Configuration
get() = Configuration.Builder()
.setWorkerFactory(workFactory)
.build()
}
12 changes: 12 additions & 0 deletions app/src/main/java/team/aliens/dms/android/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import androidx.activity.compose.setContent
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
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.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import team.aliens.dms.android.core.designsystem.DmsTheme
import team.aliens.dms.android.core.jwt.di.IsJwtAvailable
import team.aliens.dms.android.core.notification.DeviceTokenManager
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -24,6 +29,9 @@ class MainActivity : ComponentActivity() {
@Inject
lateinit var isJwtAvailable: StateFlow<Boolean>

@Inject
lateinit var deviceTokenManager: DeviceTokenManager

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -46,6 +54,10 @@ class MainActivity : ComponentActivity() {
)
}
}

lifecycleScope.launch {
deviceTokenManager.fetchDeviceToken()
}
}

private fun checkAppUpdate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package team.aliens.dms.android.app

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 android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import team.aliens.dms.android.core.designsystem.DmsIcon
import team.aliens.dms.android.core.notification.notificationPermissionGranted

private object Notifications {
const val NOTIFICATION_ID = 0
const val NOTIFICATION_CHANNEL_ID = "dms"
const val CHANNEL_NAME = "dms"
const val CHANNEL_DESCRIPTION = "dms notification channel"
}

class NotificationManager(
private val context: Context,
) {

init {
createNotificationChannel()
}

private val notificationManagerCompat: NotificationManagerCompat by lazy {
NotificationManagerCompat.from(context)
}

private val messageId = System.currentTimeMillis().toInt()
private val intent = Intent(context, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
private val pendingIntent = PendingIntent.getActivity(
context, messageId, intent, PendingIntent.FLAG_IMMUTABLE
)

private val notificationBuilder: NotificationCompat.Builder by lazy {
NotificationCompat.Builder(context, Notifications.NOTIFICATION_CHANNEL_ID)
.setSmallIcon(DmsIcon.Notification)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
}

fun setNotificationContent(
title: String?,
body: String?,
) {
notificationBuilder.run {
title?.run { setContentTitle(this) }
body?.run { setContentText(this) }
}
}

@SuppressLint("MissingPermission")
fun sendNotification() {
if (notificationPermissionGranted(context = context)) {
notificationManagerCompat.notify(
Notifications.NOTIFICATION_ID,
notificationBuilder.build(),
)
}
}

private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(
Notifications.NOTIFICATION_CHANNEL_ID,
Notifications.CHANNEL_NAME,
importance
).apply {
this.description = Notifications.CHANNEL_DESCRIPTION
}
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import team.aliens.dms.android.feature.destinations.FindIdScreenDestination
import team.aliens.dms.android.feature.destinations.MainDestination
import team.aliens.dms.android.feature.destinations.NoticeDetailsScreenDestination
import team.aliens.dms.android.feature.destinations.NotificationBoxScreenDestination
import team.aliens.dms.android.feature.destinations.NotificationSettingsScreenDestination
import team.aliens.dms.android.feature.destinations.OutingApplicationScreenDestination
import team.aliens.dms.android.feature.destinations.PointHistoryScreenDestination
import team.aliens.dms.android.feature.destinations.RemainsApplicationScreenDestination
Expand All @@ -36,6 +37,7 @@ import team.aliens.dms.android.feature.destinations.StudyRoomDetailsScreenDestin
import team.aliens.dms.android.feature.destinations.StudyRoomListScreenDestination
import team.aliens.dms.android.feature.destinations.TermsScreenDestination
import team.aliens.dms.android.feature.editpassword.navigation.EditPasswordNavGraph
import team.aliens.dms.android.feature.notification.navigation.NotificationSettingsNavigator
import team.aliens.dms.android.feature.outing.navigation.OutingNavGraph
import team.aliens.dms.android.feature.resetpassword.navigation.ResetPasswordNavGraph
import team.aliens.dms.android.feature.signup.navigation.SignUpNavGraph
Expand All @@ -46,10 +48,6 @@ class DmsNavigator(
private val navController: NavController,
) : AuthorizedNavigator, UnauthorizedNavigator {

override fun openNotificationBox() {
navController.navigateSingleTop(NotificationBoxScreenDestination within navGraph)
}

override fun openUnauthorizedNav() {
navController.navigateSingleTop(UnauthorizedNavGraph) {
popUpTo(AuthorizedNavGraph) {
Expand All @@ -58,6 +56,14 @@ class DmsNavigator(
}
}

override fun openSettingsNotification() {
navController.navigateSingleTop(NotificationSettingsScreenDestination within navGraph)
}

override fun openNotificationBox() {
navController.navigateSingleTop(NotificationBoxScreenDestination within navGraph)
}

override fun openStudyRoomList() {
navController.navigateSingleTop(StudyRoomListScreenDestination within navGraph)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import team.aliens.dms.android.feature.destinations.EditProfileImageScreenDestin
import team.aliens.dms.android.feature.destinations.MainDestination
import team.aliens.dms.android.feature.destinations.NoticeDetailsScreenDestination
import team.aliens.dms.android.feature.destinations.NotificationBoxScreenDestination
import team.aliens.dms.android.feature.destinations.NotificationSettingsScreenDestination
import team.aliens.dms.android.feature.destinations.PointHistoryScreenDestination
import team.aliens.dms.android.feature.destinations.RemainsApplicationScreenDestination
import team.aliens.dms.android.feature.destinations.StudyRoomDetailsScreenDestination
Expand Down Expand Up @@ -37,6 +38,7 @@ object AuthorizedNavGraph : NavGraphSpec {
StudyRoomDetailsScreenDestination,
NoticeDetailsScreenDestination,
NotificationBoxScreenDestination,
NotificationSettingsScreenDestination,
PointHistoryScreenDestination,
)
.routedIn(navGraphSpec = this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import team.aliens.dms.android.feature.editpassword.navigation.EditPasswordNavig
import team.aliens.dms.android.feature.editprofile.navigation.EditProfileNavigator
import team.aliens.dms.android.feature.main.navigation.MainNavigator
import team.aliens.dms.android.feature.notice.navigation.NoticeNavigator
import team.aliens.dms.android.feature.notification.navigation.NotificationNavigation
import team.aliens.dms.android.feature.notification.navigation.NotificationBoxNavigator
import team.aliens.dms.android.feature.notification.navigation.NotificationSettingsNavigator
import team.aliens.dms.android.feature.outing.navigation.OutingNavigator
import team.aliens.dms.android.feature.point.navigation.PointHistoryNavigator
import team.aliens.dms.android.feature.remains.navigator.RemainsNavigator
Expand All @@ -15,7 +16,8 @@ interface AuthorizedNavigator :
EditPasswordNavigator,
EditProfileNavigator,
NoticeNavigator,
NotificationNavigation,
NotificationBoxNavigator,
NotificationSettingsNavigator,
PointHistoryNavigator,
RemainsNavigator,
StudyRoomNavigator,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package team.aliens.dms.android.app.service

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.app.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()
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
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>
12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// TODO: Remove once KTIJ-19369 is fixed
@file:Suppress("DSL_SCOPE_VIOLATION")

buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath(libs.google.services)
}
}

plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
Expand All @@ -9,4 +20,5 @@ plugins {
alias(libs.plugins.googleServices) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.jetbrainsKotlinJvm) apply false
alias(libs.plugins.firebase.crashlytics) apply false
}
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/ProjectPaths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ object ProjectPaths {
const val SCHOOL = ":core:school"
const val UI = ":core:ui"
const val FILE = ":core:file"
const val NOTIFICATION = ":core:notification"
const val DEVICE = ":core:device"
const val WIDGET = ":core:widget"
}

object Shared {
Expand Down
Loading

0 comments on commit 9af0beb

Please sign in to comment.