fix: Remove AndroidX dependency and format code

This commit is contained in:
J-Jamet 2023-05-14 17:52:40 +02:00
parent e1ecebb4a0
commit 81930bf3a1
12 changed files with 88 additions and 69 deletions

View file

@ -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

View file

@ -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

View file

@ -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<EntryHistoryAdapter.EntryHistoryViewHolder>() {

View file

@ -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,
override fun onActionFinished(
database: ContextualDatabase,
actionTask: String,
result: ActionRunnable.Result) {
result: ActionRunnable.Result
) {
onActionFinish?.invoke(database, actionTask, result)
onActionStopped(database)
}

View file

@ -1,4 +1,4 @@
package com.kunzisoft.keepass.model
package com.kunzisoft.keepass.database.action
import androidx.annotation.StringRes

View file

@ -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,
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)
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,

View file

@ -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)
}
}
}

View file

@ -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,

View file

@ -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,

View file

@ -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

View file

@ -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()

View file

@ -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) {