Implemented saving lastSelectedOpenPdfFolder and lastSelectedImportFolder

This commit is contained in:
dankito 2020-11-04 21:35:49 +01:00
parent 013c6fa088
commit 8787b2ffd7
10 changed files with 25 additions and 13 deletions

View File

@ -1,6 +1,10 @@
package net.dankito.utils.multiplatform
fun String?.toFile(): java.io.File? {
return this?.let { File(it) }
}
fun java.util.Date.toDate(): Date {
return Date(this.time)
}

View File

@ -190,7 +190,7 @@ open class RoomBankingPersistence(protected open val applicationContext: Context
override fun saveOrUpdateAppSettings(appSettings: AppSettings) {
val mapped = net.dankito.banking.persistence.model.AppSettings(appSettings.automaticallyUpdateAccountsAfterMinutes,
appSettings.lockAppAfterMinutes, appSettings.screenshotsAllowed, appSettings.lastSelectedExportFolder)
appSettings.lockAppAfterMinutes, appSettings.screenshotsAllowed, appSettings.lastSelectedOpenPdfFolder, appSettings.lastSelectedImportFolder, appSettings.lastSelectedExportFolder)
database.appSettingsDao().saveOrUpdate(mapped)
saveOrUpdateTanMethodSettings(appSettings.flickerCodeSettings, FlickerCodeTanMethodSettingsId)
@ -215,6 +215,8 @@ open class RoomBankingPersistence(protected open val applicationContext: Context
settings.automaticallyUpdateAccountsAfterMinutes = persistedSettings.automaticallyUpdateAccountsAfterMinutes
settings.lockAppAfterMinutes = persistedSettings.lockAppAfterMinutes
settings.screenshotsAllowed = persistedSettings.screenshotsAllowed
settings.lastSelectedOpenPdfFolder = persistedSettings.lastSelectedOpenPdfFolder
settings.lastSelectedImportFolder = persistedSettings.lastSelectedImportFolder
settings.lastSelectedExportFolder = persistedSettings.lastSelectedExportFolder
}

View File

@ -11,6 +11,8 @@ open class AppSettings(
open var automaticallyUpdateAccountsAfterMinutes: Int? = AppSettings.DefaultAutomaticallyUpdateAccountsAfterMinutes,
open var lockAppAfterMinutes: Int? = null,
open var screenshotsAllowed: Boolean = false,
open var lastSelectedOpenPdfFolder: String? = null,
open var lastSelectedImportFolder: String? = null,
open var lastSelectedExportFolder: String? = null
) {

View File

@ -19,6 +19,7 @@ import net.dankito.banking.ui.model.TypedBankData
import net.dankito.filechooserdialog.FileChooserDialog
import net.dankito.filechooserdialog.model.FileChooserDialogConfig
import net.dankito.utils.android.permissions.IPermissionsService
import net.dankito.utils.multiplatform.toFile
import java.io.File
import java.text.SimpleDateFormat
import javax.inject.Inject
@ -123,7 +124,7 @@ open class SettingsDialog : SettingsDialogBase() {
protected open fun exportAccountTransactions() {
val initialDirectory = presenter.appSettings.lastSelectedExportFolder?.let { File(it) }
val initialDirectory = presenter.appSettings.lastSelectedExportFolder.toFile()
val suggestedFilename = getExportCsvSuggestedFilename()
// val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)

View File

@ -33,8 +33,6 @@ open class MainActivityFloatingActionMenuButton(
protected lateinit var fabTransferMoneyFromPdf: FloatingActionButton
protected var lastSelectedFolder: File? = null
init {
setupButtons(floatingActionMenu)
@ -98,12 +96,10 @@ open class MainActivityFloatingActionMenuButton(
protected open fun showTransferMoneyDialogWithDataFromPdf() {
(floatingActionMenu.context.asActivity() as? FragmentActivity)?.let { activity ->
val config = FileChooserDialogConfig(listOf("*.pdf"), lastSelectedFolder)
val config = FileChooserDialogConfig(listOf("*.pdf"), presenter.appSettings.lastSelectedOpenPdfFolder.toFile())
FileChooserDialog().showOpenSingleFileDialog(activity, permissionsService, config) { _, selectedFile ->
selectedFile?.let {
lastSelectedFolder = selectedFile.parentFile
val result = presenter.showTransferMoneyDialogWithDataFromPdf(selectedFile.toFile())
if (result.type != ExtractTransferMoneyDataFromPdfResultType.Success) {

View File

@ -28,8 +28,6 @@ open class MainMenuBar(protected val presenter: BankingPresenter) : View() {
protected val areAccountsThatCanTransferMoneyAdded = SimpleBooleanProperty()
protected var lastSelectedFolder: File? = null
init {
presenter.addBanksChangedListener {
@ -89,12 +87,10 @@ open class MainMenuBar(protected val presenter: BankingPresenter) : View() {
protected open fun showTransferMoneyDialogWithDataFromPdf() {
val fileChooser = FileChooser()
fileChooser.initialDirectory = lastSelectedFolder
fileChooser.initialDirectory = presenter.appSettings.lastSelectedOpenPdfFolder.toFile()
fileChooser.extensionFilters.add(FileChooser.ExtensionFilter("PDFs (*.pdf)", "*.pdf"))
fileChooser.showOpenDialog(currentStage)?.let { pdfFile ->
lastSelectedFolder = pdfFile.parentFile
val result = presenter.showTransferMoneyDialogWithDataFromPdf(pdfFile.toFile())
if (result.type != ExtractTransferMoneyDataFromPdfResultType.Success) {

View File

@ -10,6 +10,8 @@ open class AppSettings(
open var flickerCodeSettings: TanMethodSettings? = null,
open var qrCodeSettings: TanMethodSettings? = null,
open var photoTanSettings: TanMethodSettings? = null,
open var lastSelectedOpenPdfFolder: String? = null, // File is not that easily persistable so modeled it as string
open var lastSelectedImportFolder: String? = null, // File is not that easily persistable so modeled it as string
open var lastSelectedExportFolder: String? = null // File is not that easily persistable so modeled it as string
) {

View File

@ -630,6 +630,9 @@ open class BankingPresenter(
}
open fun showTransferMoneyDialogWithDataFromPdf(pdf: File): ExtractTransferMoneyDataFromPdfResult {
appSettings.lastSelectedOpenPdfFolder = pdf.parent?.getAbsolutePath()
appSettingsChanged()
val extractionResult = textExtractorRegistry.extractTextWithBestExtractorForFile(pdf)
if (extractionResult.couldExtractText == false || extractionResult.text == null) {

View File

@ -39,6 +39,8 @@
<entity name="PersistedAppSettings" representedClassName="PersistedAppSettings" syncable="YES" codeGenerationType="class">
<attribute name="automaticallyUpdateAccountsAfterMinutes" optional="YES" attributeType="Integer 32" defaultValueString="360" usesScalarValueType="NO"/>
<attribute name="lastSelectedExportFolder" optional="YES" attributeType="String"/>
<attribute name="lastSelectedImportFolder" optional="YES" attributeType="String"/>
<attribute name="lastSelectedOpenPdfFolder" optional="YES" attributeType="String"/>
<attribute name="lockAppAfterMinutes" optional="YES" attributeType="Integer 32" defaultValueString="-1" usesScalarValueType="NO"/>
<attribute name="screenshotsAllowed" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<relationship name="flickerCodeSettings" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="PersistedTanMethodSettings"/>
@ -110,7 +112,7 @@
</entity>
<elements>
<element name="PersistedAccountTransaction" positionX="-36" positionY="45" width="128" height="553"/>
<element name="PersistedAppSettings" positionX="-45" positionY="144" width="128" height="148"/>
<element name="PersistedAppSettings" positionX="-45" positionY="144" width="128" height="178"/>
<element name="PersistedBankAccount" positionX="-54" positionY="63" width="128" height="418"/>
<element name="PersistedBankData" positionX="-63" positionY="-18" width="128" height="298"/>
<element name="PersistedTanMedium" positionX="-45" positionY="144" width="128" height="28"/>

View File

@ -325,6 +325,8 @@ class Mapper {
flickerCodeSettings: map(settings.flickerCodeSettings),
qrCodeSettings: map(settings.qrCodeSettings),
photoTanSettings: map(settings.photoTanSettings),
lastSelectedOpenPdfFolder: settings.lastSelectedOpenPdfFolder,
lastSelectedImportFolder: settings.lastSelectedImportFolder,
lastSelectedExportFolder: settings.lastSelectedExportFolder)
mapped.technicalId = settings.objectIDAsString
@ -343,6 +345,8 @@ class Mapper {
mapped.qrCodeSettings = map(settings.qrCodeSettings, context)
mapped.photoTanSettings = map(settings.photoTanSettings, context)
mapped.lastSelectedOpenPdfFolder = settings.lastSelectedOpenPdfFolder
mapped.lastSelectedImportFolder = settings.lastSelectedImportFolder
mapped.lastSelectedExportFolder = settings.lastSelectedExportFolder
return mapped