Skip to content

Commit

Permalink
Upgrade to Lifecycle 2.2.0-alpha01 and lifecycleScope
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhanniballake committed May 10, 2019
1 parent 5f3a8d4 commit a9361cf
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 88 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -31,7 +31,7 @@ buildscript {
fragmentVersion = '1.1.0-alpha08'
glideVersion = '4.9.0'
kotlinVersion = '1.3.31'
lifecycleVersion = '2.1.0-alpha04'
lifecycleVersion = '2.2.0-alpha01'
materialVersion = '1.1.0-alpha06'
multidexVersion = '2.0.1'
navigationVersion = '2.1.0-alpha03'
Expand Down
2 changes: 1 addition & 1 deletion example-watchface/build.gradle
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'kotlin-android'

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
compileOnly "com.google.android.wearable:wearable:$wearableVersion"
implementation "com.google.android.support:wearable:$wearableVersion"
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion main/build.gradle
Expand Up @@ -115,7 +115,7 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
Expand Down
Expand Up @@ -40,6 +40,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
import androidx.navigation.fragment.findNavController
import com.google.android.apps.muzei.api.MuzeiArtSource
Expand All @@ -60,7 +61,6 @@ import com.google.android.apps.muzei.settings.AboutActivity
import com.google.android.apps.muzei.sync.ProviderManager
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.widget.showWidgetPreview
import com.google.firebase.analytics.FirebaseAnalytics
Expand Down Expand Up @@ -124,14 +124,14 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {

metadataView.setOnClickListener {
val context = requireContext()
coroutineScope.launch {
lifecycleScope.launch {
FirebaseAnalytics.getInstance(context).logEvent("artwork_info_open", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "art_detail"))
currentArtworkLiveData.value?.openArtworkInfo(context)
}
}

coroutineScope.launch(Dispatchers.Main) {
lifecycleScope.launch(Dispatchers.Main) {
val commands = context?.run {
currentArtwork?.getCommands(this) ?: run {
if (currentProviderLiveData.value?.authority == SOURCES_AUTHORITY) {
Expand Down Expand Up @@ -317,7 +317,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
onLongPress = {
coroutineScope.launch {
lifecycleScope.launch {
showWidgetPreview(requireContext().applicationContext)
}
}
Expand Down Expand Up @@ -363,7 +363,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {

override fun onResume() {
super.onResume()
coroutineScope.launch {
lifecycleScope.launch {
NewWallpaperNotificationReceiver.markNotificationRead(requireContext())
}
}
Expand Down Expand Up @@ -426,7 +426,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
// the loading spinner will go away.
updateLoadingSpinnerVisibility()
unsetNextFakeLoading?.cancel()
unsetNextFakeLoading = coroutineScope.launch(Dispatchers.Main) {
unsetNextFakeLoading = lifecycleScope.launch(Dispatchers.Main) {
delay(10000)
showFakeLoading = false
updateLoadingSpinnerVisibility()
Expand All @@ -441,7 +441,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
showLoadingSpinner = null
}
if (showFakeLoading) {
this.showLoadingSpinner = coroutineScope.launch(Dispatchers.Main) {
this.showLoadingSpinner = lifecycleScope.launch(Dispatchers.Main) {
delay(700)
loadingIndicatorView.start()
loadingContainerView.isVisible = true
Expand Down
Expand Up @@ -21,9 +21,9 @@ import android.content.Intent
import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import com.google.android.apps.muzei.room.MuzeiDatabase
import com.google.android.apps.muzei.room.openArtworkInfo
import com.google.android.apps.muzei.util.coroutineScope
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.launch

Expand All @@ -43,7 +43,7 @@ class ArtworkInfoRedirectActivity : FragmentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
coroutineScope.launch {
lifecycleScope.launch {
val artwork = MuzeiDatabase.getInstance(this@ArtworkInfoRedirectActivity)
.artworkDao()
.getCurrentArtwork()
Expand Down
Expand Up @@ -39,6 +39,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
import com.google.android.apps.muzei.featuredart.BuildConfig.FEATURED_ART_AUTHORITY
import com.google.android.apps.muzei.notifications.NotificationUpdater
Expand All @@ -54,7 +55,6 @@ import com.google.android.apps.muzei.settings.Prefs
import com.google.android.apps.muzei.shortcuts.ArtworkInfoShortcutController
import com.google.android.apps.muzei.sources.SourceManager
import com.google.android.apps.muzei.sync.ProviderManager
import com.google.android.apps.muzei.util.coroutineScope
import com.google.android.apps.muzei.util.filterNotNull
import com.google.android.apps.muzei.wallpaper.LockscreenObserver
import com.google.android.apps.muzei.wallpaper.WallpaperAnalytics
Expand Down Expand Up @@ -166,7 +166,7 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {

doubleTapTimeout?.cancel()
val timeout = ViewConfiguration.getDoubleTapTimeout().toLong()
doubleTapTimeout = coroutineScope.launch {
doubleTapTimeout = lifecycleScope.launch {
delay(timeout)
queueEvent {
validDoubleTap = false
Expand Down Expand Up @@ -202,7 +202,7 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
.artworkDao().currentArtwork
.filterNotNull()
.observe(this) { artwork ->
coroutineScope.launch {
lifecycleScope.launch {
updateCurrentArtwork(artwork)
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
}

cancelDelayedBlur()
delayedBlur = coroutineScope.launch {
delayedBlur = lifecycleScope.launch {
delay(TEMPORARY_FOCUS_DURATION_MILLIS)
queueEvent {
renderer.setIsBlurred(true, false)
Expand Down
Expand Up @@ -22,10 +22,10 @@ import android.os.Bundle
import android.util.Log
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import com.google.android.apps.muzei.single.BuildConfig.SINGLE_AUTHORITY
import com.google.android.apps.muzei.single.SingleArtProvider
import com.google.android.apps.muzei.sync.ProviderManager
import com.google.android.apps.muzei.util.coroutineScope
import com.google.android.apps.muzei.util.toast
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.Dispatchers
Expand All @@ -42,7 +42,7 @@ class PhotoSetAsTargetActivity : FragmentActivity() {
super.onCreate(savedInstanceState)

intent?.data?.also { uri ->
coroutineScope.launch(Dispatchers.Main) {
lifecycleScope.launch(Dispatchers.Main) {
val context = this@PhotoSetAsTargetActivity
val success = SingleArtProvider.setArtwork(context, uri)
if (!success) {
Expand Down
Expand Up @@ -29,6 +29,7 @@ import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
Expand All @@ -38,7 +39,6 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.google.android.apps.muzei.room.Artwork
import com.google.android.apps.muzei.room.MuzeiDatabase
import com.google.android.apps.muzei.util.coroutineScope
import com.google.android.apps.muzei.util.toast
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -135,7 +135,7 @@ class BrowseProviderFragment: Fragment(R.layout.browse_provider_fragment) {
}
) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
ArtViewHolder(viewLifecycleOwner.coroutineScope,
ArtViewHolder(viewLifecycleOwner.lifecycleScope,
layoutInflater.inflate(R.layout.browse_provider_item, parent, false))

override fun onBindViewHolder(holder: ArtViewHolder, position: Int) {
Expand Down
Expand Up @@ -21,7 +21,7 @@ import android.animation.ObjectAnimator
import android.content.Context
import androidx.core.animation.doOnEnd
import androidx.lifecycle.LifecycleOwner
import com.google.android.apps.muzei.util.coroutineScope
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -70,7 +70,7 @@ class DemoRenderController(

override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)
coroutineScope = owner.coroutineScope
coroutineScope = owner.lifecycleScope
runAnimation()
}

Expand Down
Expand Up @@ -21,8 +21,8 @@ import android.content.SharedPreferences
import android.os.Handler
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.google.android.apps.muzei.settings.Prefs
import com.google.android.apps.muzei.util.coroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -105,7 +105,7 @@ abstract class RenderController(
}

override fun onCreate(owner: LifecycleOwner) {
coroutineScope = owner.coroutineScope
coroutineScope = owner.lifecycleScope
Prefs.getSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
}
Expand Down
Expand Up @@ -23,8 +23,8 @@ import android.widget.SeekBar
import androidx.core.content.edit
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.google.android.apps.muzei.render.MuzeiBlurRenderer
import com.google.android.apps.muzei.util.coroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -87,7 +87,7 @@ class EffectsScreenFragment : Fragment(R.layout.effects_screen_fragment) {
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
if (fromUser) {
updateBlur?.cancel()
updateBlur = coroutineScope.launch {
updateBlur = lifecycleScope.launch {
delay(750)
prefs.edit {
putInt(blurPref, blurSeekBar.progress)
Expand All @@ -112,7 +112,7 @@ class EffectsScreenFragment : Fragment(R.layout.effects_screen_fragment) {
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
if (fromUser) {
updateDim?.cancel()
updateDim = coroutineScope.launch {
updateDim = lifecycleScope.launch {
delay(750)
prefs.edit {
putInt(dimPref, dimSeekBar.progress)
Expand All @@ -137,7 +137,7 @@ class EffectsScreenFragment : Fragment(R.layout.effects_screen_fragment) {
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
if (fromUser) {
updateGrey?.cancel()
updateGrey = coroutineScope.launch {
updateGrey = lifecycleScope.launch {
delay(750)
prefs.edit {
putInt(greyPref, greySeekBar.progress)
Expand Down
Expand Up @@ -34,6 +34,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
import androidx.room.withTransaction
import com.google.android.apps.muzei.api.MuzeiArtSource
Expand All @@ -46,7 +47,6 @@ import com.google.android.apps.muzei.room.Provider
import com.google.android.apps.muzei.room.Source
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.toastFromBackground
import com.google.firebase.analytics.FirebaseAnalytics
Expand Down Expand Up @@ -222,7 +222,7 @@ class SourceManager(private val context: Context) : DefaultLifecycleObserver, Li
// Don't do anything if it is the same Source
return@addSource
}
coroutineScope.launch(Dispatchers.Main) {
lifecycleScope.launch(Dispatchers.Main) {
currentSource?.unsubscribe()
currentSource = source
if (source != null) {
Expand Down
1 change: 1 addition & 0 deletions source-gallery/build.gradle
Expand Up @@ -34,6 +34,7 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
implementation "androidx.exifinterface:exifinterface:$exifInterfaceVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.room:room-ktx:$roomVersion"
Expand Down
Expand Up @@ -6,7 +6,7 @@ import android.util.Log
import androidx.core.app.ActivityCompat
import androidx.core.app.ShareCompat
import androidx.fragment.app.FragmentActivity
import com.google.android.apps.muzei.util.coroutineScope
import androidx.lifecycle.lifecycleScope
import com.google.android.apps.muzei.util.toast
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -43,7 +43,7 @@ class GalleryAddPhotosActivity : FragmentActivity() {
}
val chosenPhoto = ChosenPhoto(photoUri)

coroutineScope.launch(Dispatchers.Main) {
lifecycleScope.launch(Dispatchers.Main) {
val context = this@GalleryAddPhotosActivity
val id = GalleryDatabase.getInstance(context).chosenPhotoDao()
.insert(context, chosenPhoto, callingApplication)
Expand Down

0 comments on commit a9361cf

Please sign in to comment.