diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GroupDialogFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GroupDialogFragment.kt index 7c8c2daba..334d8d2a3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GroupDialogFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GroupDialogFragment.kt @@ -35,6 +35,7 @@ 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 +import com.kunzisoft.keepass.utils.TimeUtil.getDateTimeString import com.kunzisoft.keepass.utils.UuidUtil import com.kunzisoft.keepass.view.DateTimeFieldView diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt index c5fd5ef1c..a9352ba0d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt @@ -23,6 +23,7 @@ import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.StreamDirection import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.timeout.ClipboardHelper +import com.kunzisoft.keepass.utils.TimeUtil.getDateTimeString import com.kunzisoft.keepass.utils.UuidUtil import com.kunzisoft.keepass.view.TemplateView import com.kunzisoft.keepass.view.hideByFading diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt index 6a3dd1c4f..f9ed475b3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt @@ -27,6 +27,7 @@ import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.kunzisoft.keepass.R import com.kunzisoft.keepass.model.EntryInfo +import com.kunzisoft.keepass.utils.TimeUtil.getDateTimeString class EntryHistoryAdapter(val context: Context) : RecyclerView.Adapter() { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt index 69eeec2c3..ad68ec82e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt @@ -50,7 +50,6 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.model.CipherEncryptDatabase -import com.kunzisoft.keepass.model.ProgressMessage import com.kunzisoft.keepass.model.SnapFileDatabaseInfo import com.kunzisoft.keepass.services.DatabaseTaskNotificationService import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_CHALLENGE_RESPONDED @@ -135,26 +134,34 @@ class DatabaseTaskProvider(private var context: Context, } private val actionTaskListener = object: DatabaseTaskNotificationService.ActionTaskListener { - override fun onActionStarted(database: ContextualDatabase, - progressMessage: ProgressMessage) { + override fun onActionStarted( + database: ContextualDatabase, + progressMessage: ProgressMessage + ) { if (showDialog) startDialog(progressMessage) } - override fun onActionUpdated(database: ContextualDatabase, - progressMessage: ProgressMessage) { + override fun onActionUpdated( + database: ContextualDatabase, + progressMessage: ProgressMessage + ) { if (showDialog) updateDialog(progressMessage) } - override fun onActionStopped(database: ContextualDatabase) { + override fun onActionStopped( + database: ContextualDatabase + ) { // Remove the progress task stopDialog() } - override fun onActionFinished(database: ContextualDatabase, - actionTask: String, - result: ActionRunnable.Result) { + override fun onActionFinished( + database: ContextualDatabase, + actionTask: String, + result: ActionRunnable.Result + ) { onActionFinish?.invoke(database, actionTask, result) onActionStopped(database) } diff --git a/database/src/main/java/com/kunzisoft/keepass/model/ProgressMessage.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressMessage.kt similarity index 83% rename from database/src/main/java/com/kunzisoft/keepass/model/ProgressMessage.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/ProgressMessage.kt index 4b24b0d10..0a61bf563 100644 --- a/database/src/main/java/com/kunzisoft/keepass/model/ProgressMessage.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressMessage.kt @@ -1,4 +1,4 @@ -package com.kunzisoft.keepass.model +package com.kunzisoft.keepass.database.action import androidx.annotation.StringRes diff --git a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt index e530aad40..94b8a46cb 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt @@ -47,7 +47,6 @@ import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.hardware.HardwareKeyActivity import com.kunzisoft.keepass.model.CipherEncryptDatabase -import com.kunzisoft.keepass.model.ProgressMessage import com.kunzisoft.keepass.model.SnapFileDatabaseInfo import com.kunzisoft.keepass.tasks.ActionRunnable import com.kunzisoft.keepass.tasks.ProgressTaskUpdater @@ -138,14 +137,22 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress } interface ActionTaskListener { - fun onActionStarted(database: ContextualDatabase, - progressMessage: ProgressMessage) - fun onActionUpdated(database: ContextualDatabase, - progressMessage: ProgressMessage) - fun onActionStopped(database: ContextualDatabase) - fun onActionFinished(database: ContextualDatabase, - actionTask: String, - result: ActionRunnable.Result) + fun onActionStarted( + database: ContextualDatabase, + progressMessage: ProgressMessage + ) + fun onActionUpdated( + database: ContextualDatabase, + progressMessage: ProgressMessage + ) + fun onActionStopped( + database: ContextualDatabase + ) + fun onActionFinished( + database: ContextualDatabase, + actionTask: String, + result: ActionRunnable.Result + ) } fun checkDatabase() { @@ -306,31 +313,18 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress ACTION_DATABASE_LOAD_TASK -> buildDatabaseLoadActionTask(intent, database) ACTION_DATABASE_MERGE_TASK -> buildDatabaseMergeActionTask(intent, database) ACTION_DATABASE_RELOAD_TASK -> buildDatabaseReloadActionTask(database) - ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> buildDatabaseAssignPasswordActionTask(intent, - database) - ACTION_DATABASE_CREATE_GROUP_TASK -> buildDatabaseCreateGroupActionTask(intent, - database) - ACTION_DATABASE_UPDATE_GROUP_TASK -> buildDatabaseUpdateGroupActionTask(intent, - database) - ACTION_DATABASE_CREATE_ENTRY_TASK -> buildDatabaseCreateEntryActionTask(intent, - database) - ACTION_DATABASE_UPDATE_ENTRY_TASK -> buildDatabaseUpdateEntryActionTask(intent, - database) + ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> buildDatabaseAssignPasswordActionTask(intent, database) + ACTION_DATABASE_CREATE_GROUP_TASK -> buildDatabaseCreateGroupActionTask(intent, database) + ACTION_DATABASE_UPDATE_GROUP_TASK -> buildDatabaseUpdateGroupActionTask(intent, database) + ACTION_DATABASE_CREATE_ENTRY_TASK -> buildDatabaseCreateEntryActionTask(intent, database) + ACTION_DATABASE_UPDATE_ENTRY_TASK -> buildDatabaseUpdateEntryActionTask(intent, database) ACTION_DATABASE_COPY_NODES_TASK -> buildDatabaseCopyNodesActionTask(intent, database) ACTION_DATABASE_MOVE_NODES_TASK -> buildDatabaseMoveNodesActionTask(intent, database) - ACTION_DATABASE_DELETE_NODES_TASK -> buildDatabaseDeleteNodesActionTask(intent, - database) - ACTION_DATABASE_RESTORE_ENTRY_HISTORY -> buildDatabaseRestoreEntryHistoryActionTask( - intent, - database) - ACTION_DATABASE_DELETE_ENTRY_HISTORY -> buildDatabaseDeleteEntryHistoryActionTask(intent, - database) - ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> buildDatabaseUpdateCompressionActionTask( - intent, - database) - ACTION_DATABASE_REMOVE_UNLINKED_DATA_TASK -> buildDatabaseRemoveUnlinkedDataActionTask( - intent, - database) + ACTION_DATABASE_DELETE_NODES_TASK -> buildDatabaseDeleteNodesActionTask(intent, database) + ACTION_DATABASE_RESTORE_ENTRY_HISTORY -> buildDatabaseRestoreEntryHistoryActionTask(intent, database) + ACTION_DATABASE_DELETE_ENTRY_HISTORY -> buildDatabaseDeleteEntryHistoryActionTask(intent, database) + ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> buildDatabaseUpdateCompressionActionTask(intent, database) + ACTION_DATABASE_REMOVE_UNLINKED_DATA_TASK -> buildDatabaseRemoveUnlinkedDataActionTask(intent, database) ACTION_DATABASE_UPDATE_NAME_TASK, ACTION_DATABASE_UPDATE_DESCRIPTION_TASK, ACTION_DATABASE_UPDATE_DEFAULT_USERNAME_TASK, diff --git a/app/src/main/java/com/kunzisoft/keepass/utils/TimeUtil.kt b/app/src/main/java/com/kunzisoft/keepass/utils/TimeUtil.kt new file mode 100644 index 000000000..29f2cc237 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/utils/TimeUtil.kt @@ -0,0 +1,29 @@ +package com.kunzisoft.keepass.utils + +import android.content.res.Resources +import androidx.core.os.ConfigurationCompat +import com.kunzisoft.keepass.database.element.DateInstant +import java.text.DateFormat +import java.util.Locale + +object TimeUtil { + + fun DateInstant.getDateTimeString(resources: Resources): String { + val locale = ConfigurationCompat.getLocales(resources.configuration)[0] ?: Locale.ROOT + return when (type) { + DateInstant.Type.DATE -> DateFormat.getDateInstance( + DateFormat.MEDIUM, + locale) + .format(date) + DateInstant.Type.TIME -> DateFormat.getTimeInstance( + DateFormat.SHORT, + locale) + .format(date) + else -> DateFormat.getDateTimeInstance( + DateFormat.MEDIUM, + DateFormat.SHORT, + locale) + .format(date) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kunzisoft/keepass/view/DateTimeEditFieldView.kt b/app/src/main/java/com/kunzisoft/keepass/view/DateTimeEditFieldView.kt index 61e1982e0..43b6d9bb4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/DateTimeEditFieldView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/DateTimeEditFieldView.kt @@ -29,6 +29,7 @@ import androidx.core.view.isVisible import com.google.android.material.textfield.TextInputLayout import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.DateInstant +import com.kunzisoft.keepass.utils.TimeUtil.getDateTimeString class DateTimeEditFieldView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, diff --git a/app/src/main/java/com/kunzisoft/keepass/view/DateTimeFieldView.kt b/app/src/main/java/com/kunzisoft/keepass/view/DateTimeFieldView.kt index a272c4386..4eb0565c4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/DateTimeFieldView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/DateTimeFieldView.kt @@ -31,6 +31,7 @@ import android.widget.TextView import androidx.core.view.isVisible import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.DateInstant +import com.kunzisoft.keepass.utils.TimeUtil.getDateTimeString class DateTimeFieldView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, diff --git a/database/build.gradle b/database/build.gradle index 38d7feeae..655372a68 100644 --- a/database/build.gradle +++ b/database/build.gradle @@ -32,7 +32,6 @@ android { } dependencies { - implementation "androidx.core:core-ktx:$android_core_version" // Time implementation 'joda-time:joda-time:2.10.13' // Apache Commons diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/DateInstant.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/DateInstant.kt index a250cdf84..2339e612b 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/DateInstant.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/DateInstant.kt @@ -19,16 +19,20 @@ */ package com.kunzisoft.keepass.database.element -import android.content.res.Resources import android.os.Parcel import android.os.Parcelable -import androidx.core.os.ConfigurationCompat import com.kunzisoft.keepass.utils.readEnum import com.kunzisoft.keepass.utils.writeEnum -import org.joda.time.* -import java.text.DateFormat +import org.joda.time.Duration +import org.joda.time.Instant +import org.joda.time.LocalDate +import org.joda.time.LocalDateTime +import org.joda.time.LocalTime import java.text.SimpleDateFormat -import java.util.* +import java.util.Calendar +import java.util.Date +import java.util.Locale +import java.util.TimeZone class DateInstant : Parcelable { @@ -122,25 +126,6 @@ class DateInstant : Parcelable { dest.writeEnum(mType) } - fun getDateTimeString(resources: Resources): String { - val locale = ConfigurationCompat.getLocales(resources.configuration)[0] ?: Locale.ROOT - return when (mType) { - Type.DATE -> DateFormat.getDateInstance( - DateFormat.MEDIUM, - locale) - .format(jDate) - Type.TIME -> DateFormat.getTimeInstance( - DateFormat.SHORT, - locale) - .format(jDate) - else -> DateFormat.getDateTimeInstance( - DateFormat.MEDIUM, - DateFormat.SHORT, - locale) - .format(jDate) - } - } - fun getYearInt(): Int { val dateFormat = SimpleDateFormat("yyyy", Locale.ENGLISH) return dateFormat.format(date).toInt() diff --git a/database/src/main/java/com/kunzisoft/keepass/utils/UuidUtil.java b/database/src/main/java/com/kunzisoft/keepass/utils/UuidUtil.java index 53b7383ac..2b559e539 100644 --- a/database/src/main/java/com/kunzisoft/keepass/utils/UuidUtil.java +++ b/database/src/main/java/com/kunzisoft/keepass/utils/UuidUtil.java @@ -19,12 +19,12 @@ */ package com.kunzisoft.keepass.utils; -import androidx.annotation.Nullable; - import java.util.UUID; import static com.kunzisoft.keepass.utils.StreamBytesUtilsKt.uuidTo16Bytes; +import org.jetbrains.annotations.Nullable; + public class UuidUtil { public static @Nullable String toHexString(@Nullable UUID uuid) {