Skip to content

Commit

Permalink
#6 feat/홈 : 홈 화면의 리뷰 리스트를 위한 Fragment 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HayleyKim0716 committed Aug 2, 2022
1 parent 517f302 commit 1942e23
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ftw.hometerview.ui.main.home

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.ftw.hometerview.ui.main.home.review.LocationReviewListFragment

class HomeViewPagerAdapter(fragmentActivity: FragmentActivity, locations: List<String>) :
FragmentStateAdapter(fragmentActivity) {

private val fragments: ArrayList<Fragment> = arrayListOf()

init {
locations.forEach {
fragments.add(LocationReviewListFragment.newInstance(it))
}
}

override fun getItemCount(): Int = fragments.size

override fun createFragment(position: Int): Fragment = fragments[position]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ftw.hometerview.ui.main.home.review

import com.ftw.domain.entity.LocationReview
import com.ftw.domain.usecase.review.GetLocaionReviewsUseCase
import com.ftw.hometerview.dispatcher.Dispatcher
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

class LocationListViewModel(
dispatcher: Dispatcher,
getLocationReviewsUseCase: GetLocaionReviewsUseCase
) {

private val location: MutableStateFlow<String> = MutableStateFlow("")

private val _reviews: MutableStateFlow<List<LocationReview>> = MutableStateFlow(emptyList())
val reviews: StateFlow<List<LocationReview>> = _reviews.asStateFlow()

fun setLocation(location: String) {
this.location.value = location
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.ftw.hometerview.ui.main.home.review

import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import com.ftw.hometerview.R
import com.ftw.hometerview.databinding.FragmentLocationListBinding
import javax.inject.Inject
import kotlinx.parcelize.Parcelize

class LocationReviewListFragment : Fragment() {

companion object {
fun newInstance(location: String): LocationReviewListFragment {
return LocationReviewListFragment().apply {
arguments = bundleOf(
LocationReviewListFragment::class.java.simpleName to Argument(location)
)
}
}
}

@Inject
lateinit var viewModel : LocationListViewModel
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val binding = DataBindingUtil.inflate<FragmentLocationListBinding>(
inflater,
R.layout.fragment_location_list,
container,
false
)
return binding.root
}

@Parcelize
private data class Argument(
val location: String
) : Parcelable
}
11 changes: 11 additions & 0 deletions app/src/main/res/layout/fragment_location_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

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

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

0 comments on commit 1942e23

Please sign in to comment.