Skip to content

Commit

Permalink
Merge pull request #10 from KNUTICE/development
Browse files Browse the repository at this point in the history
[PR] Add Action for Back Button/Gesture.
  • Loading branch information
doyoonkim3312 authored Oct 27, 2024
2 parents e0086a9 + c77b599 commit 25b55c8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.drawable.Icon
import android.os.Build
import android.util.Log
import androidx.core.app.ActivityCompat
Expand Down Expand Up @@ -54,8 +56,8 @@ class PushNotificationHandler @Inject constructor() : FirebaseMessagingService()
val notificationBuilder = NotificationCompat.Builder(
applicationContext, getString(R.string.inapp_notification_channel_id)
)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("New Notice!")
.setLargeIcon(Icon.createWithResource(applicationContext, R.mipmap.ic_launcher))
.setContentTitle(getString(R.string.new_notice))
.setContentText(this@toPushNotification.notification?.body ?: "No message body")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,36 @@ fun MainNavigator(
viewModel.updateState(
updatedCurrentLocation = Destination.MORE_GENERAL
)
MoreCategorizedNotification(category = NoticeCategory.GENERAL_NEWS)
MoreCategorizedNotification(category = NoticeCategory.GENERAL_NEWS) {
navController.popBackStack()
}
}

composable(Destination.MORE_ACADEMIC.name) {
viewModel.updateState(
updatedCurrentLocation = Destination.MORE_ACADEMIC
)
MoreCategorizedNotification(category = NoticeCategory.ACADEMIC_NEWS)
MoreCategorizedNotification(category = NoticeCategory.ACADEMIC_NEWS) {
navController.popBackStack()
}
}

composable(Destination.MORE_SCHOLARSHIP.name) {
viewModel.updateState(
updatedCurrentLocation = Destination.MORE_SCHOLARSHIP
)
MoreCategorizedNotification(category = NoticeCategory.SCHOLARSHIP_NEWS)
MoreCategorizedNotification(category = NoticeCategory.SCHOLARSHIP_NEWS) {
navController.popBackStack()
}
}

composable(Destination.MORE_EVENT.name) {
viewModel.updateState(
updatedCurrentLocation = Destination.MORE_EVENT
)
MoreCategorizedNotification(category = NoticeCategory.EVENT_NEWS)
MoreCategorizedNotification(category = NoticeCategory.EVENT_NEWS) {
navController.popBackStack()
}
}

composable(Destination.SETTINGS.name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.doyoonkim.knutice.presentation

import android.content.res.Configuration
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -14,6 +15,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -46,6 +48,12 @@ fun CategorizedNotification(
) {
val uiState by viewModel.uiState.collectAsState()

// Back button/gesture actions
BackHandler {
if (uiState.isDetailedViewOpened) viewModel.updateState(updatedIsDetailedViewOpened = false)
else navController.popBackStack()
}

Column(
modifier = modifier.verticalScroll(
rememberScrollState(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.IconButton
Expand Down Expand Up @@ -89,13 +91,19 @@ fun DetailedNoticeContent(
fontWeight = FontWeight.Normal
)

Text(
Surface(
modifier = Modifier.fillMaxWidth()
.weight(8f),
text = requested.fullContent,
fontSize = 18.sp,
fontWeight = FontWeight.Medium,
)
.weight(8f)
.verticalScroll(rememberScrollState()),
color = MaterialTheme.colorScheme.containerBackground
) {
Text(
modifier = Modifier.fillMaxWidth(),
text = requested.fullContent,
fontSize = 18.sp,
fontWeight = FontWeight.Medium,
)
}

Button(
onClick = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.doyoonkim.knutice.presentation

import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -38,7 +39,8 @@ import com.doyoonkim.knutice.viewModel.MoreCategorizedNotificationViewModel
fun MoreCategorizedNotification(
modifier: Modifier = Modifier,
viewModel: MoreCategorizedNotificationViewModel = hiltViewModel(),
category: NoticeCategory
category: NoticeCategory,
backButtonHandler: () -> Unit = { }
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

Expand All @@ -49,6 +51,11 @@ fun MoreCategorizedNotification(
}
)

BackHandler {
if (uiState.isDetailedContentVisible) viewModel.updatedDetailedContentRequest(false)
else backButtonHandler()
}

Box(
modifier = modifier.fillMaxWidth()
.pullRefresh(pullRefreshState)
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-ko-rKR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<string name="about_title">๋”๋ณด๊ธฐ</string>
<string name="about_version">๋ฒ„์ „์ •๋ณด</string>
<string name="about_oss">์˜คํ”ˆ์†Œ์Šค ๋ผ์ด์„ผ์Šค</string>
<string name="version_code">1.0.0 ์•ŒํŒŒ (๋‚ด๋ถ€ํ…Œ์ŠคํŠธ์šฉ)</string>
<string name="version_code">1.0.1 ์•ŒํŒŒ (๋‚ด๋ถ€ํ…Œ์ŠคํŠธ์šฉ)</string>
<string name="pref_notification_title">์•Œ๋ฆผ</string>
<string name="title_preference">์„ค์ •</string>
<string name="new_notice">์ƒˆ๋กœ์šด ์•Œ๋ฆผ์ด ๋„์ฐฉํ–ˆ์–ด์š”!</string>
<string name="inapp_notificaiton_channel_name">์‹ ๊ทœ ๊ณต์ง€ ์•Œ๋ฆผ</string>
</resources>
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
<string name="about_title">About</string>
<string name="about_version">Version</string>
<string name="about_oss">Open Source License</string>
<string name="version_code">1.0.0 Alpha</string>
<string name="version_code">1.0.1 Alpha</string>
<string name="pref_notification_title">Notification</string>
<string name="title_preference">Preference</string>
<string name="new_notice">New Notice has been delivered!</string>
<string name="default_notification_channel_id" translatable="false">knutice_default_fcm_channel</string>
<string name="default_notification_channel_description" translatable="false">knutice default notification channel for FCM</string>
<string name="inapp_notification_channel_id" translatable="false">knutice_inapp_notification_channel</string>
<string name="inapp_notification_channel_description" translatable="false">knutice inapp notification channel</string>
<string name="inapp_notificaiton_channel_name" translatable="false">knutice inapp notification Channel</string>
<string name="inapp_notificaiton_channel_name">KNUTICE In-app Notice</string>
</resources>

0 comments on commit 25b55c8

Please sign in to comment.