Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

모먼트 삭제 기능 구현 #91

Merged
merged 5 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.wakeup.presentation.ui

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.cachedIn
import androidx.paging.map
import com.wakeup.domain.usecase.GetAllMomentsUseCase
import com.wakeup.domain.usecase.weather.GetWeatherDataUseCase
import com.wakeup.presentation.mapper.toDomain
Expand All @@ -12,8 +14,11 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
Expand All @@ -27,12 +32,16 @@ class MainViewModel @Inject constructor(
private val _isReady = MutableStateFlow(false)
val isReady = _isReady.asStateFlow()

// TODO: HomeViewModel에 활용
val allMoments: Flow<List<MomentModel>?> = getAllMomentListUseCase("").map { moments ->
var allMoments: StateFlow<List<MomentModel>>? = getAllMomentListUseCase("").map { moments ->
moments.map { moment ->
moment.toPresentation()
}
}.apply { _isReady.value = true }
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = emptyList()
)
.apply { _isReady.value = true }
Comment on lines +39 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어어??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

악!


fun testGetWeather() {
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -27,6 +28,7 @@ import com.wakeup.presentation.databinding.FragmentHomeBinding
import com.wakeup.presentation.extension.hideKeyboard
import com.wakeup.presentation.model.LocationModel
import com.wakeup.presentation.ui.MainActivity
import com.wakeup.presentation.ui.MainViewModel
import com.wakeup.presentation.ui.UiState
import com.wakeup.presentation.ui.home.map.MapFragment
import com.wakeup.presentation.ui.home.sheet.BottomSheetFragment
Expand All @@ -40,6 +42,7 @@ class HomeFragment : Fragment() {

private lateinit var binding: FragmentHomeBinding
private val viewModel: HomeViewModel by viewModels()
private val activityViewModel: MainViewModel by activityViewModels()

private lateinit var fusedLocationProviderClient: FusedLocationProviderClient

Expand All @@ -52,6 +55,7 @@ class HomeFragment : Fragment() {
initMap()
initBottomSheet()
initLocation()
initMoments()
}

override fun onCreateView(
Expand All @@ -72,6 +76,13 @@ class HomeFragment : Fragment() {
collectWeather()
}

private fun initMoments() {
activityViewModel.allMoments?.let { moments ->
viewModel.initMoments(moments)
activityViewModel.allMoments = null
}
}

private fun initMap() {
if (childFragmentManager.findFragmentById(R.id.map) == null) {
mapFragment = MapFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class HomeViewModel @Inject constructor(

init {
fetchMoments()
fetchAllMoments()
}

fun initMoments(data: StateFlow<List<MomentModel>>) {
allMoments = data
}

fun fetchMoments() {
Expand Down