Skip to content

Commit

Permalink
Merge pull request #168 from WithPeace/feat/#161-찜하기_기능_구현
Browse files Browse the repository at this point in the history
Feat/#161 찜하기 기능 구현
  • Loading branch information
rhkrwngud445 authored Aug 5, 2024
2 parents f00d179 + badfbd9 commit ffb9fd6
Show file tree
Hide file tree
Showing 63 changed files with 1,276 additions and 107 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Gradle files
.gradle/
build/
.kotlin/

# Local configuration file (sdk path, etc)
local.properties
Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
applicationId = "com.withpeace.withpeace"
targetSdk = 34
versionCode = 9
versionName = "1.1.1"
versionCode = 10
versionName = "2.1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -57,6 +57,7 @@ dependencies {
implementation(project(":feature:profileeditor"))
implementation(project(":feature:policydetail"))
implementation(project(":feature:policybookmarks"))
implementation(project(":feature:disablepolicy"))
implementation(project(":core:ui"))
implementation(project(":core:interceptor"))
implementation(project(":core:data"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.withpeace.withpeace

import android.util.Log
import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.material3.NavigationBar
Expand All @@ -12,6 +13,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.navOptions
import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme
Expand Down Expand Up @@ -67,12 +69,13 @@ fun MainBottomBar(
private fun NavController.navigateToTabScreen(bottomTab: BottomTab) {
val tabNavOptions =
navOptions {
popUpTo(HOME_ROUTE) {
popUpTo(graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
// 여기 아니면 NavHost

when (bottomTab) {
BottomTab.HOME -> navigateHome(tabNavOptions)
Expand Down Expand Up @@ -121,3 +124,4 @@ enum class BottomTab(
}
}
}
// https://stackoverflow.com/questions/76721423/compose-navigation-go-to-top-level-destination-when-clicking-on-navigation-bar
23 changes: 17 additions & 6 deletions app/src/main/java/com/withpeace/withpeace/WithpeaceApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.ExperimentalComposeUiApi
Expand All @@ -20,6 +21,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme
import com.withpeace.withpeace.core.designsystem.ui.snackbar.CheonghaSnackbar
import com.withpeace.withpeace.core.designsystem.ui.snackbar.NavigatorSnackbar
import com.withpeace.withpeace.core.designsystem.ui.snackbar.SnackbarState
import com.withpeace.withpeace.core.designsystem.ui.snackbar.SnackbarType
import com.withpeace.withpeace.navigation.WithpeaceNavHost
Expand All @@ -32,18 +34,20 @@ fun WithpeaceApp(
navController: NavHostController = rememberNavController(),
) {
val snackBarHostState = remember { SnackbarHostState() }
var snackBarState: SnackbarState =
remember { SnackbarState("", SnackbarType.Normal) }
val snackBarState =
remember { mutableStateOf(SnackbarState("", SnackbarType.Normal)) }

val coroutineScope = rememberCoroutineScope()
fun showSnackBar(snackbarState: SnackbarState) = coroutineScope.launch {
snackBarState = snackbarState
snackBarState.value = snackbarState
snackBarHostState.currentSnackbarData?.dismiss()
val snackbarResult = snackBarHostState.showSnackbar(snackbarState.message)
when (snackbarResult) {
SnackbarResult.Dismissed -> Unit
SnackbarResult.ActionPerformed ->
SnackbarResult.ActionPerformed -> {
(snackbarState.snackbarType as SnackbarType.Navigator).action()
snackBarHostState.currentSnackbarData?.dismiss()
}
}
}

Expand Down Expand Up @@ -72,8 +76,15 @@ fun WithpeaceApp(
snackbarHost = {
SnackbarHost(snackBarHostState)
{
when (snackBarState.snackbarType) {
is SnackbarType.Navigator -> {}
when (val snackbarType = snackBarState.value.snackbarType) {
is SnackbarType.Navigator -> {
NavigatorSnackbar(
content = it.visuals.message,
action = { snackbarType.action()
snackBarHostState.currentSnackbarData?.dismiss()},
actionName = snackbarType.actionName,
)
}
is SnackbarType.Normal -> {
CheonghaSnackbar(data = it)
}
Expand Down
68 changes: 64 additions & 4 deletions app/src/main/java/com/withpeace/withpeace/navigation/NavHost.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.withpeace.withpeace.navigation

import POLICY_REMOVED_ID_ARGUMENT
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.runtime.Composable
Expand All @@ -11,8 +12,13 @@ import androidx.navigation.navigation
import com.app.profileeditor.navigation.navigateProfileEditor
import com.app.profileeditor.navigation.profileEditorNavGraph
import com.withpeace.withpeace.core.designsystem.ui.snackbar.SnackbarState
import com.withpeace.withpeace.core.designsystem.ui.snackbar.SnackbarType
import com.withpeace.withpeace.feature.disablepolicy.navigation.DISABLE_POLICY_ID_ARGUMENT
import com.withpeace.withpeace.feature.disablepolicy.navigation.disabledPolicyNavGraph
import com.withpeace.withpeace.feature.disablepolicy.navigation.navigateDisabledPolicy
import com.withpeace.withpeace.feature.gallery.navigation.galleryNavGraph
import com.withpeace.withpeace.feature.gallery.navigation.navigateToGallery
import com.withpeace.withpeace.feature.home.navigation.HOME_ROUTE
import com.withpeace.withpeace.feature.home.navigation.homeNavGraph
import com.withpeace.withpeace.feature.home.navigation.navigateHome
import com.withpeace.withpeace.feature.login.navigation.LOGIN_ROUTE
Expand Down Expand Up @@ -171,13 +177,45 @@ fun WithpeaceNavHost(
)
homeNavGraph(
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onNavigationSnackBar = {
onShowSnackBar(
SnackbarState(
it,
SnackbarType.Navigator(
actionName = "목록 보러가기",
action = {
navController.navigatePolicyBookmarks( navOptions = navOptions {
popUpTo(HOME_ROUTE) {
saveState = true
}
launchSingleTop = true
restoreState = true
})
},
),
),
)
},
onPolicyClick = {
navController.navigateToPolicyDetail(policyId = it)
},
)
policyDetailNavGraph(
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = { navController.popBackStack() },
onNavigationSnackbar = {
onShowSnackBar(
SnackbarState(
it,
SnackbarType.Navigator(
actionName = "목록 보러가기",
action = {
navController.navigatePolicyBookmarks()
},
),
),
)
},
)
navigation(startDestination = MY_PAGE_ROUTE, MY_PAGE_NESTED_ROUTE) {
myPageNavGraph(
Expand Down Expand Up @@ -213,6 +251,20 @@ fun WithpeaceNavHost(
navController.navigatePolicyBookmarks()
},
)
disabledPolicyNavGraph(
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = {
navController.popBackStack()
},
onAuthExpired = {},
onBookmarkDeleteSuccess = {
navController.previousBackStackEntry?.savedStateHandle?.set(
POLICY_REMOVED_ID_ARGUMENT,
it,
)
navController.popBackStack()
},
)
profileEditorNavGraph(
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = {
Expand All @@ -237,8 +289,15 @@ fun WithpeaceNavHost(
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
onClickBackButton = {
navController.popBackStack()
}
},
onPolicyClick = {
navController.navigateToPolicyDetail(policyId = it)
},
onDisablePolicyClick = {
navController.navigateDisabledPolicy(policyId = it)
},
)

}
postDetailGraph(
onShowSnackBar = { onShowSnackBar(SnackbarState(it)) },
Expand All @@ -254,9 +313,10 @@ fun WithpeaceNavHost(
onAuthExpired(onShowSnackBar, navController)
},
onDeleteSuccess = {
navController.previousBackStackEntry?.savedStateHandle?.apply {
set(POST_LIST_DELETED_POST_ID_ARGUMENT, it)
}
navController.previousBackStackEntry?.savedStateHandle?.set(
POST_LIST_DELETED_POST_ID_ARGUMENT,
it,
)
navController.popBackStack()
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,41 @@ import com.withpeace.withpeace.core.domain.repository.YouthPolicyRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.android.scopes.ViewModelScoped
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
@InstallIn(ViewModelComponent::class)
interface RepositoryModule {

@Binds
@Singleton
@ViewModelScoped
fun bindsTokenRepository(defaultTokenRepository: DefaultTokenRepository): TokenRepository

@Binds
@Singleton
@ViewModelScoped
fun bindsImageRepository(defaultImageRepository: DefaultImageRepository): ImageRepository

@Binds
@Singleton
@ViewModelScoped
fun bindsPostRepository(defaultPostRepository: DefaultPostRepository): PostRepository

@Binds
@Singleton
@ViewModelScoped
fun bindsUserRepository(
defaultUserRepository: DefaultUserRepository,
): UserRepository

@Binds
@Singleton
@ViewModelScoped
fun bindsYouthPolicyRepository(
defaultYouthPolicyRepository: DefaultYouthPolicyRepository
): YouthPolicyRepository

@Binds
@Singleton
@ViewModelScoped
fun bindsAppUpdateRepository(
appUpdateRepository: DefaultAppUpdateRepository,
): AppUpdateRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.withpeace.withpeace.core.data.mapper.youthpolicy

import com.withpeace.withpeace.core.domain.model.policy.BookmarkedPolicy
import com.withpeace.withpeace.core.network.di.response.policy.BookmarkedPolicyResponse

fun BookmarkedPolicyResponse.toDomain(): BookmarkedPolicy {
return BookmarkedPolicy(
id = id,
title = title,
introduce = introduce,
ageInfo = ageInfo,
classification = classification.codeToPolicyClassification(),
region = region.codeToRegion(),
isActive = isActive,
isBookmarked = true, // Bookmarked 된 데이터들 이므로 true 설정
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.withpeace.withpeace.core.data.mapper.youthpolicy

import com.withpeace.withpeace.core.domain.model.policy.PolicyClassification
import com.withpeace.withpeace.core.domain.model.policy.YouthPolicyDetail
import com.withpeace.withpeace.core.network.di.response.policy.PolicyDetailResponse

Expand All @@ -27,5 +26,6 @@ internal fun PolicyDetailResponse.toDomain(): YouthPolicyDetail {
operatingOrganization = operatingOrganization,
businessRelatedReferenceSite1 = businessRelatedReferenceSite1,
businessRelatedReferenceSite2 = businessRelatedReferenceSite2,
isBookmarked = isBookmarked,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal fun PolicyResponse.toDomain(): YouthPolicy {
region = region.codeToRegion(),
policyClassification = classification.codeToPolicyClassification(),
ageInfo = ageInfo,
isBookmarked = isBookmarked,
)
}

Expand Down
Loading

0 comments on commit ffb9fd6

Please sign in to comment.