Skip to content

Commit

Permalink
[feat] GET 태그 조회 List Observe (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
visionWWW committed Jul 21, 2022
1 parent 2e94086 commit 4eac7a2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import com.photosurfer.android.data.remote.model.response.ChooseTagResponse
import com.photosurfer.android.data.remote.model.response.TagListResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST

interface ChooseTagService {
@Multipart
@POST("photo/")
suspend fun postTag(
@Body body: ChooseTagRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.photosurfer.android.register_tag

import android.content.ContentValues.TAG
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.viewModels
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.photosurfer.android.core.base.BaseFragment
import com.photosurfer.android.core.util.PhotoSurferSnackBar
import com.photosurfer.android.domain.entity.TagInfo
import com.photosurfer.android.register_tag.databinding.FragmentChooseTagBinding
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -29,8 +30,10 @@ class ChooseTagFragment : BaseFragment<FragmentChooseTagBinding>(R.layout.fragme

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding.isTyping = true
chooseTagViewModel.setTagList()

setRecentList()
setOftenList()
setPlatformList()
initAdapter()
setDataOnRecyclerView()
observeInputChipGroup()
Expand All @@ -39,13 +42,32 @@ class ChooseTagFragment : BaseFragment<FragmentChooseTagBinding>(R.layout.fragme
deleteInput()
checkInputNum()
initRecyclerViewLayout()
chooseTagViewModel.getTagList()


val file: File = setImgToFile(getImgToUri())

initButtonSaveClickListener()
}

private fun setPlatformList() {
chooseTagViewModel.platformList.observe(viewLifecycleOwner) {
platformTagAdapter.submitList(chooseTagViewModel.platformList.value)
}
}

private fun setOftenList() {
chooseTagViewModel.oftenList.observe(viewLifecycleOwner) {
oftenTagAdapter.submitList(chooseTagViewModel.oftenList.value)
}
}

private fun setRecentList() {
chooseTagViewModel.getTagList()
chooseTagViewModel.recentList.observe(viewLifecycleOwner) {
recentTagAdapter.submitList(chooseTagViewModel.recentList.value)
}
}

private fun initButtonSaveClickListener() {
binding.tvSave.setOnClickListener {
//chooseTagViewModel.postChooseTag()
Expand Down Expand Up @@ -85,10 +107,11 @@ class ChooseTagFragment : BaseFragment<FragmentChooseTagBinding>(R.layout.fragme
}

private fun setDataOnRecyclerView() {
inputTagAdapter.submitList(chooseTagViewModel.inputList)
recentTagAdapter.submitList(chooseTagViewModel.recentList)
oftenTagAdapter.submitList(chooseTagViewModel.oftenList)
platformTagAdapter.submitList(chooseTagViewModel.platformList)
Log.d(TAG, "setDataOnRecyclerView: recent ${chooseTagViewModel.recentList}")
inputTagAdapter.submitList(chooseTagViewModel.inputList.value)
recentTagAdapter.submitList(chooseTagViewModel.recentList.value)
oftenTagAdapter.submitList(chooseTagViewModel.oftenList.value)
platformTagAdapter.submitList(chooseTagViewModel.platformList.value)
}

private fun initAdapter() {
Expand All @@ -104,9 +127,9 @@ class ChooseTagFragment : BaseFragment<FragmentChooseTagBinding>(R.layout.fragme
}

private fun checkInputNum() {
if (chooseTagViewModel.inputList.size > 6) {
PhotoSurferSnackBar.make(requireView(), PhotoSurferSnackBar.CHOOSE_TAG_FRAGMENT).show()
}
// if (chooseTagViewModel.inputList.value?.size > 6) {
// PhotoSurferSnackBar.make(requireView(), PhotoSurferSnackBar.CHOOSE_TAG_FRAGMENT).show()
// }
}

private fun deleteInput() {
Expand Down Expand Up @@ -140,20 +163,20 @@ class ChooseTagFragment : BaseFragment<FragmentChooseTagBinding>(R.layout.fragme
}

private fun addTagWithInputText() {
chooseTagViewModel.inputList.add(TagInfo(0, binding.etTag.text.toString()))
chooseTagViewModel.setEmptyInput(chooseTagViewModel.inputList.size)
chooseTagViewModel.inputList.value?.add(TagInfo(0, binding.etTag.text.toString()))
//chooseTagViewModel.setEmptyInput(chooseTagViewModel.inputList.size)
binding.etTag.text.clear()
}

private fun selectTag(tagInfo: TagInfo) {
chooseTagViewModel.selectTag(tagInfo)
inputTagAdapter.submitList(chooseTagViewModel.inputList)
inputTagAdapter.submitList(chooseTagViewModel.inputList.value)
inputTagAdapter.notifyDataSetChanged()
}

private fun deleteTag(tagInfo: TagInfo) {
chooseTagViewModel.deleteTag(tagInfo)
inputTagAdapter.submitList(chooseTagViewModel.inputList)
inputTagAdapter.submitList(chooseTagViewModel.inputList.value)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.photosurfer.android.register_tag

import android.nfc.Tag
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
Expand All @@ -12,6 +13,7 @@ import com.photosurfer.android.domain.entity.request.DomainChooseTagRequest
import com.photosurfer.android.domain.repository.ChooseTagRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.File
import javax.inject.Inject

Expand All @@ -21,10 +23,18 @@ class ChooseTagViewModel @Inject constructor(
) : BaseViewModel() {
private var _isEmptyInput = MutableLiveData<Int>()
val isEmptyInput: LiveData<Int> get() = _isEmptyInput
var inputList: MutableList<TagInfo> = mutableListOf()
var recentList: MutableList<TagInfo> = mutableListOf()
var oftenList: MutableList<TagInfo> = mutableListOf()
var platformList: MutableList<TagInfo> = mutableListOf()

private val _inputList = MutableLiveData<MutableList<TagInfo>>()
val inputList: MutableLiveData<MutableList<TagInfo>> = _inputList

private val _recentList = MutableLiveData<MutableList<TagInfo>>()
val recentList: MutableLiveData<MutableList<TagInfo>> = _recentList

private val _oftenList = MutableLiveData<MutableList<TagInfo>>()
val oftenList: MutableLiveData<MutableList<TagInfo>> = _oftenList

private val _platformList = MutableLiveData<MutableList<TagInfo>>()
val platformList: MutableLiveData<MutableList<TagInfo>> = _platformList

private val _chooseTagSuccess = MutableLiveData<Event<Boolean>>()
val chooseTagSuccess: LiveData<Event<Boolean>> = _chooseTagSuccess
Expand All @@ -38,50 +48,16 @@ class ChooseTagViewModel @Inject constructor(
TODO()
}

fun setTagList() {
recentList.addAll(
listOf(
TagInfo(7, "포토서퍼"),
TagInfo(8, "카페"),
TagInfo(9, "생활꿀팁"),
TagInfo(10, "위시리스트"),
TagInfo(11, "휴학"),
TagInfo(12, "여행")
)
)
oftenList.addAll(
listOf(
TagInfo(13, "좋은노래"),
TagInfo(14, "솝트"),
TagInfo(15, "전시회"),
TagInfo(16, "그래픽디자인"),
TagInfo(17, "포토서퍼"),
TagInfo(18, "인턴")
)
)
platformList.addAll(
listOf(
TagInfo(1, "카카오톡"),
TagInfo(2, "유튜브"),
TagInfo(3, "인스타그램"),
TagInfo(4, "쇼핑몰"),
TagInfo(5, "커뮤니티"),
TagInfo(6, "기타")
)
)

}

fun setEmptyInput(value: Int) {
_isEmptyInput.value = value
}

fun selectTag(item: TagInfo) {
inputList.add(item)
inputList.value?.add(item)
}

fun deleteTag(item: TagInfo) {
inputList.remove(item)
inputList.value?.remove(item)
}

// TODO: GET 서버 로직 붙이고 추가할 예정
Expand All @@ -105,12 +81,12 @@ class ChooseTagViewModel @Inject constructor(
viewModelScope.launch {
chooseTagRepository.getTagList()
.onSuccess {
recentList = it.recentTagList
oftenList = it.oftenTagList
platformList = it.platformTagList
Log.d("되니?", "된다....")
_recentList.value = it.recentTagList
_oftenList.value = it.oftenTagList
_platformList.value = it.platformTagList

}.onFailure {
Log.d("되니?", "안되니...")
Timber.d(it, "${this.javaClass.name}_getTagList")
}
}
}
Expand Down

0 comments on commit 4eac7a2

Please sign in to comment.