Skip to content

Commit

Permalink
Merge pull request #103 from FakeDevelopers/feature/BDBD-535
Browse files Browse the repository at this point in the history
FEAT : BDBD-535  AlbumListViewModel의 의존성 주입을 AssistedInject로 변경
  • Loading branch information
minseonglove authored Mar 7, 2023
2 parents 4b476a0 + ed29c39 commit 3baf50e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.ItemTouchHelper
Expand All @@ -20,13 +22,24 @@ import com.fakedevelopers.presentation.ui.productEditor.DragAndDropCallback
import com.fakedevelopers.presentation.ui.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import javax.inject.Inject

@AndroidEntryPoint
class AlbumListFragment : BaseFragment<FragmentAlbumListBinding>(
R.layout.fragment_album_list
) {

private val viewModel: AlbumListViewModel by viewModels()
@Inject
lateinit var viewModelFactory: AlbumListViewModel.PathAssistedFactory

private val viewModel by viewModels<AlbumListViewModel> {
object : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return viewModelFactory.create(args.albumPath) as T
}
}
}

private val args: AlbumListFragmentArgs by navArgs()

private val backPressedCallback by lazy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.fakedevelopers.presentation.ui.productEditor.albumList

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.fakedevelopers.domain.model.AlbumItem
Expand All @@ -13,22 +12,22 @@ import com.fakedevelopers.presentation.ui.productEditor.SelectedPictureListAdapt
import com.fakedevelopers.presentation.ui.util.MutableEventFlow
import com.fakedevelopers.presentation.ui.util.ROTATE_DEGREE
import com.fakedevelopers.presentation.ui.util.asEventFlow
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import java.util.Collections
import javax.inject.Inject
import kotlin.math.roundToInt

@HiltViewModel
class AlbumListViewModel @Inject constructor(
args: SavedStateHandle,
class AlbumListViewModel @AssistedInject constructor(
isValidUriUseCase: IsValidUriUseCase,
private val getDateModifiedFromUriUseCase: GetDateModifiedByUriUseCase,
private val getValidUrisUseCase: GetValidUrisUseCase,
private val getImagesUseCase: GetImagesUseCase,
private val getImageObserverUseCase: GetImageObserverUseCase
private val getImageObserverUseCase: GetImageObserverUseCase,
@Assisted private val path: String
) : ViewModel() {
private val _albumViewMode = MutableStateFlow(AlbumViewState.GRID)
val albumViewMode: StateFlow<AlbumViewState> get() = _albumViewMode
Expand All @@ -51,9 +50,13 @@ class AlbumListViewModel @Inject constructor(
var currentViewPagerIdx = 0
private set

private val path = args.get<String>("albumPath") ?: ""
val title = path.substringAfterLast('/')

@AssistedFactory
interface PathAssistedFactory {
fun create(path: String): AlbumListViewModel
}

init {
viewModelScope.launch {
_albumTitle.emit(title)
Expand Down

0 comments on commit 3baf50e

Please sign in to comment.