Skip to content

Commit b840936

Browse files
authored
Merge pull request #346 from hyeeyoung/dev-mod-item-registration-logic
[mod] μ•„μ΄ν…œ 등둝 둜직 μˆ˜μ •
2 parents 2c999dd + 473f770 commit b840936

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

β€Žapp/src/main/java/com/hyeeyoung/wishboard/presentation/wishitem/viewmodels/WishItemRegistrationViewModel.ktβ€Ž

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.hyeeyoung.wishboard.presentation.folder.FolderListAdapter
1616
import com.hyeeyoung.wishboard.presentation.folder.types.FolderListViewType
1717
import com.hyeeyoung.wishboard.presentation.noti.types.NotiType
1818
import com.hyeeyoung.wishboard.util.ContentUriRequestBody
19+
import com.hyeeyoung.wishboard.util.extension.addSourceList
1920
import com.hyeeyoung.wishboard.util.extension.toPlainNullableRequestBody
2021
import com.hyeeyoung.wishboard.util.extension.toPlainRequestBody
2122
import 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
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.hyeeyoung.wishboard.util.extension
2+
3+
import androidx.lifecycle.MediatorLiveData
4+
import androidx.lifecycle.MutableLiveData
5+
6+
fun <T> MediatorLiveData<T>.addSourceList(
7+
vararg liveDataArgument: MutableLiveData<*>,
8+
onChanged: () -> T?,
9+
) {
10+
liveDataArgument.forEach {
11+
this.addSource(it) { value = onChanged() }
12+
}
13+
}

β€Žapp/src/main/res/layout/activity_wish_link_sharing.xmlβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@
163163
android:layout_width="match_parent"
164164
android:layout_marginHorizontal="@dimen/spacingBase"
165165
android:layout_marginBottom="@dimen/spacingBase"
166-
android:enabled="@{viewModel.itemName.length() > 0 ? true : false}"
167-
android:text="@{viewModel.registrationStatus == ProcessStatus.IN_PROGRESS ? `` : context.getString(R.string.wish_list_registration_button_text)}"
166+
android:enabled="@{viewModel.isEnabledUploadButton}"
167+
android:text="@{viewModel.registrationStatus == ProcessStatus.IN_PROGRESS ? `` : context.getString(viewModel.token == null ? R.string.wish_list_registration_button_text_for_unregister_user : R.string.wish_list_registration_button_text)}"
168168
app:layout_constraintBottom_toBottomOf="parent"
169169
tools:text="@string/wish_list_registration_button_text" />
170170

@@ -190,11 +190,11 @@
190190
android:layout_gravity="center_horizontal"
191191
android:layout_marginBottom="-40dp"
192192
android:scaleType="centerCrop"
193-
app:shapeAppearanceOverlay="@style/Style.CircleImageView.Half"
194193
app:layout_constraintBottom_toTopOf="@id/container"
195194
app:layout_constraintEnd_toEndOf="parent"
196195
app:layout_constraintStart_toStartOf="parent"
197-
tools:src="@mipmap/ic_main" />
196+
app:shapeAppearanceOverlay="@style/Style.CircleImageView.Half"
197+
tools:src="@drawable/ic_app_logo_black" />
198198

199199
<TextView
200200
android:id="@+id/networkView"

β€Žapp/src/main/res/values/strings.xmlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130

131131
<string name="item_non_update_dialog_description">μ•—, μ‚­μ œλœ μ•„μ΄ν…œμ€ μˆ˜μ •ν•  수 μ—†μ–΄μš”.\nν™ˆνƒ­μ—μ„œ μƒˆλ‘œκ³ μΉ¨μ„ μ‹œλ„ν•΄ μ£Όμ„Έμš”!</string>
132132
<string name="item_non_update_dialog_title">μ•„μ΄ν…œ μˆ˜μ • 였λ₯˜</string>
133+
<string name="wish_list_registration_button_text_for_unregister_user">둜그인 ν›„ μœ„μ‹œλ³΄λ“œμ— μ•„μ΄ν…œμ„ λ‹΄μ•„λ³΄μ„Έμš”!</string>
133134

134135
<!-- Detail -->
135136
<string name="go_to_folder">%s></string>

0 commit comments

Comments
Β (0)