Commit a4149fa1 authored by Adrien Béraud's avatar Adrien Béraud

save model during account creation

Change-Id: I08c063b7524196efd4ae2d14b53745a4e020b823
parent a4a7d2ac
......@@ -23,7 +23,6 @@ import android.content.Context;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
......@@ -38,7 +37,6 @@ import androidx.viewpager.widget.ViewPager;
import cx.ring.databinding.FragAccJamiCreateBinding;
import cx.ring.mvp.AccountCreationModel;
import cx.ring.mvp.BaseSupportFragment;
import cx.ring.views.WizardViewPager;
public class JamiAccountCreationFragment extends Fragment {
......@@ -104,12 +102,7 @@ public class JamiAccountCreationFragment extends Fragment {
LinearLayout tabStrip = ((LinearLayout) mBinding.indicator.getChildAt(0));
for(int i = 0; i < tabStrip.getChildCount(); i++) {
tabStrip.getChildAt(i).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
tabStrip.getChildAt(i).setOnTouchListener((v, event) -> true);
}
}
......@@ -142,6 +135,7 @@ public class JamiAccountCreationFragment extends Fragment {
super(fm);
}
@NonNull
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
......@@ -157,7 +151,6 @@ public class JamiAccountCreationFragment extends Fragment {
fragment = ProfileCreationFragment.newInstance(ringAccountViewModel);
break;
}
return fragment;
}
......
......@@ -63,6 +63,10 @@ public class JamiAccountPasswordFragment extends BaseSupportFragment<JamiAccount
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setRetainInstance(true);
if (savedInstanceState != null && model == null) {
model = (AccountCreationModelImpl) savedInstanceState.getSerializable(KEY_MODEL);
}
binding = FragAccJamiPasswordBinding.inflate(inflater, container, false);
((JamiApplication) requireActivity().getApplication()).getInjectionComponent().inject(this);
return binding.getRoot();
......@@ -77,10 +81,6 @@ public class JamiAccountPasswordFragment extends BaseSupportFragment<JamiAccount
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setRetainInstance(true);
if (savedInstanceState != null) {
model = (AccountCreationModelImpl) savedInstanceState.getSerializable(KEY_MODEL);
}
binding.createAccount.setOnClickListener(v -> presenter.createAccount());
binding.ringPasswordSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
......
......@@ -49,6 +49,7 @@ import cx.ring.utils.RegisteredNameFilter;
public class JamiAccountUsernameFragment extends BaseSupportFragment<JamiAccountCreationPresenter>
implements JamiAccountCreationView {
private static final String KEY_MODEL = "model";
private AccountCreationModel model;
private FragAccJamiUsernameBinding binding;
......@@ -58,9 +59,19 @@ public class JamiAccountUsernameFragment extends BaseSupportFragment<JamiAccount
return fragment;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
if (model != null)
outState.putSerializable(KEY_MODEL, model);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setRetainInstance(true);
if (savedInstanceState != null && model == null) {
model = (AccountCreationModelImpl) savedInstanceState.getSerializable(KEY_MODEL);
}
binding = FragAccJamiUsernameBinding.inflate(inflater, container, false);
((JamiApplication) getActivity().getApplication()).getInjectionComponent().inject(this);
return binding.getRoot();
......
......@@ -65,16 +65,24 @@ public class JamiLinkAccountFragment extends BaseSupportFragment {
}
};
public static JamiLinkAccountFragment newInstance(AccountCreationModelImpl ringAccountViewModel) {
JamiLinkAccountFragment fragment = new JamiLinkAccountFragment();
fragment.model = ringAccountViewModel;
return fragment;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putSerializable("model", model);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setRetainInstance(true);
if (savedInstanceState != null && model == null) {
model = (AccountCreationModel) savedInstanceState.getSerializable("model");
}
mBinding = FragAccJamiLinkBinding.inflate(inflater, container, false);
return mBinding.getRoot();
}
......@@ -109,7 +117,6 @@ public class JamiLinkAccountFragment extends BaseSupportFragment {
}
});
}
@Override
......@@ -132,7 +139,6 @@ public class JamiLinkAccountFragment extends BaseSupportFragment {
}
private static class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
AccountCreationModelImpl ringAccountViewModel;
SparseArray<Fragment> mRegisteredFragments = new SparseArray<>();
......
......@@ -24,7 +24,6 @@ import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -33,13 +32,9 @@ import android.view.inputmethod.InputMethodManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import cx.ring.R;
import cx.ring.application.JamiApplication;
import cx.ring.databinding.FragAccJamiLinkBinding;
import cx.ring.databinding.FragAccJamiLinkPasswordBinding;
import cx.ring.mvp.AccountCreationModel;
import cx.ring.mvp.BaseSupportFragment;
......@@ -60,6 +55,8 @@ public class JamiLinkAccountPasswordFragment extends BaseSupportFragment<JamiLin
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (model == null)
return null;
mBinding = FragAccJamiLinkPasswordBinding.inflate(inflater, container, false);
((JamiApplication) getActivity().getApplication()).getInjectionComponent().inject(this);
return mBinding.getRoot();
......@@ -74,7 +71,6 @@ public class JamiLinkAccountPasswordFragment extends BaseSupportFragment<JamiLin
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mBinding.linkButton.setOnClickListener(v -> presenter.linkClicked());
mBinding.ringAddPin.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
......
......@@ -48,12 +48,14 @@ public class JamiLinkAccountPresenter extends RootPresenter<JamiLinkAccountView>
}
public void passwordChanged(String password) {
mAccountCreationModel.setPassword(password);
if (mAccountCreationModel != null)
mAccountCreationModel.setPassword(password);
showHideLinkButton();
}
public void pinChanged(String pin) {
mAccountCreationModel.setPin(pin);
if (mAccountCreationModel != null)
mAccountCreationModel.setPin(pin);
showHideLinkButton();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment