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
interface DataSourceBase | |
class DataSource { | |
companion object { | |
private var sInstance: DataSource? = null | |
private var LOCK = Any() | |
fun getInstance(): DataSource? { | |
synchronized(LOCK) { | |
if (sInstance == 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
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 | |
} | |
} |
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 FooPresenter(private val dataSource: DataSource?) : BasePresenter<FooPresenter.View> { | |
fun push(data: Bar){ | |
dataSource?.push("someKey", data) | |
} | |
fun peek() : Bar { | |
return dataSource?.peek<Bar>("someKey") | |
} | |
} |
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
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) | |
} |
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 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 = |
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
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) |
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
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() |
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
{ | |
"success": { | |
"total": 1 | |
}, | |
"contents": { | |
"quotes": [ | |
{ | |
"quote": "I came from a real tough neighborhood. Once a guy pulled a knife on me. I knew he wasn't a professional, the knife had butter on it.", | |
"length": "132", | |
"author": "Rodney Dangerfield", |
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 main() { | |
val les = Executors.newFixedThreadPool(5) | |
for (i in 0..9) { | |
val worker: Runnable = WorkerThread("" + i) | |
les.execute(worker) | |
} | |
les.shutdown() | |
while (!les.isTerminated) { } | |
println("Finished all threads") | |
} |
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 Contact { | |
private(set) lazy var name: String | |
private(set) lazy var phoneNumber: String | |
private(set) lazy var address: String | |
private(set) lazy var gender: String | |
private init( | |
name: String, | |
phoneNumber: String, | |
address: String, |
OlderNewer