Skip to content

Commit

Permalink
[Feature/#918] fortune 추가 구현 (#924)
Browse files Browse the repository at this point in the history
* feature #918: change home button writing

* feature #918: change navigation logic

* feature #918: change navigation logic

* feature #918: add snackBar at enter before date fortune

* feature #918: apply baselineProfile

* feature #918: apply spotlessApply

* feature #918: separate function

* feature #918: add parameter name

* feature #918: wrapping validation function
  • Loading branch information
chattymin authored Oct 20, 2024
1 parent 8bc969a commit ec385e1
Show file tree
Hide file tree
Showing 8 changed files with 5,676 additions and 142 deletions.
2,694 changes: 2,685 additions & 9 deletions app/src/release/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

2,694 changes: 2,685 additions & 9 deletions app/src/release/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enum class DeepLinkType(
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String) =
userStatus.setIntent(navigator.getPokeNotificationActivityIntent(userStatus.name))
},
FORTUNE("home/fortune") {
FORTUNE(HOME_FORTUNE) {
override fun getIntent(context: Context, userStatus: UserStatus, deepLink: String) =
userStatus.setIntent(navigator.getFortuneActivityIntent())
},
Expand Down Expand Up @@ -115,3 +115,5 @@ enum class DeepLinkType(
}
}
}

const val HOME_FORTUNE = "home/fortune"
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class FortuneActivity : AppCompatActivity() {
SoptTheme {
CompositionLocalProvider(LocalAmplitudeTracker provides amplitudeTracker) {
FoundationScreen(
onClickLeadingIcon = {
startActivity(navigator.getNotificationActivityIntent())
},
onClickLeadingIcon = ::finish,
navigateToHome = {
startActivity(navigator.getAuthActivityIntent())
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private fun HomeScreen(
Spacer(modifier = Modifier.weight(1f))

FortuneButton(
title = "오늘의 운세 보러 가기",
title = "오늘의 운세 확인하기",
onClick = onFortuneDetailClick,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -49,151 +50,201 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.EntryPointAccessors
import kotlinx.coroutines.launch
import org.sopt.official.common.context.appContext
import org.sopt.official.common.navigator.HOME_FORTUNE
import org.sopt.official.common.navigator.NavigatorEntryPoint
import org.sopt.official.designsystem.SoptTheme
import org.sopt.official.feature.notification.detail.component.ErrorSnackBar
import java.time.LocalDate

private val navigator by lazy {
EntryPointAccessors.fromApplication(
appContext,
NavigatorEntryPoint::class.java
).navigatorProvider()
EntryPointAccessors.fromApplication(
appContext,
NavigatorEntryPoint::class.java
).navigatorProvider()
}

@AndroidEntryPoint
class NotificationDetailActivity : AppCompatActivity() {
private val viewModel by viewModels<NotificationDetailViewModel>()
private val viewModel by viewModels<NotificationDetailViewModel>()

@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val notification by viewModel.notificationDetail.collectAsStateWithLifecycle()
val context = LocalContext.current
SoptTheme {
Scaffold(modifier = Modifier
.fillMaxSize()
.background(SoptTheme.colors.background),
containerColor = SoptTheme.colors.background,
topBar = {
CenterAlignedTopAppBar(
title = {
Text(
text = "알림",
style = SoptTheme.typography.body16M
)
},
navigationIcon = {
IconButton(onClick = { onBackPressedDispatcher.onBackPressed() }) {
Icon(
Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null,
tint = SoptTheme.colors.onBackground
)
}
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = SoptTheme.colors.background,
titleContentColor = SoptTheme.colors.onBackground,
navigationIconContentColor = SoptTheme.colors.onBackground
)
)
}) { innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.background(SoptTheme.colors.background)
.padding(innerPadding)
.padding(top = 20.dp)
.padding(horizontal = 20.dp),
verticalArrangement = Arrangement.SpaceBetween
) {
Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.background(SoptTheme.colors.onSurface800)
.padding(
vertical = 24.dp,
horizontal = 12.dp
)
) {
Text(
notification?.title.orEmpty(),
style = SoptTheme.typography.heading18B,
color = SoptTheme.colors.onSurface10
)
Spacer(modifier = Modifier.padding(14.dp))
HorizontalDivider(color = SoptTheme.colors.onSurface400)
Text(
notification?.content.orEmpty(),
style = SoptTheme.typography.body16M,
color = SoptTheme.colors.onSurface10,
modifier = Modifier.padding(top = 24.dp)
)
}
if (!notification?.deepLink.isNullOrBlank() || !notification?.webLink.isNullOrBlank()) {
Column {
Button(
onClick = {
context.startActivity(
navigator.getSchemeActivityIntent(
notificationId = notification?.notificationId.orEmpty(),
link = notification?.webLink ?: notification?.deepLink ?: ""
)
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val notification by viewModel.notificationDetail.collectAsStateWithLifecycle()
val context = LocalContext.current

val snackBarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
val onShowErrorSnackBar: (String?) -> Unit = { text ->
coroutineScope.launch {
snackBarHostState.currentSnackbarData?.dismiss()

snackBarHostState.showSnackbar(
message = text ?: "오류가 발생했어요. 다시 시도해주세요.",
)
},
colors = ButtonDefaults.buttonColors(
containerColor = SoptTheme.colors.primary,
contentColor = SoptTheme.colors.onPrimary
),
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
shape = RoundedCornerShape(10.dp)
) {
Text(
text = "바로가기 >",
style = SoptTheme.typography.body16M
)
}
Spacer(modifier = Modifier.height(14.dp))
}
}

SoptTheme {
Scaffold(
modifier = Modifier
.fillMaxSize()
.background(SoptTheme.colors.background),
containerColor = SoptTheme.colors.background,
) { innerPadding ->
Box {
Column(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
) {
CenterAlignedTopAppBar(
title = {
Text(
text = "알림",
style = SoptTheme.typography.body16M
)
},
navigationIcon = {
IconButton(onClick = { onBackPressedDispatcher.onBackPressed() }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null,
tint = SoptTheme.colors.onBackground
)
}
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = SoptTheme.colors.background,
titleContentColor = SoptTheme.colors.onBackground,
navigationIconContentColor = SoptTheme.colors.onBackground
)
)
Column(
modifier = Modifier
.fillMaxSize()
.background(SoptTheme.colors.background)
.padding(top = 20.dp)
.padding(horizontal = 20.dp),
verticalArrangement = Arrangement.SpaceBetween
) {
Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.background(SoptTheme.colors.onSurface800)
.padding(
vertical = 24.dp,
horizontal = 12.dp
)
) {
Text(
text = notification?.title.orEmpty(),
style = SoptTheme.typography.heading18B,
color = SoptTheme.colors.onSurface10
)
Spacer(modifier = Modifier.padding(14.dp))
HorizontalDivider(color = SoptTheme.colors.onSurface400)
Text(
text = notification?.content.orEmpty(),
style = SoptTheme.typography.body16M,
color = SoptTheme.colors.onSurface10,
modifier = Modifier.padding(top = 24.dp)
)
}
if (isValidLinks(deepLink = notification?.deepLink, webLink = notification?.webLink)) {
Column {
Button(
onClick = {
val link = notification?.webLink ?: notification?.deepLink

when {
link == HOME_FORTUNE && !isToday(notification?.createdAt?.split("T")?.get(0)) -> {
onShowErrorSnackBar("앗, 오늘의 솝마디만 볼 수 있어요.")
}

else -> {
context.startActivity(
navigator.getSchemeActivityIntent(
notificationId = notification?.notificationId.orEmpty(),
link = link.orEmpty()
)
)
}
}
},
colors = ButtonDefaults.buttonColors(
containerColor = SoptTheme.colors.primary,
contentColor = SoptTheme.colors.onPrimary
),
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
shape = RoundedCornerShape(10.dp)
) {
Text(
text = "바로가기 >",
style = SoptTheme.typography.body16M
)
}
Spacer(modifier = Modifier.height(14.dp))
}
}
}
}

SnackbarHost(
hostState = snackBarHostState,
modifier = Modifier
.padding(top = 16.dp)
) {
ErrorSnackBar(message = it.visuals.message)
}
}
}
}
}
}
}
}
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val notificationId = intent.getStringExtra("notificationId").orEmpty()
viewModel.getNotificationDetail(notificationId)
}
private fun isValidLinks(deepLink: String?, webLink: String?): Boolean =
!deepLink.isNullOrBlank() || !webLink.isNullOrBlank()

private fun isToday(date: String?): Boolean = LocalDate.now().toString() == date

companion object {
@JvmStatic
fun getIntent(
context: Context,
notificationId: String
) = Intent(
context,
NotificationDetailActivity::class.java
).putExtra(
"notificationId",
notificationId
)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val notificationId = intent.getStringExtra("notificationId").orEmpty()
viewModel.getNotificationDetail(notificationId)
}

companion object {
@JvmStatic
fun getIntent(
context: Context,
notificationId: String,
) = Intent(
context,
NotificationDetailActivity::class.java
).putExtra(
"notificationId",
notificationId
)
}
}
Loading

0 comments on commit ec385e1

Please sign in to comment.