Skip to content
Snippets Groups Projects
Commit 0ae807bc authored by Amirhossein Naghshzan's avatar Amirhossein Naghshzan Committed by Adrien Béraud
Browse files

linkAccountFragment: bugfix

Change-Id: If3ca709d845ff0cd48adf17fb325eac255d222a9
parent 7c125f74
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ import android.text.TextUtils;
import android.widget.Toast;
import java.io.File;
import java.util.List;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
......@@ -157,6 +158,13 @@ public class AccountWizardActivity extends BaseActivity<AccountWizardPresenter>
@Override
public void goToProfileCreation(AccountCreationModel model) {
List<Fragment> fragments = getSupportFragmentManager().getFragments();
if (fragments.size() > 0) {
Fragment fragment =fragments.get(0);
if (fragment instanceof JamiLinkAccountFragment) {
((JamiLinkAccountFragment) fragment).scrollPagerFragment(model);
}
}
}
@Override
......
......@@ -63,7 +63,6 @@ public class JamiAccountCreationFragment extends BaseSupportFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mBinding = FragAccJamiCreateBinding.inflate(inflater, container, false);
mBinding.pager.setOffscreenPageLimit(NUM_PAGES);
return mBinding.getRoot();
}
......
......@@ -20,16 +20,23 @@
package cx.ring.account;
import android.app.Activity;
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;
import android.view.inputmethod.EditorInfo;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import cx.ring.R;
import cx.ring.application.JamiApplication;
......@@ -37,12 +44,27 @@ import cx.ring.databinding.FragAccJamiLinkBinding;
import cx.ring.mvp.BaseSupportFragment;
import cx.ring.mvp.AccountCreationModel;
public class JamiLinkAccountFragment extends BaseSupportFragment<JamiLinkAccountPresenter>
implements JamiLinkAccountView {
public class JamiLinkAccountFragment extends BaseSupportFragment {
public static final String TAG = JamiLinkAccountFragment.class.getSimpleName();
private AccountCreationModel model;
private FragAccJamiLinkBinding binding;
private FragAccJamiLinkBinding mBinding;
private Fragment mCurrentFragment;
private static final int NUM_PAGES = 2;
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@Override
public void handleOnBackPressed() {
if (mCurrentFragment instanceof ProfileCreationFragment) {
ProfileCreationFragment fragment = (ProfileCreationFragment) mCurrentFragment;
((AccountWizardActivity) getActivity()).profileCreated(fragment.getModel(), false);
return;
}
mBinding.pager.setCurrentItem(mBinding.pager.getCurrentItem() - 1);
}
};
public static JamiLinkAccountFragment newInstance(AccountCreationModelImpl ringAccountViewModel) {
JamiLinkAccountFragment fragment = new JamiLinkAccountFragment();
......@@ -53,80 +75,110 @@ public class JamiLinkAccountFragment extends BaseSupportFragment<JamiLinkAccount
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragAccJamiLinkBinding.inflate(inflater, container, false);
((JamiApplication) getActivity().getApplication()).getInjectionComponent().inject(this);
return binding.getRoot();
mBinding = FragAccJamiLinkBinding.inflate(inflater, container, false);
return mBinding.getRoot();
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
mBinding = null;
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.linkButton.setOnClickListener(v -> presenter.linkClicked());
binding.ringAddPin.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
presenter.linkClicked();
}
return false;
});
binding.ringAddPin.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
JamiLinkAccountFragment.ScreenSlidePagerAdapter pagerAdapter = new JamiLinkAccountFragment.ScreenSlidePagerAdapter(getChildFragmentManager(), model);
mBinding.pager.setAdapter(pagerAdapter);
mBinding.pager.disableScroll(true);
mBinding.pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void afterTextChanged(Editable s) {
presenter.pinChanged(s.toString());
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
});
binding.ringExistingPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void onPageSelected(int position) {
mCurrentFragment = pagerAdapter.getRegisteredFragment(position);
onBackPressedCallback.setEnabled(mCurrentFragment instanceof ProfileCreationFragment);
}
@Override
public void afterTextChanged(Editable s) {
presenter.passwordChanged(s.toString());
public void onPageScrollStateChanged(int state) {
}
});
}
@Override
protected void initPresenter(JamiLinkAccountPresenter presenter) {
presenter.init(model);
public void onAttach(@NonNull Context context) {
super.onAttach(context);
requireActivity().getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
}
public void scrollPagerFragment(AccountCreationModel accountCreationModel) {
if (accountCreationModel == null) {
mBinding.pager.setCurrentItem(mBinding.pager.getCurrentItem() - 1);
return;
}
mBinding.pager.setCurrentItem(mBinding.pager.getCurrentItem() + 1);
for (Fragment fragment : getChildFragmentManager().getFragments()) {
if (fragment instanceof JamiAccountPasswordFragment) {
((JamiAccountPasswordFragment) fragment).setUsername(accountCreationModel.getUsername());
}
}
}
private static class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
AccountCreationModelImpl ringAccountViewModel;
SparseArray<Fragment> mRegisteredFragments = new SparseArray<>();
public ScreenSlidePagerAdapter(FragmentManager fm, AccountCreationModel model) {
super(fm);
ringAccountViewModel = (AccountCreationModelImpl) model;
}
@Override
public void enableLinkButton(boolean enable) {
binding.linkButton.setEnabled(enable);
public Fragment getItem(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment = JamiLinkAccountPasswordFragment.newInstance(ringAccountViewModel);
break;
case 1:
fragment = ProfileCreationFragment.newInstance(ringAccountViewModel);
break;
}
return fragment;
}
@NonNull
@Override
public void showPin(boolean show) {
binding.pinBox.setVisibility(show ? View.VISIBLE : View.GONE);
binding.pinHelpMessage.setVisibility(show ? View.VISIBLE : View.GONE);
binding.linkButton.setText(show ? R.string.account_link_device : R.string.account_link_archive_button);
public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
mRegisteredFragments.put(position, fragment);
return super.instantiateItem(container, position);
}
@Override
public void createAccount(AccountCreationModel accountCreationModel) {
((AccountWizardActivity) requireActivity()).createAccount(accountCreationModel);
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
mRegisteredFragments.remove(position);
super.destroyItem(container, position, object);
}
@Override
public void cancel() {
Activity wizardActivity = getActivity();
if (wizardActivity != null) {
wizardActivity.onBackPressed();
public int getCount() {
return NUM_PAGES;
}
public Fragment getRegisteredFragment(int position) {
return mRegisteredFragments.get(position);
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2004-2020 Savoir-faire Linux Inc.
*
* Authors: AmirHossein Naghshzan <amirhossein.naghshzan@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package cx.ring.account;
import android.app.Activity;
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;
import android.view.inputmethod.EditorInfo;
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;
public class JamiLinkAccountPasswordFragment extends BaseSupportFragment<JamiLinkAccountPresenter>
implements JamiLinkAccountView {
public static final String TAG = JamiLinkAccountPasswordFragment.class.getSimpleName();
private AccountCreationModel model;
private FragAccJamiLinkPasswordBinding mBinding;
public static JamiLinkAccountPasswordFragment newInstance(AccountCreationModel ringAccountViewModel) {
JamiLinkAccountPasswordFragment fragment = new JamiLinkAccountPasswordFragment();
fragment.model = ringAccountViewModel;
return fragment;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mBinding = FragAccJamiLinkPasswordBinding.inflate(inflater, container, false);
((JamiApplication) getActivity().getApplication()).getInjectionComponent().inject(this);
return mBinding.getRoot();
}
@Override
public void onDestroyView() {
super.onDestroyView();
mBinding = null;
}
@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) {
presenter.linkClicked();
}
return false;
});
mBinding.ringAddPin.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
presenter.pinChanged(s.toString());
}
});
mBinding.ringExistingPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
presenter.passwordChanged(s.toString());
}
});
}
@Override
protected void initPresenter(JamiLinkAccountPresenter presenter) {
presenter.init(model);
}
@Override
public void enableLinkButton(boolean enable) {
mBinding.linkButton.setEnabled(enable);
}
@Override
public void showPin(boolean show) {
mBinding.pinBox.setVisibility(show ? View.VISIBLE : View.GONE);
mBinding.pinHelpMessage.setVisibility(show ? View.VISIBLE : View.GONE);
mBinding.linkButton.setText(show ? R.string.account_link_device : R.string.account_link_archive_button);
}
@Override
public void createAccount(AccountCreationModel accountCreationModel) {
((AccountWizardActivity) requireActivity()).createAccount(accountCreationModel);
}
@Override
public void cancel() {
Activity wizardActivity = getActivity();
if (wizardActivity != null) {
wizardActivity.onBackPressed();
}
}
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ import javax.inject.Singleton;
import cx.ring.account.AccountEditionFragment;
import cx.ring.account.JamiAccountPasswordFragment;
import cx.ring.account.JamiAccountUsernameFragment;
import cx.ring.account.JamiLinkAccountPasswordFragment;
import cx.ring.fragments.LocationSharingFragment;
import cx.ring.account.AccountWizardActivity;
import cx.ring.account.HomeAccountCreationFragment;
......@@ -118,8 +119,6 @@ public interface JamiInjectionComponent {
void inject(ConversationSelectionActivity fragment);
// void inject(JamiAccountCreationFragment fragment);
void inject(JamiAccountUsernameFragment fragment);
void inject(JamiAccountPasswordFragment fragment);
......@@ -178,7 +177,7 @@ public interface JamiInjectionComponent {
void inject(HomeAccountCreationFragment fragment);
void inject(JamiLinkAccountFragment fragment);
void inject(JamiLinkAccountPasswordFragment fragment);
void inject(JamiAccountConnectFragment fragment);
......
......@@ -47,115 +47,16 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.4" />
<androidx.cardview.widget.CardView
<cx.ring.views.WizardViewPager
android:id="@+id/pager"
android:layout_width="@dimen/wizard_card_width"
android:layout_height="wrap_content"
android:background="@color/white"
app:cardCornerRadius="12dp"
android:layout_height="@dimen/wizard_card_height"
app:layout_constraintTop_toBottomOf="@+id/pager_guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_gravity="center"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/wizard_card_padding">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/status"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:textStyle="bold"
android:text="@string/help_password_enter" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/wizard_status_required"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#ff1f62"
android:background="@drawable/background_status"
android:padding="6dp"/>
</RelativeLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_txt_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_existing_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:drawableStart="@drawable/baseline_lock_24"
android:drawablePadding="5dp"
android:imeOptions="actionNext"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/pin_help_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="8dp"
android:text="@string/help_pin_enter" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/pin_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_add_pin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_link_prompt_pin"
android:drawableStart="@drawable/baseline_lock_24"
android:drawablePadding="5dp"
android:imeOptions="actionDone"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/link_button"
style="@style/WizardButton"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="false"
android:textSize="12sp"
android:layout_marginTop="18dp"
android:text="@string/account_link_button"
android:theme="@style/ButtonColoredInverse" />
</LinearLayout>
android:clipToPadding="false" />
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2004-2020 Savoir-faire Linux Inc.
~
~ Authors: AmirHossein Naghshzan <amirhossein.naghshzan@savoirfairelinux.com>
~
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="cx.ring.account.AccountWizardActivity">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:cardCornerRadius="12dp"
android:clipChildren="false"
android:clipToPadding="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/wizard_card_padding">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/status"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:textStyle="bold"
android:text="@string/help_password_enter" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/wizard_status_required"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#ff1f62"
android:background="@drawable/background_status"
android:padding="6dp"/>
</RelativeLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_txt_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_existing_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:drawableStart="@drawable/baseline_lock_24"
android:drawablePadding="5dp"
android:imeOptions="actionNext"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/pin_help_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="8dp"
android:text="@string/help_pin_enter" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/pin_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_add_pin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_link_prompt_pin"
android:drawableStart="@drawable/baseline_lock_24"
android:drawablePadding="5dp"
android:imeOptions="actionDone"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/link_button"
style="@style/WizardButton"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="false"
android:textSize="12sp"
android:layout_marginTop="18dp"
android:text="@string/account_link_button"
android:theme="@style/ButtonColoredInverse" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</FrameLayout>
\ No newline at end of file
......@@ -96,10 +96,10 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView> {
public void initRingAccountCreation(AccountCreationModel accountCreationModel, String defaultAccountName) {
Single<Map<String, String>> newAccount = initRingAccountDetails(defaultAccountName)
.map(accountDetails -> {
if (!accountCreationModel.getUsername().isEmpty()) {
if (!StringUtils.isEmpty(accountCreationModel.getUsername())) {
accountDetails.put(ConfigKey.ACCOUNT_REGISTERED_NAME.key(), accountCreationModel.getUsername());
}
if (!accountCreationModel.getPassword().isEmpty()) {
if (!StringUtils.isEmpty(accountCreationModel.getPassword())) {
accountDetails.put(ConfigKey.ARCHIVE_PASSWORD.key(), accountCreationModel.getPassword());
}
if (accountCreationModel.isPush()) {
......@@ -168,8 +168,6 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView> {
getView().displayProgress(false);
getView().displayCannotBeFoundError();
}));
} else {
getView().goToProfileCreation(accountCreationModel);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment