Skip to content

Commit

Permalink
feat: Make title bold when opened from notification
Browse files Browse the repository at this point in the history
  • Loading branch information
kongwoojin committed Mar 29, 2024
1 parent aed05e0 commit 86d4fea
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FCMService : FirebaseMessagingService() {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra("screen", message.data["screen"] ?: "board")
putExtra("department", message.data["department"])
putExtra("openedFromNotification", true)
}

val pendingIntent = PendingIntent.getActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavHostController
Expand Down Expand Up @@ -58,6 +57,11 @@ class MainActivity : ComponentActivity() {
mainViewModel.setDefaultDepartment(Department.valueOf(defaultDepartment))
}

val isOpenedFromNotification = intent.getBooleanExtra("openedFromNotification", false)
if (isOpenedFromNotification) {
mainViewModel.setOpenedFromNotification()
}

setContent {
val isDynamicColor by themeViewModel.isDynamicTheme.observeAsState(true)
val isDarkTheme by themeViewModel.isDarkTheme.observeAsState()
Expand Down Expand Up @@ -159,12 +163,16 @@ fun NavigationGraph(navController: NavHostController, mainViewModel: MainViewMod
val uiState by mainViewModel.uiState.collectAsState()
val defaultScreen = uiState.defaultScreen
val defaultDepartment = uiState.defaultDepartment
val isOpenedFromNotification = uiState.isOpenedFromNotification
NavHost(navController = navController, startDestination = defaultScreen.name) {
composable(BottomNavigationItem.Home.name) {
HomeScreen()
}
composable(BottomNavigationItem.Board.name) {
BoardScreen(defaultDepartment = defaultDepartment)
BoardScreen(
defaultDepartment = defaultDepartment,
isOpenedFromNotification = isOpenedFromNotification
)
}
composable(BottomNavigationItem.Settings.name) {
SettingsScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import com.kongjak.koreatechboard.util.routes.Department
sealed class MainEvent : UiEvent {
data class SetDefaultScreen(val defaultScreen: BottomNavigationItem) : MainEvent()
data class SetDefaultDepartment(val defaultDepartment: Department) : MainEvent()
data object SetOpenedFromNotification : MainEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import com.kongjak.koreatechboard.util.routes.Department

data class MainState(
val defaultScreen: BottomNavigationItem = BottomNavigationItem.Home,
val defaultDepartment: Department? = null
val defaultDepartment: Department? = null,
val isOpenedFromNotification: Boolean = false
) : UiState
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MainViewModel : BaseViewModel<MainState, MainEvent>(MainState()) {
when (event) {
is MainEvent.SetDefaultScreen -> setState(oldState.copy(defaultScreen = event.defaultScreen))
is MainEvent.SetDefaultDepartment -> setState(oldState.copy(defaultDepartment = event.defaultDepartment))
MainEvent.SetOpenedFromNotification -> setState(oldState.copy(isOpenedFromNotification = true))
}
}

Expand All @@ -19,4 +20,8 @@ class MainViewModel : BaseViewModel<MainState, MainEvent>(MainState()) {
fun setDefaultDepartment(defaultDepartment: Department) {
sendEvent(MainEvent.SetDefaultDepartment(defaultDepartment))
}

fun setOpenedFromNotification() {
sendEvent(MainEvent.SetOpenedFromNotification)
}
}
59 changes: 49 additions & 10 deletions app/src/main/java/com/kongjak/koreatechboard/ui/main/board/Board.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,26 @@ import kotlinx.coroutines.launch
@Composable
fun BoardScreen(
boardInitViewModel: BoardInitViewModel = hiltViewModel(),
defaultDepartment: Department? // Default department from MainActivity.
defaultDepartment: Department?, // Default department from MainActivity.
isOpenedFromNotification: Boolean = false
) {
val uiState by boardInitViewModel.uiState.collectAsState()
val initDepartment = uiState.initDepartment
val userDepartment = uiState.userDepartment
BottomSheetScaffold(defaultDepartment ?: fullDeptList[initDepartment], userDepartment)
BottomSheetScaffold(
defaultDepartment ?: fullDeptList[initDepartment],
userDepartment,
isOpenedFromNotification = isOpenedFromNotification
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BottomSheetScaffold(initDepartment: Department = Department.School, userDepartment: Int = 0) {
fun BottomSheetScaffold(
initDepartment: Department = Department.School,
userDepartment: Int = 0,
isOpenedFromNotification: Boolean
) {
val scaffoldState = rememberBottomSheetScaffoldState()
val scope = rememberCoroutineScope()

Expand Down Expand Up @@ -130,14 +139,22 @@ fun BottomSheetScaffold(initDepartment: Department = Department.School, userDepa
}
}
) { innerPadding ->
Board(contentPadding = innerPadding, department = department.value)
Board(
contentPadding = innerPadding,
department = department.value,
isOpenedFromNotification
)
}
}


@OptIn(ExperimentalFoundationApi::class)
@Composable
fun Board(contentPadding: PaddingValues, department: Department) {
fun Board(
contentPadding: PaddingValues,
department: Department,
isOpenedFromNotification: Boolean
) {
val pagerState = rememberPagerState(
initialPage = 0
) {
Expand Down Expand Up @@ -176,7 +193,11 @@ fun Board(contentPadding: PaddingValues, department: Department) {
state = pagerState,
verticalAlignment = Alignment.Top
) { page ->
BoardContent(department = department, page = page)
BoardContent(
department = department,
page = page,
isOpenedFromNotification = isOpenedFromNotification
)
}
}
}
Expand All @@ -186,6 +207,7 @@ fun Board(contentPadding: PaddingValues, department: Department) {
fun BoardContent(
department: Department,
page: Int,
isOpenedFromNotification: Boolean,
networkViewModel: NetworkViewModel = hiltViewModel()
) {
val boardViewModel =
Expand Down Expand Up @@ -282,7 +304,9 @@ fun BoardContent(
),
title = it.title,
writer = it.writer,
date = it.writeDate
isNew = it.isNew,
date = it.writeDate,
isOpenedFromNotification = isOpenedFromNotification
)
HorizontalDivider(thickness = 0.5.dp, color = Gray)
}
Expand Down Expand Up @@ -316,7 +340,10 @@ fun BoardContent(
modifier = Modifier.align(Alignment.TopCenter),
state = pullToRefreshState,
indicator = { pullRefreshState ->
PullToRefreshDefaults.Indicator(state = pullRefreshState, color = MaterialTheme.colorScheme.primary)
PullToRefreshDefaults.Indicator(
state = pullRefreshState,
color = MaterialTheme.colorScheme.primary
)
}
)
}
Expand All @@ -325,7 +352,16 @@ fun BoardContent(
}

@Composable
fun BoardItem(modifier: Modifier, title: String, writer: String, date: String) {
fun BoardItem(
modifier: Modifier,
title: String,
writer: String,
date: String,
isNew: Boolean,
isOpenedFromNotification: Boolean = false
) {
val shouldSetBold = isOpenedFromNotification && isNew

Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically
Expand All @@ -337,7 +373,10 @@ fun BoardItem(modifier: Modifier, title: String, writer: String, date: String) {
modifier = Modifier
.fillMaxWidth()
.weight(1f),
style = MaterialTheme.typography.boardItemTitle
style = if (shouldSetBold)
MaterialTheme.typography.boardItemTitle.copy(fontWeight = FontWeight.Bold)
else
MaterialTheme.typography.boardItemTitle
)
Column(
modifier = Modifier.padding(start = 8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ fun SearchContent(
),
title = it.title,
writer = it.writer,
isNew = it.isNew,
date = it.writeDate
)
HorizontalDivider(thickness = 0.5.dp, color = Color.Gray)
Expand Down

0 comments on commit 86d4fea

Please sign in to comment.