1/*
2 * Copyright (C) 2017 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
17package androidx.lifecycle;
18
19import androidx.annotation.MainThread;
20import androidx.annotation.NonNull;
21import androidx.fragment.app.Fragment;
22import androidx.fragment.app.FragmentActivity;
23
24/**
25 * Factory methods for {@link ViewModelStore} class.
26 *
27 * @deprecated Use {@link FragmentActivity#getViewModelStore()} or
28 * {@link Fragment#getViewModelStore()} to retrieve a {@code ViewModelStore} directly from
29 * activities and fragments.
30 */
31@SuppressWarnings("WeakerAccess")
32@Deprecated
33public class ViewModelStores {
34
35    private ViewModelStores() {
36    }
37
38    /**
39     * Returns the {@link ViewModelStore} of the given activity.
40     *
41     * @param activity an activity whose {@code ViewModelStore} is requested
42     * @return a {@code ViewModelStore}
43     * @deprecated Use {@link FragmentActivity#getViewModelStore()}
44     */
45    @Deprecated
46    @NonNull
47    @MainThread
48    public static ViewModelStore of(@NonNull FragmentActivity activity) {
49        return activity.getViewModelStore();
50    }
51
52    /**
53     * Returns the {@link ViewModelStore} of the given fragment.
54     *
55     * @param fragment a fragment whose {@code ViewModelStore} is requested
56     * @return a {@code ViewModelStore}
57     * @deprecated Use {@link Fragment#getViewModelStore()}
58     */
59    @Deprecated
60    @NonNull
61    @MainThread
62    public static ViewModelStore of(@NonNull Fragment fragment) {
63        return fragment.getViewModelStore();
64    }
65}
66