diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6707fab3e..5290041b7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -184,7 +184,6 @@ dependencies { implementation("androidx.room:room-ktx:${Versions.room}") kapt("androidx.room:room-compiler:${Versions.room}") implementation("androidx.appcompat:appcompat:1.3.1") - implementation("io.reactivex.rxjava2:rxandroid:2.1.1") implementation("androidx.paging:paging-runtime:2.1.2") implementation("io.noties.markwon:core:${Versions.markwon}") implementation("io.noties.markwon:editor:${Versions.markwon}") diff --git a/app/licenses.yml b/app/licenses.yml index 4d4053b5c..83c9b4261 100644 --- a/app/licenses.yml +++ b/app/licenses.yml @@ -189,12 +189,6 @@ license: The Apache Software License, Version 2.0 licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt url: http://developer.android.com/tools/extras/support-library.html -- artifact: io.reactivex.rxjava2:rxandroid:+ - name: RxAndroid - copyrightHolder: The RxAndroid authors - license: The Apache Software License, Version 2.0 - licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt - url: https://github.com/ReactiveX/RxAndroid - artifact: androidx.swiperefreshlayout:swiperefreshlayout:+ name: Android Support Library Custom View copyrightHolder: Android Open Source Project @@ -274,12 +268,6 @@ license: The Apache Software License, Version 2.0 licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt url: http://developer.android.com/tools/extras/support-library.html -- artifact: org.reactivestreams:reactive-streams:+ - name: reactive-streams - copyrightHolder: Public domain - license: CC0 - licenseUrl: http://creativecommons.org/publicdomain/zero/1.0/ - url: http://www.reactive-streams.org/ - artifact: androidx.work:work-runtime:+ name: Android WorkManager Runtime copyrightHolder: Android Open Source Project @@ -333,12 +321,6 @@ license: The Apache Software License, Version 2.0 licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt url: http://developer.android.com/tools/extras/support-library.html -- artifact: io.reactivex.rxjava2:rxjava:+ - name: RxJava - copyrightHolder: RxJava Contributors - license: The Apache Software License, Version 2.0 - licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt - url: https://github.com/ReactiveX/RxJava - artifact: com.google.apis:google-api-services-tasks:+ name: Tasks API v1-rev55-1.25.0 copyrightHolder: Google Inc. diff --git a/app/src/main/assets/licenses.json b/app/src/main/assets/licenses.json index 1474b7eb1..a7edbfbcd 100644 --- a/app/src/main/assets/licenses.json +++ b/app/src/main/assets/licenses.json @@ -455,20 +455,6 @@ "url": "http://developer.android.com/tools/extras/support-library.html", "libraryName": "Android Support Library Custom View" }, - { - "artifactId": { - "name": "rxandroid", - "group": "io.reactivex.rxjava2", - "version": "+" - }, - "copyrightHolder": "The RxAndroid authors", - "copyrightStatement": "Copyright © The RxAndroid authors. All rights reserved.", - "license": "The Apache Software License, Version 2.0", - "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt", - "normalizedLicense": "apache2", - "url": "https://github.com/ReactiveX/RxAndroid", - "libraryName": "RxAndroid" - }, { "artifactId": { "name": "swiperefreshlayout", @@ -651,20 +637,6 @@ "url": "http://developer.android.com/tools/extras/support-library.html", "libraryName": "Android Support VectorDrawable" }, - { - "artifactId": { - "name": "reactive-streams", - "group": "org.reactivestreams", - "version": "+" - }, - "copyrightHolder": "Public domain", - "copyrightStatement": "Copyright © Public domain. All rights reserved.", - "license": "CC0", - "licenseUrl": "http://creativecommons.org/publicdomain/zero/1.0/", - "normalizedLicense": "cc0", - "url": "http://www.reactive-streams.org/", - "libraryName": "reactive-streams" - }, { "artifactId": { "name": "work-runtime", @@ -790,20 +762,6 @@ "url": "http://developer.android.com/tools/extras/support-library.html", "libraryName": "Android Support Library Drawer Layout" }, - { - "artifactId": { - "name": "rxjava", - "group": "io.reactivex.rxjava2", - "version": "+" - }, - "copyrightHolder": "RxJava Contributors", - "copyrightStatement": "Copyright © RxJava Contributors. All rights reserved.", - "license": "The Apache Software License, Version 2.0", - "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt", - "normalizedLicense": "apache2", - "url": "https://github.com/ReactiveX/RxJava", - "libraryName": "RxJava" - }, { "artifactId": { "name": "google-api-services-tasks", diff --git a/app/src/main/java/com/todoroo/astrid/adapter/NavigationDrawerAdapter.kt b/app/src/main/java/com/todoroo/astrid/adapter/NavigationDrawerAdapter.kt index 8fcec9b09..27ff8a22b 100644 --- a/app/src/main/java/com/todoroo/astrid/adapter/NavigationDrawerAdapter.kt +++ b/app/src/main/java/com/todoroo/astrid/adapter/NavigationDrawerAdapter.kt @@ -14,11 +14,10 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.FilterListItem -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.subjects.PublishSubject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.flow.MutableSharedFlow import org.tasks.LocalBroadcastManager import org.tasks.activities.DragAndDropDiffer import org.tasks.billing.Inventory @@ -46,13 +45,12 @@ class NavigationDrawerAdapter @Inject constructor( private lateinit var onClick: (FilterListItem?) -> Unit private var selected: Filter? = null - override val disposables = CompositeDisposable() - override val publishSubject = PublishSubject.create>() + override val flow = MutableSharedFlow>() override val updates: Queue, DiffUtil.DiffResult?>> = LinkedList() + override val scope: CoroutineScope = + CoroutineScope(Executors.newSingleThreadExecutor().asCoroutineDispatcher() + Job()) override var items = initializeDiffer(ArrayList()) override var dragging = false - override val scope: CoroutineScope = - CoroutineScope(Executors.newSingleThreadExecutor().asCoroutineDispatcher() + Job()) fun setOnClick(onClick: (FilterListItem?) -> Unit) { this.onClick = onClick diff --git a/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt b/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt index 882be245f..a2f5eda47 100644 --- a/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt +++ b/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt @@ -3,19 +3,14 @@ package org.tasks.activities import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListUpdateCallback import com.todoroo.andlib.utility.AndroidUtilities -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.schedulers.Schedulers -import io.reactivex.subjects.PublishSubject -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.cancel -import kotlinx.coroutines.launch +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import java.util.* +import java.util.concurrent.Executors interface DragAndDropDiffer : ListUpdateCallback { - val publishSubject: PublishSubject + val flow: MutableSharedFlow val updates: Queue> - val disposables: CompositeDisposable var items: R var dragging: Boolean val scope: CoroutineScope @@ -23,7 +18,7 @@ interface DragAndDropDiffer : ListUpdateCallback { fun submitList(list: List) { scope.launch { val transform = transform(list) - publishSubject.onNext(transform) + flow.emit(transform) } } @@ -50,16 +45,18 @@ interface DragAndDropDiffer : ListUpdateCallback { } } + @ExperimentalCoroutinesApi fun initializeDiffer(list: List): R { val initial = transform(list) - disposables.add(publishSubject - .observeOn(Schedulers.single()) + scope.launch(Dispatchers.Main) { + flow .scan(Pair(initial, null), { last: Pair, next: R -> calculateDiff(last, next) }) - .skip(1) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(this::applyDiff)) + .drop(1) + .flowOn(Executors.newSingleThreadExecutor().asCoroutineDispatcher()) + .collect { applyDiff(it) } + } return initial } @@ -68,7 +65,6 @@ interface DragAndDropDiffer : ListUpdateCallback { fun diff(last: R, next: R): DiffUtil.DiffResult fun dispose() { - disposables.dispose() scope.cancel() } } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/tasklist/DragAndDropRecyclerAdapter.kt b/app/src/main/java/org/tasks/tasklist/DragAndDropRecyclerAdapter.kt index e2001c03d..ad08c6d9c 100644 --- a/app/src/main/java/org/tasks/tasklist/DragAndDropRecyclerAdapter.kt +++ b/app/src/main/java/org/tasks/tasklist/DragAndDropRecyclerAdapter.kt @@ -10,11 +10,10 @@ import androidx.recyclerview.widget.RecyclerView import com.todoroo.astrid.activity.TaskListFragment import com.todoroo.astrid.adapter.TaskAdapter import com.todoroo.astrid.utility.Flags -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.subjects.PublishSubject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.runBlocking import org.tasks.activities.DragAndDropDiffer import org.tasks.data.TaskContainer @@ -40,13 +39,12 @@ class DragAndDropRecyclerAdapter( private val itemTouchHelper = ItemTouchHelper(ItemTouchHelperCallback()).apply { attachToRecyclerView(recyclerView) } - override val publishSubject = PublishSubject.create() - override val disposables = CompositeDisposable() + override val flow = MutableSharedFlow() override val updates: Queue> = LinkedList() override var dragging = false - override var items = initializeDiffer(tasks) override val scope: CoroutineScope = CoroutineScope(Executors.newSingleThreadExecutor().asCoroutineDispatcher() + Job()) + override var items = initializeDiffer(tasks) override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val viewType = getItemViewType(position)