Skip to content

Commit

Permalink
[feat] detail_image / viewModel 로직 테스트 아직 못한 코드(임시커밋) (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
2chang5 committed Jul 22, 2022
1 parent 89c7421 commit 8886bf5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package com.photosurfer.android.search_result.detailimage
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
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.EventObserver
import com.photosurfer.android.core.util.StfalconImageViewerUtil
import com.photosurfer.android.core.util.getImageUriFromBitmap
import com.photosurfer.android.core.util.useBitmapImg
Expand All @@ -34,6 +34,13 @@ class DetailImageActivity :
binding.detailImageViewModel = detailImageViewModel
startImageViewer()
initShareButtonClickListener()
deleteImageSuccess()
initDeleteButtonClickListener()
}

private fun initDeleteButtonClickListener() {
binding.ivDelete.setOnClickListener {
}
}

private fun initExtraData() {
Expand Down Expand Up @@ -95,6 +102,15 @@ class DetailImageActivity :
}
}

private fun deleteImageSuccess() {
detailImageViewModel.deleteSuccessState.observe(
this,
EventObserver {
finish()
}
)
}

companion object {
const val START = "START"
const val ADD = "ADD"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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.core.util.Event
import com.photosurfer.android.domain.entity.TagInfo
import com.photosurfer.android.domain.repository.ImageRepository
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -26,6 +26,9 @@ class DetailImageViewModel @Inject constructor(
private val _photoId = MutableLiveData<Int>()
val photoId: LiveData<Int> = _photoId

private val _deleteSuccessState = MutableLiveData<Event<Boolean>>()
val deleteSuccessState: LiveData<Event<Boolean>> = _deleteSuccessState

fun updateTagInfoList(tags: List<TagInfo>) {
_tagInfoList.value = tags
}
Expand All @@ -50,4 +53,17 @@ class DetailImageViewModel @Inject constructor(
}
}
}

fun deleteImage() {
viewModelScope.launch {
val option = mutableMapOf<String, Int>()
option["id"] = requireNotNull(photoId.value)
imageRepository.deleteImage(option)
.onSuccess {
_deleteSuccessState.value = Event(true)
}.onFailure {
Timber.d(it, "${this.javaClass.name}_deleteImage")
}
}
}
}

0 comments on commit 8886bf5

Please sign in to comment.