Skip to content
Permalink
Browse files

Upgrade to Lifecycle 2.2.0-alpha01 and lifecycleScope

  • Loading branch information...
ianhanniballake committed May 10, 2019
1 parent 5f3a8d4 commit a9361cf2afd34cd9e818da7596715d13ccaf68f5
Showing with 45 additions and 88 deletions.
  1. +1 −1 build.gradle
  2. +1 −1 example-watchface/build.gradle
  3. +0 −45 extensions/src/main/java/com/google/android/apps/muzei/util/LivecycleJob.kt
  4. +1 −1 main/build.gradle
  5. +7 −7 main/src/main/java/com/google/android/apps/muzei/ArtDetailFragment.kt
  6. +2 −2 main/src/main/java/com/google/android/apps/muzei/ArtworkInfoRedirectActivity.kt
  7. +4 −4 main/src/main/java/com/google/android/apps/muzei/MuzeiWallpaperService.kt
  8. +2 −2 main/src/main/java/com/google/android/apps/muzei/PhotoSetAsTargetActivity.kt
  9. +2 −2 main/src/main/java/com/google/android/apps/muzei/browse/BrowseProviderFragment.kt
  10. +2 −2 main/src/main/java/com/google/android/apps/muzei/render/DemoRenderController.kt
  11. +2 −2 main/src/main/java/com/google/android/apps/muzei/render/RenderController.kt
  12. +4 −4 main/src/main/java/com/google/android/apps/muzei/settings/EffectsScreenFragment.kt
  13. +2 −2 main/src/main/java/com/google/android/apps/muzei/sources/SourceManager.kt
  14. +1 −0 source-gallery/build.gradle
  15. +2 −2 source-gallery/src/main/java/com/google/android/apps/muzei/gallery/GalleryAddPhotosActivity.kt
  16. +2 −2 source-gallery/src/main/java/com/google/android/apps/muzei/gallery/GallerySettingsActivity.kt
  17. +1 −0 wearable/build.gradle
  18. +3 −3 wearable/src/main/java/com/google/android/apps/muzei/FullScreenActivity.kt
  19. +4 −4 wearable/src/main/java/com/google/android/apps/muzei/MuzeiActivity.kt
  20. +2 −2 wearable/src/main/java/com/google/android/apps/muzei/MuzeiWatchFace.kt
@@ -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'
@@ -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"

This file was deleted.

Oops, something went wrong.
@@ -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"
@@ -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
@@ -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
@@ -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) {
@@ -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)
}
}
@@ -363,7 +363,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {

override fun onResume() {
super.onResume()
coroutineScope.launch {
lifecycleScope.launch {
NewWallpaperNotificationReceiver.markNotificationRead(requireContext())
}
}
@@ -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()
@@ -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
@@ -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

@@ -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()
@@ -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
@@ -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
@@ -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
@@ -202,7 +202,7 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
.artworkDao().currentArtwork
.filterNotNull()
.observe(this) { artwork ->
coroutineScope.launch {
lifecycleScope.launch {
updateCurrentArtwork(artwork)
}
}
@@ -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)
@@ -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
@@ -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) {
@@ -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
@@ -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
@@ -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) {
@@ -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
@@ -70,7 +70,7 @@ class DemoRenderController(

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

@@ -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
@@ -105,7 +105,7 @@ abstract class RenderController(
}

override fun onCreate(owner: LifecycleOwner) {
coroutineScope = owner.coroutineScope
coroutineScope = owner.lifecycleScope
Prefs.getSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
}
@@ -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
@@ -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)
@@ -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)
@@ -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)
@@ -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
@@ -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
@@ -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) {
@@ -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"
@@ -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
@@ -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)
Oops, something went wrong.

0 comments on commit a9361cf

Please sign in to comment.
You can’t perform that action at this time.