Skip to content

Commit

Permalink
#6 mypage_fragment/설정 화면 : 3 작성한 리뷰 화면
Browse files Browse the repository at this point in the history
 - 내가 작성한 리뷰가 있는 경우의 화면 구현
  • Loading branch information
likppi10 committed Aug 23, 2022
1 parent 7a687cd commit a043c10
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import com.ftw.domain.usecase.favorite.GetFavoriteBuildingsUseCase
import com.ftw.domain.usecase.favorite.GetFavoriteReviewsUseCase
import com.ftw.domain.usecase.review.GetLocationReviewsUseCase
import com.ftw.domain.usecase.user.GetCachedUserUseCase
import com.ftw.domain.usecase.writtenreview.GetWrittenReviewsUseCase
import com.ftw.hometerview.dispatcher.Dispatcher
import com.ftw.hometerview.ui.main.favorite.favoritelist.FavoriteBuildingsViewModel
import com.ftw.hometerview.ui.main.favorite.favoritelist.FavoriteReviewsViewModel
import com.ftw.hometerview.ui.main.home.HomeViewModel
import com.ftw.hometerview.ui.main.home.review.LocationReviewListViewModel
import com.ftw.hometerview.ui.main.mypage.MyPageViewModel
import com.ftw.hometerview.ui.writtenreview.nonreview.NonReviewViewModel
import com.ftw.hometerview.ui.writtenreview.writtenreviewlist.WrittenReviewListViewModel
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -84,4 +87,17 @@ class MainFragmentViewModelModule {
getFavoriteReviewsUseCase
)
}

@Provides
@FragmentScoped
fun provideWrittenReviewListViewModel(
dispatcher: Dispatcher,
getWrittenReviewsUseCase: GetWrittenReviewsUseCase
): WrittenReviewListViewModel {
return WrittenReviewListViewModel(
dispatcher,
getWrittenReviewsUseCase
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.ftw.hometerview.ui.writtenreview.writtenreviewlist

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.ftw.hometerview.R
import com.ftw.hometerview.adapter.DataBindingRecyclerAdapter
import com.ftw.hometerview.adapter.SpacingItemDecoration
import com.ftw.hometerview.databinding.FragmentFavoriteReviewBinding
import com.ftw.hometerview.databinding.FragmentWrittenReviewListBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class WrittenReviewListFragment : Fragment() {

companion object {
fun newInstance(): WrittenReviewListFragment {
return WrittenReviewListFragment()
}
}

private var _binding: FragmentWrittenReviewListBinding? = null
private val binding get() = _binding!!

@Inject
lateinit var viewModel: WrittenReviewListViewModel

private val adapter = DataBindingRecyclerAdapter()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = DataBindingUtil.inflate<FragmentWrittenReviewListBinding?>(
inflater,
R.layout.fragment_written_review_list,
container,
false
).apply {
viewModel = this@WrittenReviewListFragment.viewModel
}
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
initList()
observe()
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun initList() {
binding.list.adapter = adapter
context?.let { binding.list.addItemDecoration(SpacingItemDecoration(it)) }
}

private fun observe() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.writtenRevieewItems.collect {
adapter.submitList(it)
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.ftw.hometerview.ui.writtenreview.writtenreviewlist

import com.ftw.domain.entity.WrittenReview
import com.ftw.domain.usecase.writtenreview.GetWrittenReviewsUseCase
import com.ftw.hometerview.BR
import com.ftw.hometerview.R
import com.ftw.hometerview.adapter.RecyclerItem
import com.ftw.hometerview.dispatcher.Dispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.*

class WrittenReviewListViewModel(
dispatcher: Dispatcher,
private val getWrittenReviewsUseCase: GetWrittenReviewsUseCase
) {

sealed class State {
object Loading : State()
class OnClickReview(val buildingId: Long) : State()
}

private val _state: MutableStateFlow<State> = MutableStateFlow(
State.Loading
)
val state: StateFlow<State> = _state.asStateFlow()

val writtenRevieewItems: StateFlow<List<RecyclerItem>> =
flow {
emit(
getWrittenReviewsUseCase()
.map { writtenReview ->
RecyclerItem(
data = WrittenReviewItem(
onClickItem = { buildingId ->
_state.value = State.OnClickReview(buildingId)
},
writtenReview = writtenReview
),
layoutId = R.layout.list_item_written_review,
variableId = BR.item
)
}
)
}.stateIn(CoroutineScope(dispatcher.ui()), SharingStarted.Eagerly, emptyList())

}

data class WrittenReviewItem(
val onClickItem: (buildingId: Long) -> Unit,
val writtenReview: WrittenReview
) {

fun onItemClick() {
onClickItem(writtenReview.buildingId)
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/fragment_written_review_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
>

<data>
<variable
name="viewModel"
type="com.ftw.hometerview.ui.writtenreview.writtenreviewlist.WrittenReviewListViewModel"
/>
</data>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/list_item_favorite_review"
tools:itemCount="10"
/>
</layout>
202 changes: 202 additions & 0 deletions app/src/main/res/layout/list_item_written_review.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?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:tools="http://schemas.android.com/tools"
>

<data>

<variable
name="item"
type="com.ftw.hometerview.ui.writtenreview.writtenreviewlist.WrittenReviewItem"
/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_size_14"
android:background="@drawable/bg_location_review_item"
android:onClick="@{() -> item.onItemClick()}"
>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_size_16"
android:fontFamily="@font/pretendard_regular"
android:textColor="@color/gray_500"
android:textSize="@dimen/sp_size_12"
android:text="@{item.writtenReview.leftAt.toString()}"
app:layout_constraintStart_toStartOf="@+id/building_name_text_view"
app:layout_constraintTop_toTopOf="parent"
tools:text="2021.08.21"
/>

<TextView
android:id="@+id/building_name_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_size_20"
android:ellipsize="end"
android:fontFamily="@font/pretendard_bold"
android:maxLines="1"
android:text="@{item.writtenReview.buildingName}"
android:textColor="@color/black"
android:textSize="@dimen/sp_size_18"
app:drawableEndCompat="@drawable/ic_baseline_navigate_next_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:text="아크로텔 오피스텔"
/>

<RatingBar
android:id="@+id/rating_bar"
style="@style/StarRatingBarSize12"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_size_12"
android:layout_marginStart="@dimen/sp_size_14"
android:layout_marginTop="@dimen/dp_size_8"
android:isIndicator="true"
android:max="5"
android:numStars="5"
android:progressBackgroundTint="@color/gray_200"
android:progressTint="@color/blue_300"
android:rating="@{item.writtenReview.rating}"
android:stepSize="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/building_name_text_view"
app:tint="@color/selector_rating_bar"
/>

<TextView
android:id="@+id/building_summary_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_size_8"
android:fontFamily="@font/pretendard_regular"
android:text="@{item.writtenReview.summary}"
android:textColor="@color/blue_300"
android:textSize="@dimen/sp_size_12"
app:layout_constraintStart_toStartOf="@+id/rating_bar"
app:layout_constraintTop_toBottomOf="@+id/rating_bar"
tools:text="내 집이 최고"
/>

<View
android:id="@+id/divide_line"
android:layout_width="@dimen/dp_size_1"
android:layout_height="@dimen/dp_size_12"
android:layout_marginStart="@dimen/dp_size_4"
android:background="@color/gray_200"
app:layout_constraintBottom_toBottomOf="@+id/building_summary_text_view"
app:layout_constraintStart_toEndOf="@+id/building_summary_text_view"
app:layout_constraintTop_toTopOf="@+id/building_summary_text_view"
app:layout_constraintVertical_bias="0.615"
/>

<TextView
android:id="@+id/review_summary_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_size_4"
android:fontFamily="@font/pretendard_regular"
android:text="@{@string/home_location_review_summary(item.writtenReview.residentialPeriod, item.writtenReview.residentialFloor, item.writtenReview.officeLocation)}"
android:textColor="@color/gray_600"
android:textSize="@dimen/sp_size_12"
app:layout_constraintBottom_toBottomOf="@+id/building_summary_text_view"
app:layout_constraintStart_toEndOf="@+id/divide_line"
app:layout_constraintTop_toTopOf="@+id/building_summary_text_view"
tools:text="3년 전 거주 · 역삼역 통근"
/>

<TextView
android:id="@+id/advantage_title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_size_14"
android:layout_marginTop="@dimen/dp_size_16"
android:fontFamily="@font/pretendard_medium"
android:text="@string/advantage_title"
android:textColor="@color/blue_300"
android:textSize="@dimen/sp_size_12"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/building_summary_text_view"
/>

<TextView
android:id="@+id/advantage_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_size_14"
android:layout_marginTop="@dimen/dp_size_2"
android:fontFamily="@font/pretendard_medium"
android:text="@{item.writtenReview.savedAdvantage}"
android:textColor="@color/gray_800"
android:textSize="@dimen/sp_size_12"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/advantage_title_text_view"
/>

<TextView
android:id="@+id/disadvantage_title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_size_14"
android:layout_marginTop="@dimen/dp_size_16"
android:fontFamily="@font/pretendard_medium"
android:text="@string/disadvantage_title"
android:textColor="@color/red_500"
android:textSize="@dimen/sp_size_12"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/advantage_text_view"
/>

<TextView
android:id="@+id/disadvantage_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_size_14"
android:layout_marginTop="@dimen/dp_size_2"
android:fontFamily="@font/pretendard_medium"
android:text="@{item.writtenReview.savedAdvantage}"
android:textColor="@color/gray_800"
android:textSize="@dimen/sp_size_12"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/disadvantage_title_text_view"
/>

<com.ftw.hometerview.design.Button
android:id="@+id/good_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_size_14"
android:layout_marginTop="@dimen/dp_size_24"
android:layout_marginBottom="@dimen/dp_size_16"
android:drawableStart="@drawable/icon_heart"
android:text="@string/it_helps"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/disadvantage_text_view"
app:number="9"
/>

<com.ftw.hometerview.design.Button
android:id="@+id/favorite_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_size_14"
android:layout_marginTop="@dimen/dp_size_24"
android:layout_marginBottom="@dimen/dp_size_16"
android:drawableStart="@drawable/icon_heart"
android:text="@string/heart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/good_button"
app:layout_constraintTop_toBottomOf="@id/disadvantage_text_view"
/>

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>

0 comments on commit a043c10

Please sign in to comment.