Fixed bug in TransferMoneyDialog.adjustCheckBoxRealTimeTransferWidth() that dialog may is already closed till timer fires and then app crashes. By that instance replaced all requireActivity()

This commit is contained in:
dankito 2020-10-16 20:45:09 +02:00
parent 64213a890f
commit 1ef89d27ec
8 changed files with 39 additions and 22 deletions

View File

@ -11,8 +11,8 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Spinner
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity
import kotlinx.android.synthetic.main.dialog_enter_tan.*
import kotlinx.android.synthetic.main.dialog_enter_tan.view.*
import kotlinx.android.synthetic.main.view_collapsible_text.view.*
@ -54,7 +54,7 @@ open class EnterTanDialog : DialogFragment() {
}
open fun show(bank: TypedBankData, tanChallenge: TanChallenge, activity: AppCompatActivity,
open fun show(bank: TypedBankData, tanChallenge: TanChallenge, activity: FragmentActivity,
fullscreen: Boolean = false, tanEnteredCallback: (EnterTanResult) -> Unit) {
this.bank = bank

View File

@ -170,8 +170,8 @@ open class TransferMoneyDialog : DialogFragment() {
protected open fun adjustCheckBoxRealTimeTransferWidth() {
// wait some time till CheckBox is layout and lineCount is set
val timer = Timer()
timer.schedule(10) { requireActivity().runOnUiThread { adjustCheckBoxRealTimeTransferWidthOnUiThread() }}
timer.schedule(2500) { requireActivity().runOnUiThread { adjustCheckBoxRealTimeTransferWidthOnUiThread() }}
timer.schedule(10) { activity?.runOnUiThread { adjustCheckBoxRealTimeTransferWidthOnUiThread() }}
timer.schedule(2500) { activity?.runOnUiThread { adjustCheckBoxRealTimeTransferWidthOnUiThread() }}
}
protected open fun adjustCheckBoxRealTimeTransferWidthOnUiThread() {
@ -193,7 +193,10 @@ open class TransferMoneyDialog : DialogFragment() {
}
protected open fun showRealTimeTransferInfo(btnShowRealTimeTransferInfo: ImageButton) {
InfoPopupWindow(requireActivity(), R.string.dialog_transfer_money_real_time_transfer_info).show(btnShowRealTimeTransferInfo)
activity?.let { activity ->
InfoPopupWindow(activity, R.string.dialog_transfer_money_real_time_transfer_info)
.show(btnShowRealTimeTransferInfo)
}
}
private fun transferMoneyIfEnterPressed(editText: EditText) {

View File

@ -3,7 +3,7 @@ package net.dankito.banking.ui.android.dialogs.settings
import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import kotlinx.android.synthetic.main.dialog_bank_account_settings.*
import kotlinx.android.synthetic.main.dialog_bank_account_settings.view.*
import net.dankito.banking.ui.android.R
@ -24,7 +24,7 @@ open class BankAccountSettingsDialog : SettingsDialogBase() {
fun show(account: TypedBankAccount, activity: AppCompatActivity) {
fun show(account: TypedBankAccount, activity: FragmentActivity) {
this.account = account
show(activity, DialogTag)

View File

@ -3,6 +3,7 @@ package net.dankito.banking.ui.android.dialogs.settings
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
@ -37,7 +38,7 @@ open class BankSettingsDialog : SettingsDialogBase() {
fun show(bank: TypedBankData, activity: AppCompatActivity) {
fun show(bank: TypedBankData, activity: FragmentActivity) {
this.bank = bank
this.selectedTanMethod = bank.selectedTanMethod
@ -109,7 +110,9 @@ open class BankSettingsDialog : SettingsDialogBase() {
protected open fun navigationToBankAccountSettingsDialog(account: TypedBankAccount) {
BankAccountSettingsDialog().show(account, requireActivity() as AppCompatActivity)
(activity as? AppCompatActivity)?.let { activity ->
BankAccountSettingsDialog().show(account, requireActivity() as AppCompatActivity)
}
}
protected open fun reorderedBankAccounts(oldPosition: Int, oldItem: TypedBankAccount, newPosition: Int, newItem: TypedBankAccount) {

View File

@ -4,8 +4,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.doOnNextLayout
import androidx.fragment.app.FragmentActivity
import kotlinx.android.synthetic.main.dialog_protect_app_settings.*
import kotlinx.android.synthetic.main.dialog_protect_app_settings.view.*
import net.dankito.banking.ui.android.R
@ -37,7 +37,7 @@ open class ProtectAppSettingsDialog : SettingsDialogBase() {
}
fun show(activity: AppCompatActivity) {
fun show(activity: FragmentActivity) {
show(activity, SettingsDialog.DialogTag)
}

View File

@ -2,8 +2,8 @@ package net.dankito.banking.ui.android.dialogs.settings
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.fragment.app.FragmentActivity
import kotlinx.android.synthetic.main.dialog_settings.*
import kotlinx.android.synthetic.main.dialog_settings.view.*
import net.dankito.banking.ui.android.R
@ -26,7 +26,7 @@ open class SettingsDialog : SettingsDialogBase() {
}
fun show(activity: AppCompatActivity) {
fun show(activity: FragmentActivity) {
show(activity, DialogTag)
}
@ -54,7 +54,7 @@ open class SettingsDialog : SettingsDialogBase() {
swtchUpdateAccountsAutomatically.isChecked = presenter.appSettings.updateAccountsAutomatically
btnSetAppProtection.setOnClickListener { ProtectAppSettingsDialog().show(requireActivity() as AppCompatActivity) }
btnSetAppProtection.setOnClickListener { navigateToProtectAppSettingsDialog() }
// 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)
@ -81,7 +81,15 @@ open class SettingsDialog : SettingsDialogBase() {
protected open fun navigationToBankSettingsDialog(bank: TypedBankData) {
BankSettingsDialog().show(bank, requireActivity() as AppCompatActivity)
activity?.let { activity ->
BankSettingsDialog().show(bank, activity)
}
}
protected open fun navigateToProtectAppSettingsDialog() {
activity?.let { activity ->
ProtectAppSettingsDialog().show(activity)
}
}
protected open fun reorderedBanks(oldPosition: Int, oldItem: TypedBankData, newPosition: Int, newItem: TypedBankData) {

View File

@ -1,9 +1,9 @@
package net.dankito.banking.ui.android.dialogs.settings
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity
import net.dankito.banking.ui.android.R
import net.dankito.banking.ui.android.alerts.AskDismissChangesAlert
import net.dankito.banking.ui.android.di.BankingComponent
@ -29,7 +29,7 @@ abstract class SettingsDialogBase : DialogFragment() {
fun show(activity: AppCompatActivity, dialogTag: String, fullscreen: Boolean = true) {
fun show(activity: FragmentActivity, dialogTag: String, fullscreen: Boolean = true) {
val style = if (fullscreen) R.style.FullscreenDialogWithStatusBar else R.style.FloatingDialog
setStyle(STYLE_NORMAL, style)

View File

@ -319,12 +319,15 @@ class HomeFragment : Fragment() {
}
private fun showFetchAllTransactionsInfo(btnShowFetchAllTransactionsInfo: ImageButton) {
val account = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched.first()
activity?.let { activity ->
val account = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched.first()
val dateOfFirstRetrievedTransaction = account.retrievedTransactionsFromOn?.let { presenter.formatToMediumDate(it) } ?: ""
val info = requireContext().getString(R.string.popup_fetch_all_transactions_info, dateOfFirstRetrievedTransaction,
account.countDaysForWhichTransactionsAreKept, presenter.formatToMediumDate(presenter.getDayOfFirstTransactionStoredOnBankServer(account)))
InfoPopupWindow(requireActivity(), info).show(btnShowFetchAllTransactionsInfo, Gravity.BOTTOM)
val dateOfFirstRetrievedTransaction = account.retrievedTransactionsFromOn?.let { presenter.formatToMediumDate(it) } ?: ""
val info = activity.getString(R.string.popup_fetch_all_transactions_info, dateOfFirstRetrievedTransaction,
account.countDaysForWhichTransactionsAreKept, presenter.formatToMediumDate(presenter.getDayOfFirstTransactionStoredOnBankServer(account)))
InfoPopupWindow(activity, info).show(btnShowFetchAllTransactionsInfo, Gravity.BOTTOM)
}
}