-
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.
[feat] detail_image / 사진 정보 가져오기 api 뷰모델 로직까지 완료(테스트 완료) (#90)
- Loading branch information
Showing
5 changed files
with
71 additions
and
17 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
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
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
37 changes: 36 additions & 1 deletion
37
...t/src/main/java/com/photosurfer/android/search_result/detailimage/DetailImageViewModel.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 |
---|---|---|
@@ -1,18 +1,53 @@ | ||
package com.photosurfer.android.search_result.detailimage | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.viewModelScope | ||
import com.photosurfer.android.core.base.BaseViewModel | ||
import com.photosurfer.android.domain.entity.TagInfo | ||
import com.photosurfer.android.domain.repository.ImageRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class DetailImageViewModel @Inject constructor() : BaseViewModel(){ | ||
class DetailImageViewModel @Inject constructor( | ||
private val imageRepository: ImageRepository | ||
) : BaseViewModel() { | ||
|
||
private val _tagInfoList = MutableLiveData<List<TagInfo>>() | ||
val tagInfoList: LiveData<List<TagInfo>> = _tagInfoList | ||
|
||
private val _imageUrl = MutableLiveData<String>() | ||
val imageUrl: LiveData<String> = _imageUrl | ||
|
||
private val _photoId = MutableLiveData<Int>() | ||
val photoId: LiveData<Int> = _photoId | ||
|
||
fun updateTagInfoList(tags: List<TagInfo>) { | ||
_tagInfoList.value = tags | ||
} | ||
|
||
fun updateImageUrl(imageUrl: String) { | ||
_imageUrl.value = imageUrl | ||
} | ||
|
||
fun updatePhotoId(photoId: Int) { | ||
_photoId.value = photoId | ||
} | ||
|
||
fun getDetailImageInfo() { | ||
viewModelScope.launch { | ||
imageRepository.getDetailImageInfo(photoId.value ?: -1) | ||
.onSuccess { | ||
updateImageUrl(it.imageUrl) | ||
updatePhotoId(it.photoId) | ||
updateTagInfoList(it.tagList) | ||
}.onFailure { | ||
Timber.d(it, "${this.javaClass.name}_getDetailImageInfo") | ||
} | ||
} | ||
} | ||
} |
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