Permalink
Browse files

Replace unneeded usages of observeNonNull with observe calls

  • Loading branch information...
ianhanniballake committed Dec 19, 2018
1 parent 0d3b6b7 commit e624a0343a280a4651b218359ed719adc2102d82
@@ -40,6 +40,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.observe
import androidx.navigation.fragment.findNavController
import com.google.android.apps.muzei.api.MuzeiArtSource
import com.google.android.apps.muzei.api.MuzeiContract
@@ -61,7 +62,6 @@ import com.google.android.apps.muzei.util.AnimatedMuzeiLoadingSpinnerView
import com.google.android.apps.muzei.util.PanScaleProxyView
import com.google.android.apps.muzei.util.coroutineScope
import com.google.android.apps.muzei.util.makeCubicGradientScrimDrawable
import com.google.android.apps.muzei.util.observeNonNull
import com.google.android.apps.muzei.widget.showWidgetPreview
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.Dispatchers
@@ -325,7 +325,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
loadingContainerView = view.findViewById(R.id.image_loading_container)
loadingIndicatorView = view.findViewById(R.id.image_loading_indicator)

WallpaperSizeLiveData.observeNonNull(this) { size ->
WallpaperSizeLiveData.observe(this) { size ->
wallpaperAspectRatio = if (size.height > 0) {
size.width * 1f / size.height
} else {
@@ -334,14 +334,14 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
resetProxyViewport()
}

ArtworkSizeLiveData.observeNonNull(this) { size ->
ArtworkSizeLiveData.observe(this) { size ->
artworkAspectRatio = size.width * 1f / size.height
resetProxyViewport()
}

ArtDetailViewport.addObserver(this)

SwitchingPhotosLiveData.observeNonNull(this) { switchingPhotos ->
SwitchingPhotosLiveData.observe(this) { switchingPhotos ->
currentViewportId = switchingPhotos.viewportId
panScaleProxyView.panScaleEnabled = switchingPhotos is SwitchingPhotosDone
// Process deferred artwork size change when done switching
@@ -210,10 +210,10 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
wallpaperLifecycle.addObserver(this)
setTouchEventsEnabled(true)
setOffsetNotificationsEnabled(true)
EffectsLockScreenOpenLiveData.observeNonNull(this) { isEffectsLockScreenOpen ->
EffectsLockScreenOpenLiveData.observe(this) { isEffectsLockScreenOpen ->
renderController.onLockScreen = isEffectsLockScreenOpen
}
ArtDetailOpenLiveData.observeNonNull(this) { isArtDetailOpened ->
ArtDetailOpenLiveData.observe(this) { isArtDetailOpened ->
cancelDelayedBlur()
queueEvent { renderer.setIsBlurred(!isArtDetailOpened, true) }
}
@@ -29,6 +29,7 @@ import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.lifecycle.observe
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
@@ -37,7 +38,6 @@ import com.bumptech.glide.request.RequestOptions
import com.google.android.apps.muzei.settings.EffectsLockScreenOpenLiveData
import com.google.android.apps.muzei.util.ImageBlurrer
import com.google.android.apps.muzei.util.blur
import com.google.android.apps.muzei.util.observeNonNull
import com.google.android.apps.muzei.util.roundMult4
import java.security.MessageDigest

@@ -179,7 +179,7 @@ class MuzeiRendererFragment : Fragment(), RenderController.Callbacks, MuzeiBlurR
}
lifecycle.addObserver(renderController)
if (!demoMode) {
EffectsLockScreenOpenLiveData.observeNonNull(this@MuzeiRendererFragment) {
EffectsLockScreenOpenLiveData.observe(this@MuzeiRendererFragment) {
isEffectsLockScreenOpen ->
renderController.onLockScreen = isEffectsLockScreenOpen
}
@@ -20,9 +20,9 @@ import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.commit
import androidx.lifecycle.observe
import com.google.android.apps.muzei.MissingResourcesDialogFragment
import com.google.android.apps.muzei.render.MuzeiRendererFragment
import com.google.android.apps.muzei.util.observeNonNull
import com.google.android.apps.muzei.wallpaper.WallpaperActiveState
import net.nurik.roman.muzei.R

@@ -44,7 +44,7 @@ class SettingsActivity : AppCompatActivity() {
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
setContentView(R.layout.settings_activity)

WallpaperActiveState.observeNonNull(this) { isActive ->
WallpaperActiveState.observe(this) { isActive ->
updateRenderLocally(!isActive)
}
}
@@ -47,7 +47,6 @@ import com.google.android.apps.muzei.room.sendAction
import com.google.android.apps.muzei.sync.ProviderManager
import com.google.android.apps.muzei.util.coroutineScope
import com.google.android.apps.muzei.util.goAsync
import com.google.android.apps.muzei.util.observeNonNull
import com.google.android.apps.muzei.util.toastFromBackground
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.Dispatchers
@@ -269,7 +268,7 @@ class SourceManager(private val context: Context) : DefaultLifecycleObserver, Li
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
}
}
SubscriberLiveData().observeNonNull(this) { source ->
SubscriberLiveData().observe(this) { source ->
sendSelectedSourceAnalytics(source.componentName)
}
// Register for package change events
@@ -27,7 +27,7 @@ import android.widget.TextView
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.google.android.apps.muzei.util.observeNonNull
import androidx.lifecycle.observe
import com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE
import com.twofortyfouram.locale.api.Intent.EXTRA_STRING_BLURB
import net.nurik.roman.muzei.R
@@ -65,7 +65,7 @@ class TaskerSettingActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel.actions.observeNonNull(this) { actions ->
viewModel.actions.observe(this) { actions ->
adapter.clear()
adapter.addAll(actions)
if (!dialog.isShowing) {
@@ -71,7 +71,7 @@ internal class TaskerSettingViewModel(
a1.text.compareTo(a2.text)
}

val actions : LiveData<List<Action>?> = object : MutableLiveData<List<Action>?>() {
val actions : LiveData<List<Action>> = object : MutableLiveData<List<Action>>() {
val nextArtworkAction = Action(
ContextCompat.getDrawable(application, R.drawable.ic_next_artwork)!!.apply {
setBounds(0, 0, imageSize, imageSize)
@@ -28,14 +28,14 @@ import android.widget.Button
import androidx.activity.viewModels
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.observe
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.wear.widget.WearableLinearLayoutManager
import androidx.wear.widget.WearableRecyclerView
import com.google.android.apps.muzei.api.provider.MuzeiArtProvider
import com.google.android.apps.muzei.sync.ProviderManager
import com.google.android.apps.muzei.util.observeNonNull
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@@ -64,7 +64,7 @@ class ChooseProviderActivity : FragmentActivity() {
providerList.layoutManager = WearableLinearLayoutManager(this)
providerList.adapter = adapter

viewModel.providers.observeNonNull(this) { providers ->
viewModel.providers.observe(this) { providers ->
adapter.submitList(providers)
}
}

0 comments on commit e624a03

Please sign in to comment.