generated from AND-SOPT-ANDROID/and-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34a6dcb
commit b4d30d0
Showing
4 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.sopt.and.presentation.ui.mypage | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import org.sopt.and.presentation.viewmodel.MyPageViewModel | ||
|
||
@Composable | ||
fun MyPageRoute( | ||
viewModel: MyPageViewModel = hiltViewModel() | ||
) { | ||
val userHobby by viewModel.userHobby.collectAsStateWithLifecycle() | ||
|
||
MyPageScreen(userHobby) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/sopt/and/presentation/viewmodel/MyPageViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.sopt.and.presentation.viewmodel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import org.sopt.and.domain.usecase.user.GetMyHobbyUseCase | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MyPageViewModel @Inject constructor( | ||
private val geyMyHobbyUseCase: GetMyHobbyUseCase | ||
) : ViewModel() { | ||
|
||
private val _userHobby = MutableStateFlow<String>("") | ||
val userHobby: StateFlow<String> = _userHobby | ||
|
||
init { | ||
geyMyHobby() | ||
} | ||
|
||
private fun geyMyHobby() { | ||
viewModelScope.launch { | ||
geyMyHobbyUseCase().onSuccess { | ||
_userHobby.value = it.hobby | ||
} | ||
} | ||
} | ||
} |