1b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets/*
2b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * Copyright (C) 2017 The Android Open Source Project
3b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets *
4b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * Licensed under the Apache License, Version 2.0 (the "License");
5b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * you may not use this file except in compliance with the License.
6b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * You may obtain a copy of the License at
7b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets *
8b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets *      http://www.apache.org/licenses/LICENSE-2.0
9b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets *
10b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * Unless required by applicable law or agreed to in writing, software
11b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * distributed under the License is distributed on an "AS IS" BASIS,
12b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * See the License for the specific language governing permissions and
14b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * limitations under the License.
15b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets */
16b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets
17ba069d50913c3fb250bb60ec310439db36895337Alan Viverettepackage androidx.lifecycle;
18b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets
19ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.annotation.MainThread;
20ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.annotation.NonNull;
21ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.fragment.app.Fragment;
22ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.fragment.app.FragmentActivity;
23b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets
24b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets/**
25b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets * Factory methods for {@link ViewModelStore} class.
265122b0151b549a81b0c8cac9192b6713df0d81abIan Lake *
275122b0151b549a81b0c8cac9192b6713df0d81abIan Lake * @deprecated Use {@link FragmentActivity#getViewModelStore()} or
285122b0151b549a81b0c8cac9192b6713df0d81abIan Lake * {@link Fragment#getViewModelStore()} to retrieve a {@code ViewModelStore} directly from
295122b0151b549a81b0c8cac9192b6713df0d81abIan Lake * activities and fragments.
30b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets */
31b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets@SuppressWarnings("WeakerAccess")
325122b0151b549a81b0c8cac9192b6713df0d81abIan Lake@Deprecated
33b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinetspublic class ViewModelStores {
34b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets
35b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    private ViewModelStores() {
36b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    }
37b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets
38b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    /**
39b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     * Returns the {@link ViewModelStore} of the given activity.
40b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     *
41b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     * @param activity an activity whose {@code ViewModelStore} is requested
42b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     * @return a {@code ViewModelStore}
435122b0151b549a81b0c8cac9192b6713df0d81abIan Lake     * @deprecated Use {@link FragmentActivity#getViewModelStore()}
44b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     */
455122b0151b549a81b0c8cac9192b6713df0d81abIan Lake    @Deprecated
4668c2e5804888c2d3e6e00784b7c1212083366410Ian Lake    @NonNull
47b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    @MainThread
489d8d936607b58e83fbf1ef57b5bd9846829abb66Sergey Vasilinets    public static ViewModelStore of(@NonNull FragmentActivity activity) {
495122b0151b549a81b0c8cac9192b6713df0d81abIan Lake        return activity.getViewModelStore();
50b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    }
51b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets
52b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    /**
53b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     * Returns the {@link ViewModelStore} of the given fragment.
54b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     *
55b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     * @param fragment a fragment whose {@code ViewModelStore} is requested
56b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     * @return a {@code ViewModelStore}
575122b0151b549a81b0c8cac9192b6713df0d81abIan Lake     * @deprecated Use {@link Fragment#getViewModelStore()}
58b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets     */
595122b0151b549a81b0c8cac9192b6713df0d81abIan Lake    @Deprecated
6068c2e5804888c2d3e6e00784b7c1212083366410Ian Lake    @NonNull
61b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    @MainThread
629d8d936607b58e83fbf1ef57b5bd9846829abb66Sergey Vasilinets    public static ViewModelStore of(@NonNull Fragment fragment) {
635122b0151b549a81b0c8cac9192b6713df0d81abIan Lake        return fragment.getViewModelStore();
64b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets    }
65b9920233c8c63b218ab8ca1f7df35fdc9649f12cSergey Vasilinets}
66