Skip to content

Commit

Permalink
Create backup password copy fix #429. Wallet restore password entry C…
Browse files Browse the repository at this point in the history
…TA button enabled/disabled fix #474. Settings and backup settings screen backup state display fix #509.
  • Loading branch information
kukabi committed Jul 27, 2020
1 parent e39a42f commit 8e68182
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ internal class BackupManager(
if (!backupStorage.hasBackupForDate(backupDate)) {
throw BackupStorageTamperedException("Backup storage is tampered.")
}
if (sharedPrefs.scheduledBackupDate?.isAfterNow == true) {
EventBus.postBackupState(BackupScheduled)
} else {
EventBus.postBackupState(BackupUpToDate)
when {
sharedPrefs.backupFailureDate != null -> {
EventBus.postBackupState(BackupOutOfDate())
}
sharedPrefs.scheduledBackupDate?.isAfterNow == true -> {
EventBus.postBackupState(BackupScheduled)
}
else -> {
EventBus.postBackupState(BackupUpToDate)
}
}
} catch (e: BackupStorageAuthRevokedException) {
sharedPrefs.lastSuccessfulBackupDate = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ package com.tari.android.wallet.ui.fragment.debug

import android.content.ClipboardManager
import android.content.Context.CLIPBOARD_SERVICE
import android.os.AsyncTask
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.tari.android.wallet.R
import com.tari.android.wallet.R.color.white
import com.tari.android.wallet.R.drawable.base_node_config_edit_text_bg
Expand All @@ -53,6 +53,9 @@ import com.tari.android.wallet.ffi.HexString
import com.tari.android.wallet.ui.extension.*
import com.tari.android.wallet.ui.util.UiUtil
import com.tari.android.wallet.util.SharedPrefsWrapper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

/**
Expand Down Expand Up @@ -180,19 +183,23 @@ internal class BaseNodeConfigFragment : Fragment() {
val address = ui.addressEditText.editableText.toString()
ui.saveButton.invisible()
ui.progressBar.visible()
AsyncTask.execute {
lifecycleScope.launch(Dispatchers.IO) {
addBaseNodePeer(publicKeyHex, address)
}
}

private fun addBaseNodePeer(publicKeyHex: String, address: String) {
private suspend fun addBaseNodePeer(publicKeyHex: String, address: String) {
val baseNodeKeyFFI = FFIPublicKey(HexString(publicKeyHex))
val success = FFIWallet.instance!!.addBaseNodePeer(baseNodeKeyFFI, address)
val success = try {
FFIWallet.instance!!.addBaseNodePeer(baseNodeKeyFFI, address)
true
} catch (exception: Exception) {
false
}
baseNodeKeyFFI.destroy()
ui.rootView.post {
withContext(Dispatchers.Main) {
if (success) {
addBaseNodePeerSuccessful(publicKeyHex, address)
// show toast
} else {
addBaseNodePeerFailed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ framework for UI tree rebuild on configuration changes"""
private fun showAuthFailedDialog() {
ErrorDialog(
requireContext(),
title = string(back_up_wallet_storage_setup_error_title),
title = string(restore_wallet_error_title),
description = string(back_up_wallet_storage_setup_error_desc)
).show()
}

private fun showBackupFileNotFoundDialog() {
ErrorDialog(
requireContext(),
title = string(back_up_wallet_storage_setup_error_title),
title = string(restore_wallet_error_title),
description = string(restore_wallet_error_file_not_found),
onClose = {
requireActivity().onBackPressed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package com.tari.android.wallet.ui.fragment.restore

import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.text.SpannableString
import android.text.SpannableStringBuilder
Expand Down Expand Up @@ -90,10 +91,10 @@ UI tree rebuild on configuration changes"""

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupUi()
setupUI()
}

private fun setupUi() {
private fun setupUI() {
requireActivity().onBackPressedDispatcher
.addCallback(viewLifecycleOwner, blockingBackPressDispatcher)
setPageDescription()
Expand All @@ -108,19 +109,30 @@ UI tree rebuild on configuration changes"""
}
}
)
setRestoreWalletCTAState(isEnabled = false)
ui.restoreWalletCtaView.setOnClickListener {
showRestoringUI()
performRestoration(ui.passwordEditText.text!!.toString())
}
ui.passwordEditText.addTextChangedListener(
afterTextChanged = {
setRestoreWalletCTAState(it?.length ?: 0 != 0)
ui.enterPasswordLabelTextView.setTextColor(color(black))
ui.passwordEditText.setTextColor(color(black))
ui.wrongPasswordLabelView.gone()
}
)
}

private fun setRestoreWalletCTAState(isEnabled: Boolean) {
if (ui.restoreWalletCtaView.isEnabled == isEnabled) return
ui.restoreWalletCtaView.isEnabled = isEnabled
ui.restoreWalletTextView.setTextColor(
if (isEnabled) Color.WHITE
else color(seed_phrase_button_disabled_text_color)
)
}

private fun showRestoringUI() {
blockingBackPressDispatcher.isEnabled = true
ui.passwordEditText.isEnabled = false
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
<string name="restore_with_cloud_page_title">Enter your backup password</string>

<!--Change password-->
<string name="change_password_enter_password_label">Create Password</string>
<string name="change_password_enter_password_label">Create a Password</string>
<string name="change_password_enter_password_hint">Make it a strong one!</string>
<string name="change_password_confirm_password_label">Confirm Password</string>
<string name="change_password_confirm_password_hint">Let’s see it again</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
ext.kotlin_version = '1.3.72'

// build & version
ext.buildNumber = 128
ext.buildNumber = 129
ext.versionNumber = "0.3.0"

// JNI libs
Expand Down

0 comments on commit 8e68182

Please sign in to comment.