Skip to content

Instantly share code, notes, and snippets.

View bearprada's full-sized avatar
🎯
Focusing

PRADA Hsiung bearprada

🎯
Focusing
  • Facebook
  • London, UK
View GitHub Profile
public class GenericApp {
private DataSource<FacebookItem> mFbSource = new FacebookDataSource();
private DataSource<InstagramItem> mIgSource = new InstagramDataSource();
public DataSource<? extends Item> getDataSource(int section) {
switch (section) {
case 0:
return mIgSource;
case 1:
default:
fun showGDPRConsentDialog() {
InMobiSdk.updateGDPRConsent(getGDPRJson(false))
// Launch GDPR concent dialog
}
fun clickAgreeButton() {
InMobiSdk.updateGDPRConsent(getGDPRJson(true))
}
fun clickDisagreeButton() {
@bearprada
bearprada / Test.kt
Last active January 2, 2019 07:30
TakeUntil and TakeLast Behavior
fun unsubsribeFirst() {
val input = PublishSubject.create<Int>()
val lifetime = CompletableSubject.create()
input.ignoreElements().subscribe(lifetime)
input.takeLast(2)
.subscribeUntil(lifetime) { println("$it") }
println("start")
@bearprada
bearprada / TestDelayAndFlatMap.kt
Created January 2, 2019 08:06
Test Delay with FlatMap operator
fun `test delay`() {
Observable.just(listOf(1,2,3,4,5))
.flatMap { nums ->
val obs = mutableListOf<Observable<Int>>()
for (i in nums) {
obs.add(Observable.just(i).delay(i.toLong(), TimeUnit.MILLISECONDS))
}
Observable.merge(obs)
}
.subscribe { println("$it") }

Scope (large -> small) : Repository > Store > Factory > Others

Class Name Read Write Comment
store Y Y Provide cache machanism. imply signlton pattern
repository Y Y the same as store, but repository have more features rather than the read/write data, e.g, update/delete data, provide metadata to archive some business goal, e,g. latest update time, sorting the items based on some rules.
source Y N get the results when calling it
provider Y N provide the real implementation, we use it when we try to inject the dependencies(eliminate it)
factory Y N imply Factory pattern, reduce the complexity of creating objects