Skip to content

Commit

Permalink
�[AN] feat: 내가 만든 & 방장인 모임 구체화 (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong authored Aug 20, 2024
1 parent d52c431 commit e5ae98b
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<Club>> {
return dummyMyClub
}
class MyClubRepositoryImpl(
private val source: MyClubDataSource,
) : MyClubRepository {
override suspend fun getMyClubs(): Result<List<Club>> = source.getParticipatingClubs().mapCatching { it.toDomain() }

override suspend fun getMyHeadClubs(): Result<List<Club>> {
return dummyMyHeadClub
}
override suspend fun getMyHeadClubs(): Result<List<Club>> = 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,
),
),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.happy.friendogly.data.source

import com.happy.friendogly.data.model.ClubDto

interface MyClubDataSource {
suspend fun getMyOwningClubs(): Result<List<ClubDto>>

suspend fun getParticipatingClubs(): Result<List<ClubDto>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,7 +113,7 @@ class ClubAddActivity : BaseActivity<ActivityClubAddBinding>(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)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.happy.friendogly.presentation.ui.club.common

object ClubChangeStateIntent {
const val CHANGE_CLUB_STATE = "clubChangeState"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,11 +49,6 @@ class ClubDetailActivity :
DetailProfileAdapter(this@ClubDetailActivity)
}

override fun onResume() {
super.onResume()
viewModel.loadClub(receiveClubId())
}

override fun initCreateView() {
initDataBinding()
initAdapter()
Expand All @@ -62,6 +57,11 @@ class ClubDetailActivity :
initClubModifyResultLauncher()
}

override fun onResume() {
super.onResume()
viewModel.loadClub(receiveClubId())
}

private fun initClubModifyResultLauncher() {
clubModifyResultLauncher =
registerForActivityResult(
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,7 +71,7 @@ class ClubListFragment : BaseFragment<FragmentClubListBinding>(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) {
Expand Down Expand Up @@ -170,8 +171,4 @@ class ClubListFragment : BaseFragment<FragmentClubListBinding>(R.layout.fragment
binding.includeClubList.rcvClubListClub.visibility = View.GONE
currentView.visibility = View.VISIBLE
}

companion object {
const val CHANGE_CLUB_LIST_STATE = "clubListChangeState"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActivityMyClubBinding>(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)
}
Expand All @@ -21,6 +32,7 @@ class MyClubActivity :
initViewPager()
initTabLayout()
initPage()
initObserver()
}

private fun initDataBinding() {
Expand All @@ -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)
Expand All @@ -63,7 +95,7 @@ class MyClubActivity :
}

override fun addClub() {
startActivity(ClubAddActivity.getIntent(this))
viewModel.loadPetState()
}

override fun openClub(clubId: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ sealed interface MyClubEvent {

data object NavigateToAddClub : Navigation
}

sealed interface AddPet : MyClubEvent {
data object OpenAddPet : AddPet

data object OpenAddClub : AddPet
}
}
Original file line number Diff line number Diff line change
@@ -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<Event<MyClubEvent.AddPet>> = MutableLiveData()
val myClubEvent: LiveData<Event<MyClubEvent.AddPet>> 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,
)
}
}
}
}
Loading

0 comments on commit e5ae98b

Please sign in to comment.