Skip to content

Commit

Permalink
[feat] detail_image / 사진 정보 가져오기 api 뷰모델 로직까지 완료(테스트 완료) (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
2chang5 committed Jul 22, 2022
1 parent 0d3122a commit d29cdd3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ interface RemoteDataSourceModule {

@Binds
@Singleton
fun bindsRemoteTagListDataSource(source: RemoteImageDataSourceImpl): RemoteImageDataSource
fun bindsRemoteImageDataSource(source: RemoteImageDataSourceImpl): RemoteImageDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import retrofit2.http.Path
interface DetailImageService {
@GET("photo/detail/{photoId}")
suspend fun getDetailImageInfo(
@Path("photoID") photoId: Int
@Path("photoId") photoId: Int
): NetworkState<BaseResponse<DetailImageResponse>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,55 @@ import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.widget.PopupMenu
import androidx.activity.viewModels
import com.photosurfer.android.core.base.BaseActivity
import com.photosurfer.android.core.util.StfalconImageViewerUtil
import com.photosurfer.android.search_result.R
import com.photosurfer.android.search_result.SearchResultActivity.Companion.PHOTO_ID
import com.photosurfer.android.search_result.databinding.ActivityDetailImageBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlin.properties.Delegates

@AndroidEntryPoint
class DetailImageActivity :
BaseActivity<ActivityDetailImageBinding>(R.layout.activity_detail_image) {

private val detailImageViewModel by viewModels<DetailImageViewModel>()
var photoId by Delegates.notNull<Int>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

onClickMenu()
initExtraData()
// startImageViewer()
initViewModelData()
getDetailImageInfo()
binding.detailImageViewModel = detailImageViewModel
startImageViewer()
}

private fun initExtraData(){
photoId = intent.getIntExtra(PHOTO_ID,-1)
private fun initExtraData() {
photoId = intent.getIntExtra(PHOTO_ID, -1)
}

// private fun startImageViewer() {
// binding.ivDetail.setOnClickListener {
// StfalconImageViewerUtil.initImageViewer(
// this,
// binding.ivDetail,
// listOf(imgUrl),
// 0
// )
// }
// }
private fun initViewModelData() {
detailImageViewModel.updatePhotoId(photoId)
}

private fun getDetailImageInfo() {
detailImageViewModel.getDetailImageInfo()
}

private fun startImageViewer() {
binding.ivDetail.setOnClickListener {
StfalconImageViewerUtil.initImageViewer(
this,
binding.ivDetail,
listOf(detailImageViewModel.imageUrl.value ?: ""),
0
)
}
}

private fun onClickMenu() {
binding.btnMore.setOnClickListener {
Expand Down
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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="detailImageViewModel"
type="com.photosurfer.android.search_result.detailimage.DetailImageViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -57,6 +59,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:setImage="@{detailImageViewModel.imageUrl}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_tool_bar"
Expand Down

0 comments on commit d29cdd3

Please sign in to comment.