-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: BindingAdapter 파일 분리 * refactor: ButtonBindingAdapter 리팩토링 * refactor: ImageBindingAdapter 리팩토링 * refactor: TextBindingAdapter 리팩토링 * refactor: ExtBindingAdapter 리팩토링 * refactor: 오전, 오후 텍스트 strings.xml로 분리 * refactor: 매직 넘버 상수로 분리 * style: EtxBindingAdapters -> BindingAdapters.kt * chore: 불필요한 메서드 제거 * refactor: 상수화 및 String formatting * fix: 추억 수정 화면 dateRangePicker 중복 버그 해결 * refactor: 추억 기간 선택 시 visibility 바인딩 어댑터 적용 * refactor: okhttp3 import 제거 및 scrollToBottom rename
- Loading branch information
Showing
24 changed files
with
557 additions
and
688 deletions.
There are no files selected for viewing
610 changes: 0 additions & 610 deletions
610
android/Staccato_AN/app/src/main/java/com/on/staccato/presentation/BindingAdapters.kt
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
...ccato_AN/app/src/main/java/com/on/staccato/presentation/bindingadapter/BindingAdapters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.on.staccato.presentation.bindingadapter | ||
|
||
import android.net.Uri | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ProgressBar | ||
import android.widget.ScrollView | ||
import androidx.databinding.BindingAdapter | ||
import com.on.staccato.presentation.timeline.model.TimelineUiModel | ||
|
||
@BindingAdapter("visibleOrGone") | ||
fun View.setVisibility(isVisible: Boolean?) { | ||
visibility = | ||
if (isVisible == true) { | ||
View.VISIBLE | ||
} else { | ||
View.GONE | ||
} | ||
} | ||
|
||
@BindingAdapter("scrollToBottom") | ||
fun ScrollView.setScrollToBottom(isScrollable: Boolean) { | ||
if (isScrollable) { | ||
post { fullScroll(ScrollView.FOCUS_DOWN) } | ||
} | ||
} | ||
|
||
@BindingAdapter(value = ["visibilityByThumbnailUri", "visibilityByThumbnailUrl"]) | ||
fun View.setThumbnail( | ||
thumbnailUri: Uri?, | ||
thumbnailUrl: String?, | ||
) { | ||
visibility = | ||
if (thumbnailUri == null && thumbnailUrl == null) { | ||
View.VISIBLE | ||
} else { | ||
View.GONE | ||
} | ||
} | ||
|
||
@BindingAdapter(value = ["visibilityByThumbnailUri", "visibilityByThumbnailUrl"]) | ||
fun ProgressBar.setThumbnailLoadingProgressBar( | ||
thumbnailUri: Uri?, | ||
thumbnailUrl: String?, | ||
) { | ||
visibility = | ||
if (thumbnailUri != null && thumbnailUrl == null) { | ||
View.VISIBLE | ||
} else { | ||
View.GONE | ||
} | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["visibilityByTimeline", "visibilityByLoading"], | ||
) | ||
fun View.setTimelineEmptyViewVisible( | ||
timeLine: List<TimelineUiModel>? = null, | ||
isTimelineLoading: Boolean, | ||
) { | ||
visibility = if (isTimeLineEmpty(timeLine, isTimelineLoading)) View.VISIBLE else View.GONE | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["visibilityByTimeline", "visibilityByLoading"], | ||
) | ||
fun ViewGroup.setMemoryAddButtonVisible( | ||
timeLine: List<TimelineUiModel>? = null, | ||
isTimelineLoading: Boolean, | ||
) { | ||
visibility = if (isTimeLineEmpty(timeLine, isTimelineLoading)) View.GONE else View.VISIBLE | ||
} | ||
|
||
private fun isTimeLineEmpty( | ||
timeLine: List<TimelineUiModel>?, | ||
isTimelineLoading: Boolean, | ||
) = timeLine.isNullOrEmpty() && isTimelineLoading.not() |
112 changes: 112 additions & 0 deletions
112
..._AN/app/src/main/java/com/on/staccato/presentation/bindingadapter/ButtonBindingAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.on.staccato.presentation.bindingadapter | ||
|
||
import android.widget.Button | ||
import android.widget.ImageButton | ||
import androidx.databinding.BindingAdapter | ||
import com.google.android.material.button.MaterialButton | ||
import com.on.staccato.R | ||
import com.on.staccato.domain.model.MemoryCandidate | ||
import com.on.staccato.presentation.momentcreation.model.AttachedPhotosUiModel | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
@BindingAdapter("loginButtonEnabled") | ||
fun Button.setLoginButtonEnabled(nickName: String?) { | ||
isEnabled = | ||
if (nickName.isNullOrBlank()) { | ||
setTextColor(resources.getColor(R.color.gray4, null)) | ||
false | ||
} else { | ||
setTextColor(resources.getColor(R.color.white, null)) | ||
true | ||
} | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["staccatoTitle", "staccatoAddress", "staccatoVisitedAt", "staccatoPhotos", "staccatoMemory"], | ||
) | ||
fun Button.setStaccatoSaveButtonEnabled( | ||
staccatoTitle: String?, | ||
staccatoAddress: String?, | ||
staccatoVisitedAt: LocalDateTime?, | ||
staccatoPhotos: AttachedPhotosUiModel?, | ||
staccatoMemory: MemoryCandidate?, | ||
) { | ||
isEnabled = | ||
if (staccatoTitle.isNullOrBlank() || | ||
staccatoAddress == null || | ||
staccatoMemory == null || | ||
staccatoVisitedAt == null || | ||
staccatoPhotos?.isLoading() == true | ||
) { | ||
setTextColor(resources.getColor(R.color.gray4, null)) | ||
false | ||
} else { | ||
setTextColor(resources.getColor(R.color.white, null)) | ||
true | ||
} | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["memoryTitle", "memoryStartDate", "memoryEndDate", "isPeriodActive", "isPhotoUploading"], | ||
) | ||
fun Button.setMemorySaveButtonEnabled( | ||
memoryTitle: String?, | ||
memoryStartDate: LocalDate?, | ||
memoryEndDate: LocalDate?, | ||
isPeriodActive: Boolean, | ||
isPhotoUploading: Boolean?, | ||
) { | ||
val isPeriodNotExistent = (memoryStartDate == null) || (memoryEndDate == null) | ||
val isPeriodRequirementsInvalid = isPeriodActive && isPeriodNotExistent | ||
isEnabled = | ||
if (memoryTitle.isNullOrBlank() || isPhotoUploading == true || isPeriodRequirementsInvalid) { | ||
setTextColor(resources.getColor(R.color.gray4, null)) | ||
false | ||
} else { | ||
setTextColor(resources.getColor(R.color.white, null)) | ||
true | ||
} | ||
} | ||
|
||
@BindingAdapter("visitedAtSelectButtonEnabled") | ||
fun Button.setVisitedAtSelectButtonEnabled(years: List<Int>?) { | ||
isEnabled = | ||
if (years.isNullOrEmpty()) { | ||
setTextColor(resources.getColor(R.color.gray4, null)) | ||
false | ||
} else { | ||
setTextColor(resources.getColor(R.color.white, null)) | ||
true | ||
} | ||
} | ||
|
||
@BindingAdapter("recoveryButtonEnabled") | ||
fun Button.setRecoveryButtonEnabled(recoveryCode: String?) { | ||
isEnabled = | ||
if (recoveryCode.isNullOrBlank() || recoveryCode.length < MAX_RECOVERY_CODE) { | ||
setTextColor(resources.getColor(R.color.gray4, null)) | ||
false | ||
} else { | ||
setTextColor(resources.getColor(R.color.white, null)) | ||
true | ||
} | ||
} | ||
|
||
@BindingAdapter("currentLocationButtonLoading") | ||
fun MaterialButton.setCurrentLocationButtonLoading(isLoading: Boolean?) { | ||
isClickable = isLoading == false | ||
if (isLoading == true) { | ||
setText(R.string.all_empty) | ||
setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) | ||
} else { | ||
setText(R.string.visit_creation_load_current_location) | ||
} | ||
} | ||
|
||
@BindingAdapter("sendButtonEnabled") | ||
fun ImageButton.setSendButtonEnabled(value: String?) { | ||
isEnabled = !value.isNullOrBlank() | ||
} | ||
|
||
private const val MAX_RECOVERY_CODE = 36 |
91 changes: 91 additions & 0 deletions
91
...o_AN/app/src/main/java/com/on/staccato/presentation/bindingadapter/ImageBindingAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.on.staccato.presentation.bindingadapter | ||
|
||
import android.graphics.drawable.Drawable | ||
import android.net.Uri | ||
import android.widget.ImageView | ||
import androidx.databinding.BindingAdapter | ||
import coil.load | ||
import coil.transform.RoundedCornersTransformation | ||
|
||
@BindingAdapter("selected") | ||
fun ImageView.setSelected(selected: Boolean) { | ||
isSelected = selected | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["coilImageUrl", "coilPlaceHolder"], | ||
) | ||
fun ImageView.loadCoilImage( | ||
url: String?, | ||
placeHolder: Drawable? = null, | ||
) { | ||
load(url) { | ||
placeholder(placeHolder) | ||
error(placeHolder) | ||
} | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["coilCircleImageUrl", "coilPlaceHolder"], | ||
) | ||
fun ImageView.loadCoilCircleImage( | ||
url: String?, | ||
placeHolder: Drawable? = null, | ||
) { | ||
load(url) { | ||
placeholder(placeHolder) | ||
transformations(RoundedCornersTransformation(1000f)) | ||
error(placeHolder) | ||
} | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["coilRoundedCornerImageUrl", "coilRoundedCornerPlaceHolder", "coilRoundingRadius"], | ||
) | ||
fun ImageView.setCoilRoundedCornerImage( | ||
url: String?, | ||
placeHolder: Drawable? = null, | ||
roundingRadius: Float, | ||
) { | ||
load(url) { | ||
placeholder(placeHolder) | ||
transformations(RoundedCornersTransformation(roundingRadius)) | ||
error(placeHolder) | ||
} | ||
} | ||
|
||
@BindingAdapter( | ||
value = ["coilRoundedCornerImageUrl", "coilRoundedCornerImageUri", "coilRoundedCornerPlaceHolder", "coilRoundingRadius"], | ||
) | ||
fun ImageView.setCoilRoundedCornerImageWithUri( | ||
url: String?, | ||
uri: Uri?, | ||
placeHolder: Drawable? = null, | ||
roundingRadius: Float, | ||
) { | ||
val image = uri ?: url | ||
load(image) { | ||
placeholder(placeHolder) | ||
transformations(RoundedCornersTransformation(roundingRadius)) | ||
error(placeHolder) | ||
} | ||
} | ||
|
||
@BindingAdapter( | ||
value = [ | ||
"colorImageResource", | ||
"grayImageResource", | ||
], | ||
) | ||
fun ImageView.setImageResourceWithId( | ||
colorResId: Int, | ||
grayResId: Int, | ||
) { | ||
setImageResource( | ||
if (isSelected) { | ||
colorResId | ||
} else { | ||
grayResId | ||
}, | ||
) | ||
} |
Oops, something went wrong.