This file contains hidden or 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 DataSource { | |
| fun all(): Observable<List<Data>> | |
| fun save(data: Data): Boolean | |
| } | |
| class DataRepository(private val dao: DataDao) : DataSource { | |
| private val generateData: () -> List<Data> = { | |
| dao.all() | |
| } | |
| private val mergeData: (List<Data>, Data) -> List<Data> = { cache, newData -> |
This file contains hidden or 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 DatabaseObservable<T>(private val generateData: () -> List<T>, private val mergeData: (cache: List<T>, data: T) -> List<T>) { | |
| private var bs: BehaviorSubject<List<T>>? = null | |
| fun cache(): Observable<List<T>> { | |
| if(bs == null) { | |
| bs = BehaviorSubject.create() | |
| AsyncTask.execute { bs?.onNext(generateData()) } | |
| } | |
| return bs!!.replay(1).autoConnect() | |
| } |
This file contains hidden or 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 DataSource { | |
| fun all(): List<Data> | |
| fun save(data: Data): Boolean | |
| } | |
| class DataRepository(val dao: DataDao) : DataSource { | |
| override fun all(): List<Data> = dao.all() | |
| override fun save(data: Data): Boolean = dao.save(data) != 0L | |
| } |
This file contains hidden or 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
| @Dao | |
| interface DataDao { | |
| @Query("SELECT * FROM Data") | |
| fun all(): List<Data> | |
| @Insert(onConflict = OnConflictStrategy.REPLACE) | |
| fun save(data: Data): Long | |
| } |
This file contains hidden or 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
| @Entity | |
| data class Data(@PrimaryKey(autoGenerate = true) var id: Long = 0, var name: String = "") |
This file contains hidden or 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
| s1 accept 1 | |
| s1 accept 2 | |
| s2 accept 2 | |
| s3 accept 2 | |
| s1 accept 3 | |
| s2 accept 3 | |
| s3 accept 3 | |
| s4 accept 3 | |
| s1 accept 4 | |
| s2 accept 4 |
This file contains hidden or 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
| import io.reactivex.Observable; | |
| import io.reactivex.subjects.BehaviorSubject; | |
| public class Q47000608 { | |
| public static void main(String[] args) { | |
| BehaviorSubject<Integer> bs = BehaviorSubject.createDefault(1); | |
| Observable<Integer> o = bs.replay(1).autoConnect().distinctUntilChanged(); | |
| o.subscribe(i -> System.out.println("s1 accept " + i)); | |
| bs.onNext(2); | |
| o.subscribe(i -> System.out.println("s2 accept " + i)); |
This file contains hidden or 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
| onView(allOf( | |
| withId(R.id.name), | |
| isDescendantOfA(withTagValue(is((Object)1L)))) | |
| ).check(matches(withText("Name"))); |
This file contains hidden or 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
| onView(withId(R.id.name)).check(matches(withText("Name"))); |
This file contains hidden or 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
| onView(allOf(matcher1, allOf(matcher2, matcher3))).check(assertion); |
NewerOlder