Implemented displaying a switch to be able to set if password should be saved or not, but there's not logic behind it yet

This commit is contained in:
dankito 2020-10-17 03:11:28 +02:00
parent 197a984353
commit a7b47665a5
16 changed files with 150 additions and 32 deletions

View File

@ -70,11 +70,11 @@ open class AddAccountDialog : DialogFragment() {
initBankListAutocompletion(edtxtBank.actualEditText)
edtxtUserName.actualEditText.addTextChangedListener(otherEditTextChangedWatcher)
edtxtPassword.actualEditText.addTextChangedListener(otherEditTextChangedWatcher)
bankCredentialsPassword.passwordBox.addTextChangedListener(otherEditTextChangedWatcher)
addAccountIfEnterPressed(edtxtBank.actualEditText)
addAccountIfEnterPressed(edtxtUserName.actualEditText)
addAccountIfEnterPressed(edtxtPassword.actualEditText)
addAccountIfEnterPressed(bankCredentialsPassword.passwordBox)
btnAddAccount.setOnClickListener { addAccount() }
btnCancel.setOnClickListener { dismiss() }
@ -112,12 +112,12 @@ open class AddAccountDialog : DialogFragment() {
protected open fun addAccount() {
selectedBank?.let { selectedBank -> // should always be non-null at this stage
val userName = edtxtUserName.text
val password = edtxtPassword.text
val password = bankCredentialsPassword.password
btnAddAccount.isEnabled = false
pgrbrAddAccount.visibility = View.VISIBLE
presenter.addAccountAsync(selectedBank, userName, password) { response ->
presenter.addAccountAsync(selectedBank, userName, password, bankCredentialsPassword.savePassword) { response ->
context?.asActivity()?.runOnUiThread {
btnAddAccount.isEnabled = true
pgrbrAddAccount.visibility = View.GONE
@ -184,7 +184,7 @@ open class AddAccountDialog : DialogFragment() {
val requiredDataEntered = selectedBank != null
&& selectedBank?.supportsFinTs3_0 == true
&& edtxtUserName.text.isNotEmpty()
&& edtxtPassword.text.isNotEmpty()
&& bankCredentialsPassword.password.isNotEmpty()
btnAddAccount.isEnabled = requiredDataEntered
}

View File

@ -4,9 +4,7 @@ import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import kotlinx.android.synthetic.main.dialog_bank_settings.edtxtBankName
import kotlinx.android.synthetic.main.dialog_bank_settings.edtxtUserName
import kotlinx.android.synthetic.main.dialog_bank_settings.edtxtPassword
import kotlinx.android.synthetic.main.dialog_bank_settings.*
import kotlinx.android.synthetic.main.dialog_bank_settings.view.*
import kotlinx.android.synthetic.main.dialog_bank_settings.view.toolbar
import net.dankito.banking.ui.android.R
@ -64,7 +62,8 @@ open class BankSettingsDialog : SettingsDialogBase() {
edtxtBankName.text = bank.displayName
edtxtUserName.text = bank.userName
edtxtPassword.text = bank.password
bankCredentialsPassword.password = bank.password
bankCredentialsPassword.savePassword = bank.savePassword
val tanMethodItems = createTanMethodItems()
val tanMethodsAdapter = FastAdapterRecyclerView(rootView.rcyTanMethods, tanMethodItems)
@ -127,13 +126,14 @@ open class BankSettingsDialog : SettingsDialogBase() {
override val hasUnsavedChanges: Boolean
get() = didChange(edtxtBankName, bank.displayName)
|| didChange(edtxtUserName, bank.userName)
|| didChange(edtxtPassword, bank.password)
|| bankCredentialsPassword.password != bank.password
|| bankCredentialsPassword.savePassword != bank.savePassword
|| bank.selectedTanMethod != selectedTanMethod
override fun saveChanges() {
bank.userSetDisplayName = edtxtBankName.text
presenter.bankUpdated(bank, edtxtUserName.text, edtxtPassword.text, selectedTanMethod)
presenter.bankUpdated(bank, edtxtUserName.text, bankCredentialsPassword.password, bankCredentialsPassword.savePassword, selectedTanMethod)
}
protected open fun askUserToDeleteAccount() {

View File

@ -0,0 +1,47 @@
package net.dankito.banking.ui.android.views
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.LinearLayout
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.view_bank_credentials_password.view.*
import kotlinx.android.synthetic.main.view_form_edit_text.view.*
import net.dankito.banking.ui.android.R
import net.dankito.banking.ui.android.extensions.textString
open class BankCredentialsPasswordView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
init {
setupUi(context, attrs)
}
private fun setupUi(context: Context, attrs: AttributeSet?) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
inflater.inflate(R.layout.view_bank_credentials_password, this, true)
}
open var password: String
get() = edtxtPassword.text
set(value) {
edtxtPassword.text = value
}
open val passwordBox: TextInputEditText
get() = textInputEditText
open var savePassword: Boolean
get() = swtchSavePassword.isChecked
set(value) {
swtchSavePassword.isChecked = value
}
}

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -34,14 +33,10 @@
android:inputType="text"
/>
<net.dankito.banking.ui.android.views.FormEditText
android:id="@+id/edtxtPassword"
<net.dankito.banking.ui.android.views.BankCredentialsPasswordView
android:id="@+id/bankCredentialsPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:showPasswordToggle="true"
android:hint="@string/online_banking_credentials_password"
android:inputType="textPassword"
/>

View File

@ -78,13 +78,10 @@
android:inputType="text"
/>
<net.dankito.banking.ui.android.views.FormEditText
android:id="@+id/edtxtPassword"
<net.dankito.banking.ui.android.views.BankCredentialsPasswordView
android:id="@+id/bankCredentialsPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:showPasswordToggle="true"
android:hint="@string/online_banking_credentials_password"
android:inputType="textPassword"
/>
</LinearLayout>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<net.dankito.banking.ui.android.views.FormEditText
android:id="@+id/edtxtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:showPasswordToggle="true"
android:hint="@string/online_banking_credentials_password"
android:inputType="textPassword"
/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swtchSavePassword"
style="@style/FormSwitchStyle"
android:text="@string/online_banking_credentials_save_password"
android:checked="true"
android:enabled="false"
/>
</LinearLayout>

View File

@ -24,6 +24,7 @@
<string name="online_banking_credentials_section_title">Online-Banking Zugangsdaten</string>
<string name="online_banking_credentials_login_name">Login Name</string>
<string name="online_banking_credentials_password">Passwort</string>
<string name="online_banking_credentials_save_password">Password speichern (kommt noch)</string>
<string name="accounts">Konten</string>
<string name="bank_credentials">Bankzugänge</string>

View File

@ -24,6 +24,7 @@
<string name="online_banking_credentials_section_title">Online banking login data</string>
<string name="online_banking_credentials_login_name">Login name</string>
<string name="online_banking_credentials_password">Password</string>
<string name="online_banking_credentials_save_password">Save password (to be implemented)</string>
<string name="accounts">Accounts</string>
<string name="bank_credentials">Bank credentials</string>

View File

@ -243,7 +243,7 @@ open class AddAccountDialog(protected val presenter: BankingPresenter) : Window(
isEnteredCredentialsResultVisible.value = false
selectedBank?.let {
presenter.addAccountAsync(it, userName.value, password.value) { response ->
presenter.addAccountAsync(it, userName.value, password.value, true) { response ->
runLater { handleAddAccountResultOnUiThread(response) }
}
}

View File

@ -164,8 +164,9 @@ open class BankingPresenter(
// TODO: move BankInfo out of fints4k
open fun addAccountAsync(bankInfo: BankInfo, userName: String, password: String, callback: (AddAccountResponse) -> Unit) {
open fun addAccountAsync(bankInfo: BankInfo, userName: String, password: String, savePassword: Boolean = true, callback: (AddAccountResponse) -> Unit) {
val bank = modelCreator.createBank(bankInfo.bankCode, userName, password, bankInfo.pinTanAddress ?: "", bankInfo.name, bankInfo.bic, "")
bank.savePassword = savePassword
val newClient = bankingClientCreator.createClient(bank, dataFolder, asyncRunner, this.callback)
@ -504,13 +505,14 @@ open class BankingPresenter(
callBanksChangedListeners()
}
open fun bankUpdated(bank: TypedBankData, enteredUsername: String, enteredPassword: String, selectedTanMethod: TanMethod?) {
val didCredentialsChange = bank.userName != enteredUsername || bank.password != enteredPassword
open fun bankUpdated(bank: TypedBankData, enteredUsername: String, enteredPassword: String, savePassword: Boolean, selectedTanMethod: TanMethod?) {
val didCredentialsChange = bank.userName != enteredUsername || bank.password != enteredPassword || bank.savePassword != savePassword
val didSelectedTanMethodChange = bank.selectedTanMethod != selectedTanMethod
if (didCredentialsChange) {
bank.userName = enteredUsername
bank.password = enteredPassword
bank.savePassword = savePassword
if (bank.wrongCredentialsEntered) {
bank.wrongCredentialsEntered = false // so that on next call its accounts are considered and so it gets checked if credentials are now correct

View File

@ -34,6 +34,7 @@
3642F0182502723A005186FE /* UIKitButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3642F0172502723A005186FE /* UIKitButton.swift */; };
3642F01A2502931F005186FE /* RealTimeTransferInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3642F0192502931F005186FE /* RealTimeTransferInfoView.swift */; };
3642F04B25031157005186FE /* SectionHeaderWithRightAlignedEditButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3642F04A25031157005186FE /* SectionHeaderWithRightAlignedEditButton.swift */; };
36671255253A761500BD2301 /* BankCredentialsPasswordView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36671254253A761500BD2301 /* BankCredentialsPasswordView.swift */; };
36693A4E25280BCB00BB7AE5 /* InfoButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36693A4D25280BCB00BB7AE5 /* InfoButton.swift */; };
366FA4DA24C472A90094F009 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366FA4D924C472A90094F009 /* Extensions.swift */; };
366FA4DC24C479120094F009 /* BankInfoListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366FA4DB24C479120094F009 /* BankInfoListItem.swift */; };
@ -197,6 +198,7 @@
3642F0172502723A005186FE /* UIKitButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitButton.swift; sourceTree = "<group>"; };
3642F0192502931F005186FE /* RealTimeTransferInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealTimeTransferInfoView.swift; sourceTree = "<group>"; };
3642F04A25031157005186FE /* SectionHeaderWithRightAlignedEditButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderWithRightAlignedEditButton.swift; sourceTree = "<group>"; };
36671254253A761500BD2301 /* BankCredentialsPasswordView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankCredentialsPasswordView.swift; sourceTree = "<group>"; };
36693A4D25280BCB00BB7AE5 /* InfoButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoButton.swift; sourceTree = "<group>"; };
366FA4D924C472A90094F009 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
366FA4DB24C479120094F009 /* BankInfoListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankInfoListItem.swift; sourceTree = "<group>"; };
@ -626,6 +628,7 @@
36750531252006C9006B13A0 /* TextWithScrollView.swift */,
36428CFE251BEC4C009DE1AE /* SectionWithoutBackground.swift */,
361282C125223D7700392A4D /* SelectableText.swift */,
36671254253A761500BD2301 /* BankCredentialsPasswordView.swift */,
);
path = views;
sourceTree = "<group>";
@ -935,6 +938,7 @@
36FC92A124B39A05002B12E9 /* BankingiOSApp.xcdatamodeld in Sources */,
360782D324F429F80098FEFE /* FlickerCodeStripe.swift in Sources */,
36BE06C624D080C900CBBB68 /* FaviconType.swift in Sources */,
36671255253A761500BD2301 /* BankCredentialsPasswordView.swift in Sources */,
360782CD24F1A57F0098FEFE /* LabelledUIKitTextFieldWithValidationLabel.swift in Sources */,
3642F00A2500F5AE005186FE /* Divider.swift in Sources */,
36BCF89324C25BC3005BEC29 /* Mapper.swift in Sources */,

View File

@ -77,6 +77,7 @@
"Enter Online banking login name" = "Enter login name";
"Online banking login password" = "Password";
"Enter Online banking login password" = "Enter password";
"Save online banking login password" = "Save password (to be implemented)";
"Could not add account" = "Could not add account";
"Error message from your bank %@" = "Error message from your bank:\n\n%@";

View File

@ -77,6 +77,7 @@
"Enter Online banking login name" = "Login Name eingeben";
"Online banking login password" = "Passwort";
"Enter Online banking login password" = "Passwort eingeben";
"Save online banking login password" = "Password speichern (kommt noch)";
"Could not add account" = "Konto konnte nicht hinzugefügt werden.";
"Error message from your bank %@" = "Fehlermeldung Ihrer Bank:\n\n%@";

View File

@ -9,6 +9,7 @@ struct AddAccountDialog: View {
@State private var userName = ""
@State private var password = ""
@State private var savePassword: Bool = true
@State private var focusLoginNameTextField: Bool = false
@ -45,8 +46,7 @@ struct AddAccountDialog: View {
LabelledUIKitTextField(label: "Online banking login name", text: $userName, placeholder: "Enter Online banking login name", autocapitalizationType: .none,
focusNextTextFieldOnReturnKeyPress: true, focusTextField: $focusLoginNameTextField, actionOnReturnKeyPress: handleReturnKeyPress)
LabelledUIKitTextField(label: "Online banking login password", text: $password, placeholder: "Enter Online banking login password",
autocapitalizationType: .none, isPasswordField: true, actionOnReturnKeyPress: handleReturnKeyPress)
BankCredentialsPasswordView($password, $savePassword, handleReturnKeyPress)
}
Section {
@ -96,7 +96,7 @@ struct AddAccountDialog: View {
isTryingToAddAccount = true
UIApplication.hideKeyboard()
presenter.addAccountAsync(bankInfo: bank, userName: userName, password: password) { (response) in
presenter.addAccountAsync(bankInfo: bank, userName: userName, password: password, savePassword: savePassword) { (response) in
self.handleAddAccountResponse(response)
}
}

View File

@ -16,6 +16,7 @@ struct BankSettingsDialog: View {
@State private var userName: String
@State private var password: String
@State private var savePassword: Bool
@State private var selectedTanMethod: TanMethod?
@ -39,6 +40,7 @@ struct BankSettingsDialog: View {
_userName = State(initialValue: bank.userName)
_password = State(initialValue: bank.password)
_savePassword = State(initialValue: bank.savePassword)
_selectedTanMethod = State(initialValue: bank.selectedTanMethod)
@ -55,7 +57,8 @@ struct BankSettingsDialog: View {
Section(header: Text("Credentials")) {
LabelledUIKitTextField(label: "Online banking login name", text: $userName, autocapitalizationType: .none)
LabelledUIKitTextField(label: "Online banking login password", text: $password, autocapitalizationType: .none, isPasswordField: true)
BankCredentialsPasswordView($password, $savePassword)
}
Section {
@ -130,7 +133,7 @@ struct BankSettingsDialog: View {
if hasUnsavedData {
bank.userSetDisplayName = displayName
presenter.bankUpdated(bank: bank, enteredUsername: userName, enteredPassword: password, selectedTanMethod: selectedTanMethod)
presenter.bankUpdated(bank: bank, enteredUsername: userName, enteredPassword: password, savePassword: savePassword, selectedTanMethod: selectedTanMethod)
}
closeDialog()

View File

@ -0,0 +1,38 @@
import SwiftUI
struct BankCredentialsPasswordView: View {
@Binding private var password: String
@Binding private var savePassword: Bool
private var handleReturnKeyPress: (() -> Bool)? = nil
init(_ password: Binding<String>, _ showPassword: Binding<Bool>, _ handleReturnKeyPress: (() -> Bool)? = nil) {
self._password = password
self._savePassword = showPassword
self.handleReturnKeyPress = handleReturnKeyPress
}
@ViewBuilder
var body: some View {
LabelledUIKitTextField(label: "Online banking login password", text: $password, placeholder: "Enter Online banking login password",
autocapitalizationType: .none, isPasswordField: true, actionOnReturnKeyPress: handleReturnKeyPress)
Toggle("Save online banking login password", isOn: $savePassword)
.disabled(true)
}
}
struct BankCredentialsPasswordView_Previews: PreviewProvider {
static var previews: some View {
BankCredentialsPasswordView(.constant(""), .constant(true))
}
}