From 4eac7a2708cb3fafb67978f6ac5bf2af9dbfc8dc Mon Sep 17 00:00:00 2001 From: chaeyeong Date: Fri, 22 Jul 2022 00:07:23 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20GET=20=ED=83=9C=EA=B7=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20List=20Observe=20(#71)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/remote/service/ChooseTagService.kt | 2 + .../android/register_tag/ChooseTagFragment.kt | 51 ++++++++++---- .../register_tag/ChooseTagViewModel.kt | 66 ++++++------------- 3 files changed, 60 insertions(+), 59 deletions(-) diff --git a/data/src/main/java/com/photosurfer/android/data/remote/service/ChooseTagService.kt b/data/src/main/java/com/photosurfer/android/data/remote/service/ChooseTagService.kt index fd1a24d..216e248 100644 --- a/data/src/main/java/com/photosurfer/android/data/remote/service/ChooseTagService.kt +++ b/data/src/main/java/com/photosurfer/android/data/remote/service/ChooseTagService.kt @@ -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 diff --git a/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagFragment.kt b/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagFragment.kt index 6afc900..d571adb 100644 --- a/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagFragment.kt +++ b/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagFragment.kt @@ -1,9 +1,11 @@ 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 @@ -11,7 +13,6 @@ 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 @@ -29,8 +30,10 @@ class ChooseTagFragment : BaseFragment(R.layout.fragme override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.isTyping = true - chooseTagViewModel.setTagList() + setRecentList() + setOftenList() + setPlatformList() initAdapter() setDataOnRecyclerView() observeInputChipGroup() @@ -39,13 +42,32 @@ class ChooseTagFragment : BaseFragment(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() @@ -85,10 +107,11 @@ class ChooseTagFragment : BaseFragment(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() { @@ -104,9 +127,9 @@ class ChooseTagFragment : BaseFragment(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() { @@ -140,20 +163,20 @@ class ChooseTagFragment : BaseFragment(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) } } diff --git a/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagViewModel.kt b/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagViewModel.kt index 22fb2d5..d844bcd 100644 --- a/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagViewModel.kt +++ b/feature/register-tag/src/main/java/com/photosurfer/android/register_tag/ChooseTagViewModel.kt @@ -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 @@ -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 @@ -21,10 +23,18 @@ class ChooseTagViewModel @Inject constructor( ) : BaseViewModel() { private var _isEmptyInput = MutableLiveData() val isEmptyInput: LiveData get() = _isEmptyInput - var inputList: MutableList = mutableListOf() - var recentList: MutableList = mutableListOf() - var oftenList: MutableList = mutableListOf() - var platformList: MutableList = mutableListOf() + + private val _inputList = MutableLiveData>() + val inputList: MutableLiveData> = _inputList + + private val _recentList = MutableLiveData>() + val recentList: MutableLiveData> = _recentList + + private val _oftenList = MutableLiveData>() + val oftenList: MutableLiveData> = _oftenList + + private val _platformList = MutableLiveData>() + val platformList: MutableLiveData> = _platformList private val _chooseTagSuccess = MutableLiveData>() val chooseTagSuccess: LiveData> = _chooseTagSuccess @@ -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 서버 로직 붙이고 추가할 예정 @@ -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") } } }