diff --git a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/datasource/DeleteMyAlbumDataSource.kt b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/datasource/DeleteMyAlbumDataSource.kt new file mode 100644 index 00000000..7b9a66ef --- /dev/null +++ b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/datasource/DeleteMyAlbumDataSource.kt @@ -0,0 +1,7 @@ +package com.nexters.ilab.android.core.data.datasource + +import com.nexters.ilab.android.core.data.response.UserInfoResponse + +interface DeleteMyAlbumDataSource { + suspend fun deleteMyAlbum(uuid: Long, thumbnailId: Int): UserInfoResponse +} diff --git a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/datasource/DeleteMyAlbumDataSourceImpl.kt b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/datasource/DeleteMyAlbumDataSourceImpl.kt new file mode 100644 index 00000000..5c68a15a --- /dev/null +++ b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/datasource/DeleteMyAlbumDataSourceImpl.kt @@ -0,0 +1,13 @@ +package com.nexters.ilab.android.core.data.datasource + +import com.nexters.ilab.android.core.data.response.UserInfoResponse +import com.nexters.ilab.android.core.data.service.ILabService +import javax.inject.Inject + +class DeleteMyAlbumDataSourceImpl @Inject constructor( + private val service: ILabService, +) : DeleteMyAlbumDataSource { + override suspend fun deleteMyAlbum(uuid: Long, thumbnailId: Int): UserInfoResponse { + return service.deleteMyAlbumImage(uuid, thumbnailId) + } +} diff --git a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/DataSourceModule.kt b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/DataSourceModule.kt index bc243f1e..04369a22 100644 --- a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/DataSourceModule.kt +++ b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/DataSourceModule.kt @@ -4,6 +4,8 @@ import com.nexters.ilab.android.core.data.datasource.FileDataSource import com.nexters.ilab.android.core.data.datasource.FileDataSourceImpl import com.nexters.ilab.android.core.data.datasource.AuthDataSource import com.nexters.ilab.android.core.data.datasource.AuthDataSourceImpl +import com.nexters.ilab.android.core.data.datasource.DeleteMyAlbumDataSource +import com.nexters.ilab.android.core.data.datasource.DeleteMyAlbumDataSourceImpl import com.nexters.ilab.android.core.data.datasource.ProfileDataSource import com.nexters.ilab.android.core.data.datasource.ProfileDataSourceImpl import com.nexters.ilab.android.core.data.datasource.StyleDataSource @@ -45,4 +47,8 @@ abstract class DataSourceModule { @Singleton @Binds abstract fun bindProfileDataSource(profileDataSourceImpl: ProfileDataSourceImpl): ProfileDataSource + + @Binds + @Singleton + abstract fun bindDeleteMyAlbumDataSource(deleteMyAlbumDataSourceImpl: DeleteMyAlbumDataSourceImpl): DeleteMyAlbumDataSource } diff --git a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/RepositoryModule.kt b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/RepositoryModule.kt index 26d23652..d3701b2b 100644 --- a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/RepositoryModule.kt +++ b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/di/RepositoryModule.kt @@ -2,12 +2,14 @@ package com.nexters.ilab.android.core.data.di import com.nexters.ilab.android.core.data.repository.FileRepositoryImpl import com.nexters.ilab.android.core.data.repository.AuthRepositoryImpl +import com.nexters.ilab.android.core.data.repository.DeleteMyAlbumRepositoryImpl import com.nexters.ilab.android.core.data.repository.PrivacyPolicyRepositoryImpl import com.nexters.ilab.android.core.data.repository.ProfileRepositoryImpl import com.nexters.ilab.android.core.data.repository.StyleRepositoryImpl import com.nexters.ilab.android.core.data.repository.TokenRepositoryImpl import com.nexters.ilab.android.core.domain.repository.FileRepository import com.nexters.ilab.android.core.domain.repository.AuthRepository +import com.nexters.ilab.android.core.domain.repository.DeleteMyAlbumRepository import com.nexters.ilab.android.core.domain.repository.PrivacyPolicyRepository import com.nexters.ilab.android.core.domain.repository.ProfileRepository import com.nexters.ilab.android.core.domain.repository.StyleRepository @@ -45,4 +47,8 @@ abstract class RepositoryModule { @Binds @Singleton abstract fun bindProfileRepository(profileRepositoryImpl: ProfileRepositoryImpl): ProfileRepository + + @Binds + @Singleton + abstract fun bindDeleteMyAlbumRepository(deleteMyAlbumRepositoryImpl: DeleteMyAlbumRepositoryImpl): DeleteMyAlbumRepository } diff --git a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/repository/DeleteMyAlbumRepositoryImpl.kt b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/repository/DeleteMyAlbumRepositoryImpl.kt new file mode 100644 index 00000000..0f843d3b --- /dev/null +++ b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/repository/DeleteMyAlbumRepositoryImpl.kt @@ -0,0 +1,18 @@ +package com.nexters.ilab.android.core.data.repository + +import com.nexters.ilab.android.core.data.datasource.DeleteMyAlbumDataSource +import com.nexters.ilab.android.core.data.mapper.toEntity +import com.nexters.ilab.android.core.data.util.runSuspendCatching +import com.nexters.ilab.android.core.datastore.TokenDataSource +import com.nexters.ilab.android.core.domain.repository.DeleteMyAlbumRepository +import javax.inject.Inject + +class DeleteMyAlbumRepositoryImpl @Inject constructor( + private val tokenDataSource: TokenDataSource, + private val myAlbumDataSource: DeleteMyAlbumDataSource, +) : DeleteMyAlbumRepository { + override suspend fun deleteMyAlbum(thumbnailId: Int) = runSuspendCatching { + val uuid = tokenDataSource.getUUID() + myAlbumDataSource.deleteMyAlbum(uuid, thumbnailId).toEntity() + } +} diff --git a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/service/ILabService.kt b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/service/ILabService.kt index 98712d13..bc1215a7 100644 --- a/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/service/ILabService.kt +++ b/core/data/src/main/kotlin/com/nexters/ilab/android/core/data/service/ILabService.kt @@ -3,11 +3,13 @@ package com.nexters.ilab.android.core.data.service import com.nexters.ilab.android.core.data.response.CreatedProfileResponse import com.nexters.ilab.android.core.data.response.ProfileResponse import com.nexters.ilab.android.core.data.response.StyleResponse +import com.nexters.ilab.android.core.data.response.UserInfoResponse import okhttp3.MultipartBody import retrofit2.http.GET import retrofit2.http.Multipart import retrofit2.http.POST import retrofit2.http.Part +import retrofit2.http.Path interface ILabService { @GET("style") @@ -23,4 +25,10 @@ interface ILabService { @Part("styleId") styleId: Int, @Part("uuid") uuid: Long, ): List + + @POST("thumbnails/delete/{uuid}/{thumbnailId}") + suspend fun deleteMyAlbumImage( + @Path("uuid") uuid: Long, + @Path("thumbnailId") thumbnailId: Int, + ): UserInfoResponse } diff --git a/core/domain/src/main/kotlin/com/nexters/ilab/android/core/domain/repository/DeleteMyAlbumRepository.kt b/core/domain/src/main/kotlin/com/nexters/ilab/android/core/domain/repository/DeleteMyAlbumRepository.kt new file mode 100644 index 00000000..58da20f2 --- /dev/null +++ b/core/domain/src/main/kotlin/com/nexters/ilab/android/core/domain/repository/DeleteMyAlbumRepository.kt @@ -0,0 +1,7 @@ +package com.nexters.ilab.android.core.domain.repository + +import com.nexters.ilab.android.core.domain.entity.UserInfoEntity + +interface DeleteMyAlbumRepository { + suspend fun deleteMyAlbum(thumbnailId: Int): Result +} diff --git a/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/HomeScreen.kt b/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/HomeScreen.kt index c8123342..1f8c2ca2 100644 --- a/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/HomeScreen.kt +++ b/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/HomeScreen.kt @@ -84,11 +84,11 @@ internal fun HomeRoute( LaunchedEffect(viewModel) { viewModel.container.sideEffectFlow.collect { sideEffect -> when (sideEffect) { - is HomeSideEffect.OnCreateImageButtonClickFromStyle -> { + is HomeSideEffect.OnCreateImageBtnClickFromStyle -> { onNavigateToUploadPhoto(sideEffect.selectedStyle) } - is HomeSideEffect.OnCreateImageButtonClickFromProfile -> { + is HomeSideEffect.OnCreateImageBtnClickFromProfile -> { onNavigateToUploadPhoto(sideEffect.selectedProfile) } } @@ -99,8 +99,8 @@ internal fun HomeRoute( uiState = uiState, padding = padding, onSettingClick = onSettingClick, - onCreateImageButtonClickFromStyle = viewModel::onCreateImageButtonClickFromStyle, - onCreateImageButtonClickFromProfile = viewModel::onCreateImageButtonClickFromProfile, + onCreateImageBtnClickFromStyle = viewModel::onCreateImageBtnClickFromStyle, + onCreateImageBtnClickFromProfile = viewModel::onCreateImageBtnClickFromProfile, openProfileImageDialog = viewModel::openProfileImageDialog, dismissProfileImageDialog = viewModel::dismissProfileImageDialog, getStyleProfileList = viewModel::getStyleProfileList, @@ -115,8 +115,8 @@ internal fun HomeScreen( uiState: HomeState, padding: PaddingValues, onSettingClick: () -> Unit, - onCreateImageButtonClickFromStyle: () -> Unit, - onCreateImageButtonClickFromProfile: () -> Unit, + onCreateImageBtnClickFromStyle: () -> Unit, + onCreateImageBtnClickFromProfile: () -> Unit, openProfileImageDialog: (Int) -> Unit, dismissProfileImageDialog: () -> Unit, getStyleProfileList: () -> Unit, @@ -153,9 +153,9 @@ internal fun HomeScreen( ProfileImageDialog( profileImage = uiState.selectedProfileImage, onCloseClick = dismissProfileImageDialog, - onCreateImageButtonClickFromProfile = { + onCreateImageBtnClickFromProfile = { dismissProfileImageDialog() - onCreateImageButtonClickFromProfile() + onCreateImageBtnClickFromProfile() }, ) } @@ -163,7 +163,7 @@ internal fun HomeScreen( HomeContent( styleImageList = uiState.styleImageList, profileImageList = uiState.profileImageList, - onCreateImageButtonClickFromStyle = onCreateImageButtonClickFromStyle, + onCreateImageBtnClickFromStyle = onCreateImageBtnClickFromStyle, openProfileImageDialog = openProfileImageDialog, setSelectedStyleImage = setSelectedStyleImage, ) @@ -189,7 +189,7 @@ internal fun HomeTopAppBar(onSettingClick: () -> Unit) { internal fun HomeContent( styleImageList: List, profileImageList: List, - onCreateImageButtonClickFromStyle: () -> Unit, + onCreateImageBtnClickFromStyle: () -> Unit, openProfileImageDialog: (Int) -> Unit, setSelectedStyleImage: (Int) -> Unit, ) { @@ -205,7 +205,7 @@ internal fun HomeContent( item(span = StaggeredGridItemSpan.FullLine) { HomeKeywordView( styleImageList = styleImageList, - onCreateImageButtonClickFromStyle = onCreateImageButtonClickFromStyle, + onCreateImageBtnClickFromStyle = onCreateImageBtnClickFromStyle, setSelectedStyleImage = setSelectedStyleImage, ) } @@ -236,7 +236,7 @@ internal fun HomeContent( @Composable internal fun HomeKeywordView( styleImageList: List, - onCreateImageButtonClickFromStyle: () -> Unit, + onCreateImageBtnClickFromStyle: () -> Unit, setSelectedStyleImage: (Int) -> Unit, ) { val pageCount = styleImageList.size @@ -296,7 +296,7 @@ internal fun HomeKeywordView( ) Spacer(modifier = Modifier.height(32.dp)) ILabButton( - onClick = onCreateImageButtonClickFromStyle, + onClick = onCreateImageBtnClickFromStyle, modifier = Modifier .fillMaxWidth() .padding(start = 20.dp, end = 20.dp) @@ -364,7 +364,7 @@ internal fun ProfileImageItem( internal fun ProfileImageDialog( profileImage: ProfileEntity, onCloseClick: () -> Unit, - onCreateImageButtonClickFromProfile: () -> Unit, + onCreateImageBtnClickFromProfile: () -> Unit, ) { BasicAlertDialog( onDismissRequest = onCloseClick, @@ -409,7 +409,7 @@ internal fun ProfileImageDialog( ) Spacer(modifier = Modifier.height(24.dp)) ILabButton( - onClick = onCreateImageButtonClickFromProfile, + onClick = onCreateImageBtnClickFromProfile, modifier = Modifier .fillMaxWidth() .padding(start = 20.dp, end = 20.dp, bottom = 16.dp) @@ -435,8 +435,8 @@ internal fun HomeScreenPreview() { uiState = HomeState(), padding = PaddingValues(0.dp), onSettingClick = {}, - onCreateImageButtonClickFromStyle = {}, - onCreateImageButtonClickFromProfile = {}, + onCreateImageBtnClickFromStyle = {}, + onCreateImageBtnClickFromProfile = {}, openProfileImageDialog = {}, dismissProfileImageDialog = {}, getStyleProfileList = {}, @@ -452,6 +452,6 @@ fun ProfileImageDialogPreview() { ProfileImageDialog( profileImage = ProfileEntity("", "", ""), onCloseClick = {}, - onCreateImageButtonClickFromProfile = {}, + onCreateImageBtnClickFromProfile = {}, ) } diff --git a/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeSideEffect.kt b/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeSideEffect.kt index 19a91be3..c90d7383 100644 --- a/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeSideEffect.kt +++ b/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeSideEffect.kt @@ -1,6 +1,6 @@ package com.nexters.ilab.android.feature.home.viewmodel sealed interface HomeSideEffect { - data class OnCreateImageButtonClickFromStyle(val selectedStyle: String) : HomeSideEffect - data class OnCreateImageButtonClickFromProfile(val selectedProfile: String) : HomeSideEffect + data class OnCreateImageBtnClickFromStyle(val selectedStyle: String) : HomeSideEffect + data class OnCreateImageBtnClickFromProfile(val selectedProfile: String) : HomeSideEffect } diff --git a/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeViewModel.kt b/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeViewModel.kt index d2a9a5fc..ec37b515 100644 --- a/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeViewModel.kt +++ b/feature/home/src/main/kotlin/com/nexters/ilab/android/feature/home/viewmodel/HomeViewModel.kt @@ -73,9 +73,9 @@ class HomeViewModel @Inject constructor( } } - fun onCreateImageButtonClickFromStyle() = intent { + fun onCreateImageBtnClickFromStyle() = intent { postSideEffect( - HomeSideEffect.OnCreateImageButtonClickFromStyle( + HomeSideEffect.OnCreateImageBtnClickFromStyle( if (state.selectedStyle.name.isEmpty()) { state.styleImageList[0].name } else { @@ -85,9 +85,9 @@ class HomeViewModel @Inject constructor( ) } - fun onCreateImageButtonClickFromProfile() = intent { + fun onCreateImageBtnClickFromProfile() = intent { postSideEffect( - HomeSideEffect.OnCreateImageButtonClickFromProfile(state.selectedProfileImage.name), + HomeSideEffect.OnCreateImageBtnClickFromProfile(state.selectedProfileImage.name), ) } diff --git a/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/LoginScreen.kt b/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/LoginScreen.kt index 75b4ffc0..f8ee3ead 100644 --- a/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/LoginScreen.kt +++ b/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/LoginScreen.kt @@ -129,7 +129,7 @@ internal fun LoginRoute( LoginScreen( uiState = uiState, - onLoginClick = viewModel::onLoginButtonClick, + onLoginClick = viewModel::onLoginBtnClick, ) } diff --git a/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/viewmodel/LoginViewModel.kt b/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/viewmodel/LoginViewModel.kt index d8eea144..1c017973 100644 --- a/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/viewmodel/LoginViewModel.kt +++ b/feature/login/src/main/kotlin/com/nexters/ilab/android/feature/login/viewmodel/LoginViewModel.kt @@ -23,7 +23,7 @@ class LoginViewModel @Inject constructor( override val container = container(LoginState()) - fun onLoginButtonClick() = intent { + fun onLoginBtnClick() = intent { postSideEffect(LoginSideEffect.KakaoLogin) } diff --git a/feature/myalbum/src/main/kotlin/com/nexters/ilab/android/feature/myalbum/viewmodel/MyAlbumViewModel.kt b/feature/myalbum/src/main/kotlin/com/nexters/ilab/android/feature/myalbum/viewmodel/MyAlbumViewModel.kt index 34a28918..baa7c77a 100644 --- a/feature/myalbum/src/main/kotlin/com/nexters/ilab/android/feature/myalbum/viewmodel/MyAlbumViewModel.kt +++ b/feature/myalbum/src/main/kotlin/com/nexters/ilab/android/feature/myalbum/viewmodel/MyAlbumViewModel.kt @@ -28,7 +28,8 @@ class MyAlbumViewModel @Inject constructor( // init { // Timber.d("imageUrlList: $myAlbumImageUrlList") -// Timber.d("imageUrlList.toList(): ${listOf(*myAlbumImageUrlList)}") +// Timber.d("listOf(*myAlbumImageUrlList): ${listOf(*myAlbumImageUrlList)}") +// Timber.d("imageUrlList.toList(): ${myAlbumImageUrlList.toList()}") // intent { // reduce { // state.copy( diff --git a/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/MyPageScreen.kt b/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/MyPageScreen.kt index 8adfa774..315d9643 100644 --- a/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/MyPageScreen.kt +++ b/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/MyPageScreen.kt @@ -74,7 +74,6 @@ import com.nexters.ilab.core.ui.component.NetworkImage import com.nexters.ilab.core.ui.component.ServerErrorDialog import com.nexters.ilab.core.ui.component.TopAppBarNavigationType import kotlinx.collections.immutable.ImmutableList -import timber.log.Timber @Composable internal fun MyPageRoute( @@ -111,9 +110,9 @@ internal fun MyPageRoute( } is MyPageSideEffect.NavigateToMyAlbum -> { - Timber.d("imageUrlList: ${sideEffect.imageUrlList}") - Timber.d("imageUrlList.toTypedArray(): ${sideEffect.imageUrlList.toTypedArray()}") - Timber.d("imageUrlList.toTypedArray().toList(): ${sideEffect.imageUrlList.toTypedArray().toList()}") +// Timber.d("imageUrlList: ${sideEffect.imageUrlList}") +// Timber.d("imageUrlList.toTypedArray(): ${sideEffect.imageUrlList.toTypedArray()}") +// Timber.d("imageUrlList.toTypedArray().toList(): ${sideEffect.imageUrlList.toTypedArray().toList()}") onNavigateToMyAlbum( sideEffect.imageStyle, sideEffect.imageUrlList, @@ -129,7 +128,7 @@ internal fun MyPageRoute( onSettingClick = onSettingClick, getUserInfo = viewModel::getUserInfo, onShareBtnClick = viewModel::shareMyAlbum, - onDeleteBtnClick = {}, + onDeleteBtnClick = viewModel::deleteMyAlbum, onAlbumClick = viewModel::onAlbumClick, dismissServerErrorDialog = viewModel::dismissServerErrorDialog, dismissNetworkErrorDialog = viewModel::dismissNetworkErrorDialog, @@ -143,7 +142,7 @@ internal fun MyPageScreen( onSettingClick: () -> Unit, getUserInfo: () -> Unit, onShareBtnClick: () -> Unit, - onDeleteBtnClick: () -> Unit, + onDeleteBtnClick: (Int) -> Unit, onAlbumClick: (Int) -> Unit, dismissServerErrorDialog: () -> Unit, dismissNetworkErrorDialog: () -> Unit, @@ -203,7 +202,7 @@ internal fun MyPageContent( userInfo: UserInfoEntity, myAlbumImageList: ImmutableList, onShareBtnClick: () -> Unit, - onDeleteBtnClick: () -> Unit, + onDeleteBtnClick: (Int) -> Unit, onAlbumClick: (Int) -> Unit, ) { val span: (LazyGridItemSpanScope) -> GridItemSpan = { GridItemSpan(2) } @@ -236,13 +235,17 @@ internal fun MyPageContent( MyPageContentEmpty() } } else { - items(myAlbumCount) { iter -> + items( + count = myAlbumCount, + key = { index -> myAlbumImageList[index].id }, + ) { iter -> MyAlbumImage( myAlbum = myAlbumImageList[iter], onShareBtnClick = onShareBtnClick, - onDeleteBtnClick = onDeleteBtnClick, - onAlbumClick = onAlbumClick, - index = iter, + onDeleteBtnClick = { onDeleteBtnClick(myAlbumImageList[iter].id) }, + modifier = Modifier.clickable { + onAlbumClick(iter) + }, ) } } @@ -328,25 +331,19 @@ internal fun MyAlbumImage( myAlbum: UserThumbnailEntity, onShareBtnClick: () -> Unit, onDeleteBtnClick: () -> Unit, - onAlbumClick: (Int) -> Unit, - index: Int, + modifier: Modifier = Modifier, ) { var isExpanded by remember { mutableStateOf(false) } Box( - modifier = Modifier + modifier = modifier .clip(RoundedCornerShape(12.dp)) .aspectRatio(1f), ) { NetworkImage( imageUrl = myAlbum.images.first().imageUrl, contentDescription = "My Album Image", - modifier = Modifier - .fillMaxSize() - .aspectRatio(1f) - .clickable { - onAlbumClick(index) - }, + modifier = Modifier.fillMaxSize(), ) Image( painter = painterResource(id = R.drawable.bg_img_dim_small), diff --git a/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/viewmodel/MyPageViewModel.kt b/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/viewmodel/MyPageViewModel.kt index 4ad10dd3..524b1608 100644 --- a/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/viewmodel/MyPageViewModel.kt +++ b/feature/mypage/src/main/kotlin/com/nexters/ilab/android/feature/mypage/viewmodel/MyPageViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope import com.nexters.ilab.android.core.common.ErrorHandlerActions import com.nexters.ilab.android.core.common.handleException import com.nexters.ilab.android.core.domain.repository.AuthRepository +import com.nexters.ilab.android.core.domain.repository.DeleteMyAlbumRepository import com.nexters.ilab.android.core.domain.repository.FileRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.collections.immutable.toImmutableList @@ -14,12 +15,14 @@ import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce import org.orbitmvi.orbit.viewmodel.container +import timber.log.Timber import javax.inject.Inject @HiltViewModel class MyPageViewModel @Inject constructor( private val authRepository: AuthRepository, private val fileRepository: FileRepository, + private val deleteMyAlbumRepository: DeleteMyAlbumRepository, ) : ViewModel(), ContainerHost, ErrorHandlerActions { override val container = container(MyPageState()) @@ -51,6 +54,29 @@ class MyPageViewModel @Inject constructor( } } + fun deleteMyAlbum(index: Int) = intent { + viewModelScope.launch { + reduce { + state.copy(isLoading = true) + } + deleteMyAlbumRepository.deleteMyAlbum(index) + .onSuccess { userInfo -> + reduce { + state.copy( + myAlbumFullImageList = userInfo.thumbnails.toImmutableList(), + ) + } + }.onFailure { exception -> + handleException(exception, this@MyPageViewModel) + } + reduce { + state.copy( + isLoading = false, + ) + } + } + } + private fun setSelectedMyAlbum(index: Int) = intent { reduce { state.copy(selectedMyAlbum = index) @@ -79,11 +105,16 @@ class MyPageViewModel @Inject constructor( } fun onAlbumClick(index: Int) = intent { + Timber.d("before: state.selectedMyAlbum: ${state.selectedMyAlbum}") setSelectedMyAlbum(index) + Timber.d("selectedIndex: $index") + Timber.d("state.selectedMyAlbum: ${state.selectedMyAlbum}") + Timber.d("MyAlbumImageUrlList: ${state.myAlbumFullImageList[state.selectedMyAlbum].images.map { it.imageUrl }}") + Timber.d("StyleName: ${state.myAlbumFullImageList[state.selectedMyAlbum].images.map { it.imageStyle.name }.first()}") postSideEffect( MyPageSideEffect.NavigateToMyAlbum( - state.myAlbumFullImageList[state.selectedMyAlbum].images.map { it.imageUrl }, - state.myAlbumFullImageList[state.selectedMyAlbum].images.map { it.imageStyle.name }.first(), + state.myAlbumFullImageList[index].images.map { it.imageUrl }, + state.myAlbumFullImageList[index].images.map { it.imageStyle.name }.first(), ), ) }