Skip to content

Instantly share code, notes, and snippets.

View radityagumay's full-sized avatar
🏠
Working from home

raditya gumay radityagumay

🏠
Working from home
View GitHub Profile
@radityagumay
radityagumay / compose.kt
Last active January 3, 2018 13:56
RxCompose
override fun doSomeWork() {
val d = Observable.create(ObservableOnSubscribe<String> { e ->
for (i in 0 until 10) {
val number = Math.pow(Random().nextInt(100).toDouble(), Random().nextInt(100).toDouble())
e.onNext(number.toString())
}
e.onComplete()
}).compose(loading { isShow ->
if (isShow) {
view.showLoading()
interface Universal<in T> {
fun addAll(items: Collection<T>)
fun add(item: T)
fun update(item: T)
fun updateRange(vararg items: T)
fun remove(item: T, position: Int)
class UniversalAdapter<T, VH : RecyclerView.ViewHolder>(
private val onCreateViewHolder: (ViewGroup?, Int) -> VH,
private val onBindViewHolder: (VH, Int, T) -> Unit,
private val onViewType: ((Int) -> Int)? = null) : RecyclerView.Adapter<VH>(),
Universal<T> {
var items = mutableListOf<T>()
private set
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): VH =
override fun setupView(view: View?) {
safeWith(arguments) { arguments ->
safeWitCouple(zoo, arguments.getParcelable(ZOO), poo, arguments.getParcelable(POO)) { zoo, poo, fromIntent ->
this@Foo.zoo = zoo as World.Zoo
this@Foo.poo = poo as World.Poo
if (fromIntent) {
arguments.remove(ZOO)
arguments.remove(POO)
}
class FooPresenter(private val dataSource: DataSource?) : BasePresenter<FooPresenter.View> {
fun push(data: Bar){
dataSource?.push("someKey", data)
}
fun peek() : Bar {
return dataSource?.peek<Bar>("someKey")
}
}
class FooFragment : BaseFragment<FooPresenter.View, FooPresenter>() {
companion object {
fun newInstance(data: Bar): FooFragment {
val fragment = FooFragment()
val bundle = Bundle()
bundle.putParcelable("bar", data)
fragment.arguments = bundle
return fragment
}
}
@radityagumay
radityagumay / DataSource.kt
Last active November 11, 2017 12:42
Fragment Navigation Pattern
interface DataSourceBase
class DataSource {
companion object {
private var sInstance: DataSource? = null
private var LOCK = Any()
fun getInstance(): DataSource? {
synchronized(LOCK) {
if (sInstance == null) {