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
abstract class AnkoRecyclerViewAdapter<Model : Any, AnkoView : AnkoComponent<ViewGroup>, ViewHolder : RecyclerView.ViewHolder> : RecyclerView.Adapter<ViewHolder>() { | |
abstract val data: List<Model> // Data list | |
abstract val ankoView: AnkoView // Layout as AnkoComponent<ViewGroup> | |
abstract fun ViewHolder.setup(model: Model) // setup model from ViewHolder | |
abstract val onItemClickListenerUnit: (Model) -> Unit // Item Click Listener | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.setup(data[position]) | |
holder.itemView.setOnClickListener { |
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 test() { | |
class City(var name: String, var location: GeoPoint) | |
var query = FirebaseFirestore.getInstance().collection("city").limit(10) | |
var error : (Exception) -> Unit = { it.printStackTrace() } | |
query.query<City>(callbackWithKey = { keyList, cityList -> }, error = error) | |
query.query(callback = { documentSnapshotList -> }, error = error) | |
query.addChangeListener(isAdded = {}, isRemoved = {}, isModified = {}, error = error) |
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
class User : HashMappable() { | |
var name: String by HashMappableProperty("") | |
var age: Int? by HashMappableProperty(null) | |
} | |
fun main() { | |
val harry = User() | |
harry.name = "Harry" |
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 <V : View> V.alpha(alpha: Double): V { | |
this.alpha = alpha.toFloat() | |
return this | |
} | |
inline fun <V : View> V.backgroundColor(color: Int): V { | |
backgroundColor = color | |
return this | |
} |
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
class LifecycleGetter<T : View>(var lifecycleOwner: LifecycleOwner, var view: T) | |
fun <T : View> T.observe(lifecycleOwner: LifecycleOwner): LifecycleGetter<T> { | |
return LifecycleGetter(lifecycleOwner, this) | |
} | |
fun <T : TextView> LifecycleGetter<T>.liveText(liveData: LiveData<String>): LifecycleGetter<T> { | |
liveData.observe(lifecycleOwner, Observer { | |
this.view.text = it | |
}) |
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
class DelegatedPreference<T>(val context: Context, val default: T) : ReadWriteProperty<Any, T> { | |
override fun getValue(thisRef: Any, property: KProperty<*>): T { | |
return context.defaultSharedPreferences.run { | |
when (default) { | |
is String -> getString(property.name, default) | |
is Long -> getLong(property.name, default) | |
is Int -> getInt(property.name, default) | |
is Boolean -> getBoolean(property.name, default) |
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 { |
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
// 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
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)) |
OlderNewer