fix: Better icon builder implementation, add ContextualDatabase

This commit is contained in:
J-Jamet 2023-05-14 13:04:49 +02:00
parent 0d2c814b3d
commit ee1a0a53a6
86 changed files with 506 additions and 424 deletions

View file

@ -36,7 +36,7 @@ import com.kunzisoft.keepass.autofill.AutofillComponent
import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.autofill.CompatInlineSuggestionsRequest
import com.kunzisoft.keepass.autofill.KeeAutofillService
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.helper.SearchHelper
import com.kunzisoft.keepass.model.RegisterInfo
import com.kunzisoft.keepass.model.SearchInfo
@ -59,7 +59,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() {
return true
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
// Retrieve selection mode
@ -116,7 +116,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() {
}
}
private fun launchSelection(database: Database?,
private fun launchSelection(database: ContextualDatabase?,
autofillComponent: AutofillComponent?,
searchInfo: SearchInfo) {
if (autofillComponent == null) {
@ -159,7 +159,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() {
}
}
private fun launchRegistration(database: Database?,
private fun launchRegistration(database: ContextualDatabase?,
searchInfo: SearchInfo,
registerInfo: RegisterInfo?) {
if (!KeeAutofillService.autofillAllowedFor(searchInfo.applicationId,

View file

@ -51,6 +51,7 @@ import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
import com.kunzisoft.keepass.activities.helpers.SpecialMode
import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
import com.kunzisoft.keepass.adapters.TagsAdapter
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.icon.IconImage
@ -74,7 +75,7 @@ import com.kunzisoft.keepass.view.changeTitleColor
import com.kunzisoft.keepass.view.hideByFading
import com.kunzisoft.keepass.view.showActionErrorIfNeeded
import com.kunzisoft.keepass.viewmodels.EntryViewModel
import java.util.*
import java.util.UUID
class EntryActivity : DatabaseLockActivity() {
@ -310,14 +311,14 @@ class EntryActivity : DatabaseLockActivity() {
return coordinatorLayout
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
mEntryViewModel.loadDatabase(database)
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {
@ -376,7 +377,7 @@ class EntryActivity : DatabaseLockActivity() {
.createBlendModeColorFilterCompat(backgroundDarker, BlendModeCompat.SRC_IN)
mIcon?.let { icon ->
titleIconView?.let { iconView ->
mIconDrawableFactory?.assignDatabaseIcon(
mDatabase?.iconDrawableFactory?.assignDatabaseIcon(
iconView,
icon,
mForegroundColor ?: mColorAccent

View file

@ -32,7 +32,11 @@ import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.*
import android.widget.AdapterView
import android.widget.DatePicker
import android.widget.ProgressBar
import android.widget.Spinner
import android.widget.TimePicker
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
@ -46,8 +50,14 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.google.android.material.snackbar.Snackbar
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.*
import com.kunzisoft.keepass.activities.dialogs.ColorPickerDialogFragment
import com.kunzisoft.keepass.activities.dialogs.DatePickerFragment
import com.kunzisoft.keepass.activities.dialogs.EntryCustomFieldDialogFragment
import com.kunzisoft.keepass.activities.dialogs.FileTooBigDialogFragment
import com.kunzisoft.keepass.activities.dialogs.FileTooBigDialogFragment.Companion.MAX_WARNING_BINARY_FILE
import com.kunzisoft.keepass.activities.dialogs.ReplaceFileDialogFragment
import com.kunzisoft.keepass.activities.dialogs.SetOTPDialogFragment
import com.kunzisoft.keepass.activities.dialogs.TimePickerFragment
import com.kunzisoft.keepass.activities.fragments.EntryEditFragment
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
@ -55,7 +65,12 @@ import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
import com.kunzisoft.keepass.adapters.TemplatesSelectorAdapter
import com.kunzisoft.keepass.autofill.AutofillComponent
import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.database.element.*
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.template.Template
@ -77,11 +92,15 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.tasks.AttachmentFileBinderManager
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.UriUtil.getDocumentFile
import com.kunzisoft.keepass.view.*
import com.kunzisoft.keepass.view.ToolbarAction
import com.kunzisoft.keepass.view.asError
import com.kunzisoft.keepass.view.hideByFading
import com.kunzisoft.keepass.view.showActionErrorIfNeeded
import com.kunzisoft.keepass.view.updateLockPaddingLeft
import com.kunzisoft.keepass.viewmodels.ColorPickerViewModel
import com.kunzisoft.keepass.viewmodels.EntryEditViewModel
import org.joda.time.DateTime
import java.util.*
import java.util.UUID
class EntryEditActivity : DatabaseLockActivity(),
EntryCustomFieldDialogFragment.EntryCustomFieldListener,
@ -221,7 +240,7 @@ class EntryEditActivity : DatabaseLockActivity(),
this@EntryEditActivity,
templates
).apply {
iconDrawableFactory = mIconDrawableFactory
iconDrawableFactory = mDatabase?.iconDrawableFactory
}
adapter = mTemplatesSelectorAdapter
val selectedTemplate = if (mTemplate != null)
@ -368,19 +387,19 @@ class EntryEditActivity : DatabaseLockActivity(),
return true
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
mAllowCustomFields = database?.allowEntryCustomFields() == true
mAllowOTP = database?.allowOTP == true
mEntryEditViewModel.loadDatabase(database)
mTemplatesSelectorAdapter?.apply {
iconDrawableFactory = mIconDrawableFactory
iconDrawableFactory = mDatabase?.iconDrawableFactory
notifyDataSetChanged()
}
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {
@ -444,7 +463,7 @@ class EntryEditActivity : DatabaseLockActivity(),
finishForEntryResult(entry)
}
private fun entryValidatedForAutofillSelection(database: Database, entry: Entry) {
private fun entryValidatedForAutofillSelection(database: ContextualDatabase, entry: Entry) {
// Build Autofill response with the entry selected
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillHelper.buildResponseAndSetResult(this@EntryEditActivity,

View file

@ -26,7 +26,7 @@ import android.os.Bundle
import android.widget.Toast
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.legacy.DatabaseModeActivity
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.helper.SearchHelper
import com.kunzisoft.keepass.magikeyboard.MagikeyboardService
import com.kunzisoft.keepass.model.SearchInfo
@ -47,7 +47,7 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() {
return false
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
val keySelectionBundle = intent.getBundleExtra(KEY_SELECTION_BUNDLE)
@ -96,7 +96,7 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() {
finish()
}
private fun launchSelection(database: Database?,
private fun launchSelection(database: ContextualDatabase?,
sharedWebDomain: String?,
otpString: String?) {
// Build domain search param
@ -111,7 +111,7 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() {
}
}
private fun launch(database: Database?,
private fun launch(database: ContextualDatabase?,
searchInfo: SearchInfo) {
// Setting to integrate Magikeyboard

View file

@ -53,7 +53,7 @@ import com.kunzisoft.keepass.adapters.FileDatabaseHistoryAdapter
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.autofill.AutofillComponent
import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.education.FileDatabaseSelectActivityEducation
import com.kunzisoft.keepass.hardware.HardwareKey
@ -233,7 +233,7 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
if (database != null) {
launchGroupActivityIfLoaded(database)
@ -241,7 +241,7 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {
@ -309,7 +309,7 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
mAutofillActivityResultLauncher)
}
private fun launchGroupActivityIfLoaded(database: Database) {
private fun launchGroupActivityIfLoaded(database: ContextualDatabase) {
if (database.loaded) {
GroupActivity.launch(this,
database,

View file

@ -27,13 +27,23 @@ import android.content.Context
import android.content.Intent
import android.graphics.PorterDuff
import android.net.Uri
import android.os.*
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Parcel
import android.os.Parcelable
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.*
import android.widget.DatePicker
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.TimePicker
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
@ -50,7 +60,12 @@ import androidx.core.view.isVisible
import androidx.drawerlayout.widget.DrawerLayout
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.*
import com.kunzisoft.keepass.activities.dialogs.DatePickerFragment
import com.kunzisoft.keepass.activities.dialogs.GroupDialogFragment
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment
import com.kunzisoft.keepass.activities.dialogs.MainCredentialDialogFragment
import com.kunzisoft.keepass.activities.dialogs.SortDialogFragment
import com.kunzisoft.keepass.activities.dialogs.TimePickerFragment
import com.kunzisoft.keepass.activities.fragments.GroupFragment
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
@ -59,7 +74,12 @@ import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
import com.kunzisoft.keepass.adapters.BreadcrumbAdapter
import com.kunzisoft.keepass.autofill.AutofillComponent
import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.database.element.*
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.element.SortNodeEnum
import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
@ -81,7 +101,13 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.BACK_PREVIOUS_KEYBOARD_ACTION
import com.kunzisoft.keepass.utils.UriUtil.openUrl
import com.kunzisoft.keepass.view.*
import com.kunzisoft.keepass.view.AddNodeButtonView
import com.kunzisoft.keepass.view.NavigationDatabaseView
import com.kunzisoft.keepass.view.SearchFiltersView
import com.kunzisoft.keepass.view.ToolbarAction
import com.kunzisoft.keepass.view.hideByFading
import com.kunzisoft.keepass.view.showActionErrorIfNeeded
import com.kunzisoft.keepass.view.updateLockPaddingLeft
import com.kunzisoft.keepass.viewmodels.GroupEditViewModel
import com.kunzisoft.keepass.viewmodels.GroupViewModel
import org.joda.time.DateTime
@ -569,7 +595,7 @@ class GroupActivity : DatabaseLockActivity(),
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
mGroupEditViewModel.setGroupNamesNotAllowed(database?.groupNamesNotAllowed)
@ -613,7 +639,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {
@ -799,7 +825,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onNodeClick(
database: Database,
database: ContextualDatabase,
node: Node
) {
when (node.type) {
@ -872,7 +898,7 @@ class GroupActivity : DatabaseLockActivity(),
reloadGroupIfSearch()
}
private fun entrySelectedForSave(database: Database, entry: Entry, searchInfo: SearchInfo) {
private fun entrySelectedForSave(database: ContextualDatabase, entry: Entry, searchInfo: SearchInfo) {
reloadCurrentGroup()
// Save to update the entry
EntryEditActivity.launchToUpdateForSave(
@ -884,7 +910,7 @@ class GroupActivity : DatabaseLockActivity(),
onLaunchActivitySpecialMode()
}
private fun entrySelectedForKeyboardSelection(database: Database, entry: Entry) {
private fun entrySelectedForKeyboardSelection(database: ContextualDatabase, entry: Entry) {
reloadCurrentGroup()
// Populate Magikeyboard with entry
MagikeyboardService.populateKeyboardAndMoveAppToBackground(
@ -894,7 +920,7 @@ class GroupActivity : DatabaseLockActivity(),
onValidateSpecialMode()
}
private fun entrySelectedForAutofillSelection(database: Database, entry: Entry) {
private fun entrySelectedForAutofillSelection(database: ContextualDatabase, entry: Entry) {
// Build response with the entry selected
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillHelper.buildResponseAndSetResult(
@ -907,7 +933,7 @@ class GroupActivity : DatabaseLockActivity(),
}
private fun entrySelectedForRegistration(
database: Database,
database: ContextualDatabase,
entry: Entry,
registerInfo: RegisterInfo?
) {
@ -923,7 +949,7 @@ class GroupActivity : DatabaseLockActivity(),
}
private fun updateEntryWithSearchInfo(
database: Database,
database: ContextualDatabase,
entry: Entry,
searchInfo: SearchInfo
) {
@ -963,7 +989,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onNodeSelected(
database: Database,
database: ContextualDatabase,
nodes: List<Node>
): Boolean {
if (nodes.isNotEmpty()) {
@ -989,7 +1015,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onOpenMenuClick(
database: Database,
database: ContextualDatabase,
node: Node
): Boolean {
finishNodeAction()
@ -998,7 +1024,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onEditMenuClick(
database: Database,
database: ContextualDatabase,
node: Node
): Boolean {
finishNodeAction()
@ -1046,7 +1072,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onCopyMenuClick(
database: Database,
database: ContextualDatabase,
nodes: List<Node>
): Boolean {
actionNodeMode?.invalidate()
@ -1056,7 +1082,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onMoveMenuClick(
database: Database,
database: ContextualDatabase,
nodes: List<Node>
): Boolean {
actionNodeMode?.invalidate()
@ -1066,7 +1092,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onPasteMenuClick(
database: Database,
database: ContextualDatabase,
pasteMode: GroupFragment.PasteMode?,
nodes: List<Node>
): Boolean {
@ -1091,7 +1117,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onDeleteMenuClick(
database: Database,
database: ContextualDatabase,
nodes: List<Node>
): Boolean {
deleteNodes(nodes)
@ -1474,7 +1500,7 @@ class GroupActivity : DatabaseLockActivity(),
* -------------------------
*/
fun launch(context: Context,
database: Database,
database: ContextualDatabase,
autoSearch: Boolean = false) {
if (database.loaded) {
checkTimeAndBuildIntent(context, null) { intent ->
@ -1490,7 +1516,7 @@ class GroupActivity : DatabaseLockActivity(),
* -------------------------
*/
fun launchForSearchResult(context: Context,
database: Database,
database: ContextualDatabase,
searchInfo: SearchInfo,
autoSearch: Boolean = false) {
if (database.loaded) {
@ -1511,7 +1537,7 @@ class GroupActivity : DatabaseLockActivity(),
* -------------------------
*/
fun launchForSaveResult(context: Context,
database: Database,
database: ContextualDatabase,
searchInfo: SearchInfo,
autoSearch: Boolean = false) {
if (database.loaded && !database.isReadOnly) {
@ -1532,7 +1558,7 @@ class GroupActivity : DatabaseLockActivity(),
* -------------------------
*/
fun launchForKeyboardSelectionResult(context: Context,
database: Database,
database: ContextualDatabase,
searchInfo: SearchInfo? = null,
autoSearch: Boolean = false) {
if (database.loaded) {
@ -1554,7 +1580,7 @@ class GroupActivity : DatabaseLockActivity(),
*/
@RequiresApi(api = Build.VERSION_CODES.O)
fun launchForAutofillResult(activity: AppCompatActivity,
database: Database,
database: ContextualDatabase,
activityResultLaunch: ActivityResultLauncher<Intent>?,
autofillComponent: AutofillComponent,
searchInfo: SearchInfo? = null,
@ -1579,7 +1605,7 @@ class GroupActivity : DatabaseLockActivity(),
* -------------------------
*/
fun launchForRegistration(context: Context,
database: Database,
database: ContextualDatabase,
registerInfo: RegisterInfo? = null) {
if (database.loaded && !database.isReadOnly) {
checkTimeAndBuildIntent(context, null) { intent ->
@ -1599,7 +1625,7 @@ class GroupActivity : DatabaseLockActivity(),
* -------------------------
*/
fun launch(activity: AppCompatActivity,
database: Database,
database: ContextualDatabase,
onValidateSpecialMode: () -> Unit,
onCancelSpecialMode: () -> Unit,
onLaunchActivitySpecialMode: () -> Unit,

View file

@ -41,7 +41,7 @@ import com.kunzisoft.keepass.activities.fragments.IconPickerFragment
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
import com.kunzisoft.keepass.activities.helpers.setOpenDocumentClickListener
import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.settings.PreferencesUtil
@ -51,7 +51,12 @@ import com.kunzisoft.keepass.utils.UriUtil.openUrl
import com.kunzisoft.keepass.view.asError
import com.kunzisoft.keepass.view.updateLockPaddingLeft
import com.kunzisoft.keepass.viewmodels.IconPickerViewModel
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class IconPickerActivity : DatabaseLockActivity() {
@ -167,7 +172,7 @@ class IconPickerActivity : DatabaseLockActivity() {
return true
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
if (database?.allowCustomIcons == true) {

View file

@ -33,8 +33,8 @@ import androidx.appcompat.widget.Toolbar
import com.igreenwood.loupe.Loupe
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.tasks.BinaryDatabaseManager
import kotlin.math.max
@ -100,7 +100,7 @@ class ImageViewerActivity : DatabaseLockActivity() {
return true
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
try {

View file

@ -55,7 +55,7 @@ import com.kunzisoft.keepass.autofill.AutofillComponent
import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.biometric.AdvancedUnlockFragment
import com.kunzisoft.keepass.biometric.AdvancedUnlockManager
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
import com.kunzisoft.keepass.database.exception.FileNotFoundDatabaseException
@ -72,7 +72,6 @@ import com.kunzisoft.keepass.settings.SettingsAdvancedUnlockActivity
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.utils.BACK_PREVIOUS_KEYBOARD_ACTION
import com.kunzisoft.keepass.utils.MenuUtil
import com.kunzisoft.keepass.utils.UriUtil
import com.kunzisoft.keepass.utils.UriUtil.getUri
import com.kunzisoft.keepass.view.MainCredentialView
import com.kunzisoft.keepass.view.asError
@ -263,7 +262,7 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
if (database != null) {
// Trying to load another database
@ -280,7 +279,7 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {
@ -377,7 +376,7 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
getUriFromIntent(intent)
}
private fun launchGroupActivityIfLoaded(database: Database) {
private fun launchGroupActivityIfLoaded(database: ContextualDatabase) {
// Check if database really loaded
if (database.loaded) {
clearCredentialsViews(clearKeyFile = true, clearHardwareKey = true)

View file

@ -5,7 +5,9 @@ import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import com.kunzisoft.keepass.activities.legacy.DatabaseRetrieval
import com.kunzisoft.keepass.activities.legacy.resetAppTimeoutWhenViewTouchedOrFocused
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.icons.IconDrawableFactory
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.viewmodels.DatabaseViewModel
@ -15,6 +17,8 @@ abstract class DatabaseDialogFragment : DialogFragment(), DatabaseRetrieval {
private val mDatabaseViewModel: DatabaseViewModel by activityViewModels()
private var mDatabase: Database? = null
protected var mIconDrawableFactory: IconDrawableFactory? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -36,12 +40,12 @@ abstract class DatabaseDialogFragment : DialogFragment(), DatabaseRetrieval {
resetAppTimeoutOnTouchOrFocus()
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
// Can be overridden by a subclass
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {

View file

@ -31,7 +31,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.adapters.TagsAdapter
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.model.GroupInfo
import com.kunzisoft.keepass.settings.PreferencesUtil
@ -60,10 +60,10 @@ class GroupDialogFragment : DatabaseDialogFragment() {
private lateinit var uuidContainerView: ViewGroup
private lateinit var uuidReferenceView: TextView
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
mPopulateIconMethod = { imageView, icon ->
database?.iconDrawableFactory?.assignDatabaseIcon(imageView, icon, mIconColor)
mIconDrawableFactory?.assignDatabaseIcon(imageView, icon, mIconColor)
}
mPopulateIconMethod?.invoke(iconView, mGroupInfo.icon)

View file

@ -24,14 +24,18 @@ import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.*
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.activityViewModels
import com.google.android.material.textfield.TextInputLayout
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment.EditGroupDialogAction.*
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment.EditGroupDialogAction.CREATION
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment.EditGroupDialogAction.NONE
import com.kunzisoft.keepass.activities.dialogs.GroupEditDialogFragment.EditGroupDialogAction.UPDATE
import com.kunzisoft.keepass.adapters.TagsProposalAdapter
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.model.GroupInfo
@ -116,7 +120,7 @@ class GroupEditDialogFragment : DatabaseDialogFragment() {
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
mPopulateIconMethod = { imageView, icon ->

View file

@ -27,7 +27,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.activityViewModels
import com.google.android.material.textfield.TextInputLayout
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
@ -44,7 +44,7 @@ class IconEditDialogFragment : DatabaseDialogFragment() {
private var mCustomIcon: IconImageCustom? = null
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
mPopulateIconMethod = { imageView, icon ->
database?.iconDrawableFactory?.assignDatabaseIcon(imageView, icon)

View file

@ -6,6 +6,7 @@ import androidx.fragment.app.activityViewModels
import com.kunzisoft.keepass.activities.legacy.DatabaseRetrieval
import com.kunzisoft.keepass.activities.legacy.resetAppTimeoutWhenViewTouchedOrFocused
import com.kunzisoft.keepass.activities.stylish.StylishFragment
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.tasks.ActionRunnable
@ -38,7 +39,7 @@ abstract class DatabaseFragment : StylishFragment(), DatabaseRetrieval {
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {

View file

@ -35,14 +35,18 @@ import com.kunzisoft.keepass.activities.dialogs.ReplaceFileDialogFragment
import com.kunzisoft.keepass.activities.dialogs.SetOTPDialogFragment
import com.kunzisoft.keepass.adapters.EntryAttachmentsItemsAdapter
import com.kunzisoft.keepass.adapters.TagsProposalAdapter
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.template.Template
import com.kunzisoft.keepass.model.AttachmentState
import com.kunzisoft.keepass.model.EntryAttachmentState
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.StreamDirection
import com.kunzisoft.keepass.view.*
import com.kunzisoft.keepass.view.TagsCompletionView
import com.kunzisoft.keepass.view.TemplateEditView
import com.kunzisoft.keepass.view.collapse
import com.kunzisoft.keepass.view.expand
import com.kunzisoft.keepass.view.showByFading
import com.kunzisoft.keepass.viewmodels.EntryEditViewModel
import com.tokenautocomplete.FilteredArrayAdapter
@ -268,7 +272,7 @@ class EntryEditFragment: DatabaseFragment() {
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
templateView.populateIconMethod = { imageView, icon ->
database?.iconDrawableFactory?.assignDatabaseIcon(imageView, icon, mIconColor)

View file

@ -14,8 +14,8 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.adapters.EntryAttachmentsItemsAdapter
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.template.TemplateField
import com.kunzisoft.keepass.database.helper.getLocalizedName
import com.kunzisoft.keepass.model.EntryAttachmentState
@ -133,7 +133,7 @@ class EntryFragment: DatabaseFragment() {
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
context?.let { context ->
attachmentsAdapter = EntryAttachmentsItemsAdapter(context)
attachmentsAdapter?.database = database

View file

@ -22,7 +22,12 @@ package com.kunzisoft.keepass.activities.fragments
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.*
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.view.ActionMode
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
@ -34,7 +39,7 @@ import com.kunzisoft.keepass.activities.dialogs.SortDialogFragment
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.activities.helpers.SpecialMode
import com.kunzisoft.keepass.adapters.NodesAdapter
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.SortNodeEnum
import com.kunzisoft.keepass.database.element.node.Node
@ -42,7 +47,7 @@ import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.viewmodels.GroupViewModel
import java.util.*
import java.util.LinkedList
class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListener {
@ -143,7 +148,7 @@ class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
setHasOptionsMenu(true)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
mRecycleBinEnable = database?.isRecycleBinEnabled == true
mRecycleBin = database?.recycleBin
@ -151,7 +156,7 @@ class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
database?.let { database ->
mAdapter = NodesAdapter(context, database).apply {
setOnNodeClickListener(object : NodesAdapter.NodeClickCallback {
override fun onNodeClick(database: Database, node: Node) {
override fun onNodeClick(database: ContextualDatabase, node: Node) {
if (mCurrentGroup?.isVirtual == false
&& nodeActionSelectionMode) {
if (listActionNodes.contains(node)) {
@ -169,7 +174,7 @@ class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
}
}
override fun onNodeLongClick(database: Database, node: Node): Boolean {
override fun onNodeLongClick(database: ContextualDatabase, node: Node): Boolean {
if (mCurrentGroup?.isVirtual == false
&& nodeActionPasteMode == PasteMode.UNDEFINED) {
// Select the first item after a long click
@ -191,7 +196,7 @@ class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {
@ -329,7 +334,7 @@ class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
}
}
fun actionNodesCallback(database: Database,
fun actionNodesCallback(database: ContextualDatabase,
nodes: List<Node>,
menuListener: NodesActionMenuListener?,
onDestroyActionMode: (mode: ActionMode?) -> Unit) : ActionMode.Callback {
@ -433,20 +438,20 @@ class GroupFragment : DatabaseFragment(), SortDialogFragment.SortSelectionListen
* Callback listener to redefine to do an action when a node is click
*/
interface NodeClickListener {
fun onNodeClick(database: Database, node: Node)
fun onNodeSelected(database: Database, nodes: List<Node>): Boolean
fun onNodeClick(database: ContextualDatabase, node: Node)
fun onNodeSelected(database: ContextualDatabase, nodes: List<Node>): Boolean
}
/**
* Menu listener to redefine to do an action in menu
*/
interface NodesActionMenuListener {
fun onOpenMenuClick(database: Database, node: Node): Boolean
fun onEditMenuClick(database: Database, node: Node): Boolean
fun onCopyMenuClick(database: Database, nodes: List<Node>): Boolean
fun onMoveMenuClick(database: Database, nodes: List<Node>): Boolean
fun onDeleteMenuClick(database: Database, nodes: List<Node>): Boolean
fun onPasteMenuClick(database: Database, pasteMode: PasteMode?, nodes: List<Node>): Boolean
fun onOpenMenuClick(database: ContextualDatabase, node: Node): Boolean
fun onEditMenuClick(database: ContextualDatabase, node: Node): Boolean
fun onCopyMenuClick(database: ContextualDatabase, nodes: List<Node>): Boolean
fun onMoveMenuClick(database: ContextualDatabase, nodes: List<Node>): Boolean
fun onDeleteMenuClick(database: ContextualDatabase, nodes: List<Node>): Boolean
fun onPasteMenuClick(database: ContextualDatabase, pasteMode: PasteMode?, nodes: List<Node>): Boolean
}
enum class PasteMode {

View file

@ -22,7 +22,7 @@ package com.kunzisoft.keepass.activities.fragments
import android.os.Bundle
import android.view.View
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
@ -32,7 +32,7 @@ class IconCustomFragment : IconFragment<IconImageCustom>() {
return R.layout.fragment_icon_grid
}
override fun defineIconList(database: Database?) {
override fun defineIconList(database: ContextualDatabase?) {
database?.doForEachCustomIcons { customIcon, _ ->
iconPickerAdapter.addIcon(customIcon, false)
}

View file

@ -28,7 +28,7 @@ import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.adapters.IconPickerAdapter
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.icon.IconImageDraw
import com.kunzisoft.keepass.viewmodels.IconPickerViewModel
import kotlinx.coroutines.CoroutineScope
@ -47,7 +47,7 @@ abstract class IconFragment<T: IconImageDraw> : DatabaseFragment(),
abstract fun retrieveMainLayoutId(): Int
abstract fun defineIconList(database: Database?)
abstract fun defineIconList(database: ContextualDatabase?)
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?,
@ -71,7 +71,7 @@ abstract class IconFragment<T: IconImageDraw> : DatabaseFragment(),
resetAppTimeoutWhenViewFocusedOrChanged(view)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
iconPickerAdapter.iconDrawableFactory = database?.iconDrawableFactory
CoroutineScope(Dispatchers.IO).launch {

View file

@ -10,7 +10,7 @@ import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.adapters.IconPickerPagerAdapter
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.viewmodels.IconPickerViewModel
class IconPickerFragment : DatabaseFragment() {
@ -48,7 +48,7 @@ class IconPickerFragment : DatabaseFragment() {
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
iconPickerPagerAdapter = IconPickerPagerAdapter(this,
if (database?.allowCustomIcons == true) 2 else 1)
viewPager.adapter = iconPickerPagerAdapter

View file

@ -20,7 +20,7 @@
package com.kunzisoft.keepass.activities.fragments
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
@ -30,7 +30,7 @@ class IconStandardFragment : IconFragment<IconImageStandard>() {
return R.layout.fragment_icon_grid
}
override fun defineIconList(database: Database?) {
override fun defineIconList(database: ContextualDatabase?) {
database?.doForEachStandardIcons { standardIcon ->
iconPickerAdapter.addIcon(standardIcon, false)
}

View file

@ -30,7 +30,7 @@ import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.adapters.KeyGeneratorPagerAdapter
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.viewmodels.KeyGeneratorViewModel
class KeyGeneratorFragment : DatabaseFragment() {
@ -107,7 +107,7 @@ class KeyGeneratorFragment : DatabaseFragment() {
super.onDestroyView()
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
// Nothing here
}

View file

@ -30,7 +30,7 @@ import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.activityViewModels
import com.google.android.material.slider.Slider
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.password.PassphraseGenerator
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.ClipboardHelper
@ -244,7 +244,7 @@ class PassphraseGeneratorFragment : DatabaseFragment() {
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
// Nothing here
}

View file

@ -32,7 +32,7 @@ import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.activityViewModels
import com.google.android.material.slider.Slider
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.password.PasswordGenerator
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.ClipboardHelper
@ -318,7 +318,7 @@ class PasswordGeneratorFragment : DatabaseFragment() {
super.onDestroy()
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
// Nothing here
}

View file

@ -4,8 +4,8 @@ import android.net.Uri
import android.os.Bundle
import androidx.activity.viewModels
import com.kunzisoft.keepass.activities.stylish.StylishActivity
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.model.CipherEncryptDatabase
import com.kunzisoft.keepass.tasks.ActionRunnable
@ -16,7 +16,7 @@ abstract class DatabaseActivity: StylishActivity(), DatabaseRetrieval {
protected val mDatabaseViewModel: DatabaseViewModel by viewModels()
protected var mDatabaseTaskProvider: DatabaseTaskProvider? = null
protected var mDatabase: Database? = null
protected var mDatabase: ContextualDatabase? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -48,14 +48,14 @@ abstract class DatabaseActivity: StylishActivity(), DatabaseRetrieval {
super.onDestroy()
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
mDatabase = database
mDatabaseViewModel.defineDatabase(database)
// optional method implementation
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {

View file

@ -36,14 +36,14 @@ import com.kunzisoft.keepass.activities.dialogs.DeleteNodesDialogFragment
import com.kunzisoft.keepass.activities.dialogs.PasswordEncodingDialogFragment
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.activities.helpers.SpecialMode
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.icons.IconDrawableFactory
import com.kunzisoft.keepass.model.GroupInfo
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable
@ -67,8 +67,6 @@ abstract class DatabaseLockActivity : DatabaseModeActivity(),
protected var mMergeDataAllowed: Boolean = false
private var mAutoSaveEnable: Boolean = true
protected var mIconDrawableFactory: IconDrawableFactory? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -167,7 +165,7 @@ abstract class DatabaseLockActivity : DatabaseModeActivity(),
return true
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
// End activity if database not loaded
@ -207,7 +205,6 @@ abstract class DatabaseLockActivity : DatabaseModeActivity(),
mDatabaseReadOnly = database.isReadOnly
mMergeDataAllowed = database.isMergeDataAllowed()
mIconDrawableFactory = database.iconDrawableFactory
checkRegister()
}
@ -216,7 +213,7 @@ abstract class DatabaseLockActivity : DatabaseModeActivity(),
abstract fun viewToInvalidateTimeout(): View?
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {

View file

@ -1,11 +1,11 @@
package com.kunzisoft.keepass.activities.legacy
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.tasks.ActionRunnable
interface DatabaseRetrieval {
fun onDatabaseRetrieved(database: Database?)
fun onDatabaseActionFinished(database: Database,
fun onDatabaseRetrieved(database: ContextualDatabase?)
fun onDatabaseActionFinished(database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result)
}

View file

@ -34,7 +34,7 @@ import androidx.recyclerview.widget.SortedList
import androidx.recyclerview.widget.SortedListAdapterCallback
import com.google.android.material.progressindicator.CircularProgressIndicator
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.SortNodeEnum
@ -49,15 +49,16 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.ClipboardHelper
import com.kunzisoft.keepass.view.setTextSize
import com.kunzisoft.keepass.view.strikeOut
import java.util.*
import java.util.LinkedList
/**
* Create node list adapter with contextMenu or not
* @param context Context to use
*/
class NodesAdapter (private val context: Context,
private val database: Database)
: RecyclerView.Adapter<NodesAdapter.NodeViewHolder>() {
class NodesAdapter (
private val context: Context,
private val database: ContextualDatabase
) : RecyclerView.Adapter<NodesAdapter.NodeViewHolder>() {
private var mNodeComparator: Comparator<NodeVersionedInterface<Group>>? = null
private val mNodeSortedListCallback: NodeSortedListCallback
@ -565,8 +566,8 @@ class NodesAdapter (private val context: Context,
* Callback listener to redefine to do an action when a node is click
*/
interface NodeClickCallback {
fun onNodeClick(database: Database, node: Node)
fun onNodeLongClick(database: Database, node: Node): Boolean
fun onNodeClick(database: ContextualDatabase, node: Node)
fun onNodeLongClick(database: ContextualDatabase, node: Node): Boolean
}
class NodeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

View file

@ -48,7 +48,7 @@ import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.AutofillLauncherActivity
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.activities.helpers.SpecialMode
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.template.TemplateField
import com.kunzisoft.keepass.model.EntryInfo
@ -89,7 +89,7 @@ object AutofillHelper {
}
private fun newRemoteViews(context: Context,
database: Database,
database: ContextualDatabase,
remoteViewsText: String,
remoteViewsIcon: IconImage? = null): RemoteViews {
val presentation = RemoteViews(context.packageName, R.layout.item_autofill_entry)
@ -108,7 +108,7 @@ object AutofillHelper {
}
private fun buildDataset(context: Context,
database: Database,
database: ContextualDatabase,
entryInfo: EntryInfo,
struct: StructureParser.Result,
additionalBuild: ((build: Dataset.Builder) -> Unit)? = null): Dataset? {
@ -214,7 +214,7 @@ object AutofillHelper {
* Method to assign a drawable to a new icon from a database icon
*/
private fun buildIconFromEntry(context: Context,
database: Database,
database: ContextualDatabase,
entryInfo: EntryInfo): Icon? {
try {
database.iconDrawableFactory.getBitmapFromIcon(context,
@ -230,7 +230,7 @@ object AutofillHelper {
@RequiresApi(Build.VERSION_CODES.R)
@SuppressLint("RestrictedApi")
private fun buildInlinePresentationForEntry(context: Context,
database: Database,
database: ContextualDatabase,
compatInlineSuggestionsRequest: CompatInlineSuggestionsRequest,
positionItem: Int,
entryInfo: EntryInfo): InlinePresentation? {
@ -302,7 +302,7 @@ object AutofillHelper {
}
fun buildResponse(context: Context,
database: Database,
database: ContextualDatabase,
entriesInfo: List<EntryInfo>,
parseResult: StructureParser.Result,
compatInlineSuggestionsRequest: CompatInlineSuggestionsRequest?): FillResponse? {
@ -395,7 +395,7 @@ object AutofillHelper {
* Build the Autofill response for one entry
*/
fun buildResponseAndSetResult(activity: Activity,
database: Database,
database: ContextualDatabase,
entryInfo: EntryInfo) {
buildResponseAndSetResult(activity, database, ArrayList<EntryInfo>().apply { add(entryInfo) })
}
@ -404,7 +404,7 @@ object AutofillHelper {
* Build the Autofill response for many entry
*/
fun buildResponseAndSetResult(activity: Activity,
database: Database,
database: ContextualDatabase,
entriesInfo: List<EntryInfo>) {
if (entriesInfo.isEmpty()) {
activity.setResult(Activity.RESULT_CANCELED)

View file

@ -35,6 +35,7 @@ import androidx.autofill.inline.UiVersions
import androidx.autofill.inline.v1.InlineSuggestionUi
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.AutofillLauncherActivity
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.helper.SearchHelper
@ -52,7 +53,7 @@ import java.util.concurrent.atomic.AtomicBoolean
class KeeAutofillService : AutofillService() {
private var mDatabaseTaskProvider: DatabaseTaskProvider? = null
private var mDatabase: Database? = null
private var mDatabase: ContextualDatabase? = null
private var applicationIdBlocklist: Set<String>? = null
private var webDomainBlocklist: Set<String>? = null
private var askToSaveData: Boolean = false
@ -124,7 +125,7 @@ class KeeAutofillService : AutofillService() {
}
}
private fun launchSelection(database: Database?,
private fun launchSelection(database: ContextualDatabase?,
searchInfo: SearchInfo,
parseResult: StructureParser.Result,
inlineSuggestionsRequest: CompatInlineSuggestionsRequest?,

View file

@ -0,0 +1,29 @@
package com.kunzisoft.keepass.database
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.icons.IconDrawableFactory
import com.kunzisoft.keepass.utils.SingletonHolder
import java.io.File
class ContextualDatabase: Database() {
val iconDrawableFactory = IconDrawableFactory(
retrieveBinaryCache = { binaryCache },
retrieveCustomIconBinary = { iconId -> getBinaryForCustomIcon(iconId) }
)
override fun removeCustomIcon(customIcon: IconImageCustom) {
iconDrawableFactory.clearFromCache(customIcon)
super.removeCustomIcon(customIcon)
}
override fun clearIndexesAndBinaries(filesDirectory: File?) {
iconDrawableFactory.clearCache()
super.clearIndexesAndBinaries(filesDirectory)
}
companion object : SingletonHolder<ContextualDatabase>(::ContextualDatabase) {
private val TAG = ContextualDatabase::class.java.name
}
}

View file

@ -23,13 +23,13 @@ import android.content.Context
import android.net.Uri
import com.kunzisoft.keepass.app.database.CipherDatabaseAction
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.hardware.HardwareKey
open class AssignMainCredentialInDatabaseRunnable (
context: Context,
database: Database,
database: ContextualDatabase,
protected val mDatabaseUri: Uri,
mainCredential: MainCredential,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray

View file

@ -23,7 +23,7 @@ import android.content.Context
import android.net.Uri
import android.util.Log
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.settings.PreferencesUtil
@ -31,7 +31,7 @@ import com.kunzisoft.keepass.utils.UriUtil.getBinaryDir
class CreateDatabaseRunnable(
context: Context,
private val mDatabase: Database,
private val mDatabase: ContextualDatabase,
databaseUri: Uri,
private val databaseName: String,
private val rootName: String,

View file

@ -20,8 +20,15 @@
package com.kunzisoft.keepass.database.action
import android.app.AlertDialog
import android.content.*
import android.content.Context.*
import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Context.BIND_ABOVE_CLIENT
import android.content.Context.BIND_AUTO_CREATE
import android.content.Context.BIND_IMPORTANT
import android.content.Intent
import android.content.IntentFilter
import android.content.ServiceConnection
import android.net.Uri
import android.os.Bundle
import android.os.IBinder
@ -32,9 +39,9 @@ import androidx.lifecycle.lifecycleScope
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.DatabaseChangedDialogFragment
import com.kunzisoft.keepass.activities.dialogs.DatabaseChangedDialogFragment.Companion.DATABASE_CHANGED_DIALOG_TAG
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.MainCredential
@ -84,7 +91,7 @@ import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment.Companion.PROGRESS
import com.kunzisoft.keepass.utils.DATABASE_START_TASK_ACTION
import com.kunzisoft.keepass.utils.DATABASE_STOP_TASK_ACTION
import kotlinx.coroutines.launch
import java.util.*
import java.util.UUID
/**
* Utility class to connect an activity or a service to the DatabaseTaskNotificationService,
@ -97,9 +104,9 @@ class DatabaseTaskProvider(private var context: Context,
private var activity: FragmentActivity? = try { context as? FragmentActivity? }
catch (_: Exception) { null }
var onDatabaseRetrieved: ((database: Database?) -> Unit)? = null
var onDatabaseRetrieved: ((database: ContextualDatabase?) -> Unit)? = null
var onActionFinish: ((database: Database,
var onActionFinish: ((database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result) -> Unit)? = null
@ -128,24 +135,24 @@ class DatabaseTaskProvider(private var context: Context,
}
private val actionTaskListener = object: DatabaseTaskNotificationService.ActionTaskListener {
override fun onActionStarted(database: Database,
override fun onActionStarted(database: ContextualDatabase,
progressMessage: ProgressMessage) {
if (showDialog)
startDialog(progressMessage)
}
override fun onActionUpdated(database: Database,
override fun onActionUpdated(database: ContextualDatabase,
progressMessage: ProgressMessage) {
if (showDialog)
updateDialog(progressMessage)
}
override fun onActionStopped(database: Database) {
override fun onActionStopped(database: ContextualDatabase) {
// Remove the progress task
stopDialog()
}
override fun onActionFinished(database: Database,
override fun onActionFinished(database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result) {
onActionFinish?.invoke(database, actionTask, result)
@ -188,7 +195,7 @@ class DatabaseTaskProvider(private var context: Context,
}
private var databaseListener = object: DatabaseTaskNotificationService.DatabaseListener {
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
onDatabaseRetrieved?.invoke(database)
}
}

View file

@ -23,7 +23,7 @@ import android.content.Context
import android.net.Uri
import com.kunzisoft.keepass.app.database.CipherDatabaseAction
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.exception.DatabaseInputException
@ -36,7 +36,7 @@ import com.kunzisoft.keepass.utils.UriUtil.getBinaryDir
class LoadDatabaseRunnable(
private val context: Context,
private val mDatabase: Database,
private val mDatabase: ContextualDatabase,
private val mDatabaseUri: Uri,
private val mMainCredential: MainCredential,
private val mChallengeResponseRetriever: (hardwareKey: HardwareKey, seed: ByteArray?) -> ByteArray,

View file

@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.action
import android.content.Context
import android.net.Uri
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.exception.DatabaseException
@ -34,7 +34,7 @@ class MergeDatabaseRunnable(
private val mDatabaseToMergeUri: Uri?,
private val mDatabaseToMergeMainCredential: MainCredential?,
private val mDatabaseToMergeChallengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
database: Database,
database: ContextualDatabase,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
private val progressTaskUpdater: ProgressTaskUpdater?,

View file

@ -20,7 +20,7 @@
package com.kunzisoft.keepass.database.action
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.exception.DatabaseException
import com.kunzisoft.keepass.settings.PreferencesUtil
@ -30,7 +30,7 @@ import com.kunzisoft.keepass.utils.UriUtil.getBinaryDir
class ReloadDatabaseRunnable(
private val context: Context,
private val mDatabase: Database,
private val mDatabase: ContextualDatabase,
private val progressTaskUpdater: ProgressTaskUpdater?,
private val mLoadDatabaseResult: ((Result) -> Unit)?
) : ActionRunnable() {

View file

@ -20,14 +20,14 @@
package com.kunzisoft.keepass.database.action
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.hardware.HardwareKey
class RemoveUnlinkedDataDatabaseRunnable (
context: Context,
database: Database,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
context: Context,
database: ContextualDatabase,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
override fun onActionRun() {

View file

@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.action
import android.content.Context
import android.net.Uri
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.exception.DatabaseException
import com.kunzisoft.keepass.hardware.HardwareKey
@ -29,7 +29,7 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
open class SaveDatabaseRunnable(
protected var context: Context,
protected var database: Database,
protected var database: ContextualDatabase,
private var saveDatabase: Boolean,
private var mainCredential: MainCredential?, // If null, uses composite Key
private var challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,

View file

@ -20,17 +20,17 @@
package com.kunzisoft.keepass.database.action
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
import com.kunzisoft.keepass.hardware.HardwareKey
class UpdateCompressionBinariesDatabaseRunnable (
context: Context,
database: Database,
private val oldCompressionAlgorithm: CompressionAlgorithm,
private val newCompressionAlgorithm: CompressionAlgorithm,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
context: Context,
database: ContextualDatabase,
private val oldCompressionAlgorithm: CompressionAlgorithm,
private val newCompressionAlgorithm: CompressionAlgorithm,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
override fun onStartRun() {

View file

@ -20,19 +20,19 @@
package com.kunzisoft.keepass.database.action.history
import android.content.Context
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.action.SaveDatabaseRunnable
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.hardware.HardwareKey
class DeleteEntryHistoryDatabaseRunnable (
context: Context,
database: Database,
private val mainEntry: Entry,
private val entryHistoryPosition: Int,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray)
: SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
context: Context,
database: ContextualDatabase,
private val mainEntry: Entry,
private val entryHistoryPosition: Int,
saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
override fun onStartRun() {
try {

View file

@ -20,20 +20,20 @@
package com.kunzisoft.keepass.database.action.history
import android.content.Context
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.action.node.UpdateEntryRunnable
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.tasks.ActionRunnable
class RestoreEntryHistoryDatabaseRunnable (
private val context: Context,
private val database: Database,
private val mainEntry: Entry,
private val entryHistoryPosition: Int,
private val saveDatabase: Boolean,
private val challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray)
: ActionRunnable() {
private val context: Context,
private val database: ContextualDatabase,
private val mainEntry: Entry,
private val entryHistoryPosition: Int,
private val saveDatabase: Boolean,
private val challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
) : ActionRunnable() {
private var updateEntryRunnable: UpdateEntryRunnable? = null

View file

@ -20,13 +20,13 @@
package com.kunzisoft.keepass.database.action.node
import android.content.Context
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.action.SaveDatabaseRunnable
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.hardware.HardwareKey
abstract class ActionNodeDatabaseRunnable(
context: Context,
database: Database,
database: ContextualDatabase,
private val afterActionNodesFinish: AfterActionNodesFinish?,
save: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray

View file

@ -20,7 +20,7 @@
package com.kunzisoft.keepass.database.action.node
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.node.Node
@ -28,7 +28,7 @@ import com.kunzisoft.keepass.hardware.HardwareKey
class AddEntryRunnable constructor(
context: Context,
database: Database,
database: ContextualDatabase,
private val mNewEntry: Entry,
private val mParent: Group,
save: Boolean,

View file

@ -20,14 +20,14 @@
package com.kunzisoft.keepass.database.action.node
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.hardware.HardwareKey
class AddGroupRunnable constructor(
context: Context,
database: Database,
database: ContextualDatabase,
private val mNewGroup: Group,
private val mParent: Group,
save: Boolean,

View file

@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.action.node
import android.content.Context
import android.util.Log
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.node.Node
@ -32,7 +32,7 @@ import com.kunzisoft.keepass.hardware.HardwareKey
class CopyNodesRunnable constructor(
context: Context,
database: Database,
database: ContextualDatabase,
private val mNodesToCopy: List<Node>,
private val mNewParent: Group,
save: Boolean,

View file

@ -20,7 +20,7 @@
package com.kunzisoft.keepass.database.action.node
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.node.Node
@ -29,7 +29,7 @@ import com.kunzisoft.keepass.hardware.HardwareKey
class DeleteNodesRunnable(
context: Context,
database: Database,
database: ContextualDatabase,
private val mNodesToDelete: List<Node>,
private val recyclerBinTitle: String,
save: Boolean,

View file

@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.action.node
import android.content.Context
import android.util.Log
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.node.Node
@ -32,7 +32,7 @@ import com.kunzisoft.keepass.hardware.HardwareKey
class MoveNodesRunnable constructor(
context: Context,
database: Database,
database: ContextualDatabase,
private val mNodesToMove: List<Node>,
private val mNewParent: Group,
save: Boolean,

View file

@ -20,15 +20,15 @@
package com.kunzisoft.keepass.database.action.node
import android.content.Context
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.hardware.HardwareKey
class UpdateEntryRunnable constructor(
context: Context,
database: Database,
database: ContextualDatabase,
private val mOldEntry: Entry,
private val mNewEntry: Entry,
save: Boolean,

View file

@ -20,14 +20,14 @@
package com.kunzisoft.keepass.database.action.node
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.hardware.HardwareKey
class UpdateGroupRunnable constructor(
context: Context,
database: Database,
database: ContextualDatabase,
private val mOldGroup: Group,
private val mNewGroup: Group,
save: Boolean,

View file

@ -20,7 +20,7 @@
package com.kunzisoft.keepass.database.helper
import android.content.Context
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.timeout.TimeoutHelper
@ -44,11 +44,11 @@ object SearchHelper {
* Utility method to perform actions if item is found or not after an auto search in [database]
*/
fun checkAutoSearchInfo(context: Context,
database: Database?,
database: ContextualDatabase?,
searchInfo: SearchInfo?,
onItemsFound: (openedDatabase: Database,
onItemsFound: (openedDatabase: ContextualDatabase,
items: List<EntryInfo>) -> Unit,
onItemNotFound: (openedDatabase: Database) -> Unit,
onItemNotFound: (openedDatabase: ContextualDatabase) -> Unit,
onDatabaseClosed: () -> Unit) {
if (database == null || !database.loaded) {
onDatabaseClosed.invoke()

View file

@ -13,7 +13,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.legacy.DatabaseModeActivity
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.utils.UriUtil.openExternalApp
/**
@ -48,7 +48,7 @@ class HardwareKeyActivity: DatabaseModeActivity(){
return false
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
val hardwareKey = HardwareKey.getHardwareKeyFromString(

View file

@ -36,18 +36,17 @@ import com.kunzisoft.keepass.database.element.binary.BinaryCache
import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.database.element.icon.IconImageDraw
import java.lang.ref.WeakReference
import java.util.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.lang.ref.WeakReference
import java.util.*
/**
* Factory class who build database icons dynamically, can assign an icon of IconPack, or a custom icon to an ImageView with a tint
*/
class IconDrawableFactory(
private val iconPackChooser: InterfaceIconPackChooser,
private val retrieveBinaryCache: () -> BinaryCache?,
private val retrieveCustomIconBinary: (iconId: UUID) -> BinaryData?,
) {
@ -86,7 +85,7 @@ class IconDrawableFactory(
return SuperDrawable(it)
}
}
val iconPack = iconPackChooser.getSelectedIconPack(context)
val iconPack = IconPackChooser.getSelectedIconPack(context)
if (mCurrentIconPack != iconPack) {
this.mCurrentIconPack = iconPack
this.clearCache()
@ -95,7 +94,7 @@ class IconDrawableFactory(
return SuperDrawable(getIconDrawable(context.resources, iconId, width, tintColor),
iconPack.tintable())
} ?: run {
return SuperDrawable(PatternIcon(iconPackChooser.getDefaultIconSize()).blankDrawable)
return SuperDrawable(PatternIcon(IconPackChooser.defaultIconSize).blankDrawable)
}
}
@ -107,15 +106,14 @@ class IconDrawableFactory(
icon: IconImageCustom,
iconCustomBinary: BinaryData?,
): Drawable? {
val patternIcon = PatternIcon(iconPackChooser.getDefaultIconSize())
val binaryManager = retrieveBinaryCache()
if (binaryManager != null) {
val patternIcon = PatternIcon(IconPackChooser.defaultIconSize)
retrieveBinaryCache()?.let { binaryCache ->
val draw: Drawable? = customIconMap[icon.uuid]?.get()
if (draw == null) {
iconCustomBinary?.let { binaryFile ->
try {
var bitmap: Bitmap? =
BitmapFactory.decodeStream(binaryFile.getInputDataStream(binaryManager))
BitmapFactory.decodeStream(binaryFile.getInputDataStream(binaryCache))
bitmap?.let { bitmapIcon ->
bitmap = resize(bitmapIcon, patternIcon)
val createdDraw = BitmapDrawable(resources, bitmap)
@ -160,7 +158,7 @@ class IconDrawableFactory(
}
if (draw == null) {
draw = PatternIcon(iconPackChooser.getDefaultIconSize()).blankDrawable
draw = PatternIcon(IconPackChooser.defaultIconSize).blankDrawable
}
draw.isFilterBitmap = false

View file

@ -30,16 +30,17 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
*
* @author J-Jamet
*/
object IconPackChooser : InterfaceIconPackChooser {
object IconPackChooser {
private val TAG = IconPackChooser::class.java.name
private val iconPackList = ArrayList<IconPack>()
private var iconPackSelected: IconPack? = null
private var defaultIconSize: Int? = null
var defaultIconSize: Int = 0
private var isIconPackChooserBuilt: Boolean = false
/**
* Built the icon pack chooser based on imports made in *build.gradle*
*
@ -51,7 +52,7 @@ object IconPackChooser : InterfaceIconPackChooser {
* @param context Context to construct each pack with the resources
* @return An unique instance of [IconPackChooser], recall [.build] provide the same instance
*/
override fun build(context: Context) {
private fun build(context: Context) {
synchronized(IconPackChooser::class.java) {
if (!isIconPackChooserBuilt) {
isIconPackChooserBuilt = true
@ -63,8 +64,8 @@ object IconPackChooser : InterfaceIconPackChooser {
Log.e(TAG, "Icon packs can't be load, retry with one by default")
addDefaultIconPack(context)
}
if(defaultIconSize == null) {
setDefaultIconSize(context.resources.getDimension(R.dimen.icon_size).toInt())
if(defaultIconSize == 0) {
defaultIconSize = context.resources.getDimension(R.dimen.icon_size).toInt()
}
}
}
@ -73,7 +74,7 @@ object IconPackChooser : InterfaceIconPackChooser {
/**
* Construct dynamically the icon pack provide by the default string resource "resource_id"
*/
override fun addDefaultIconPack(context: Context) {
private fun addDefaultIconPack(context: Context) {
val resourceId = context.resources.getIdentifier("resource_id", "string", context.packageName)
iconPackList.add(IconPack(context.packageName, context.resources, resourceId))
}
@ -81,21 +82,23 @@ object IconPackChooser : InterfaceIconPackChooser {
/**
* Utility method to add new icon pack or catch exception if not retrieve
*/
override fun addOrCatchNewIconPack(context: Context, iconPackString: String) {
private fun addOrCatchNewIconPack(context: Context, iconPackString: String) {
try {
iconPackList.add(IconPack(context.packageName,
iconPackList.add(
IconPack(context.packageName,
context.resources,
context.resources.getIdentifier(
iconPackString + "_resource_id",
"string",
context.packageName)))
context.packageName))
)
} catch (e: Exception) {
Log.w(TAG, "Icon pack $iconPackString can't be load")
}
}
override fun setSelectedIconPack(iconPackIdString: String?) {
fun setSelectedIconPack(iconPackIdString: String?) {
for (iconPack in iconPackList) {
if (iconPack.id == iconPackIdString) {
iconPackSelected = iconPack
@ -110,7 +113,7 @@ object IconPackChooser : InterfaceIconPackChooser {
* @param context Context to build the icon pack if not already build
* @return IconPack currently in usage
*/
override fun getSelectedIconPack(context: Context): IconPack? {
fun getSelectedIconPack(context: Context): IconPack? {
build(context)
if (iconPackSelected == null) {
setSelectedIconPack(PreferencesUtil.getIconPackSelectedId(context))
@ -124,16 +127,8 @@ object IconPackChooser : InterfaceIconPackChooser {
* @param context Context to build the icon pack if not already build
* @return IconPack available
*/
override fun getIconPackList(context: Context): List<IconPack> {
fun getIconPackList(context: Context): List<IconPack> {
build(context)
return iconPackList
}
override fun setDefaultIconSize(size: Int) {
defaultIconSize = size
}
override fun getDefaultIconSize(): Int {
return defaultIconSize!!
}
}

View file

@ -43,8 +43,8 @@ import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.EntrySelectionLauncherActivity
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.adapters.FieldsAdapter
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
import com.kunzisoft.keepass.database.helper.SearchHelper
@ -59,7 +59,7 @@ import java.util.*
class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionListener {
private var mDatabaseTaskProvider: DatabaseTaskProvider? = null
private var mDatabase: Database? = null
private var mDatabase: ContextualDatabase? = null
private var keyboardView: KeyboardView? = null
private var entryContainer: View? = null

View file

@ -365,9 +365,9 @@ class AttachmentFileNotificationService: LockNotificationService() {
}
private class AttachmentFileAction(
private val attachmentNotification: AttachmentNotification,
private val database: Database,
private val contentResolver: ContentResolver) {
private val attachmentNotification: AttachmentNotification,
private val database: Database,
private val contentResolver: ContentResolver) {
private val updateMinFrequency = 1000
private var previousSaveTime = System.currentTimeMillis()

View file

@ -31,6 +31,7 @@ import androidx.annotation.StringRes
import androidx.media.app.NotificationCompat
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.GroupActivity
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.action.*
import com.kunzisoft.keepass.database.action.history.DeleteEntryHistoryDatabaseRunnable
import com.kunzisoft.keepass.database.action.history.RestoreEntryHistoryDatabaseRunnable
@ -45,7 +46,6 @@ import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.hardware.HardwareKeyActivity
import com.kunzisoft.keepass.icons.IconPackChooser
import com.kunzisoft.keepass.model.CipherEncryptDatabase
import com.kunzisoft.keepass.model.ProgressMessage
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
@ -65,7 +65,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override val notificationId: Int = 575
private var mDatabase: Database? = null
private var mDatabase: ContextualDatabase? = null
// File description
private var mSnapFileDatabaseInfo: SnapFileDatabaseInfo? = null
@ -127,7 +127,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
interface DatabaseListener {
fun onDatabaseRetrieved(database: Database?)
fun onDatabaseRetrieved(database: ContextualDatabase?)
}
interface DatabaseInfoListener {
@ -138,12 +138,12 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
interface ActionTaskListener {
fun onActionStarted(database: Database,
fun onActionStarted(database: ContextualDatabase,
progressMessage: ProgressMessage)
fun onActionUpdated(database: Database,
fun onActionUpdated(database: ContextualDatabase,
progressMessage: ProgressMessage)
fun onActionStopped(database: Database)
fun onActionFinished(database: Database,
fun onActionStopped(database: ContextualDatabase)
fun onActionFinished(database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result)
}
@ -272,7 +272,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
val database = Database.getInstance(IconPackChooser)
val database = ContextualDatabase.getInstance()
if (mDatabase != database) {
mDatabase = database
mDatabaseListeners.forEach { listener ->
@ -697,8 +697,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return response
}
private fun buildDatabaseCreateActionTask(intent: Intent, database: Database): ActionRunnable? {
private fun buildDatabaseCreateActionTask(
intent: Intent,
database: ContextualDatabase
): ActionRunnable? {
if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
) {
@ -730,8 +732,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseLoadActionTask(intent: Intent, database: Database): ActionRunnable? {
private fun buildDatabaseLoadActionTask(
intent: Intent,
database: ContextualDatabase
): ActionRunnable? {
if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
&& intent.hasExtra(READ_ONLY_KEY)
@ -774,7 +778,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseMergeActionTask(intent: Intent, database: Database): ActionRunnable {
private fun buildDatabaseMergeActionTask(
intent: Intent,
database: ContextualDatabase
): ActionRunnable {
var databaseToMergeUri: Uri? = null
var databaseToMergeMainCredential: MainCredential? = null
if (intent.hasExtra(DATABASE_URI_KEY)) {
@ -803,7 +810,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseReloadActionTask(database: Database): ActionRunnable {
private fun buildDatabaseReloadActionTask(
database: ContextualDatabase
): ActionRunnable {
return ReloadDatabaseRunnable(
this,
database,
@ -816,13 +825,13 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseAssignPasswordActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
) {
val databaseUri: Uri = intent.getParcelableExtra(DATABASE_URI_KEY) ?: return null
com.kunzisoft.keepass.database.action.AssignMainCredentialInDatabaseRunnable(
AssignMainCredentialInDatabaseRunnable(
this,
database,
databaseUri,
@ -849,7 +858,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseCreateGroupActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(GROUP_KEY)
&& intent.hasExtra(PARENT_ID_KEY)
@ -881,7 +890,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseUpdateGroupActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(GROUP_ID_KEY)
&& intent.hasExtra(GROUP_KEY)
@ -913,7 +922,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseCreateEntryActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(ENTRY_KEY)
&& intent.hasExtra(PARENT_ID_KEY)
@ -945,7 +954,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseUpdateEntryActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(ENTRY_ID_KEY)
&& intent.hasExtra(ENTRY_KEY)
@ -977,7 +986,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseCopyNodesActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(GROUPS_ID_KEY)
&& intent.hasExtra(ENTRIES_ID_KEY)
@ -1004,7 +1013,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseMoveNodesActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(GROUPS_ID_KEY)
&& intent.hasExtra(ENTRIES_ID_KEY)
@ -1031,7 +1040,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseDeleteNodesActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(GROUPS_ID_KEY)
&& intent.hasExtra(ENTRIES_ID_KEY)
@ -1053,7 +1062,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseRestoreEntryHistoryActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(ENTRY_ID_KEY)
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
@ -1078,7 +1087,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseDeleteEntryHistoryActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(ENTRY_ID_KEY)
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
@ -1103,7 +1112,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseUpdateCompressionActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(OLD_ELEMENT_KEY)
&& intent.hasExtra(NEW_ELEMENT_KEY)
@ -1137,7 +1146,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseRemoveUnlinkedDataActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
@ -1158,7 +1167,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private fun buildDatabaseUpdateElementActionTask(
intent: Intent,
database: Database,
database: ContextualDatabase,
): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
return SaveDatabaseRunnable(this,
@ -1181,7 +1190,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
/**
* Save database without parameter
*/
private fun buildDatabaseSaveActionTask(intent: Intent, database: Database): ActionRunnable? {
private fun buildDatabaseSaveActionTask(
intent: Intent,
database: ContextualDatabase
): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
var databaseCopyUri: Uri? = null

View file

@ -33,6 +33,7 @@ import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.SetMainCredentialDialogFragment
import com.kunzisoft.keepass.activities.legacy.DatabaseRetrieval
import com.kunzisoft.keepass.activities.legacy.resetAppTimeoutWhenViewTouchedOrFocused
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database
@ -123,7 +124,7 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
mDatabaseViewModel.reloadDatabase(false)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
mDatabase = database
mDatabaseReadOnly = database?.isReadOnly == true
mMergeDataAllowed = database?.isMergeDataAllowed() == true
@ -371,7 +372,7 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
}
// TODO check error
override fun onDatabaseActionFinished(database: Database,
override fun onDatabaseActionFinished(database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result) {
result.data?.let { data ->

View file

@ -35,13 +35,13 @@ import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.SetMainCredentialDialogFragment
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.view.showActionErrorIfNeeded
import org.joda.time.DateTime
import java.util.*
import java.util.Properties
open class SettingsActivity
: DatabaseLockActivity(),
@ -150,7 +150,7 @@ open class SettingsActivity
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {

View file

@ -23,7 +23,6 @@ import android.content.Context
import androidx.preference.ListPreference
import android.util.AttributeSet
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.icons.IconPackChooser
import java.util.*

View file

@ -22,7 +22,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.app.Dialog
import android.graphics.Color
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -30,14 +29,9 @@ import android.view.Window
import android.widget.CompoundButton
import androidx.annotation.ColorInt
import androidx.appcompat.app.AlertDialog
import com.kunzisoft.androidclearchroma.IndicatorMode
import com.kunzisoft.androidclearchroma.colormode.ColorMode
import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment
import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment.*
import com.kunzisoft.androidclearchroma.view.ChromaColorView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.ColorPickerDialogFragment
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@ -101,7 +95,7 @@ class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialog
return dialog
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.let {
@ -117,7 +111,7 @@ class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialog
}
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
val newColor: Int? = if (enableSwitchView.isChecked)

View file

@ -24,7 +24,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
@ -50,7 +50,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
setExplanationText(R.string.database_data_compression_summary)
@ -62,7 +62,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
}
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -20,16 +20,16 @@
package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseDefaultUsernamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
inputText = database?.defaultUsername?: ""
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
database?.let {
if (positiveResult) {

View file

@ -20,16 +20,16 @@
package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseDescriptionPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
inputText = database?.description ?: ""
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
database?.let {
if (positiveResult) {

View file

@ -24,8 +24,8 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
@ -51,7 +51,7 @@ class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.let {
algorithmSelected = database.encryptionAlgorithm
@ -59,7 +59,7 @@ class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
}
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -25,8 +25,8 @@ import androidx.preference.Preference
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
class DatabaseKeyDerivationPreferenceDialogFragmentCompat
@ -54,7 +54,7 @@ class DatabaseKeyDerivationPreferenceDialogFragmentCompat
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.let {
kdfEngineSelected = database.kdfEngine
@ -62,7 +62,7 @@ class DatabaseKeyDerivationPreferenceDialogFragmentCompat
}
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -22,7 +22,7 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle
import android.view.View
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseMaxHistoryItemsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@ -31,7 +31,7 @@ class DatabaseMaxHistoryItemsPreferenceDialogFragmentCompat : DatabaseSavePrefer
setExplanationText(R.string.max_history_items_summary)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.historyMaxItems?.let { maxItemsDatabase ->
inputText = maxItemsDatabase.toString()
@ -46,7 +46,7 @@ class DatabaseMaxHistoryItemsPreferenceDialogFragmentCompat : DatabaseSavePrefer
}
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -22,7 +22,7 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle
import android.view.View
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.utils.DataByte
class DatabaseMaxHistorySizePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@ -34,7 +34,7 @@ class DatabaseMaxHistorySizePreferenceDialogFragmentCompat : DatabaseSavePrefere
setExplanationText(R.string.max_history_size_summary)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.historyMaxSize?.let { maxItemsDatabase ->
dataByte = DataByte(maxItemsDatabase, DataByte.ByteFormat.BYTE)
@ -61,7 +61,7 @@ class DatabaseMaxHistorySizePreferenceDialogFragmentCompat : DatabaseSavePrefere
}
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -22,7 +22,7 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle
import android.view.View
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.utils.DataByte
class DatabaseMemoryUsagePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@ -34,7 +34,7 @@ class DatabaseMemoryUsagePreferenceDialogFragmentCompat : DatabaseSavePreference
setExplanationText(R.string.memory_usage_explanation)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.let {
val memoryBytes = database.memoryUsage
@ -45,7 +45,7 @@ class DatabaseMemoryUsagePreferenceDialogFragmentCompat : DatabaseSavePreference
}
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
if (positiveResult) {
database?.let {
var newMemoryUsage: Long = try {

View file

@ -20,16 +20,16 @@
package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseNamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
inputText = database?.name ?: ""
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -22,7 +22,7 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle
import android.view.View
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseParallelismPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@ -31,12 +31,12 @@ class DatabaseParallelismPreferenceDialogFragmentCompat : DatabaseSavePreference
setExplanationText(R.string.parallelism_explanation)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
inputText = database?.parallelism?.toString() ?: MIN_PARALLELISM.toString()
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
if (positiveResult) {
database?.let {
val parallelism: Long = try {

View file

@ -24,7 +24,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
@ -48,7 +48,7 @@ class DatabaseRecycleBinGroupPreferenceDialogFragmentCompat
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.let {
mGroupRecycleBin = database.recycleBin
@ -60,7 +60,7 @@ class DatabaseRecycleBinGroupPreferenceDialogFragmentCompat
mGroupRecycleBin = item
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -23,7 +23,7 @@ import android.os.Bundle
import android.text.SpannableStringBuilder
import android.view.View
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseRemoveUnlinkedDataPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@ -37,7 +37,7 @@ class DatabaseRemoveUnlinkedDataPreferenceDialogFragmentCompat : DatabaseSavePre
}.toString()
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
database?.let {
if (positiveResult) {

View file

@ -23,7 +23,7 @@ import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
class DatabaseRoundsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@ -32,12 +32,12 @@ class DatabaseRoundsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialo
explanationText = getString(R.string.rounds_explanation)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
inputText = database?.numberKeyEncryptionRounds?.toString() ?: MIN_ITERATIONS.toString()
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
if (positiveResult) {
database?.let {
var rounds: Long = try {

View file

@ -24,9 +24,9 @@ import android.os.Bundle
import androidx.fragment.app.activityViewModels
import com.kunzisoft.androidclearchroma.ChromaUtil
import com.kunzisoft.keepass.activities.legacy.DatabaseRetrieval
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
import com.kunzisoft.keepass.settings.PreferencesUtil
@ -38,7 +38,7 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat
private var mDatabaseAutoSaveEnable = true
private val mDatabaseViewModel: DatabaseViewModel by activityViewModels()
private var mDatabase: Database? = null
private var mDatabase: ContextualDatabase? = null
override fun onAttach(context: Context) {
super.onAttach(context)
@ -57,12 +57,12 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat
onDatabaseRetrieved(mDatabase)
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
this.mDatabase = database
}
override fun onDatabaseActionFinished(
database: Database,
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result
) {
@ -73,7 +73,7 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat
onDialogClosed(mDatabase, positiveResult)
}
open fun onDialogClosed(database: Database?, positiveResult: Boolean) {
open fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
// To inherit to save element in database
}

View file

@ -24,7 +24,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
@ -48,7 +48,7 @@ class DatabaseTemplatesGroupPreferenceDialogFragmentCompat
}
}
override fun onDatabaseRetrieved(database: Database?) {
override fun onDatabaseRetrieved(database: ContextualDatabase?) {
super.onDatabaseRetrieved(database)
database?.let {
mGroupTemplates = database.templatesGroup
@ -60,7 +60,7 @@ class DatabaseTemplatesGroupPreferenceDialogFragmentCompat
mGroupTemplates = item
}
override fun onDialogClosed(database: Database?, positiveResult: Boolean) {
override fun onDialogClosed(database: ContextualDatabase?, positiveResult: Boolean) {
super.onDialogClosed(database, positiveResult)
if (positiveResult) {
database?.let {

View file

@ -3,17 +3,17 @@ package com.kunzisoft.keepass.viewmodels
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseViewModel: ViewModel() {
val database : LiveData<Database?> get() = _database
private val _database = MutableLiveData<Database?>()
val database : LiveData<ContextualDatabase?> get() = _database
private val _database = MutableLiveData<ContextualDatabase?>()
val actionFinished : LiveData<ActionResult> get() = _actionFinished
private val _actionFinished = SingleLiveEvent<ActionResult>()
@ -73,11 +73,11 @@ class DatabaseViewModel: ViewModel() {
private val _saveParallelism = SingleLiveEvent<SuperLong>()
fun defineDatabase(database: Database?) {
fun defineDatabase(database: ContextualDatabase?) {
this._database.value = database
}
fun onActionFinished(database: Database,
fun onActionFinished(database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result) {
this._actionFinished.value = ActionResult(database, actionTask, result)
@ -184,7 +184,7 @@ class DatabaseViewModel: ViewModel() {
_saveParallelism.value = SuperLong(oldValue, newValue, save)
}
data class ActionResult(val database: Database,
data class ActionResult(val database: ContextualDatabase,
val actionTask: String,
val result: ActionRunnable.Result)
data class SuperString(val oldValue: String,

View file

@ -34,6 +34,7 @@ import com.kunzisoft.keepass.database.element.database.DatabaseKDB
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.NUMBER_STANDARD_ICONS
import com.kunzisoft.keepass.database.element.icon.IconsManager
import com.kunzisoft.keepass.database.element.node.NodeHandler
import com.kunzisoft.keepass.database.element.node.NodeId
@ -53,8 +54,6 @@ import com.kunzisoft.keepass.database.merge.DatabaseKDBXMerger
import com.kunzisoft.keepass.database.search.SearchHelper
import com.kunzisoft.keepass.database.search.SearchParameters
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.icons.IconDrawableFactory
import com.kunzisoft.keepass.icons.InterfaceIconPackChooser
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
import com.kunzisoft.keepass.utils.*
import com.kunzisoft.keepass.utils.UriHelper.getUriInputStream
@ -63,7 +62,7 @@ import java.io.*
import java.util.*
class Database(private val iconPackChooser: InterfaceIconPackChooser) {
open class Database {
// To keep a reference for specific methods provided by version
private var mDatabaseKDB: DatabaseKDB? = null
@ -76,12 +75,6 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
var isReadOnly = false
val iconDrawableFactory = IconDrawableFactory(
iconPackChooser = iconPackChooser,
retrieveBinaryCache = { binaryCache },
retrieveCustomIconBinary = { iconId -> iconsManager.getBinaryForCustomIcon(iconId) }
)
var loaded = false
set(value) {
field = value
@ -113,7 +106,8 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
private val iconsManager: IconsManager
get() {
return mDatabaseKDB?.iconsManager ?: mDatabaseKDBX?.iconsManager ?: IconsManager()
return mDatabaseKDB?.iconsManager ?: mDatabaseKDBX?.iconsManager
?: IconsManager(NUMBER_STANDARD_ICONS)
}
fun doForEachStandardIcons(action: (IconImageStandard) -> Unit) {
@ -143,8 +137,11 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
return mDatabaseKDBX?.isCustomIconBinaryDuplicate(binaryData) ?: false
}
fun removeCustomIcon(customIcon: IconImageCustom) {
iconDrawableFactory.clearFromCache(customIcon)
fun getBinaryForCustomIcon(iconId: UUID): BinaryData? {
return iconsManager.getBinaryForCustomIcon(iconId)
}
open fun removeCustomIcon(customIcon: IconImageCustom) {
iconsManager.removeCustomIcon(customIcon.uuid, binaryCache)
mDatabaseKDBX?.addDeletedObject(customIcon.uuid)
}
@ -649,7 +646,7 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
}
// New database instance to get new changes
val databaseToMerge = Database(iconPackChooser)
val databaseToMerge = Database()
databaseToMerge.fileUri = databaseToMergeUri ?: this.fileUri
try {
@ -990,7 +987,7 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
dataModifiedSinceLastLoading = true
}
fun clearIndexesAndBinaries(filesDirectory: File? = null) {
open fun clearIndexesAndBinaries(filesDirectory: File?) {
this.mDatabaseKDB?.clearIndexes()
this.mDatabaseKDBX?.clearIndexes()
@ -1003,8 +1000,6 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
this.mDatabaseKDB?.clearBinaries()
this.mDatabaseKDBX?.clearBinaries()
iconDrawableFactory.clearCache()
// delete all the files in the temp dir if allowed
try {
filesDirectory?.let { directory ->
@ -1390,7 +1385,6 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
}
companion object : SingletonHolder<Database>(::Database) {
private val TAG = Database::class.java.name
}
}

View file

@ -19,7 +19,6 @@
*/
package com.kunzisoft.keepass.database.element
import android.content.Context
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned

View file

@ -29,9 +29,9 @@ enum class SortNodeEnum {
DB, TITLE, USERNAME, CREATION_TIME, LAST_MODIFY_TIME, LAST_ACCESS_TIME;
fun <G: GroupVersionedInterface<G, *>> getNodeComparator(
database: Database,
sortNodeParameters: SortNodeParameters)
: Comparator<NodeVersionedInterface<G>> {
database: Database,
sortNodeParameters: SortNodeParameters
) : Comparator<NodeVersionedInterface<G>> {
return when (this) {
DB -> NodeNaturalComparator(database, sortNodeParameters) // Force false because natural order contains recycle bin
TITLE -> NodeTitleComparator(database, sortNodeParameters)
@ -110,9 +110,9 @@ enum class SortNodeEnum {
* Comparator of node by natural database placement
*/
class NodeNaturalComparator<G: GroupVersionedInterface<*, *>, T: NodeVersionedInterface<G>>(
database: Database,
sortNodeParameters: SortNodeParameters)
: NodeComparator<G, T>(database, sortNodeParameters) {
database: Database,
sortNodeParameters: SortNodeParameters
) : NodeComparator<G, T>(database, sortNodeParameters) {
override fun compareBySpecificOrder(object1: T, object2: T): Int {
return object1.nodeIndexInParentForNaturalOrder()
@ -124,9 +124,9 @@ enum class SortNodeEnum {
* Comparator of Node by Title
*/
class NodeTitleComparator<G: GroupVersionedInterface<*, *>, T: NodeVersionedInterface<G>>(
database: Database,
sortNodeParameters: SortNodeParameters)
: NodeComparator<G, T>(database, sortNodeParameters) {
database: Database,
sortNodeParameters: SortNodeParameters
) : NodeComparator<G, T>(database, sortNodeParameters) {
override fun compareBySpecificOrder(object1: T, object2: T): Int {
val titleCompare = object1.title.compareTo(object2.title, ignoreCase = true)
@ -142,9 +142,9 @@ enum class SortNodeEnum {
* Comparator of Node by Username, Groups by title
*/
class NodeUsernameComparator<G: GroupVersionedInterface<*, *>, T: NodeVersionedInterface<G>>(
database: Database,
sortNodeParameters: SortNodeParameters)
: NodeComparator<G, T>(database, sortNodeParameters) {
database: Database,
sortNodeParameters: SortNodeParameters
) : NodeComparator<G, T>(database, sortNodeParameters) {
override fun compareBySpecificOrder(object1: T, object2: T): Int {
return if (object1.type == Type.ENTRY && object2.type == Type.ENTRY) {
@ -168,9 +168,9 @@ enum class SortNodeEnum {
* Comparator of node by creation
*/
class NodeCreationComparator<G: GroupVersionedInterface<*, *>, T: NodeVersionedInterface<G>>(
database: Database,
sortNodeParameters: SortNodeParameters)
: NodeComparator<G, T>(database, sortNodeParameters) {
database: Database,
sortNodeParameters: SortNodeParameters
) : NodeComparator<G, T>(database, sortNodeParameters) {
override fun compareBySpecificOrder(object1: T, object2: T): Int {
val creationCompare = object1.creationTime.date
@ -187,9 +187,9 @@ enum class SortNodeEnum {
* Comparator of node by last modification
*/
class NodeLastModificationComparator<G: GroupVersionedInterface<*, *>, T: NodeVersionedInterface<G>>(
database: Database,
sortNodeParameters: SortNodeParameters)
: NodeComparator<G, T>(database, sortNodeParameters) {
database: Database,
sortNodeParameters: SortNodeParameters
) : NodeComparator<G, T>(database, sortNodeParameters) {
override fun compareBySpecificOrder(object1: T, object2: T): Int {
val lastModificationCompare = object1.lastModificationTime.date
@ -206,9 +206,9 @@ enum class SortNodeEnum {
* Comparator of node by last access
*/
class NodeLastAccessComparator<G: GroupVersionedInterface<*, *>, T: NodeVersionedInterface<G>>(
database: Database,
sortNodeParameters: SortNodeParameters)
: NodeComparator<G, T>(database, sortNodeParameters) {
database: Database,
sortNodeParameters: SortNodeParameters
) : NodeComparator<G, T>(database, sortNodeParameters) {
override fun compareBySpecificOrder(object1: T, object2: T): Int {
val lastAccessCompare = object1.lastAccessTime.date

View file

@ -67,7 +67,8 @@ abstract class DatabaseVersioned<
* Can be used to temporarily store database elements
*/
var binaryCache = BinaryCache()
var iconsManager = IconsManager()
// For now, same number of icons for each database version
var iconsManager = IconsManager(IconImageStandard.NUMBER_STANDARD_ICONS)
var attachmentPool = AttachmentPool()
var changeDuplicateId = false

View file

@ -21,7 +21,6 @@ package com.kunzisoft.keepass.database.element.icon
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.icons.IconPack.Companion.NB_ICONS
class IconImageStandard : IconImageDraw {
@ -74,6 +73,8 @@ class IconImageStandard : IconImageDraw {
companion object {
const val NUMBER_STANDARD_ICONS = 69
const val KEY_ID = 0
const val ID_CARD_ID = 9
const val WIRELESS_ID = 12
@ -88,7 +89,7 @@ class IconImageStandard : IconImageDraw {
const val DOLLAR_ID = 66
fun isCorrectIconId(iconId: Int): Boolean {
return iconId in 0 until NB_ICONS
return iconId in 0 until NUMBER_STANDARD_ICONS
}
@JvmField

View file

@ -25,12 +25,11 @@ import com.kunzisoft.keepass.database.element.binary.BinaryCache
import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.element.binary.CustomIconPool
import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.KEY_ID
import com.kunzisoft.keepass.icons.IconPack.Companion.NB_ICONS
import java.util.*
import java.util.UUID
class IconsManager {
class IconsManager(numberOfIcons: Int) {
private val standardCache = List(NB_ICONS) {
private val standardCache = List(numberOfIcons) {
IconImageStandard(it)
}
private val customCache = CustomIconPool()

View file

@ -1,14 +0,0 @@
package com.kunzisoft.keepass.icons
import android.content.Context
interface InterfaceIconPackChooser {
fun build(context: Context)
fun addDefaultIconPack(context: Context)
fun addOrCatchNewIconPack(context: Context, iconPackString: String)
fun setSelectedIconPack(iconPackIdString: String?)
fun getSelectedIconPack(context: Context): IconPack?
fun getIconPackList(context: Context): List<IconPack>
fun setDefaultIconSize(int: Int)
fun getDefaultIconSize(): Int
}

View file

@ -19,27 +19,11 @@
*/
package com.kunzisoft.keepass.utils
import com.kunzisoft.keepass.icons.InterfaceIconPackChooser
open class SingletonHolder<out T>(private val constructor: (iconPackChooser : InterfaceIconPackChooser) -> T) {
@Volatile
private var instance: T? = null
fun getInstance(iconPackChooser: InterfaceIconPackChooser): T {
return when {
instance != null -> instance!!
else -> synchronized(this) {
if (instance == null) instance = constructor(iconPackChooser)
instance!!
}
}
}
}
open class SingletonHolderParameter<out T, in A>(private val constructor: (A) -> T) {
@Volatile
private var instance: T? = null
fun getInstance(arg: A): T {
return when {
instance != null -> instance!!
@ -50,3 +34,19 @@ open class SingletonHolderParameter<out T, in A>(private val constructor: (A) ->
}
}
}
open class SingletonHolder<out T>(private val constructor: () -> T) {
@Volatile
private var instance: T? = null
fun getInstance(): T {
return when {
instance != null -> instance!!
else -> synchronized(this) {
if (instance == null) instance = constructor()
instance!!
}
}
}
}