1
0
Fork 0

7410 remove rxjava (#7426)

* For #7410: rewrite updateBookmarkFromObservableInput with coroutines

* For 7410: remove RxJava from project. :(

* For 7410: converted updateBookmarkFromTextChanges to Flow per review
master
Severin Rudie 2020-01-03 14:37:12 -08:00 committed by GitHub
parent ab4f4bd4d8
commit 9cbc3f7a4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 54 deletions

View File

@ -374,13 +374,6 @@ dependencies {
implementation Deps.androidx_constraintlayout
implementation Deps.androidx_coordinatorlayout
implementation Deps.rxAndroid
implementation Deps.rxKotlin
implementation Deps.rxBindings
implementation Deps.autodispose
implementation Deps.autodispose_android
implementation Deps.autodispose_android_aac
implementation Deps.sentry
implementation Deps.leanplum
implementation Deps.osslicenses_library
@ -468,8 +461,6 @@ dependencies {
implementation Deps.androidx_work_ktx
implementation Deps.google_material
implementation Deps.autodispose
implementation Deps.lottie
implementation Deps.adjust

View File

@ -12,7 +12,6 @@ import android.os.StrictMode
import androidx.annotation.CallSuper
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.getSystemService
import io.reactivex.plugins.RxJavaPlugins
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@ -81,7 +80,6 @@ open class FenixApplication : Application() {
val megazordSetup = setupMegazord()
setDayNightTheme()
registerRxExceptionHandling()
enableStrictMode()
// Make sure the engine is initialized and ready to use.
@ -151,12 +149,6 @@ open class FenixApplication : Application() {
settings().lastPlacesStorageMaintenance = System.currentTimeMillis()
}
private fun registerRxExceptionHandling() {
RxJavaPlugins.setErrorHandler {
throw it.cause ?: it
}
}
protected open fun setupLeakCanary() {
// no-op, LeakCanary is disabled by default
}

View File

@ -10,25 +10,34 @@ import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.navigation.Navigation
import com.jakewharton.rxbinding3.widget.textChanges
import com.uber.autodispose.AutoDispose
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.BiFunction
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.fragment_edit_bookmark.*
import kotlinx.android.synthetic.main.fragment_edit_bookmark.bookmarkNameEdit
import kotlinx.android.synthetic.main.fragment_edit_bookmark.bookmarkParentFolderSelector
import kotlinx.android.synthetic.main.fragment_edit_bookmark.bookmarkUrlEdit
import kotlinx.android.synthetic.main.fragment_edit_bookmark.bookmarkUrlLabel
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import mozilla.appservices.places.UrlParseFailed
import mozilla.components.concept.storage.BookmarkInfo
@ -36,6 +45,7 @@ import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.ktx.android.view.toScope
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
@ -47,11 +57,13 @@ import org.mozilla.fenix.ext.setToolbarColors
import org.mozilla.fenix.ext.toShortUrl
import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel
import org.mozilla.fenix.library.bookmarks.DesktopFolders
import java.util.concurrent.TimeUnit
/**
* Menu to edit the name, URL, and location of a bookmark item.
*/
@FlowPreview
@ExperimentalCoroutinesApi
@InternalCoroutinesApi // Cannot use collect as a lambda due to Kotlin SAM conversion issue
class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
private lateinit var guidToEdit: String
@ -118,7 +130,7 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
}
}
updateBookmarkFromObservableInput()
updateBookmarkFromTextChanges()
}
private fun initToolbar() {
@ -139,21 +151,29 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
bookmarkUrlEdit.hideKeyboard()
}
private fun updateBookmarkFromObservableInput() {
Observable.combineLatest(
bookmarkNameEdit.textChanges().skipInitialValue(),
bookmarkUrlEdit.textChanges().skipInitialValue(),
BiFunction { name: CharSequence, url: CharSequence ->
Pair(name.toString(), url.toString())
})
.filter { (name) -> name.isNotBlank() }
.debounce(debouncePeriodInMs, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(this@EditBookmarkFragment)))
.subscribe { (name, url) ->
updateBookmarkNode(name, url)
private fun updateBookmarkFromTextChanges() {
fun EditText.observe() = channelFlow {
this@observe.doOnTextChanged { text, _, _, _ ->
runBlocking { send(text.toString()) }
}
awaitClose()
}
val nameText = bookmarkNameEdit.observe()
val urlText = bookmarkUrlEdit.observe()
bookmarkNameEdit.toScope().launch {
nameText.combine(urlText) { name, url -> name to url }
.drop(1)
.filter { (name) -> name.isNotBlank() }
.debounce(timeoutMillis = debouncePeriodInMs)
// TODO convert collect to lambda when Kotlin SAM conversions are supported
.collect(object : FlowCollector<Pair<String, String>> {
override suspend fun emit(value: Pair<String, String>) {
updateBookmarkNode(value.first, value.second)
}
})
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {

View File

@ -6,9 +6,6 @@ object Versions {
const val kotlin = "1.3.30"
const val coroutines = "1.3.3"
const val android_gradle_plugin = "3.5.0"
const val rxAndroid = "2.1.0"
const val rxKotlin = "2.3.0"
const val rxBindings = "3.0.0-alpha2"
const val sentry = "1.7.10"
const val leakcanary = "2.0"
const val leanplum = "5.2.3"
@ -45,7 +42,6 @@ object Versions {
const val mozilla_glean = "19.0.0"
const val autodispose = "1.1.0"
const val adjust = "4.18.3"
const val installreferrer = "1.0"
@ -80,10 +76,6 @@ object Deps {
const val osslicenses_plugin = "com.google.android.gms:oss-licenses-plugin:${Versions.osslicenses_plugin}"
const val osslicenses_library = "com.google.android.gms:play-services-oss-licenses:${Versions.osslicenses_library}"
const val rxKotlin = "io.reactivex.rxjava2:rxkotlin:${Versions.rxKotlin}"
const val rxAndroid = "io.reactivex.rxjava2:rxandroid:${Versions.rxAndroid}"
const val rxBindings = "com.jakewharton.rxbinding3:rxbinding:${Versions.rxBindings}"
const val mozilla_concept_engine = "org.mozilla.components:concept-engine:${Versions.mozilla_android_components}"
const val mozilla_concept_push = "org.mozilla.components:concept-push:${Versions.mozilla_android_components}"
const val mozilla_concept_tabstray = "org.mozilla.components:concept-tabstray:${Versions.mozilla_android_components}"
@ -184,11 +176,6 @@ object Deps {
const val androidx_work_testing = "androidx.work:work-testing:${Versions.androidx_work}"
const val google_material = "com.google.android.material:material:${Versions.google_material}"
const val autodispose = "com.uber.autodispose:autodispose:${Versions.autodispose}"
const val autodispose_android = "com.uber.autodispose:autodispose-android:${Versions.autodispose}"
const val autodispose_android_aac = "com.uber.autodispose:autodispose-android-archcomponents:${Versions.autodispose}"
const val autodispose_android_aac_test = "com.uber.autodispose:autodispose-android-archcomponents-test:${Versions.autodispose}"
const val adjust = "com.adjust.sdk:adjust-android:${Versions.adjust}"
const val installreferrer = "com.android.installreferrer:installreferrer:${Versions.installreferrer}"