Implemented displaying that automaticallyUpdateAccountsAfterMinutes and lockAppAfterMinutes can be set, but they have no functionality yet

This commit is contained in:
dankito 2020-10-17 00:54:11 +02:00
parent 5a4f962293
commit 6c17449fc4
15 changed files with 273 additions and 28 deletions

View File

@ -52,9 +52,11 @@ open class SettingsDialog : SettingsDialogBase() {
banksAdapter.onClickListener = { navigationToBankSettingsDialog(it.bank) }
banksAdapter.itemDropped = { oldPosition, oldItem, newPosition, newItem -> reorderedBanks(oldPosition, oldItem.bank, newPosition, newItem.bank) }
swtchUpdateAccountsAutomatically.isChecked = presenter.appSettings.updateAccountsAutomatically
swtchAutomaticallyUpdateAccounts.isChecked = presenter.appSettings.automaticallyUpdateAccounts
selectUpdateAccountsAfter.periodInMinutes = presenter.appSettings.automaticallyUpdateAccountsAfterMinutes
btnSetAppProtection.setOnClickListener { navigateToProtectAppSettingsDialog() }
selectLockAppAfter.periodInMinutes = presenter.appSettings.lockAppAfterMinutes
// on Pre Lollipop devices setting vector drawables in xml is not supported -> set left drawable here
val sendIcon = AppCompatResources.getDrawable(context, R.drawable.ic_baseline_send_24)
@ -102,10 +104,10 @@ open class SettingsDialog : SettingsDialogBase() {
override val hasUnsavedChanges: Boolean
get() = presenter.appSettings.updateAccountsAutomatically != swtchUpdateAccountsAutomatically.isChecked
get() = presenter.appSettings.automaticallyUpdateAccounts != swtchAutomaticallyUpdateAccounts.isChecked
override fun saveChanges() {
presenter.appSettings.updateAccountsAutomatically = swtchUpdateAccountsAutomatically.isChecked
presenter.appSettings.automaticallyUpdateAccounts = swtchAutomaticallyUpdateAccounts.isChecked
presenter.appSettingsChanged()
}

View File

@ -5,6 +5,7 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import kotlinx.android.synthetic.main.view_form_labelled_value.view.*
import net.dankito.banking.ui.android.R
@ -13,6 +14,10 @@ open class FormLabelledValue @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
protected lateinit var txtLabel: TextView
protected lateinit var txtValue: TextView
init {
setupUi(context, attrs)
@ -23,6 +28,8 @@ open class FormLabelledValue @JvmOverloads constructor(
val rootView = inflater.inflate(R.layout.view_form_labelled_value, this, true)
rootView.apply {
txtLabel = findViewById(R.id.txtLabel)
txtValue = findViewById(R.id.txtValue)
context.theme.obtainStyledAttributes(
attrs,

View File

@ -0,0 +1,102 @@
package net.dankito.banking.ui.android.views
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import net.dankito.banking.ui.android.R
open class FormSelectPeriod @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : RelativeLayout(context, attrs, defStyleAttr) {
protected lateinit var txtLabel: TextView
protected lateinit var txtValue: TextView
init {
setupUi(context, attrs)
}
private fun setupUi(context: Context, attrs: AttributeSet?) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val rootView = inflater.inflate(R.layout.view_form_select_period, this, true)
rootView.apply {
txtLabel = findViewById(R.id.txtLabel)
txtValue = findViewById(R.id.txtValue)
txtLabel.gravity = Gravity.CENTER_VERTICAL
txtValue.gravity = Gravity.CENTER_VERTICAL
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
txtLabel.textAlignment = View.TEXT_ALIGNMENT_GRAVITY
txtValue.textAlignment = View.TEXT_ALIGNMENT_GRAVITY
}
this.isEnabled = false // TODO: undo as soon as selecting periods is implemented
context.theme.obtainStyledAttributes(
attrs,
R.styleable.FormLabelledValue,
0, 0).apply {
try {
txtLabel.text = getString(R.styleable.FormSelectPeriod_android_label)
val defaultValue = Int.MIN_VALUE
val configuredPeriod = getInteger(R.styleable.FormSelectPeriod_periodInMinutes, defaultValue)
periodInMinutes = if (configuredPeriod == defaultValue) null else configuredPeriod
displaySelectedPeriod()
} finally {
recycle()
}
}
}
}
protected open fun displaySelectedPeriod() {
txtValue.text = getDisplayTextForSelectedPeriod()
}
protected open fun getDisplayTextForSelectedPeriod(): String {
periodInMinutes?.let { periodInMinutes ->
if (periodInMinutes > 0) {
if (periodInMinutes < 60) {
return context.getString(R.string.minutes, periodInMinutes)
}
return context.getString(R.string.hours, (periodInMinutes / 60))
}
}
return context.getString(R.string.never)
}
open var label: CharSequence
get() = txtLabel.text
set(value) {
txtLabel.text = value
}
open var periodInMinutes: Int? = null
set(value) {
field = value
displaySelectedPeriod()
}
override fun setEnabled(enabled: Boolean) {
super.setEnabled(enabled)
alpha = if (enabled) 1f else 0.5f
}
}

View File

@ -71,11 +71,18 @@
/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swtchUpdateAccountsAutomatically"
android:id="@+id/swtchAutomaticallyUpdateAccounts"
style="@style/FormSwitchStyle"
android:text="@string/dialog_settings_update_accounts_automatically"
/>
<net.dankito.banking.ui.android.views.FormSelectPeriod
android:id="@+id/selectUpdateAccountsAfter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:label="@string/dialog_settings_update_accounts_automatically_after"
/>
</LinearLayout>
@ -93,6 +100,13 @@
android:text="@string/dialog_settings_secure_app_data"
/>
<net.dankito.banking.ui.android.views.FormSelectPeriod
android:id="@+id/selectLockAppAfter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:label="@string/dialog_settings_lock_app_after"
/>
<!-- left drawable is set in code as pre Lollipop devices don't support setting vector drawables in xml -->
<Button

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/form_labelled_value_label_margin_top"
android:layout_marginBottom="@dimen/form_labelled_value_label_margin_bottom"
android:maxLines="1"
android:textSize="@dimen/form_labelled_value_label_text_size"
android:textColor="@color/formLabelTextColor"
/>

View File

@ -6,25 +6,12 @@
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/txtLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/form_labelled_value_label_margin_top"
android:layout_marginBottom="@dimen/form_labelled_value_label_margin_bottom"
android:maxLines="1"
android:textSize="@dimen/form_labelled_value_label_text_size"
android:textColor="@color/formLabelTextColor"
<include
layout="@layout/view_form_label"
/>
<TextView
android:id="@+id/txtValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/form_labelled_value_value_margin_bottom"
android:textIsSelectable="true"
android:textSize="@dimen/form_labelled_value_value_text_size"
android:textColor="@color/formValueTextColor"
<include
layout="@layout/view_form_value"
/>
</LinearLayout>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="@dimen/form_select_period_height"
>
<include
layout="@layout/view_form_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<include
layout="@layout/view_form_value"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="@dimen/form_select_period_value_margin_end"
android:layout_marginEnd="@dimen/form_select_period_value_margin_end"
/>
</RelativeLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/form_labelled_value_value_margin_bottom"
android:textIsSelectable="true"
android:textSize="@dimen/form_labelled_value_value_text_size"
android:textColor="@color/formValueTextColor"
/>

View File

@ -16,6 +16,10 @@
<string name="add_account">Konto hinzufügen</string>
<string name="settings">Einstellungen</string>
<string name="never">Nie</string>
<string name="minutes">%d min</string>
<string name="hours">%d h</string>
<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>
@ -131,7 +135,9 @@
<string name="dialog_settings_update_accounts_automatically">Konten automatisch aktualisieren</string>
<string name="dialog_settings_update_accounts_automatically_after">Aktualisieren nach (kommt noch)</string>
<string name="dialog_settings_secure_app_data">Appdaten schützen</string>
<string name="dialog_settings_lock_app_after">App sperren nach (kommt noch)</string>
<string name="dialog_settings_send_message_log_title">Message Log senden</string>
<string name="dialog_protect_app_settings_title">Appzugangsschutz</string>

View File

@ -35,4 +35,12 @@
</declare-styleable>
<declare-styleable name="FormSelectPeriod">
<attr name="android:label" />
<attr name="periodInMinutes" format="integer" />
</declare-styleable>
</resources>

View File

@ -34,6 +34,9 @@
<dimen name="form_on_off_value_height">30dp</dimen>
<dimen name="form_on_off_value_label_text_size">15sp</dimen>
<dimen name="form_select_period_height">26dp</dimen>
<dimen name="form_select_period_value_margin_end">4dp</dimen>
<dimen name="info_button_size">20dp</dimen>
<dimen name="activity_login_app_logo_size">70dp</dimen>

View File

@ -16,6 +16,10 @@
<string name="add_account">Add account</string>
<string name="settings">Settings</string>
<string name="never">Never</string>
<string name="minutes">%d min</string>
<string name="hours">%d h</string>
<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>
@ -131,7 +135,9 @@
<string name="dialog_settings_update_accounts_automatically">Update accounts automatically</string>
<string name="dialog_settings_update_accounts_automatically_after">Update after (to be implemented)</string>
<string name="dialog_settings_secure_app_data">Secure app data</string>
<string name="dialog_settings_lock_app_after">Lock app after (to be implemented)</string>
<string name="dialog_settings_send_message_log_title">Send message log</string>
<string name="dialog_protect_app_settings_title">App protection</string>

View File

@ -171,8 +171,15 @@ Unfortunately, Bankmeister cannot know whether a bank charges for real-time tran
/* SettingsDialog */
"Update accounts automatically" = "Update accounts automatically";
"Automatically update accounts" = "Update accounts automatically";
"Automatically update accounts after" = "Update after (to be implemented)";
"Secure app data" = "Secure app data";
"Lock app after" = "Lock app after (to be implemented)";
"Instantly" = "Instantly";
"%@ minutes" = "%@ minutes";
"%@ hours" = "%@ hours";
"Never" = "Never";
/* BankSettingsDialog */

View File

@ -172,8 +172,15 @@ Ob eine Bank Gebühren für Echtzeitüberweisungen erhebt, kann Bankmeister leid
/* SettingsDialog */
"Update accounts automatically" = "Konten automatisch aktualisieren";
"Automatically update accounts" = "Konten automatisch aktualisieren";
"Automatically update accounts after" = "Aktualisieren nach (kommt noch)";
"Secure app data" = "Appdaten schützen";
"Lock app after" = "App sperren nach (kommt noch)";
"Instantly" = "Sofort";
"%@ minutes" = "%@ Minuten";
"%@ hours" = "%@ Stunden";
"Never" = "Nie";
/* BankSettingsDialog */

View File

@ -4,6 +4,11 @@ import BankingUiSwift
struct SettingsDialog: View {
static private let AutomaticallyUpdateAccountsAfterOptions: [Int] = [ 60, 2 * 60, 4 * 60, 6 * 60, 8 * 60, 10 * 60, 12 * 60, 24 * 60 ]
static private let LockAppAfterOptions: [Int] = [ 0, 1, 2, 5, 10, 15, 30, 60, 2 * 60, 4 * 60, 8 * 60, 12 * 60, -1 ]
@Environment(\.editMode) var editMode
@ObservedObject var data: AppData
@ -15,13 +20,23 @@ struct SettingsDialog: View {
@State private var automaticallyUpdateAccounts: Bool = true
@State private var automaticallyUpdateAccountsAfterMinutesSelectedIndex: Int = 0
@State private var lockAppAfterMinutesSelectedIndex: Int = 0
@State private var askToDeleteAccountMessage: Message? = nil
init(_ data: AppData) {
self.data = data
self._automaticallyUpdateAccounts = State(initialValue: presenter.appSettings.automaticallyUpdateAccounts)
let settings = presenter.appSettings
self._automaticallyUpdateAccounts = State(initialValue: settings.automaticallyUpdateAccounts)
self._automaticallyUpdateAccountsAfterMinutesSelectedIndex = State(initialValue: Self.AutomaticallyUpdateAccountsAfterOptions.firstIndex(of: Int(settings.automaticallyUpdateAccountsAfterMinutes)) ?? 0)
let lockAppAfterMinutes = settings.lockAppAfterMinutes != nil ? Int(settings.lockAppAfterMinutes!) : -1
self._lockAppAfterMinutesSelectedIndex = State(initialValue: Self.LockAppAfterOptions.firstIndex(of: lockAppAfterMinutes) ?? 0)
}
@ -39,7 +54,14 @@ struct SettingsDialog: View {
}
Section {
Toggle("Update accounts automatically", isOn: $automaticallyUpdateAccounts)
Toggle("Automatically update accounts", isOn: $automaticallyUpdateAccounts)
Picker("Automatically update accounts after", selection: $automaticallyUpdateAccountsAfterMinutesSelectedIndex) {
ForEach(0 ..< Self.AutomaticallyUpdateAccountsAfterOptions.count) { optionIndex in
Text(getDisplayTextForPeriod(Self.AutomaticallyUpdateAccountsAfterOptions[optionIndex]))
}
}
.disabled(true)
}
Section {
@ -48,10 +70,17 @@ struct SettingsDialog: View {
.frame(maxWidth: .infinity, alignment: .leading) // stretch over full width
.makeBackgroundTapable()
}
}
.onTapGesture {
self.navigateToProtectAppSettingsDialog()
}
Picker("Lock app after", selection: $lockAppAfterMinutesSelectedIndex) {
ForEach(0 ..< Self.LockAppAfterOptions.count) { optionIndex in
Text(getDisplayTextForPeriod(Self.LockAppAfterOptions[optionIndex]))
}
}
.disabled(true)
}
}
.onDisappear { self.saveChanges() }
.alert(message: $askToDeleteAccountMessage)
@ -69,6 +98,23 @@ struct SettingsDialog: View {
}
private func getDisplayTextForPeriod(_ periodInMinutes: Int) -> String {
if periodInMinutes == 0 {
return "Instantly".localize()
}
if periodInMinutes > 0 && periodInMinutes < 60 {
return "%@ minutes".localize(String(periodInMinutes))
}
if periodInMinutes >= 60 {
return "%@ hours".localize(String(periodInMinutes / 60))
}
return "Never".localize()
}
func reorderBanks(from sourceIndices: IndexSet, to destinationIndex: Int) {
let _ = data.banksSorted.reorder(from: sourceIndices, to: destinationIndex)