-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6 feat/홈 : 홈 화면의 리뷰 리스트를 위한 Fragment 구현
- Loading branch information
1 parent
517f302
commit 1942e23
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/ftw/hometerview/ui/main/home/HomeViewPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/ftw/hometerview/ui/main/home/review/LocationListViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/ftw/hometerview/ui/main/home/review/LocationReviewListFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|