// Path: library/src/main/java/com/oasisfeng/android/app/LifecycleViewModelActivity.java
// public class LifecycleViewModelActivity extends LifecycleActivity implements ViewModelStoreOwner {
// 
// 	@Override public @NonNull ViewModelStore getViewModelStore() {
// 		if (getApplication() == null) {
// 			throw new IllegalStateException("Your activity is not yet attached to the "
// 					+ "Application instance. You can't request ViewModel before onCreate call.");
// 		}
// 		if (mViewModelStore == null) {
// 			mViewModelStore = new ViewModelStore();
// 		}
// 		return mViewModelStore;
// 	}
// 
// 	private ViewModelStore mViewModelStore;
// }
// 
// Path: library/src/main/java/com/oasisfeng/android/app/LifecycleViewModelFragment.java
// public class LifecycleViewModelFragment extends LifecycleFragment implements ViewModelStoreOwner {
// 
// 	@Override public @NonNull ViewModelStore getViewModelStore() {
// 		if ((SDK_INT >= M ? getContext() : getActivity()) == null) throw new IllegalStateException("Can't access ViewModels from detached fragment");
// 		if (mViewModelStore == null) mViewModelStore = new ViewModelStore();
// 		return mViewModelStore;
// 	}
// 
// 	private ViewModelStore mViewModelStore;		// TODO: Retain across configuration changes
// }


import androidx.lifecycle.ViewModelStoreOwner;
import android.app.Activity;
import android.app.Application;
import android.app.Fragment;
import com.oasisfeng.android.app.LifecycleViewModelActivity;
import com.oasisfeng.android.app.LifecycleViewModelFragment;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStore;
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.oasisfeng.androidx.lifecycle;




/**
 * Utilities methods for {@link ViewModelStore} class.
 */
public class ViewModelProviders {

	private static Application checkApplication(Activity activity) {
		Application application = activity.getApplication();
		if (application == null) {
			throw new IllegalStateException("Your activity/fragment is not yet attached to "
					+ "Application. You can't request ViewModel before onCreate call.");
		}
		return application;
	}

	private static Activity checkActivity(Fragment fragment) {
		Activity activity = fragment.getActivity();
		if (activity == null) {
			throw new IllegalStateException("Can't create ViewModelProvider for detached fragment");
		}
		return activity;
	}

	/**
	 * Creates a {@link ViewModelProvider}, which retains ViewModels while a scope of given
	 * {@code fragment} is alive. More detailed explanation is in {@link ViewModel}.
	 * <p>
	 * It uses {@link ViewModelProvider.AndroidViewModelFactory} to instantiate new ViewModels.
	 *
	 * @param fragment a fragment, in whose scope ViewModels should be retained
	 * @return a ViewModelProvider instance
	 */
	@NonNull
	@MainThread
	public static ViewModelProvider of(@NonNull LifecycleViewModelFragment fragment) {
		return of(fragment, null);
	}

	/**
	 * Creates a {@link ViewModelProvider}, which retains ViewModels while a scope of given Activity
	 * is alive. More detailed explanation is in {@link ViewModel}.
	 * <p>
	 * It uses {@link ViewModelProvider.AndroidViewModelFactory} to instantiate new ViewModels.
	 *
	 * @param activity an activity, in whose scope ViewModels should be retained
	 * @return a ViewModelProvider instance
	 */
	@NonNull
	@MainThread
// Path: library/src/main/java/com/oasisfeng/android/app/LifecycleViewModelActivity.java
// public class LifecycleViewModelActivity extends LifecycleActivity implements ViewModelStoreOwner {
// 
// 	@Override public @NonNull ViewModelStore getViewModelStore() {
// 		if (getApplication() == null) {
// 			throw new IllegalStateException("Your activity is not yet attached to the "
// 					+ "Application instance. You can't request ViewModel before onCreate call.");
// 		}
// 		if (mViewModelStore == null) {
// 			mViewModelStore = new ViewModelStore();
// 		}
// 		return mViewModelStore;
// 	}
// 
// 	private ViewModelStore mViewModelStore;
// }
// 
// Path: library/src/main/java/com/oasisfeng/android/app/LifecycleViewModelFragment.java
// public class LifecycleViewModelFragment extends LifecycleFragment implements ViewModelStoreOwner {
// 
// 	@Override public @NonNull ViewModelStore getViewModelStore() {
// 		if ((SDK_INT >= M ? getContext() : getActivity()) == null) throw new IllegalStateException("Can't access ViewModels from detached fragment");
// 		if (mViewModelStore == null) mViewModelStore = new ViewModelStore();
// 		return mViewModelStore;
// 	}
// 
// 	private ViewModelStore mViewModelStore;		// TODO: Retain across configuration changes
// }


// Path: library/src/main/java/com/oasisfeng/androidx/lifecycle/ViewModelProviders.java
import androidx.lifecycle.ViewModelStoreOwner;
import android.app.Activity;
import android.app.Application;
import android.app.Fragment;
import com.oasisfeng.android.app.LifecycleViewModelActivity;
import com.oasisfeng.android.app.LifecycleViewModelFragment;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStore;

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.oasisfeng.androidx.lifecycle;




/**
 * Utilities methods for {@link ViewModelStore} class.
 */
public class ViewModelProviders {

	private static Application checkApplication(Activity activity) {
		Application application = activity.getApplication();
		if (application == null) {
			throw new IllegalStateException("Your activity/fragment is not yet attached to "
					+ "Application. You can't request ViewModel before onCreate call.");
		}
		return application;
	}

	private static Activity checkActivity(Fragment fragment) {
		Activity activity = fragment.getActivity();
		if (activity == null) {
			throw new IllegalStateException("Can't create ViewModelProvider for detached fragment");
		}
		return activity;
	}

	/**
	 * Creates a {@link ViewModelProvider}, which retains ViewModels while a scope of given
	 * {@code fragment} is alive. More detailed explanation is in {@link ViewModel}.
	 * <p>
	 * It uses {@link ViewModelProvider.AndroidViewModelFactory} to instantiate new ViewModels.
	 *
	 * @param fragment a fragment, in whose scope ViewModels should be retained
	 * @return a ViewModelProvider instance
	 */
	@NonNull
	@MainThread
	public static ViewModelProvider of(@NonNull LifecycleViewModelFragment fragment) {
		return of(fragment, null);
	}

	/**
	 * Creates a {@link ViewModelProvider}, which retains ViewModels while a scope of given Activity
	 * is alive. More detailed explanation is in {@link ViewModel}.
	 * <p>
	 * It uses {@link ViewModelProvider.AndroidViewModelFactory} to instantiate new ViewModels.
	 *
	 * @param activity an activity, in whose scope ViewModels should be retained
	 * @return a ViewModelProvider instance
	 */
	@NonNull
	@MainThread
	public static ViewModelProvider of(@NonNull LifecycleViewModelActivity activity) {