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 a043c10 commit d917007
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ class MainFragmentViewModelModule {
)
}

@Provides
@FragmentScoped
fun provideNonReviewViewModel(): NonReviewViewModel {
return NonReviewViewModel()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.ftw.hometerview.ui.writtenreview.nonreview

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.databinding.FragmentNonReviewBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class NonReviewFragment : Fragment() {

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

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

@Inject
lateinit var viewModel: NonReviewViewModel

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

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

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

private fun observeEvent() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.event.collect { event ->
when (event) {
NonReviewViewModel.Event.None -> {}
NonReviewViewModel.Event.onClickWriteReview -> {
// ㄹㅣ뷰 작성 화면으로 이동
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ftw.hometerview.ui.writtenreview.nonreview

import kotlinx.coroutines.flow.*

class NonReviewViewModel() {

sealed class Event {
object None : Event()
object onClickWriteReview : Event()
}

private val _event: MutableStateFlow<Event> = MutableStateFlow(Event.None)
val event: StateFlow<Event> = _event.asStateFlow()

fun onClickWriteReview() {
_event.value = Event.onClickWriteReview
_event.value = Event.None
}

}
47 changes: 47 additions & 0 deletions app/src/main/res/layout/fragment_non_review.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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="viewModel"
type="com.ftw.hometerview.ui.writtenreview.nonreview.NonReviewViewModel"
/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView
android:id="@+id/non_review_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/pretendard_regular"
android:text="작성한 집터뷰가 없어요"
android:textColor="@color/gray_600"
android:layout_marginBottom="@dimen/dp_size_32"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="작성한 집터뷰가 없어요"
/>

<com.ftw.hometerview.design.MainButton
android:id="@+id/write_review_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="집터뷰 작성하기"
android:onClick="@{() -> viewModel.onClickWriteReview()}"
android:layout_marginTop="@dimen/dp_size_16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/non_review_text"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit d917007

Please sign in to comment.