From e5ae98bb308c16059d41f790d87a26675fa905aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A7=84=EC=9A=B0?= <85734140+jinuemong@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:26:04 +0900 Subject: [PATCH] =?UTF-8?q?=08[AN]=20feat:=20=EB=82=B4=EA=B0=80=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A0=20&=20=EB=B0=A9=EC=9E=A5=EC=9D=B8=20?= =?UTF-8?q?=EB=AA=A8=EC=9E=84=20=EA=B5=AC=EC=B2=B4=ED=99=94=20(#450)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friendogly/application/di/AppModule.kt | 13 ++- .../data/repository/MyClubRepositoryImpl.kt | 97 ++----------------- .../data/source/MyClubDataSource.kt | 9 ++ .../ui/club/add/ClubAddActivity.kt | 4 +- .../ui/club/common/ClubChangeStateIntent.kt | 5 + .../ui/club/detail/ClubDetailActivity.kt | 14 +-- .../ui/club/list/ClubListFragment.kt | 7 +- .../presentation/ui/club/my/MyClubActivity.kt | 34 ++++++- .../presentation/ui/club/my/MyClubEvent.kt | 6 ++ .../ui/club/my/MyClubViewModel.kt | 47 +++++++++ .../ui/club/my/adapter/MyClubAdapter.kt | 4 +- .../ui/club/my/head/MyHeadClubFragment.kt | 5 + .../ui/club/my/head/MyHeadClubViewModel.kt | 6 +- .../MyParticipatingClubViewModel.kt} | 12 +-- .../MyParticipatingFragment.kt} | 13 ++- .../ui/club/select/PetSelectViewModel.kt | 4 +- .../mylocation/SettingMyLocationActivity.kt | 4 +- .../happy/friendogly/remote/api/ApiClient.kt | 6 ++ .../friendogly/remote/api/MyClubService.kt | 13 +++ .../friendogly/remote/di/RemoteModule.kt | 14 +++ .../remote/source/MyClubDataSourceImpl.kt | 20 ++++ .../src/main/res/layout/activity_club_add.xml | 56 +++++------ .../src/main/res/layout/fragment_my_club.xml | 2 +- 23 files changed, 242 insertions(+), 153 deletions(-) create mode 100644 android/app/src/main/java/com/happy/friendogly/data/source/MyClubDataSource.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/presentation/ui/club/common/ClubChangeStateIntent.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubViewModel.kt rename android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/{club/MyClubViewModel.kt => participating/MyParticipatingClubViewModel.kt} (86%) rename android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/{club/MyClubFragment.kt => participating/MyParticipatingFragment.kt} (86%) create mode 100644 android/app/src/main/java/com/happy/friendogly/remote/api/MyClubService.kt create mode 100644 android/app/src/main/java/com/happy/friendogly/remote/source/MyClubDataSourceImpl.kt diff --git a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt index 30d60806d..4694d8ce8 100644 --- a/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt +++ b/android/app/src/main/java/com/happy/friendogly/application/di/AppModule.kt @@ -25,6 +25,7 @@ import com.happy.friendogly.data.source.ChatDataSource import com.happy.friendogly.data.source.ClubDataSource import com.happy.friendogly.data.source.KakaoLoginDataSource import com.happy.friendogly.data.source.MemberDataSource +import com.happy.friendogly.data.source.MyClubDataSource import com.happy.friendogly.data.source.PetDataSource import com.happy.friendogly.data.source.TokenDataSource import com.happy.friendogly.data.source.WebSocketDataSource @@ -97,6 +98,7 @@ import com.happy.friendogly.remote.source.AuthDataSourceImpl import com.happy.friendogly.remote.source.ChatDataSourceImpl import com.happy.friendogly.remote.source.ClubDataSourceImpl import com.happy.friendogly.remote.source.MemberDataSourceImpl +import com.happy.friendogly.remote.source.MyClubDataSourceImpl import com.happy.friendogly.remote.source.PetDataSourceImpl import com.happy.friendogly.remote.source.WebSocketDataSourceImpl import com.happy.friendogly.remote.source.WoofDataSourceImpl @@ -130,6 +132,14 @@ class AppModule(context: Context) { tokenManager = tokenManager, authenticationListener = authenticationListener, ) + + private val myClubService = + RemoteModule.createMyClubService( + baseUrl = baseUrl, + tokenManager = tokenManager, + authenticationListener = authenticationListener, + ) + private val woofService = RemoteModule.createWoofService( baseUrl = baseUrl, @@ -180,6 +190,7 @@ class AppModule(context: Context) { // data source private val authDataSource: AuthDataSource = AuthDataSourceImpl(service = authService) private val clubDataSource: ClubDataSource = ClubDataSourceImpl(service = clubService) + private val myClubDataSource: MyClubDataSource = MyClubDataSourceImpl(service = myClubService) private val tokenDataSource: TokenDataSource = TokenDataSourceImpl(tokenManager = tokenManager) private val addressDataSource: AddressDataSource = AddressDataSourceImpl(addressModule = addressModule) @@ -198,7 +209,7 @@ class AppModule(context: Context) { // repository private val authRepository: AuthRepository = AuthRepositoryImpl(source = authDataSource) private val clubRepository: ClubRepository = ClubRepositoryImpl(source = clubDataSource) - private val myClubRepository: MyClubRepository = MyClubRepositoryImpl() + private val myClubRepository: MyClubRepository = MyClubRepositoryImpl(source = myClubDataSource) private val tokenRepository: TokenRepository = TokenRepositoryImpl(source = tokenDataSource) private val kakaoLoginRepository: KakaoLoginRepository = KakaoLoginRepositoryImpl(dataSource = kakaoLoginDataSource) diff --git a/android/app/src/main/java/com/happy/friendogly/data/repository/MyClubRepositoryImpl.kt b/android/app/src/main/java/com/happy/friendogly/data/repository/MyClubRepositoryImpl.kt index 80671ff69..363b97bbb 100644 --- a/android/app/src/main/java/com/happy/friendogly/data/repository/MyClubRepositoryImpl.kt +++ b/android/app/src/main/java/com/happy/friendogly/data/repository/MyClubRepositoryImpl.kt @@ -1,97 +1,14 @@ package com.happy.friendogly.data.repository +import com.happy.friendogly.data.mapper.toDomain +import com.happy.friendogly.data.source.MyClubDataSource import com.happy.friendogly.domain.model.Club -import com.happy.friendogly.domain.model.ClubAddress -import com.happy.friendogly.domain.model.ClubState -import com.happy.friendogly.domain.model.Gender -import com.happy.friendogly.domain.model.SizeType import com.happy.friendogly.domain.repository.MyClubRepository -import kotlinx.datetime.toKotlinLocalDateTime -import java.time.LocalDateTime -// TODO: change club api -class MyClubRepositoryImpl : MyClubRepository { - override suspend fun getMyClubs(): Result> { - return dummyMyClub - } +class MyClubRepositoryImpl( + private val source: MyClubDataSource, +) : MyClubRepository { + override suspend fun getMyClubs(): Result> = source.getParticipatingClubs().mapCatching { it.toDomain() } - override suspend fun getMyHeadClubs(): Result> { - return dummyMyHeadClub - } + override suspend fun getMyHeadClubs(): Result> = source.getMyOwningClubs().mapCatching { it.toDomain() } } - -private val dummyMyHeadClub = - runCatching { - listOf( - Club( - id = -1, - title = "내가만든클럽~", - content = "내가 방장인 클럽", - ownerMemberName = "누누", - address = - ClubAddress( - "서울특별시", - "송파구", - "올림픽로", - ), - status = ClubState.OPEN, - createdAt = java.time.LocalDateTime.now().toKotlinLocalDateTime(), - allowedSize = - listOf( - SizeType.LARGE, - SizeType.SMALL, - ), - allowedGender = - listOf( - Gender.FEMALE, - Gender.MALE_NEUTERED, - ), - memberCapacity = 5, - currentMemberCount = 3, - imageUrl = null, - petImageUrls = - listOf( - null, - null, - ), - ), - ) - } - -private val dummyMyClub = - runCatching { - listOf( - Club( - id = -1, - title = "내가가입한클럽~", - content = "내가 가입한 클럽", - ownerMemberName = "땡이", - address = - ClubAddress( - "서울특별시", - "송파구", - "올림픽로", - ), - status = ClubState.OPEN, - createdAt = LocalDateTime.now().toKotlinLocalDateTime(), - allowedSize = - listOf( - SizeType.LARGE, - SizeType.SMALL, - ), - allowedGender = - listOf( - Gender.FEMALE, - Gender.MALE_NEUTERED, - ), - memberCapacity = 5, - currentMemberCount = 3, - imageUrl = null, - petImageUrls = - listOf( - null, - null, - ), - ), - ) - } diff --git a/android/app/src/main/java/com/happy/friendogly/data/source/MyClubDataSource.kt b/android/app/src/main/java/com/happy/friendogly/data/source/MyClubDataSource.kt new file mode 100644 index 000000000..28751369b --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/data/source/MyClubDataSource.kt @@ -0,0 +1,9 @@ +package com.happy.friendogly.data.source + +import com.happy.friendogly.data.model.ClubDto + +interface MyClubDataSource { + suspend fun getMyOwningClubs(): Result> + + suspend fun getParticipatingClubs(): Result> +} diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/add/ClubAddActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/add/ClubAddActivity.kt index ec9c050fc..f89cffb8b 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/add/ClubAddActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/add/ClubAddActivity.kt @@ -18,8 +18,8 @@ import com.happy.friendogly.databinding.ActivityClubAddBinding import com.happy.friendogly.presentation.base.BaseActivity import com.happy.friendogly.presentation.base.observeEvent import com.happy.friendogly.presentation.ui.club.add.adapter.ClubAddAdapter +import com.happy.friendogly.presentation.ui.club.common.ClubChangeStateIntent import com.happy.friendogly.presentation.ui.club.common.model.clubfilter.ClubFilter -import com.happy.friendogly.presentation.ui.club.list.ClubListFragment.Companion.CHANGE_CLUB_LIST_STATE import com.happy.friendogly.presentation.ui.club.select.PetSelectBottomSheet import com.happy.friendogly.presentation.ui.profilesetting.bottom.EditProfileImageBottomSheet import com.happy.friendogly.presentation.utils.saveBitmapToFile @@ -113,7 +113,7 @@ class ClubAddActivity : BaseActivity(R.layout.activity_c } private fun putLoadState() { - intent.putExtra(CHANGE_CLUB_LIST_STATE, true) + intent.putExtra(ClubChangeStateIntent.CHANGE_CLUB_STATE, true) setResult(Activity.RESULT_OK, intent) } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/common/ClubChangeStateIntent.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/common/ClubChangeStateIntent.kt new file mode 100644 index 000000000..35407d844 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/common/ClubChangeStateIntent.kt @@ -0,0 +1,5 @@ +package com.happy.friendogly.presentation.ui.club.common + +object ClubChangeStateIntent { + const val CHANGE_CLUB_STATE = "clubChangeState" +} diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/detail/ClubDetailActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/detail/ClubDetailActivity.kt index 29c13def4..52e6446dc 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/detail/ClubDetailActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/detail/ClubDetailActivity.kt @@ -15,10 +15,10 @@ import com.happy.friendogly.presentation.base.BaseActivity import com.happy.friendogly.presentation.base.observeEvent import com.happy.friendogly.presentation.dialog.PetAddAlertDialog import com.happy.friendogly.presentation.ui.chatlist.chat.ChatActivity +import com.happy.friendogly.presentation.ui.club.common.ClubChangeStateIntent import com.happy.friendogly.presentation.ui.club.common.model.clubfilter.ClubFilter import com.happy.friendogly.presentation.ui.club.detail.adapter.DetailProfileAdapter import com.happy.friendogly.presentation.ui.club.detail.model.ClubDetailProfileUiModel -import com.happy.friendogly.presentation.ui.club.list.ClubListFragment import com.happy.friendogly.presentation.ui.club.list.adapter.filter.FilterAdapter import com.happy.friendogly.presentation.ui.club.menu.ClubMenuBottomSheet import com.happy.friendogly.presentation.ui.club.modify.ClubModifyActivity @@ -49,11 +49,6 @@ class ClubDetailActivity : DetailProfileAdapter(this@ClubDetailActivity) } - override fun onResume() { - super.onResume() - viewModel.loadClub(receiveClubId()) - } - override fun initCreateView() { initDataBinding() initAdapter() @@ -62,6 +57,11 @@ class ClubDetailActivity : initClubModifyResultLauncher() } + override fun onResume() { + super.onResume() + viewModel.loadClub(receiveClubId()) + } + private fun initClubModifyResultLauncher() { clubModifyResultLauncher = registerForActivityResult( @@ -218,7 +218,7 @@ class ClubDetailActivity : } private fun putLoadState() { - intent.putExtra(ClubListFragment.CHANGE_CLUB_LIST_STATE, true) + intent.putExtra(ClubChangeStateIntent.CHANGE_CLUB_STATE, true) setResult(Activity.RESULT_OK, intent) } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/list/ClubListFragment.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/list/ClubListFragment.kt index ccd315d5c..6ea099eec 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/list/ClubListFragment.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/list/ClubListFragment.kt @@ -14,6 +14,7 @@ import com.happy.friendogly.presentation.base.BaseFragment import com.happy.friendogly.presentation.base.observeEvent import com.happy.friendogly.presentation.dialog.PetAddAlertDialog import com.happy.friendogly.presentation.ui.MainActivityActionHandler +import com.happy.friendogly.presentation.ui.club.common.ClubChangeStateIntent import com.happy.friendogly.presentation.ui.club.common.ClubItemActionHandler import com.happy.friendogly.presentation.ui.club.common.adapter.club.ClubListAdapter import com.happy.friendogly.presentation.ui.club.filter.bottom.ClubFilterBottomSheet @@ -70,7 +71,7 @@ class ClubListFragment : BaseFragment(R.layout.fragment if (result.resultCode == Activity.RESULT_OK) { val isChange = result.data?.getBooleanExtra( - CHANGE_CLUB_LIST_STATE, + ClubChangeStateIntent.CHANGE_CLUB_STATE, false, ) ?: false if (isChange) { @@ -170,8 +171,4 @@ class ClubListFragment : BaseFragment(R.layout.fragment binding.includeClubList.rcvClubListClub.visibility = View.GONE currentView.visibility = View.VISIBLE } - - companion object { - const val CHANGE_CLUB_LIST_STATE = "clubListChangeState" - } } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubActivity.kt index e09044753..cf6c34a56 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubActivity.kt @@ -2,16 +2,27 @@ package com.happy.friendogly.presentation.ui.club.my import android.content.Context import android.content.Intent +import androidx.activity.viewModels import com.google.android.material.tabs.TabLayoutMediator import com.happy.friendogly.R +import com.happy.friendogly.application.di.AppModule import com.happy.friendogly.databinding.ActivityMyClubBinding import com.happy.friendogly.presentation.base.BaseActivity +import com.happy.friendogly.presentation.base.observeEvent +import com.happy.friendogly.presentation.dialog.PetAddAlertDialog import com.happy.friendogly.presentation.ui.club.add.ClubAddActivity import com.happy.friendogly.presentation.ui.club.detail.ClubDetailActivity import com.happy.friendogly.presentation.ui.club.my.adapter.MyClubAdapter +import com.happy.friendogly.presentation.ui.registerpet.RegisterPetActivity class MyClubActivity : BaseActivity(R.layout.activity_my_club), MyClubActionHandler { + private val viewModel: MyClubViewModel by viewModels { + MyClubViewModel.factory( + getPetsMineUseCase = AppModule.getInstance().getPetsMineUseCase, + ) + } + private val adapter: MyClubAdapter by lazy { MyClubAdapter(this@MyClubActivity) } @@ -21,6 +32,7 @@ class MyClubActivity : initViewPager() initTabLayout() initPage() + initObserver() } private fun initDataBinding() { @@ -42,6 +54,26 @@ class MyClubActivity : updateClubFragment(isMyHead) } + private fun initObserver() { + viewModel.myClubEvent.observeEvent(this) { event -> + when (event) { + MyClubEvent.AddPet.OpenAddClub -> + startActivity(ClubAddActivity.getIntent(this)) + + MyClubEvent.AddPet.OpenAddPet -> openRegisterPetDialog() + } + } + } + + private fun openRegisterPetDialog() { + PetAddAlertDialog( + clickToNegative = {}, + clickToPositive = { + startActivity(RegisterPetActivity.getIntent(this, null)) + }, + ).show(supportFragmentManager, "TAG") + } + private fun updateClubFragment(isMyHead: Boolean) { if (isMyHead) { binding.vpMyClub.setCurrentItem(1, true) @@ -63,7 +95,7 @@ class MyClubActivity : } override fun addClub() { - startActivity(ClubAddActivity.getIntent(this)) + viewModel.loadPetState() } override fun openClub(clubId: Long) { diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubEvent.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubEvent.kt index f75dd6345..876b8ca0f 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubEvent.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubEvent.kt @@ -6,4 +6,10 @@ sealed interface MyClubEvent { data object NavigateToAddClub : Navigation } + + sealed interface AddPet : MyClubEvent { + data object OpenAddPet : AddPet + + data object OpenAddClub : AddPet + } } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubViewModel.kt new file mode 100644 index 000000000..3a67aaddf --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/MyClubViewModel.kt @@ -0,0 +1,47 @@ +package com.happy.friendogly.presentation.ui.club.my + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.viewModelScope +import com.happy.friendogly.domain.fold +import com.happy.friendogly.domain.usecase.GetPetsMineUseCase +import com.happy.friendogly.presentation.base.BaseViewModel +import com.happy.friendogly.presentation.base.BaseViewModelFactory +import com.happy.friendogly.presentation.base.Event +import com.happy.friendogly.presentation.base.emit +import kotlinx.coroutines.launch + +class MyClubViewModel( + private val getPetsMineUseCase: GetPetsMineUseCase, +) : BaseViewModel() { + private val _myClubEvent: MutableLiveData> = MutableLiveData() + val myClubEvent: LiveData> get() = _myClubEvent + + fun loadPetState() = + viewModelScope.launch { + getPetsMineUseCase() + .fold( + onSuccess = { pets -> + if (pets.isEmpty()) { + _myClubEvent.emit(MyClubEvent.AddPet.OpenAddPet) + } else { + _myClubEvent.emit(MyClubEvent.AddPet.OpenAddClub) + } + }, + onError = { + // TODO 예외처리 + }, + ) + } + + companion object { + fun factory(getPetsMineUseCase: GetPetsMineUseCase): ViewModelProvider.Factory { + return BaseViewModelFactory { + MyClubViewModel( + getPetsMineUseCase = getPetsMineUseCase, + ) + } + } + } +} diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/adapter/MyClubAdapter.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/adapter/MyClubAdapter.kt index d218901ff..b9fefc5cf 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/adapter/MyClubAdapter.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/adapter/MyClubAdapter.kt @@ -3,13 +3,13 @@ package com.happy.friendogly.presentation.ui.club.my.adapter import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.viewpager2.adapter.FragmentStateAdapter -import com.happy.friendogly.presentation.ui.club.my.club.MyClubFragment import com.happy.friendogly.presentation.ui.club.my.head.MyHeadClubFragment +import com.happy.friendogly.presentation.ui.club.my.participating.MyParticipatingFragment class MyClubAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) { private val myClubFragments: List = listOf( - MyClubFragment(), + MyParticipatingFragment(), MyHeadClubFragment(), ) diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubFragment.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubFragment.kt index 252ebf88f..5d7befe2c 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubFragment.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubFragment.kt @@ -29,6 +29,11 @@ class MyHeadClubFragment : BaseFragment(R.layout.fragment initObserver() } + override fun onResume() { + super.onResume() + viewModel.loadMyHeadClubs() + } + private fun initDataBinding() { binding.actionHandler = viewModel binding.includeClubList.rcvClubListClub.adapter = adapter diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubViewModel.kt index 9f99a33b9..72bd594ce 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/head/MyHeadClubViewModel.kt @@ -25,14 +25,14 @@ class MyHeadClubViewModel( private val _myHeadClubUiState: MutableLiveData = MutableLiveData() val myHeadClubUiState: LiveData get() = _myHeadClubUiState - private val _myClubEvent: MutableLiveData> = MutableLiveData() - val myClubEvent: LiveData> get() = _myClubEvent + private val _myClubEvent: MutableLiveData> = MutableLiveData() + val myClubEvent: LiveData> get() = _myClubEvent init { loadMyHeadClubs() } - private fun loadMyHeadClubs() = + fun loadMyHeadClubs() = viewModelScope.launch { getMyHeadClubUseCase() .onSuccess { clubs -> diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/club/MyClubViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/participating/MyParticipatingClubViewModel.kt similarity index 86% rename from android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/club/MyClubViewModel.kt rename to android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/participating/MyParticipatingClubViewModel.kt index fa6b28104..845b932b9 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/club/MyClubViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/participating/MyParticipatingClubViewModel.kt @@ -1,4 +1,4 @@ -package com.happy.friendogly.presentation.ui.club.my.club +package com.happy.friendogly.presentation.ui.club.my.participating import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -16,7 +16,7 @@ import com.happy.friendogly.presentation.ui.club.my.MyClubEvent import com.happy.friendogly.presentation.ui.club.my.MyClubUiState import kotlinx.coroutines.launch -class MyClubViewModel( +class MyParticipatingClubViewModel( private val getMyClubUseCase: GetMyClubUseCase, ) : BaseViewModel(), ClubItemActionHandler { private val _myClubs: MutableLiveData> = MutableLiveData() @@ -25,14 +25,14 @@ class MyClubViewModel( private val _myClubUiState: MutableLiveData = MutableLiveData() val myClubUiState: LiveData get() = _myClubUiState - private val _myClubEvent: MutableLiveData> = MutableLiveData() - val myClubEvent: LiveData> get() = _myClubEvent + private val _myClubEvent: MutableLiveData> = MutableLiveData() + val myClubEvent: LiveData> get() = _myClubEvent init { loadMyClubs() } - private fun loadMyClubs() = + fun loadMyClubs() = viewModelScope.launch { getMyClubUseCase() .onSuccess { clubs -> @@ -59,7 +59,7 @@ class MyClubViewModel( companion object { fun factory(getMyClubUseCase: GetMyClubUseCase): ViewModelProvider.Factory { return BaseViewModelFactory { - MyClubViewModel( + MyParticipatingClubViewModel( getMyClubUseCase = getMyClubUseCase, ) } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/club/MyClubFragment.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/participating/MyParticipatingFragment.kt similarity index 86% rename from android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/club/MyClubFragment.kt rename to android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/participating/MyParticipatingFragment.kt index f3c3d4cb7..b8ed0b7b9 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/club/MyClubFragment.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/my/participating/MyParticipatingFragment.kt @@ -1,4 +1,4 @@ -package com.happy.friendogly.presentation.ui.club.my.club +package com.happy.friendogly.presentation.ui.club.my.participating import android.view.View import androidx.fragment.app.viewModels @@ -13,9 +13,9 @@ import com.happy.friendogly.presentation.ui.club.my.MyClubActivity import com.happy.friendogly.presentation.ui.club.my.MyClubEvent import com.happy.friendogly.presentation.ui.club.my.MyClubUiState -class MyClubFragment : BaseFragment(R.layout.fragment_my_club) { - private val viewModel: MyClubViewModel by viewModels { - MyClubViewModel.factory( +class MyParticipatingFragment : BaseFragment(R.layout.fragment_my_club) { + private val viewModel: MyParticipatingClubViewModel by viewModels { + MyParticipatingClubViewModel.factory( getMyClubUseCase = AppModule.getInstance().getMyClubsUseCase, ) } @@ -29,6 +29,11 @@ class MyClubFragment : BaseFragment(R.layout.fragment_my_ initObserver() } + override fun onResume() { + super.onResume() + viewModel.loadMyClubs() + } + private fun initDataBinding() { binding.actionHandler = viewModel binding.includeClubList.rcvClubListClub.adapter = adapter diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/select/PetSelectViewModel.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/select/PetSelectViewModel.kt index ff0bcafb7..f94546b17 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/select/PetSelectViewModel.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/club/select/PetSelectViewModel.kt @@ -88,7 +88,7 @@ class PetSelectViewModel( } override fun submitDogs() { - validCommit.value?.takeIf { it } ?: return preventCommit() + validCommit.value?.takeIf { it } ?: return preventComplete() _petSelectEvent.emit( PetSelectEvent.SelectPets( pets = selectedPets.map { it.id }, @@ -96,7 +96,7 @@ class PetSelectViewModel( ) } - private fun preventCommit() { + private fun preventComplete() { _petSelectEvent.emit(PetSelectEvent.PreventCommit) } diff --git a/android/app/src/main/java/com/happy/friendogly/presentation/ui/mylocation/SettingMyLocationActivity.kt b/android/app/src/main/java/com/happy/friendogly/presentation/ui/mylocation/SettingMyLocationActivity.kt index 701ba42fb..418cd04ee 100644 --- a/android/app/src/main/java/com/happy/friendogly/presentation/ui/mylocation/SettingMyLocationActivity.kt +++ b/android/app/src/main/java/com/happy/friendogly/presentation/ui/mylocation/SettingMyLocationActivity.kt @@ -15,7 +15,7 @@ import com.happy.friendogly.databinding.ActivitySettingMyLocationBinding import com.happy.friendogly.presentation.base.BaseActivity import com.happy.friendogly.presentation.base.observeEvent import com.happy.friendogly.presentation.ui.MainActivity -import com.happy.friendogly.presentation.ui.club.list.ClubListFragment +import com.happy.friendogly.presentation.ui.club.common.ClubChangeStateIntent import com.happy.friendogly.presentation.ui.permission.LocationPermission import com.naver.maps.geometry.LatLng import com.naver.maps.map.CameraUpdate @@ -91,7 +91,7 @@ class SettingMyLocationActivity : } private fun putLoadState() { - intent.putExtra(ClubListFragment.CHANGE_CLUB_LIST_STATE, true) + intent.putExtra(ClubChangeStateIntent.CHANGE_CLUB_STATE, true) setResult(Activity.RESULT_OK, intent) } diff --git a/android/app/src/main/java/com/happy/friendogly/remote/api/ApiClient.kt b/android/app/src/main/java/com/happy/friendogly/remote/api/ApiClient.kt index b326315f1..a4658053a 100644 --- a/android/app/src/main/java/com/happy/friendogly/remote/api/ApiClient.kt +++ b/android/app/src/main/java/com/happy/friendogly/remote/api/ApiClient.kt @@ -40,6 +40,12 @@ class ApiClient { const val DELETE_CLUB_MEMBER = "$BASE_URL/{clubId}$MEMBER_URL" } + object MyClub { + private const val BASE_URL = "/clubs" + const val OWNING = "$BASE_URL/owning" + const val PARTICIPATING = "$BASE_URL/participating" + } + object Chat { private const val BASE_URL = "/chat-rooms" const val CHAT_LIST = "$BASE_URL/mine" diff --git a/android/app/src/main/java/com/happy/friendogly/remote/api/MyClubService.kt b/android/app/src/main/java/com/happy/friendogly/remote/api/MyClubService.kt new file mode 100644 index 000000000..a8e4100b1 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/remote/api/MyClubService.kt @@ -0,0 +1,13 @@ +package com.happy.friendogly.remote.api + +import com.happy.friendogly.remote.model.response.BaseResponse +import com.happy.friendogly.remote.model.response.ClubResponse +import retrofit2.http.GET + +interface MyClubService { + @GET(ApiClient.MyClub.OWNING) + suspend fun getMyOwningClubs(): BaseResponse> + + @GET(ApiClient.MyClub.PARTICIPATING) + suspend fun getParticipatingClubs(): BaseResponse> +} diff --git a/android/app/src/main/java/com/happy/friendogly/remote/di/RemoteModule.kt b/android/app/src/main/java/com/happy/friendogly/remote/di/RemoteModule.kt index 09cdbd138..b38abd7db 100644 --- a/android/app/src/main/java/com/happy/friendogly/remote/di/RemoteModule.kt +++ b/android/app/src/main/java/com/happy/friendogly/remote/di/RemoteModule.kt @@ -9,6 +9,7 @@ import com.happy.friendogly.remote.api.BaseUrl import com.happy.friendogly.remote.api.ChatService import com.happy.friendogly.remote.api.ClubService import com.happy.friendogly.remote.api.MemberService +import com.happy.friendogly.remote.api.MyClubService import com.happy.friendogly.remote.api.PetService import com.happy.friendogly.remote.api.WoofService import com.happy.friendogly.remote.interceptor.AuthorizationInterceptor @@ -21,6 +22,7 @@ import okhttp3.logging.HttpLoggingInterceptor import org.hildan.krossbow.stomp.StompClient import org.hildan.krossbow.websocket.okhttp.OkHttpWebSocketClient import retrofit2.Retrofit +import retrofit2.create import java.time.Duration object RemoteModule { @@ -57,6 +59,18 @@ object RemoteModule { ).create(ClubService::class.java) } + fun createMyClubService( + baseUrl: BaseUrl, + tokenManager: TokenManager, + authenticationListener: AuthenticationListener, + ): MyClubService { + return createRetrofit( + baseUrl, + tokenManager, + authenticationListener, + ).create(MyClubService::class.java) + } + fun createWoofService( baseUrl: BaseUrl, tokenManager: TokenManager, diff --git a/android/app/src/main/java/com/happy/friendogly/remote/source/MyClubDataSourceImpl.kt b/android/app/src/main/java/com/happy/friendogly/remote/source/MyClubDataSourceImpl.kt new file mode 100644 index 000000000..4b4c9f579 --- /dev/null +++ b/android/app/src/main/java/com/happy/friendogly/remote/source/MyClubDataSourceImpl.kt @@ -0,0 +1,20 @@ +package com.happy.friendogly.remote.source + +import com.happy.friendogly.data.model.ClubDto +import com.happy.friendogly.data.source.MyClubDataSource +import com.happy.friendogly.remote.api.MyClubService +import com.happy.friendogly.remote.mapper.toData + +class MyClubDataSourceImpl( + private val service: MyClubService, +) : MyClubDataSource { + override suspend fun getMyOwningClubs(): Result> = + runCatching { + service.getMyOwningClubs().data.toData() + } + + override suspend fun getParticipatingClubs(): Result> = + runCatching { + service.getParticipatingClubs().data.toData() + } +} diff --git a/android/app/src/main/res/layout/activity_club_add.xml b/android/app/src/main/res/layout/activity_club_add.xml index 78c50132b..f15736811 100644 --- a/android/app/src/main/res/layout/activity_club_add.xml +++ b/android/app/src/main/res/layout/activity_club_add.xml @@ -16,36 +16,12 @@ android:paddingHorizontal="10dp" tools:context=".presentation.ui.club.add.ClubAddActivity"> - - - - - - - - - + android:layout_height="match_parent" + tools:layout_editor_absoluteX="10dp" + tools:layout_editor_absoluteY="0dp" /> + + + + + + + + + diff --git a/android/app/src/main/res/layout/fragment_my_club.xml b/android/app/src/main/res/layout/fragment_my_club.xml index bafc454ed..a8082612d 100644 --- a/android/app/src/main/res/layout/fragment_my_club.xml +++ b/android/app/src/main/res/layout/fragment_my_club.xml @@ -12,7 +12,7 @@ + tools:context=".presentation.ui.club.my.participating.MyParticipatingFragment">