Search in sources :

Example 1 with FragmentIntroduce

use of net.iGap.fragments.FragmentIntroduce in project iGap-Android by KianIranian-STDG.

the class ActivityRegistration method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registeration);
    isStop = false;
    isOnGetPermission = true;
    G.updateResources(getBaseContext());
    viewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {

        @NonNull
        @Override
        public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
            boolean showPro = false;
            boolean isAddAccount = false;
            if (getIntent() != null && getIntent().getExtras() != null) {
                showPro = getIntent().getExtras().getBoolean(showProfile);
                isAddAccount = getIntent().getBooleanExtra("add account", false);
            }
            return (T) new RegistrationViewModel(showPro, isAddAccount);
        }
    }).get(RegistrationViewModel.class);
    viewModel.goToMainPage().observe(this, data -> {
        if (data != null) {
            if (data.isShowDialogDisableTwoStepVerification()) {
                new DefaultRoundDialog(this).setTitle(R.string.warning).setMessage(R.string.two_step_verification_disable).setPositiveButton(R.string.dialog_ok, (dialog, which) -> goToMainPage(data.getUserId())).show();
            } else {
                goToMainPage(data.getUserId());
            }
        }
    });
    viewModel.goToContactPage().observe(this, userId -> {
        if (!isFinishing() && userId != null) {
            HelperTracker.sendTracker(HelperTracker.TRACKER_REGISTRATION_NEW_USER);
            removeAllFragment();
            FragmentSyncRegisteredContacts fragment = new FragmentSyncRegisteredContacts();
            Bundle bundle = new Bundle();
            bundle.putLong(FragmentSyncRegisteredContacts.ARG_USER_ID, userId);
            fragment.setArguments(bundle);
            loadFragment(fragment, true);
        }
    });
    viewModel.getExistUser().observe(this, isExist -> {
        if (isExist != null && isExist) {
            new DefaultRoundDialog(this).setTitle(R.string.warning).setMessage(R.string.login_exist_account_error).setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
            }).show();
        }
    });
    viewModel.goToWelcomePage().observe(this, userId -> {
        if (userId != null) {
            getSupportFragmentManager().popBackStack();
            getSupportFragmentManager().popBackStack();
            getSupportFragmentManager().popBackStack();
            loadFragment(new WelcomeFragment(), true);
        }
    });
    viewModel.getGrantPermission().observe(this, isGrantPermission -> {
        if (isGrantPermission != null && isGrantPermission) {
            viewModel.startApp(getSupportFragmentManager().getBackStackEntryCount());
        }
    });
    viewModel.getGoToIntroduction().observe(this, isGo -> loadFragment(new FragmentIntroduce(), true));
    viewModel.getGoToNicknamePage().observe(this, isGo -> loadFragment(new FragmentRegistrationNickname(), true));
    viewModel.getGoToRegisterPage().observe(this, isGo -> loadFragment(new FragmentRegister(), true));
    viewModel.getLoadFromBackStack().observe(this, isLoad -> {
        if (isLoad != null && isLoad) {
            loadFragment(getSupportFragmentManager().findFragmentByTag(getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName()), false);
        }
    });
    G.isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {

        @Override
        public void onBackStackChanged() {
            Log.wtf(this.getClass().getName(), "-----------------------------------------");
            for (int i = 0; i < getSupportFragmentManager().getBackStackEntryCount(); i++) {
                Log.wtf(this.getClass().getName(), "fragment: " + getSupportFragmentManager().getBackStackEntryAt(i).getName());
            }
            Log.wtf(this.getClass().getName(), "-----------------------------------------");
        }
    });
}
Also used : Bundle(android.os.Bundle) FragmentIntroduce(net.iGap.fragments.FragmentIntroduce) NonNull(androidx.annotation.NonNull) AccountManager(net.iGap.module.accountManager.AccountManager) ViewModel(androidx.lifecycle.ViewModel) Intent(android.content.Intent) FragmentRegistrationNickname(net.iGap.fragments.FragmentRegistrationNickname) PermissionHelper(net.iGap.helper.PermissionHelper) G(net.iGap.G) Lifecycle(androidx.lifecycle.Lifecycle) FragmentRegister(net.iGap.fragments.FragmentRegister) Fragment(androidx.fragment.app.Fragment) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Log(android.util.Log) WelcomeFragment(net.iGap.fragments.WelcomeFragment) FragmentManager(androidx.fragment.app.FragmentManager) HelperTracker(net.iGap.helper.HelperTracker) ViewModelProvider(androidx.lifecycle.ViewModelProvider) RegistrationViewModel(net.iGap.viewmodel.RegistrationViewModel) FragmentTransaction(androidx.fragment.app.FragmentTransaction) DefaultRoundDialog(net.iGap.module.dialog.DefaultRoundDialog) SharedPreferences(android.content.SharedPreferences) FragmentActivation(net.iGap.fragments.FragmentActivation) FragmentSyncRegisteredContacts(net.iGap.fragments.FragmentSyncRegisteredContacts) SHP_SETTING(net.iGap.module.SHP_SETTING) Configuration(android.content.res.Configuration) AccountHelper(net.iGap.module.accountManager.AccountHelper) R(net.iGap.R) WelcomeFragment(net.iGap.fragments.WelcomeFragment) FragmentSyncRegisteredContacts(net.iGap.fragments.FragmentSyncRegisteredContacts) Bundle(android.os.Bundle) FragmentRegistrationNickname(net.iGap.fragments.FragmentRegistrationNickname) DefaultRoundDialog(net.iGap.module.dialog.DefaultRoundDialog) FragmentRegister(net.iGap.fragments.FragmentRegister) RegistrationViewModel(net.iGap.viewmodel.RegistrationViewModel) FragmentManager(androidx.fragment.app.FragmentManager) FragmentIntroduce(net.iGap.fragments.FragmentIntroduce) NonNull(androidx.annotation.NonNull) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Configuration (android.content.res.Configuration)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 NonNull (androidx.annotation.NonNull)1 Fragment (androidx.fragment.app.Fragment)1 FragmentManager (androidx.fragment.app.FragmentManager)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 Lifecycle (androidx.lifecycle.Lifecycle)1 ViewModel (androidx.lifecycle.ViewModel)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 ViewModelProviders (androidx.lifecycle.ViewModelProviders)1 G (net.iGap.G)1 R (net.iGap.R)1 FragmentActivation (net.iGap.fragments.FragmentActivation)1 FragmentIntroduce (net.iGap.fragments.FragmentIntroduce)1 FragmentRegister (net.iGap.fragments.FragmentRegister)1 FragmentRegistrationNickname (net.iGap.fragments.FragmentRegistrationNickname)1 FragmentSyncRegisteredContacts (net.iGap.fragments.FragmentSyncRegisteredContacts)1