// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java
// public abstract class MvvmApplication extends Application {
// 
//     private AppComponent appComponent;
// 
//     protected abstract AppComponent createAppComponent();
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         if (appComponent == null) {
//             appComponent = createAppComponent();
//         }
//     }
// 
//     public AppComponent getAppComponent() {
//         return appComponent;
//     }
// 
//     public void setAppComponent(AppComponent appComponent) {
//         this.appComponent = appComponent;
//     }
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java
// public abstract class ViewModelActivity extends AppCompatActivity {
// 
//     private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";
// 
//     private ActivityComponent activityComponent;
//     private ViewModel viewModel;
// 
//     protected void inject(AppComponent appComponent) {
//         appComponent.inject(this);
//     }
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
// 
//         AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent();
//         inject(appComponent);
// 
//         activityComponent = DaggerActivityComponent.builder()
//                 .appComponent(appComponent)
//                 .activityModule(new ActivityModule(this))
//                 .build();
// 
//         ViewModel.State savedViewModelState = null;
//         if (savedInstanceState != null) {
//             savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE);
//         }
//         viewModel = createViewModel(savedViewModelState);
//     }
// 
//     @Nullable
//     protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) {
//         return null;
//     }
// 
//     @Override
//     protected void onStart() {
//         super.onStart();
//         if (viewModel != null) {
//             viewModel.onStart();
//         }
//     }
// 
//     @Override
//     protected void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         if (viewModel != null) {
//             outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState());
//         }
//     }
// 
//     @Override
//     protected void onStop() {
//         super.onStop();
//         if (viewModel != null) {
//             viewModel.onStop();
//         }
//     }
// 
//     public final ActivityComponent getActivityComponent() {
//         return activityComponent;
//     }
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java
// @PerActivity
// @Component(
//         dependencies = AppComponent.class,
//         modules = {ActivityModule.class})
// public interface ActivityComponent {
// 
//     void inject(ViewModel viewModel);
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java
// public interface AppComponent {
// 
//     @AppContext
//     Context appContext();
// 
//     void inject(ViewModelActivity viewModelActivity);
// 
//     void inject(ViewModelFragment viewModelFragment);
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java
// public abstract class ViewModel extends BaseObservable {
// 
//     @Inject
//     @AppContext
//     protected Context appContext;
// 
//     @Inject
//     protected AttachedActivity attachedActivity;
// 
//     protected ViewModel(@NonNull ActivityComponent activityComponent,
//                         @Nullable State savedInstanceState) {
//         activityComponent.inject(this);
//     }
// 
//     @CallSuper
//     public void onStart() {
// 
//     }
// 
//     public State getInstanceState() {
//         return new State(this);
//     }
// 
//     @CallSuper
//     public void onStop() {
// 
//     }
// 
//     public static class State implements Parcelable {
// 
//         protected State(ViewModel viewModel) {
// 
//         }
// 
//         public State(Parcel in) {
// 
//         }
// 
//         @Override
//         public int describeContents() {
//             return 0;
//         }
// 
//         @CallSuper
//         @Override
//         public void writeToParcel(Parcel dest, int flags) {
// 
//         }
// 
//         public static Creator<State> CREATOR = new Creator<State>() {
//             @Override
//             public State createFromParcel(Parcel source) {
//                 return new State(source);
//             }
// 
//             @Override
//             public State[] newArray(int size) {
//                 return new State[size];
//             }
//         };
//     }
// }


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import com.hibrianlee.mvvmapp.MvvmApplication;
import com.hibrianlee.mvvmapp.activity.ViewModelActivity;
import com.hibrianlee.mvvmapp.inject.ActivityComponent;
import com.hibrianlee.mvvmapp.inject.AppComponent;
import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/*
 * Copyright (C) 2015 Brian Lee (@hiBrianLee)
 *
 * 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.hibrianlee.mvvmapp.fragment;



public abstract class ViewModelFragment extends Fragment {

    private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";

    private ViewModel viewModel;

    protected void inject(AppComponent appComponent) {
        appComponent.inject(this);
    }

    @Nullable
    protected abstract ViewModel createAndBindViewModel(View root,
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java
// public abstract class MvvmApplication extends Application {
// 
//     private AppComponent appComponent;
// 
//     protected abstract AppComponent createAppComponent();
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         if (appComponent == null) {
//             appComponent = createAppComponent();
//         }
//     }
// 
//     public AppComponent getAppComponent() {
//         return appComponent;
//     }
// 
//     public void setAppComponent(AppComponent appComponent) {
//         this.appComponent = appComponent;
//     }
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java
// public abstract class ViewModelActivity extends AppCompatActivity {
// 
//     private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";
// 
//     private ActivityComponent activityComponent;
//     private ViewModel viewModel;
// 
//     protected void inject(AppComponent appComponent) {
//         appComponent.inject(this);
//     }
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
// 
//         AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent();
//         inject(appComponent);
// 
//         activityComponent = DaggerActivityComponent.builder()
//                 .appComponent(appComponent)
//                 .activityModule(new ActivityModule(this))
//                 .build();
// 
//         ViewModel.State savedViewModelState = null;
//         if (savedInstanceState != null) {
//             savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE);
//         }
//         viewModel = createViewModel(savedViewModelState);
//     }
// 
//     @Nullable
//     protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) {
//         return null;
//     }
// 
//     @Override
//     protected void onStart() {
//         super.onStart();
//         if (viewModel != null) {
//             viewModel.onStart();
//         }
//     }
// 
//     @Override
//     protected void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         if (viewModel != null) {
//             outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState());
//         }
//     }
// 
//     @Override
//     protected void onStop() {
//         super.onStop();
//         if (viewModel != null) {
//             viewModel.onStop();
//         }
//     }
// 
//     public final ActivityComponent getActivityComponent() {
//         return activityComponent;
//     }
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java
// @PerActivity
// @Component(
//         dependencies = AppComponent.class,
//         modules = {ActivityModule.class})
// public interface ActivityComponent {
// 
//     void inject(ViewModel viewModel);
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java
// public interface AppComponent {
// 
//     @AppContext
//     Context appContext();
// 
//     void inject(ViewModelActivity viewModelActivity);
// 
//     void inject(ViewModelFragment viewModelFragment);
// }
// 
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java
// public abstract class ViewModel extends BaseObservable {
// 
//     @Inject
//     @AppContext
//     protected Context appContext;
// 
//     @Inject
//     protected AttachedActivity attachedActivity;
// 
//     protected ViewModel(@NonNull ActivityComponent activityComponent,
//                         @Nullable State savedInstanceState) {
//         activityComponent.inject(this);
//     }
// 
//     @CallSuper
//     public void onStart() {
// 
//     }
// 
//     public State getInstanceState() {
//         return new State(this);
//     }
// 
//     @CallSuper
//     public void onStop() {
// 
//     }
// 
//     public static class State implements Parcelable {
// 
//         protected State(ViewModel viewModel) {
// 
//         }
// 
//         public State(Parcel in) {
// 
//         }
// 
//         @Override
//         public int describeContents() {
//             return 0;
//         }
// 
//         @CallSuper
//         @Override
//         public void writeToParcel(Parcel dest, int flags) {
// 
//         }
// 
//         public static Creator<State> CREATOR = new Creator<State>() {
//             @Override
//             public State createFromParcel(Parcel source) {
//                 return new State(source);
//             }
// 
//             @Override
//             public State[] newArray(int size) {
//                 return new State[size];
//             }
//         };
//     }
// }


// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import com.hibrianlee.mvvmapp.MvvmApplication;
import com.hibrianlee.mvvmapp.activity.ViewModelActivity;
import com.hibrianlee.mvvmapp.inject.ActivityComponent;
import com.hibrianlee.mvvmapp.inject.AppComponent;
import com.hibrianlee.mvvmapp.viewmodel.ViewModel;

/*
 * Copyright (C) 2015 Brian Lee (@hiBrianLee)
 *
 * 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.hibrianlee.mvvmapp.fragment;



public abstract class ViewModelFragment extends Fragment {

    private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";

    private ViewModel viewModel;

    protected void inject(AppComponent appComponent) {
        appComponent.inject(this);
    }

    @Nullable
    protected abstract ViewModel createAndBindViewModel(View root,
                                                 @NonNull ActivityComponent activityComponent,