// Path: app/src/main/java/apidez/com/android_mvvm_sample/MyApplication.java
// public class MyApplication extends Application {
// 
//     protected AppComponent mAppComponent;
//     protected ComponentBuilder mComponentBuilder;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         // Create app component
//         mAppComponent = DaggerAppComponent.builder()
//                 .appModule(new AppModule())
//                 .build();
// 
//         // Create component builder
//         mComponentBuilder = new ComponentBuilder(mAppComponent);
//     }
// 
//     public AppComponent component() {
//         return mAppComponent;
//     }
// 
//     public ComponentBuilder builder() {
//         return mComponentBuilder;
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/utils/RxTextViewEx.java
// public class RxTextViewEx {
// 
//     /**
//      * Create an observable of character sequences for text changes on {@code view}.
//      * <p>
//      * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
//      * to free this reference.
//      * <p>
//      * <em>Note:</em> A value will be emitted immediately on subscribe.
//      */
//     @CheckResult
//     @NonNull
//     public static Observable<CharSequence> textChanges(@NonNull TextView view) {
//         return Observable.create(new TextViewSubscribeUnInit(view));
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/utils/UiUtils.java
// public class UiUtils {
//     public static void resetTintColor(Context context, View view) {
//         TintManager tintManager = TintManager.get(context);
//         ViewCompat.setBackgroundTintList(view,
//                 tintManager.getTintList(android.support.design.R.drawable.abc_edit_text_material));
//     }
// 
//     public static void showDialog(String text, Context context) {
//         new AlertDialog.Builder(context)
//                 .setMessage(text)
//                 .setPositiveButton(android.R.string.yes, (dialog, which) -> {
//                 })
//                 .show();
//     }
// 
//     public static void closeKeyboard(Activity context) {
//         // Check if no view has focus:
//         View view = context.getCurrentFocus();
//         if (view != null) {
//             InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
//             imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
//         }
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/viewmodel/IPurchaseViewModel.java
// public interface IPurchaseViewModel {
//     /**
//      * Return observable that check valid credit card
//      */
//     Observable<Boolean> creditCardValid();
// 
//     /**
//      * Return observable check valid email
//      */
//     Observable<Boolean> emailValid();
// 
//     /**
//      * update credit card
//      */
//     void nextCreditCard(CharSequence creditCard);
// 
//     /**
//      * update email
//      */
//     void nextEmail(CharSequence email);
// 
//     /**
//      * Create observable check be able to submit?
//      */
//     Observable<Boolean> canSubmit();
// 
//     /**
//      * Command submit
//      */
//     Observable<Boolean> submit();
// }


import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import javax.inject.Inject;
import apidez.com.android_mvvm_sample.MyApplication;
import apidez.com.android_mvvm_sample.R;
import apidez.com.android_mvvm_sample.utils.RxTextViewEx;
import apidez.com.android_mvvm_sample.utils.UiUtils;
import apidez.com.android_mvvm_sample.viewmodel.IPurchaseViewModel;
import butterknife.Bind;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setMessage(getString(R.string.loading));
        mProgressDialog.setCancelable(false);

        // Toolbar
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    private void bindViewModel() {
        // binding credit card
        RxTextViewEx.textChanges(mEdtCreditCard)
                .takeUntil(preDestroy())
                .subscribe(mViewModel::nextCreditCard);

        // binding email
        RxTextViewEx.textChanges(mEdtEmail)
                .takeUntil(preDestroy())
                .subscribe(mViewModel::nextEmail);

        // create event on click on submit
        onSubmitClickListener = v -> mViewModel.submit()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .takeUntil(preDestroy())
                .doOnSubscribe(mProgressDialog::show)
                .doOnTerminate(mProgressDialog::hide)
                .subscribe(done -> {
                    UiUtils.showDialog(getString(R.string.success), this);
                }, throwable -> {
// Path: app/src/main/java/apidez/com/android_mvvm_sample/MyApplication.java
// public class MyApplication extends Application {
// 
//     protected AppComponent mAppComponent;
//     protected ComponentBuilder mComponentBuilder;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         // Create app component
//         mAppComponent = DaggerAppComponent.builder()
//                 .appModule(new AppModule())
//                 .build();
// 
//         // Create component builder
//         mComponentBuilder = new ComponentBuilder(mAppComponent);
//     }
// 
//     public AppComponent component() {
//         return mAppComponent;
//     }
// 
//     public ComponentBuilder builder() {
//         return mComponentBuilder;
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/utils/RxTextViewEx.java
// public class RxTextViewEx {
// 
//     /**
//      * Create an observable of character sequences for text changes on {@code view}.
//      * <p>
//      * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
//      * to free this reference.
//      * <p>
//      * <em>Note:</em> A value will be emitted immediately on subscribe.
//      */
//     @CheckResult
//     @NonNull
//     public static Observable<CharSequence> textChanges(@NonNull TextView view) {
//         return Observable.create(new TextViewSubscribeUnInit(view));
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/utils/UiUtils.java
// public class UiUtils {
//     public static void resetTintColor(Context context, View view) {
//         TintManager tintManager = TintManager.get(context);
//         ViewCompat.setBackgroundTintList(view,
//                 tintManager.getTintList(android.support.design.R.drawable.abc_edit_text_material));
//     }
// 
//     public static void showDialog(String text, Context context) {
//         new AlertDialog.Builder(context)
//                 .setMessage(text)
//                 .setPositiveButton(android.R.string.yes, (dialog, which) -> {
//                 })
//                 .show();
//     }
// 
//     public static void closeKeyboard(Activity context) {
//         // Check if no view has focus:
//         View view = context.getCurrentFocus();
//         if (view != null) {
//             InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
//             imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
//         }
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/viewmodel/IPurchaseViewModel.java
// public interface IPurchaseViewModel {
//     /**
//      * Return observable that check valid credit card
//      */
//     Observable<Boolean> creditCardValid();
// 
//     /**
//      * Return observable check valid email
//      */
//     Observable<Boolean> emailValid();
// 
//     /**
//      * update credit card
//      */
//     void nextCreditCard(CharSequence creditCard);
// 
//     /**
//      * update email
//      */
//     void nextEmail(CharSequence email);
// 
//     /**
//      * Create observable check be able to submit?
//      */
//     Observable<Boolean> canSubmit();
// 
//     /**
//      * Command submit
//      */
//     Observable<Boolean> submit();
// }


// Path: app/src/main/java/apidez/com/android_mvvm_sample/view/activity/PurchaseActivity.java
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import javax.inject.Inject;
import apidez.com.android_mvvm_sample.MyApplication;
import apidez.com.android_mvvm_sample.R;
import apidez.com.android_mvvm_sample.utils.RxTextViewEx;
import apidez.com.android_mvvm_sample.utils.UiUtils;
import apidez.com.android_mvvm_sample.viewmodel.IPurchaseViewModel;
import butterknife.Bind;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setMessage(getString(R.string.loading));
        mProgressDialog.setCancelable(false);

        // Toolbar
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    private void bindViewModel() {
        // binding credit card
        RxTextViewEx.textChanges(mEdtCreditCard)
                .takeUntil(preDestroy())
                .subscribe(mViewModel::nextCreditCard);

        // binding email
        RxTextViewEx.textChanges(mEdtEmail)
                .takeUntil(preDestroy())
                .subscribe(mViewModel::nextEmail);

        // create event on click on submit
        onSubmitClickListener = v -> mViewModel.submit()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .takeUntil(preDestroy())
                .doOnSubscribe(mProgressDialog::show)
                .doOnTerminate(mProgressDialog::hide)
                .subscribe(done -> {
                    UiUtils.showDialog(getString(R.string.success), this);
                }, throwable -> {
                    UiUtils.showDialog(getString(R.string.error), this);