@@ -16,6 +16,7 @@ import com.hyeeyoung.wishboard.presentation.folder.FolderListAdapter
1616import com.hyeeyoung.wishboard.presentation.folder.types.FolderListViewType
1717import com.hyeeyoung.wishboard.presentation.noti.types.NotiType
1818import com.hyeeyoung.wishboard.util.ContentUriRequestBody
19+ import com.hyeeyoung.wishboard.util.extension.addSourceList
1920import com.hyeeyoung.wishboard.util.extension.toPlainNullableRequestBody
2021import com.hyeeyoung.wishboard.util.extension.toPlainRequestBody
2122import com.hyeeyoung.wishboard.util.getBitmapFromURL
@@ -81,18 +82,27 @@ class WishItemRegistrationViewModel @Inject constructor(
8182 private val folderListSquareAdapter =
8283 FolderListAdapter (FolderListViewType .SQUARE_VIEW_TYPE )
8384
85+ val isEnabledUploadButton = MediatorLiveData <Boolean >().apply {
86+ addSourceList(itemName, itemPrice) { checkValidItemInfoInput() }
87+ }
88+
89+ private fun checkValidItemInfoInput (): Boolean {
90+ return ! (itemName.value.isNullOrBlank() || itemPrice.value.isNullOrBlank() || token == null )
91+ }
92+
8493 init {
8594 initEnabledSaveButton()
8695 fetchFolderList()
8796 }
8897
8998 /* * 오픈그래프 메타태그 파싱을 통해 아이템 정보 가져오기 */
90- suspend fun getWishItemInfo (url : String ) {
91- val result = wishRepository.getItemParsingInfo(url)
92- if (result?.first == null ) return
93- itemName.value = result.first!! .name
94- itemPrice.value = result.first!! .price.toString()
95- itemImage.value = result.first!! .image
99+ fun getWishItemInfo (url : String ) {
100+ viewModelScope.launch {
101+ val result = wishRepository.getItemParsingInfo(url)
102+ itemName.value = result?.first?.name
103+ itemPrice.value = if (result?.first?.price == null || result.first?.price == " 0" ) null else result.first?.price
104+ itemImage.value = result?.first?.image
105+ }
96106 }
97107
98108 suspend fun uploadWishItemByLinkSharing () {
@@ -207,7 +217,8 @@ class WishItemRegistrationViewModel @Inject constructor(
207217 private suspend fun updateWishItem (trimmedItemName : String ) { // TODO need refactoring, uploadWishItemByBasics()와 합치기
208218 // 파싱으로 아이템 이미지 불러온 경우 비트맵이미지로 이미지 파일 만들기
209219 val folderId: RequestBody ? =
210- (folderItem.value?.id ? : wishItemDetail?.folderId)?.toString()?.toPlainNullableRequestBody()
220+ (folderItem.value?.id ? : wishItemDetail?.folderId)?.toString()
221+ ?.toPlainNullableRequestBody()
211222 val itemName: RequestBody = trimmedItemName.toPlainRequestBody()
212223 val itemPrice: RequestBody ? = itemPrice.value?.replace(" ," , " " )?.toIntOrNull()?.toString()
213224 ?.toPlainNullableRequestBody()
@@ -291,9 +302,7 @@ class WishItemRegistrationViewModel @Inject constructor(
291302 if (! isValid) return
292303
293304 selectedGalleryImageUri.value = null // 파싱한 이미지를 적용할 것이기 때문에 기존에 선택된 이미지를 제거
294- viewModelScope.launch {
295- getWishItemInfo(url!! )
296- }
305+ getWishItemInfo(url!! )
297306 }
298307
299308 /* * url 유효성 검증 */
@@ -437,7 +446,8 @@ class WishItemRegistrationViewModel @Inject constructor(
437446
438447 fun setSelectedGalleryImage (imageUri : Uri , imageFile : File ) {
439448 // 갤러리 이미지를 적용할 것이기 때문에 기존에 파싱한 이미지를 제거
440- itemImage.value = null // TODO need refactoring, 아이템 정보 파싱 후 갤러리에서 이미지 선택 하지 않아도 이전에 갤러리에서 이미지를 선택한 적이 있는 경우, 갤러리 이미지가 보이는 버그를 방지하기 위함
449+ itemImage.value =
450+ null // TODO need refactoring, 아이템 정보 파싱 후 갤러리에서 이미지 선택 하지 않아도 이전에 갤러리에서 이미지를 선택한 적이 있는 경우, 갤러리 이미지가 보이는 버그를 방지하기 위함
441451 selectedGalleryImageUri.value = imageUri
442452 this .imageFile = imageFile
443453 }
0 commit comments