Commit eaddf85b authored by Adrien Béraud's avatar Adrien Béraud
Browse files

account creation: handle fragment recreation

Change-Id: Ic6348eef89eee2473f4b409654a83a787052b5eb
parent b3506346
......@@ -28,7 +28,6 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import cx.ring.R
import cx.ring.account.JamiLinkAccountFragment.Companion.newInstance
import cx.ring.databinding.FragAccHomeCreateBinding
import cx.ring.mvp.BaseSupportFragment
import cx.ring.utils.AndroidFileUtils.getCacheFile
......@@ -43,13 +42,15 @@ class HomeAccountCreationFragment :
BaseSupportFragment<HomeAccountCreationPresenter, HomeAccountCreationView>(),
HomeAccountCreationView {
private var binding: FragAccHomeCreateBinding? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragAccHomeCreateBinding.inflate(inflater, container, false)
return binding!!.root
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return FragAccHomeCreateBinding.inflate(inflater, container, false).apply {
ringAddAccount.setOnClickListener {presenter.clickOnLinkAccount() }
ringCreateBtn.setOnClickListener { presenter.clickOnCreateAccount() }
accountConnectServer.setOnClickListener { presenter.clickOnConnectAccount() }
ringImportAccount.setOnClickListener {performFileSearch() }
binding = this
}.root
}
override fun onDestroyView() {
......@@ -57,31 +58,22 @@ class HomeAccountCreationFragment :
binding = null
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
retainInstance = true
binding!!.ringAddAccount.setOnClickListener { v: View? -> presenter.clickOnLinkAccount() }
binding!!.ringCreateBtn.setOnClickListener { v: View? -> presenter.clickOnCreateAccount() }
binding!!.accountConnectServer.setOnClickListener { v: View? -> presenter.clickOnConnectAccount() }
binding!!.ringImportAccount.setOnClickListener { v: View? -> performFileSearch() }
}
override fun goToAccountCreation() {
val fragment: Fragment = JamiAccountCreationFragment()
replaceFragmentWithSlide(fragment, R.id.wizard_container)
}
override fun goToAccountLink() {
val ringAccountViewModel = AccountCreationModelImpl()
ringAccountViewModel.isLink = true
val fragment: Fragment = newInstance(ringAccountViewModel)
val fragment: Fragment = JamiLinkAccountFragment.newInstance(AccountCreationModelImpl().apply {
isLink = true
})
replaceFragmentWithSlide(fragment, R.id.wizard_container)
}
override fun goToAccountConnect() {
val ringAccountViewModel = AccountCreationModelImpl()
ringAccountViewModel.isLink = true
val fragment: Fragment = JamiAccountConnectFragment.newInstance(ringAccountViewModel)
val fragment: Fragment = JamiAccountConnectFragment.newInstance(AccountCreationModelImpl().apply {
isLink = true
})
replaceFragmentWithSlide(fragment, R.id.wizard_container)
}
......@@ -92,34 +84,26 @@ class HomeAccountCreationFragment :
.setType("*/*")
startActivityForResult(intent, ARCHIVE_REQUEST_CODE)
} catch (e: Exception) {
val v = view
if (v != null) Snackbar.make(
v,
"No file browser available on this device",
Snackbar.LENGTH_SHORT
).show()
view?.let { v ->
Snackbar.make(v, "No file browser available on this device", Snackbar.LENGTH_SHORT).show() }
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (requestCode == ARCHIVE_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (resultData != null) {
val uri = resultData.data
if (uri != null) {
getCacheFile(requireContext(), uri)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ file: File? ->
val ringAccountViewModel = AccountCreationModelImpl()
ringAccountViewModel.isLink = true
ringAccountViewModel.archive = file
val fragment: Fragment = newInstance(ringAccountViewModel)
replaceFragmentWithSlide(fragment, R.id.wizard_container)
}) { e: Throwable ->
val v = view
if (v != null)
Snackbar.make(v, "Can't import archive: " + e.message, Snackbar.LENGTH_LONG).show()
}
}
resultData?.data?.let { uri ->
getCacheFile(requireContext(), uri)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ file: File ->
val ringAccountViewModel = AccountCreationModelImpl()
ringAccountViewModel.isLink = true
ringAccountViewModel.archive = file
val fragment: Fragment = JamiLinkAccountFragment.newInstance(ringAccountViewModel)
replaceFragmentWithSlide(fragment, R.id.wizard_container)
}) { e: Throwable ->
view?.let { v ->
Snackbar.make(v, "Can't import archive: " + e.message, Snackbar.LENGTH_LONG).show() }
}
}
}
}
......
/*
* Copyright (C) 2004-2021 Savoir-faire Linux Inc.
*
* Author: Adrien Béraud <adrien.beraud@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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cx.ring.databinding.FragAccJamiConnectBinding;
import net.jami.account.JamiAccountConnectPresenter;
import net.jami.account.JamiConnectAccountView;
import net.jami.model.AccountCreationModel;
import cx.ring.mvp.BaseSupportFragment;
import dagger.hilt.android.AndroidEntryPoint;
@AndroidEntryPoint
public class JamiAccountConnectFragment extends BaseSupportFragment<JamiAccountConnectPresenter, JamiConnectAccountView> implements JamiConnectAccountView {
public static final String TAG = JamiAccountConnectFragment.class.getSimpleName();
private AccountCreationModel model;
private FragAccJamiConnectBinding mBinding;
public static JamiAccountConnectFragment newInstance(AccountCreationModelImpl ringAccountViewModel) {
JamiAccountConnectFragment fragment = new JamiAccountConnectFragment();
fragment.model = ringAccountViewModel;
return fragment;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mBinding = FragAccJamiConnectBinding.inflate(inflater, container, false);
return mBinding.getRoot();
}
@Override
public void onDestroyView() {
super.onDestroyView();
mBinding = null;
}
@Override
protected void initPresenter(net.jami.account.JamiAccountConnectPresenter presenter) {
presenter.init(model);
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mBinding.connectButton.setOnClickListener(v -> presenter.connectClicked());
mBinding.usernameTxt.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.usernameChanged(s.toString());
}
});
mBinding.passwordTxt.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());
}
});
mBinding.promptServer.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.serverChanged(s.toString());
}
});
mBinding.passwordTxt.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
presenter.connectClicked();
}
return false;
});
}
@Override
public void enableConnectButton(boolean enable) {
mBinding.connectButton.setEnabled(enable);
}
@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
/*
* Copyright (C) 2004-2021 Savoir-faire Linux Inc.
*
* Author: Adrien Béraud <adrien.beraud@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.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import cx.ring.databinding.FragAccJamiConnectBinding
import cx.ring.mvp.BaseSupportFragment
import dagger.hilt.android.AndroidEntryPoint
import net.jami.account.JamiAccountConnectPresenter
import net.jami.account.JamiConnectAccountView
import net.jami.model.AccountCreationModel
@AndroidEntryPoint
class JamiAccountConnectFragment : BaseSupportFragment<JamiAccountConnectPresenter, JamiConnectAccountView>(),
JamiConnectAccountView {
private var model: AccountCreationModel? = null
private var mBinding: FragAccJamiConnectBinding? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
mBinding = FragAccJamiConnectBinding.inflate(inflater, container, false)
return mBinding!!.root
}
override fun onDestroyView() {
super.onDestroyView()
mBinding = null
}
override fun initPresenter(presenter: JamiAccountConnectPresenter) {
presenter.init(model)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mBinding!!.connectButton.setOnClickListener { presenter.connectClicked() }
mBinding!!.usernameTxt.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable) {
presenter.usernameChanged(s.toString())
}
})
mBinding!!.passwordTxt.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable) {
presenter.passwordChanged(s.toString())
}
})
mBinding!!.promptServer.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable) {
presenter.serverChanged(s.toString())
}
})
mBinding!!.passwordTxt.setOnEditorActionListener { v: TextView?, actionId: Int, event: KeyEvent? ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
presenter.connectClicked()
}
false
}
}
override fun enableConnectButton(enable: Boolean) {
mBinding!!.connectButton.isEnabled = enable
}
override fun createAccount(accountCreationModel: AccountCreationModel) {
(requireActivity() as AccountWizardActivity).createAccount(accountCreationModel)
}
override fun cancel() {
activity?.onBackPressed()
}
companion object {
val TAG = JamiAccountConnectFragment::class.simpleName!!
fun newInstance(ringAccountViewModel: AccountCreationModelImpl): JamiAccountConnectFragment {
val fragment = JamiAccountConnectFragment()
fragment.model = ringAccountViewModel
return fragment
}
}
}
\ No newline at end of file
......@@ -55,7 +55,6 @@ class JamiLinkAccountFragment : Fragment() {
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
retainInstance = true
if (savedInstanceState != null) {
model = savedInstanceState.getSerializable("model") as AccountCreationModel
}
......
Supports Markdown
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