Skip to content

Commit

Permalink
[D83T-66] 메인 탭 바텀시트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
YHKOO95 committed Mar 3, 2023
1 parent b647a1d commit 5a4278b
Show file tree
Hide file tree
Showing 22 changed files with 228 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.d83t.bpm.data.repositoryImpl

import com.d83t.bpm.data.model.response.StudioListResponse.Companion.toDataModel
import com.d83t.bpm.data.model.response.StudioResponse.Companion.toDataModel
import com.d83t.bpm.data.network.BPMResponse
import com.d83t.bpm.data.network.BPMResponseHandler
import com.d83t.bpm.data.network.ErrorResponse.Companion.toDataModel
import com.d83t.bpm.data.network.MainApi
import com.d83t.bpm.domain.model.ResponseState
import com.d83t.bpm.domain.model.Studio
import com.d83t.bpm.domain.model.StudioList
import com.d83t.bpm.domain.repository.SearchStudioRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
Expand All @@ -19,13 +21,13 @@ class SearchStudioRepositoryImpl @Inject constructor(
) : SearchStudioRepository {
override suspend fun fetchSearchStudioResult(
query: String
): Flow<ResponseState<List<Studio>>> {
): Flow<ResponseState<StudioList>> {
return flow {
BPMResponseHandler().handle {
mainApi.searchStudio(query = query)
}.onEach { result ->
when (result) {
is BPMResponse.Success -> emit(ResponseState.Success(result.data.studios.map { it.toDataModel() }))
is BPMResponse.Success -> emit(ResponseState.Success(result.data.toDataModel()))
is BPMResponse.Error -> emit(ResponseState.Error(result.error.toDataModel()))
}
}.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.d83t.bpm.domain.repository

import com.d83t.bpm.domain.model.ResponseState
import com.d83t.bpm.domain.model.Studio
import com.d83t.bpm.domain.model.StudioList
import kotlinx.coroutines.flow.Flow

interface SearchStudioRepository {
suspend fun fetchSearchStudioResult(
query: String
) : Flow<ResponseState<List<Studio>>>
) : Flow<ResponseState<StudioList>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.d83t.bpm.domain.usecase.search_studio

import com.d83t.bpm.domain.model.ResponseState
import com.d83t.bpm.domain.model.Studio
import com.d83t.bpm.domain.model.StudioList
import com.d83t.bpm.domain.repository.SearchStudioRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
Expand All @@ -11,7 +12,7 @@ class SearchStudioUseCase @Inject constructor(
) {
suspend operator fun invoke(
query: String
): Flow<ResponseState<List<Studio>>> {
): Flow<ResponseState<StudioList>> {
return searchStudioRepository.fetchSearchStudioResult(query = query)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.fragment.app.commitNow
import com.d83t.bpm.presentation.R
import com.d83t.bpm.presentation.base.BaseActivity
import com.d83t.bpm.presentation.databinding.ActivityMainBinding
import com.d83t.bpm.presentation.ui.main.add.MainAddBottomSheet
import com.d83t.bpm.presentation.ui.main.community.CommunityFragment
import com.d83t.bpm.presentation.ui.main.home.HomeFragment
import com.d83t.bpm.presentation.ui.main.mypage.MyPageFragment
Expand Down Expand Up @@ -55,7 +56,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
viewModel.event.collect { event ->
when (event) {
MainViewEvent.Add -> {
showToast("Add Clicked")
showAddBottomSheet()
}
}
}
Expand All @@ -76,6 +77,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
}
}

private fun showAddBottomSheet(){
MainAddBottomSheet().show(supportFragmentManager, MainAddBottomSheet::class.simpleName)
}

private fun changeFragment(fragmentId: Int? = null) {
val fragment = when (fragmentId) {
R.id.nav_noti -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.d83t.bpm.presentation.ui.main.add

import androidx.fragment.app.viewModels
import com.d83t.bpm.presentation.R
import com.d83t.bpm.presentation.base.BaseBottomSheetFragment
import com.d83t.bpm.presentation.databinding.BottomsheetMainAddBinding
import com.d83t.bpm.presentation.util.repeatCallDefaultOnStarted
import com.d83t.bpm.presentation.util.showToast
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainAddBottomSheet :
BaseBottomSheetFragment<BottomsheetMainAddBinding>(BottomsheetMainAddBinding::inflate) {

override fun getTheme(): Int = R.style.DdoreumBottomSheetDialog

override val viewModel: MainAddViewModel by viewModels()

override fun initLayout() {
bind {
vm = viewModel
lifecycleOwner = viewLifecycleOwner
}
}

override fun setupCollect() {
repeatCallDefaultOnStarted {
viewModel.event.collect { event ->
when (event) {
MainAddViewEvent.Click -> {
requireContext().showToast("오픈 예정입니다!")
}
}
}
}
}

companion object {

fun newInstance(): MainAddBottomSheet {
return MainAddBottomSheet()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.d83t.bpm.presentation.ui.main.add

sealed interface MainAddViewEvent {
object Click : MainAddViewEvent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.d83t.bpm.presentation.ui.main.add

import androidx.lifecycle.viewModelScope
import com.d83t.bpm.presentation.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch

@HiltViewModel
class MainAddViewModel @Inject constructor() : BaseViewModel() {

private val _event = MutableSharedFlow<MainAddViewEvent>()
val event: SharedFlow<MainAddViewEvent>
get() = _event

fun clickDisable() {
viewModelScope.launch {
_event.emit(MainAddViewEvent.Click)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class HomeRecommendImageItemDecoration : ItemDecoration() {
state: RecyclerView.State
) {
super.getItemOffsets(outRect, view, parent, state)

outRect.bottom = 4.dp
outRect.top = 4.dp
outRect.left = 4.dp
outRect.right = 4.dp
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ class HomeRecommendViewHolder(
this.item = item

list.adapter = HomeRecommendImageAdapter()
list.addItemDecoration(HomeRecommendImageItemDecoration())

root.setOnClickListener {
listener.invoke(item.id)
}
}

}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,34 @@ package com.d83t.bpm.presentation.ui.main.mypage

import androidx.fragment.app.viewModels
import com.d83t.bpm.presentation.base.BaseFragment
import com.d83t.bpm.presentation.databinding.FragmentHomeBinding
import com.d83t.bpm.presentation.databinding.FragmentMypageBinding
import com.d83t.bpm.presentation.util.repeatCallDefaultOnStarted
import com.d83t.bpm.presentation.util.showToast
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MyPageFragment : BaseFragment<FragmentMypageBinding>(FragmentMypageBinding::inflate) {

override val viewModel: MyPageViewModel by viewModels()

override fun initLayout() = Unit
override fun initLayout() {
bind {
vm = viewModel
lifecycleOwner = viewLifecycleOwner
}
}

override fun setupCollect() {
repeatCallDefaultOnStarted {
viewModel.event.collect { event ->
when (event) {
MyPageViewEvent.Click -> {
requireContext().showToast("오픈 예정입니다!")
}
}
}
}
}

companion object {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.d83t.bpm.presentation.ui.main.mypage

sealed interface MyPageViewEvent {
object Click : MyPageViewEvent
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
package com.d83t.bpm.presentation.ui.main.mypage

import androidx.lifecycle.viewModelScope
import com.d83t.bpm.presentation.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch

@HiltViewModel
class MyPageViewModel @Inject constructor() : BaseViewModel() {

private val _event = MutableSharedFlow<MyPageViewEvent>()
val event: SharedFlow<MyPageViewEvent>
get() = _event

fun clickDisable() {
viewModelScope.launch {
_event.emit(MyPageViewEvent.Click)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SelectStudioViewModel @Inject constructor(
query = query
).onEach { state ->
when(state) {
is ResponseState.Success -> _state.emit(SelectStudioState.Success(state.data))
is ResponseState.Success -> _state.emit(SelectStudioState.Success(state.data.studios ?: emptyList()))
is ResponseState.Error -> _state.emit(SelectStudioState.Error)
}
}.launchIn(viewModelScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fun View.bindVisibleOrGone(text: String?) {
}
}


@BindingAdapter("bind:list_item")
fun RecyclerView.bindListItems(list: List<Any>?) {
if (adapter != null) {
Expand All @@ -44,6 +43,7 @@ fun RecyclerView.bindListItems(list: List<Any>?) {
@BindingAdapter("bind:review_chips")
fun ChipGroup.bindChips(reviewList: List<String>?) {
if (reviewList.isNullOrEmpty()) return else {
isClickable = false
reviewList.forEach {
addView(
Chip(context).apply {
Expand Down
8 changes: 8 additions & 0 deletions presentation/src/main/res/drawable/bg_bottomsheet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
64 changes: 64 additions & 0 deletions presentation/src/main/res/layout/bottomsheet_main_add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/bind">

<data>

<variable
name="vm"
type="com.d83t.bpm.presentation.ui.main.add.MainAddViewModel" />

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="40dp">

<View
android:id="@+id/divider"
android:layout_width="56dp"
android:layout_height="4dp"
android:layout_marginTop="12dp"
android:background="@color/gray_05"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<include
android:id="@+id/content_eyebody"
layout="@layout/layout_mypage_content_disable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider"
app:onItemClick="@{vm.clickDisable}"
bind:content="@{@string/main_add_eyebody}" />

<include
android:id="@+id/content_share"
layout="@layout/layout_mypage_content_disable"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/content_eyebody"
app:onItemClick="@{vm.clickDisable}"
bind:content="@{@string/mypage_content_history_bf}" />

<include
android:id="@+id/content_ask"
layout="@layout/layout_mypage_content_disable"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/content_share"
app:onItemClick="@{vm.clickDisable}"
bind:content="@{@string/mypage_content_history_bf}" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
5 changes: 3 additions & 2 deletions presentation/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
style="@style/Widget.Design.TabLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -283,8 +284,8 @@
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:minHeight="1000dp"
android:layout_height="1200dp"
android:minHeight="1200dp"
android:nestedScrollingEnabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Loading

0 comments on commit 5a4278b

Please sign in to comment.