Skip to content
Snippets Groups Projects
Commit 972d0327 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

account migration: update

Change-Id: I3bd86ef0bbec75be5077db7c788ee25506bcf599
parent edd7cdb3
No related branches found
No related tags found
No related merge requests found
......@@ -55,8 +55,56 @@ class JamiAccountPasswordFragment : BaseSupportFragment<JamiAccountCreationPrese
if (savedInstanceState != null && model == null) {
model = savedInstanceState.getSerializable(KEY_MODEL) as AccountCreationModelImpl?
}
binding = FragAccJamiPasswordBinding.inflate(inflater, container, false)
return binding!!.root
return FragAccJamiPasswordBinding.inflate(inflater, container, false).apply {
createAccount.setOnClickListener { presenter.createAccount() }
ringPasswordSwitch.setOnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean ->
mIsChecked = isChecked
if (isChecked) {
passwordTxtBox.visibility = View.VISIBLE
ringPasswordRepeatTxtBox.visibility = View.VISIBLE
placeholder.visibility = View.GONE
val password: CharSequence? = password.text
presenter.passwordChanged(password.toString(), ringPasswordRepeat.text!!)
} else {
passwordTxtBox.visibility = View.GONE
ringPasswordRepeatTxtBox.visibility = View.GONE
placeholder.visibility = View.VISIBLE
presenter.passwordUnset()
}
}
password.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) {
presenter.passwordChanged(s.toString())
}
override fun afterTextChanged(s: Editable) {}
})
ringPasswordRepeat.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) {
presenter.passwordConfirmChanged(s.toString())
}
override fun afterTextChanged(s: Editable) {}
})
ringPasswordRepeat.setOnEditorActionListener { v: TextView?, actionId: Int, event: KeyEvent? ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
presenter.createAccount()
}
false
}
ringPasswordRepeat.setOnEditorActionListener { v: TextView, actionId: Int, event: KeyEvent? ->
if (actionId == EditorInfo.IME_ACTION_DONE && binding!!.createAccount.isEnabled) {
val inputMethodManager = v.context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(v.windowToken, 0)
presenter.createAccount()
return@setOnEditorActionListener true
}
false
}
binding = this
}.root
}
override fun onDestroyView() {
......@@ -66,53 +114,6 @@ class JamiAccountPasswordFragment : BaseSupportFragment<JamiAccountCreationPrese
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding!!.createAccount.setOnClickListener { presenter.createAccount() }
binding!!.ringPasswordSwitch.setOnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean ->
mIsChecked = isChecked
if (isChecked) {
binding!!.passwordTxtBox.visibility = View.VISIBLE
binding!!.ringPasswordRepeatTxtBox.visibility = View.VISIBLE
binding!!.placeholder.visibility = View.GONE
val password: CharSequence? = binding!!.ringPassword.text
presenter.passwordChanged(password.toString(), binding!!.ringPasswordRepeat.text!!)
} else {
binding!!.passwordTxtBox.visibility = View.GONE
binding!!.ringPasswordRepeatTxtBox.visibility = View.GONE
binding!!.placeholder.visibility = View.VISIBLE
presenter.passwordUnset()
}
}
binding!!.ringPassword.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) {
presenter.passwordChanged(s.toString())
}
override fun afterTextChanged(s: Editable) {}
})
binding!!.ringPasswordRepeat.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) {
presenter.passwordConfirmChanged(s.toString())
}
override fun afterTextChanged(s: Editable) {}
})
binding!!.ringPasswordRepeat.setOnEditorActionListener { v: TextView?, actionId: Int, event: KeyEvent? ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
presenter.createAccount()
}
false
}
binding!!.ringPasswordRepeat.setOnEditorActionListener { v: TextView, actionId: Int, event: KeyEvent? ->
if (actionId == EditorInfo.IME_ACTION_DONE && binding!!.createAccount.isEnabled) {
val inputMethodManager = v.context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(v.windowToken, 0)
presenter.createAccount()
return@setOnEditorActionListener true
}
false
}
presenter.init(model)
}
......@@ -131,16 +132,12 @@ class JamiAccountPasswordFragment : BaseSupportFragment<JamiAccountCreationPrese
}
override fun goToAccountCreation(accountCreationModel: AccountCreationModel) {
val wizardActivity: Activity? = activity
if (wizardActivity is AccountWizardActivity) {
wizardActivity.createAccount(accountCreationModel)
val parent = parentFragment as JamiAccountCreationFragment?
if (parent != null) {
parent.scrollPagerFragment(accountCreationModel)
val imm = wizardActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(binding!!.ringPassword.windowToken, 0)
}
}
val wizardActivity = activity as AccountWizardActivity? ?: return
wizardActivity.createAccount(accountCreationModel)
val parent = parentFragment as JamiAccountCreationFragment?
parent?.scrollPagerFragment(accountCreationModel)
val imm = wizardActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
imm?.hideSoftInputFromWindow(binding!!.password.windowToken, 0)
}
override fun cancel() {
......
......@@ -42,7 +42,6 @@ import dagger.hilt.android.AndroidEntryPoint
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.CompositeDisposable
import net.jami.model.AccountConfig
import net.jami.model.ConfigKey
import net.jami.services.AccountService
import javax.inject.Inject
......@@ -55,26 +54,26 @@ class AccountMigrationFragment : Fragment() {
private var mProgress: ProgressDialog? = null
private var migratingAccount = false
private val mDisposableBag = CompositeDisposable()
override fun onDestroy() {
super.onDestroy()
mDisposableBag.clear()
}
override fun onCreateView(inflater: LayoutInflater, parent: ViewGroup?, savedInstanceState: Bundle?): View {
return FragAccountMigrationBinding.inflate(inflater, parent, false).apply {
ringPassword.setOnEditorActionListener { v: TextView, actionId: Int, event: KeyEvent? ->
actionId == EditorInfo.IME_ACTION_NEXT && checkPassword(v, null)
override fun onCreateView(inflater: LayoutInflater, parent: ViewGroup?, savedInstanceState: Bundle?): View =
FragAccountMigrationBinding.inflate(inflater, parent, false).apply {
password.setOnEditorActionListener { v: TextView, actionId: Int, event: KeyEvent? ->
actionId == EditorInfo.IME_ACTION_NEXT && checkPassword(v)
}
ringPassword.onFocusChangeListener = View.OnFocusChangeListener { v: View, hasFocus: Boolean ->
password.onFocusChangeListener = View.OnFocusChangeListener { v: View, hasFocus: Boolean ->
if (!hasFocus) {
checkPassword(v as TextView, null)
checkPassword(v as TextView)
}
}
ringMigrateBtn.setOnClickListener { initAccountMigration(ringPassword.text.toString()) }
migrateBtn.setOnClickListener { initAccountMigration(password.text.toString()) }
deleteBtn.setOnClickListener { initAccountDelete() }
binding = this
}.root
}
override fun onResume() {
super.onResume()
......@@ -96,11 +95,15 @@ class AccountMigrationFragment : Fragment() {
private fun deleteAccount() {
mAccountService.removeAccount(mAccountId!!)
val activity = activity ?: return
activity.setResult(Activity.RESULT_OK, Intent())
activity.finish()
}
private fun initAccountMigration(password: String) {
if (migratingAccount) return
migratingAccount = true
val accountId = mAccountId ?: return
//orientation is locked during the migration of account to avoid the destruction of the thread
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED
......@@ -111,17 +114,12 @@ class AccountMigrationFragment : Fragment() {
setCanceledOnTouchOutside(false)
show()
}
val accountId = mAccountId!!
val account = mAccountService.getAccount(accountId)!!
val details = account.details
details[ConfigKey.ARCHIVE_PASSWORD.key()] = password
mAccountService.setAccountDetails(account.accountId, details)
mDisposableBag.add(mAccountService.migrateAccount(accountId, password)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { newState: String -> handleMigrationState(newState) })
}
private fun checkPassword(pwd: TextView, confirm: TextView?): Boolean {
private fun checkPassword(pwd: TextView): Boolean {
var error = false
if (pwd.text.isEmpty()) {
error = true
......@@ -133,15 +131,6 @@ class AccountMigrationFragment : Fragment() {
pwd.error = null
}
}
if (confirm != null) {
if (pwd.text.toString() != confirm.text.toString()) {
confirm.error = getString(R.string.error_passwords_not_equals)
confirm.requestFocus()
error = true
} else {
confirm.error = null
}
}
return error
}
......
......@@ -68,7 +68,7 @@ class LinkDeviceFragment : BaseBottomSheetFragment<LinkDevicePresenter>(), LinkD
}
}
mBinding!!.btnStartExport.setOnClickListener { onClickStart() }
mBinding!!.ringPassword.setOnEditorActionListener { pwd: TextView, actionId: Int, event: KeyEvent? ->
mBinding!!.password.setOnEditorActionListener { pwd: TextView, actionId: Int, event: KeyEvent? ->
onPasswordEditorAction(pwd, actionId, event)
}
mBinding!!.passwordLayout.visibility = if (mAccountHasPassword) View.VISIBLE else View.GONE
......@@ -146,7 +146,7 @@ class LinkDeviceFragment : BaseBottomSheetFragment<LinkDevicePresenter>(), LinkD
override fun showPasswordError() {
mBinding!!.passwordLayout.error = getString(R.string.account_export_end_decryption_message)
mBinding!!.ringPassword.setText("")
mBinding!!.password.setText("")
}
override fun showGenericError() {
......@@ -159,7 +159,7 @@ class LinkDeviceFragment : BaseBottomSheetFragment<LinkDevicePresenter>(), LinkD
override fun showPIN(pin: String) {
dismissExportingProgress()
mBinding!!.ringPassword.setText("")
mBinding!!.password.setText("")
mBinding!!.passwordLayout.visibility = View.GONE
mBinding!!.btnStartExport.visibility = View.GONE
val pined = getString(R.string.account_end_export_infos).replace("%%", pin)
......@@ -180,7 +180,7 @@ class LinkDeviceFragment : BaseBottomSheetFragment<LinkDevicePresenter>(), LinkD
private fun onClickStart() {
mBinding!!.passwordLayout.error = null
val password = mBinding!!.ringPassword.text.toString()
val password = mBinding!!.password.text.toString()
presenter.startAccountExport(password)
}
......
......@@ -78,7 +78,7 @@
app:startIconDrawable="@drawable/baseline_lock_24">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_password"
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="password,newPassword"
......
......@@ -35,11 +35,12 @@ along with this program; if not, write to the Free Software
android:orientation="vertical"
app:bounded_width="380dp">
<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:animateLayoutChanges="false">
android:animateLayoutChanges="false"
app:cardElevation="4dp">
<RelativeLayout
android:layout_width="match_parent"
......@@ -66,7 +67,7 @@ along with this program; if not, write to the Free Software
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_password"
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_enter_password"
......@@ -92,7 +93,7 @@ along with this program; if not, write to the Free Software
android:textColor="@color/red_800"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/ring_migrate_btn"
android:id="@+id/migrate_btn"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -129,7 +130,7 @@ along with this program; if not, write to the Free Software
</RelativeLayout>
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
</cx.ring.views.BoundedLinearLayout>
......
......@@ -44,7 +44,7 @@
app:passwordToggleTint="@color/colorPrimary">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_password"
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_enter_password"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment