1 /*
2  * Copyright (C) 2021 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.managedprovisioning.provisioning;
18 
19 import androidx.lifecycle.ViewModel;
20 import androidx.lifecycle.ViewModelProvider;
21 
22 import com.android.managedprovisioning.provisioning.TransitionAnimationHelper.TransitionAnimationState;
23 
24 /**
25  * An {@link ViewModel} which maintains data related to provisioning.
26  */
27 public class ProvisioningViewModel extends ViewModel {
28 
29     private TransitionAnimationState mTransitionAnimationState;
30 
31     /**
32      * Saves the state of the transition animation.
33      *
34      * @see #restoreTransitionAnimationState()
35      */
saveTransitionAnimationState(TransitionAnimationState state)36     public void saveTransitionAnimationState(TransitionAnimationState state) {
37         mTransitionAnimationState = state;
38     }
39 
40     /**
41      * Returns the state that was saved via {@link
42      * #saveTransitionAnimationState(TransitionAnimationState)}.
43      */
restoreTransitionAnimationState()44     public TransitionAnimationState restoreTransitionAnimationState() {
45         return mTransitionAnimationState;
46     }
47 
48     static class ProvisioningViewModelFactory implements ViewModelProvider.Factory {
49         @Override
50         @SuppressWarnings("unchecked")
create(Class<T> modelClass)51         public <T extends ViewModel> T create(Class<T> modelClass) {
52             if (!ProvisioningViewModel.class.isAssignableFrom(modelClass)) {
53                 throw new IllegalArgumentException(
54                         "Invalid class for creating a " + "PreProvisioningViewModel: "
55                                 + modelClass);
56             }
57             return (T) new ProvisioningViewModel();
58         }
59     }
60 }
61