Skip to content

Commit

Permalink
[MOD/#3] inline 키워드 반영 및 safeValueOf 함수 default 인자 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Apr 12, 2023
1 parent b8e3d1f commit 2c883cf
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ class LocalPrefDataSource @Inject constructor(
}

fun clearLocalPref() {
with(prefs.edit()) {
clear()
commit()
}
with(prefs.edit()) { clear() }
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import javax.inject.Inject
class MainViewModel @Inject constructor(
private val authRepository: AuthRepository,
) : ViewModel() {
// TODO : 프로필 보여주는 Fragment ViewModel 으로 로직 옮기기
val signedUpUser = MutableLiveData<User>()

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
}

private fun initRepoListAdapter() {
with (binding) {
with(binding) {
rvHomeRepo.adapter = repoAdapter
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SignupViewModel @Inject constructor(
requireNotNull(pwd.value).trim(),
name.value?.trim(),
specialty.value?.trim(),
safeValueOf<MBTI>(mbti.value?.trim()?.uppercase()) ?: NONE,
safeValueOf(mbti.value?.trim()?.uppercase(), NONE),
)
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/android/go/sopt/util/EnumUtil.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.android.go.sopt.util

inline fun <reified T : Enum<T>> safeValueOf(type: String?): T? {
inline fun <reified T : Enum<T>> safeValueOf(type: String?, default: T?): T? {
return try {
java.lang.Enum.valueOf(T::class.java, type ?: return null)
java.lang.Enum.valueOf(T::class.java, type ?: return default)
} catch (e: IllegalArgumentException) {
null
default
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class OnSingleClickListener(

override fun onClick(v: View) {
val elapsedRealtime = SystemClock.elapsedRealtime()
if ((elapsedRealtime - lastClickTime) < interval) {
return
}
if ((elapsedRealtime - lastClickTime) < interval) return
lastClickTime = elapsedRealtime
onSingleClick(v)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.google.android.material.snackbar.Snackbar
import org.android.go.sopt.util.OnSingleClickListener

/** Register a callback to be invoked when this view is clicked. If this view was clicked within 1 second, the callback will not be invoked. */
fun View.setOnSingleClickListener(onSingleClick: (View) -> Unit) {
inline fun View.setOnSingleClickListener(crossinline onSingleClick: (View) -> Unit) {
setOnClickListener(OnSingleClickListener { onSingleClick(it) })
}

Expand Down

0 comments on commit 2c883cf

Please sign in to comment.