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
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 ->
[email protected] = zoo as World.Zoo
[email protected] = 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) {