1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 package com.android.wallpaper.picker.customization.ui.viewmodel 18 19 import android.graphics.drawable.Drawable 20 import androidx.lifecycle.ViewModel 21 import com.android.wallpaper.model.Screen 22 23 /** 24 * Interface for a view model that can store the animation state for use after a configuration 25 * change restart. 26 */ 27 abstract class AnimationStateViewModel : ViewModel() { 28 /** Used to persist the preview loading animation state through config change restarts */ 29 data class AnimationState( 30 /** The drawable used as animation background */ 31 val drawable: Drawable?, 32 /** The elapsed time of the animation */ 33 val time: Long?, 34 /** The transition progress for fade in animation */ 35 val transitionProgress: Float?, 36 /** The color used for animation effects */ 37 val color: Int?, 38 ) 39 40 private var homePreviewAnimationState: AnimationState? = null 41 private var lockPreviewAnimationState: AnimationState? = null 42 saveAnimationStatenull43 fun saveAnimationState(screen: Screen, state: AnimationState?) { 44 if (screen == Screen.LOCK_SCREEN) { 45 lockPreviewAnimationState = state 46 } else { 47 homePreviewAnimationState = state 48 } 49 } 50 getAnimationStatenull51 fun getAnimationState(screen: Screen): AnimationState? { 52 return if (screen == Screen.LOCK_SCREEN) { 53 lockPreviewAnimationState 54 } else { 55 homePreviewAnimationState 56 } 57 } 58 } 59