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
@Composable | |
fun LottoTheme( | |
content : @Composable () -> Unit | |
) { | |
MaterialTheme( | |
content = content | |
) | |
} |
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
@Composable | |
fun ConstraintLayoutScope.t2t( | |
ref: ConstrainedLayoutReference? = null, | |
margin: Dp = 0.dp | |
): Constraint = { | |
val reference = ref ?: parent | |
top.linkTo(reference.top, margin) | |
} |
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
fun <T> intentExtra(defaultValue: T? = null) = object : ReadOnlyProperty<Activity, T?> { | |
override fun getValue(thisRef: Activity, property: KProperty<*>): T? { | |
return when (defaultValue) { | |
is String -> thisRef.intent.getStringExtra(property.name) as T | |
is Int -> thisRef.intent.getIntExtra(property.name, defaultValue) as T | |
is Long -> thisRef.intent.getLongExtra(property.name, defaultValue) as T | |
// And More... | |
else -> null | |
} | |
} |
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
binding.btnRequest.setOnClickListener { | |
viewModel.requestFestival( ... ) | |
} | |
binding.btnRetry.setOnClickListener { | |
viewModel.refreshFestival() | |
} | |
viewModel.festival.observer { | |
// 페스티벌 데이터가 나옵니다. | |
} | |
val observer = { state: NetworkState? -> |
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
private val festivalRequest = MutableLiveData<An>() | |
private val festivalResponse = festivalRequest.map { getFestivalUseCase.execute(it) } | |
val festival = festivalResponse.switchMap { it.data } | |
val festivalState = festivalResponse.switchMap { it.state } | |
val festivalRefreshState = festivalResponse.switchMap { it.refreshState } |
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
fun getFestival( ... ): ResponseWrapper<FestivalData> { | |
val request: suspend () -> Unit = { | |
val festival = festivalAPI.get( ... ) | |
("Festival API" to "Fetched from API").debug() | |
festivalDAO.insert(festival) | |
("Festival DAO" to "Inserted to DB").debug() | |
} | |
val refreshTrigger = MutableLiveData<Unit>() | |
val refreshState = refresh.switchMap { | |
("Festival Refresh" to "Refresh Request").debug() |
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
private fun createStateForRequest(request: suspend () -> Unit) = | |
// LiveData (Lifecycle) 2.2.0-alph01 버전 부터 지원 | |
liveData(Dispatchers.IO) { | |
emit(NetworkState.loading) | |
try { | |
request() | |
emit(NetworkState.success) | |
} catch (e: IOException) { | |
e.printStackTrace() | |
emit(NetworkState.failed(e)) |
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
// ResponseWrapper | |
data class ResponseWrapper<T>( | |
val data: LiveData<T>, | |
val state: LiveData<NetworkState>, | |
val refreshState: LiveData<NetworkState>, | |
val refresh: () -> Unit | |
) | |
// NetworkState |
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
// FestivalAPI | |
@GET(" ... ") | |
suspend fun get( ... ): FestivalData | |
// ... | |
// FestivalDAO | |
@Query("select * from festivals ...") | |
fun get( ... ): LiveData<FestivalData> |
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
inline fun date(timeInMillis: Long = System.currentTimeMillis(), block: SimpleDate.() -> Unit = {}): SimpleDate { | |
val dateDsl = SimpleDate() | |
dateDsl.timeInMillis = timeInMillis | |
block(dateDsl) | |
return dateDsl | |
} | |
class SimpleDate { |
NewerOlder