diff --git a/Legacy/AppLock/build.gradle b/Legacy/AppLock/build.gradle index 79e6c5ff..faadb309 100644 --- a/Legacy/AppLock/build.gradle +++ b/Legacy/AppLock/build.gradle @@ -26,7 +26,7 @@ android { } dependencies { - implementation project(path: ':Core:Legacy') + implementation project(':Core:Legacy') implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05' implementation("com.louiscad.splitties:splitties-appctx:3.0.0") diff --git a/Legacy/BugTracker/build.gradle b/Legacy/BugTracker/build.gradle index 7c172f11..df81d9e6 100644 --- a/Legacy/BugTracker/build.gradle +++ b/Legacy/BugTracker/build.gradle @@ -26,5 +26,5 @@ android { } dependencies { - implementation project(path: ':Core:Legacy') + implementation project(':Core:Legacy') } diff --git a/Legacy/Confetti/build.gradle b/Legacy/Confetti/build.gradle index fa15f34b..9a277122 100644 --- a/Legacy/Confetti/build.gradle +++ b/Legacy/Confetti/build.gradle @@ -22,6 +22,6 @@ android { kotlinOptions { jvmTarget = javaVersion } dependencies { - implementation project(path: ':Core:Legacy') + implementation project(':Core:Legacy') } } diff --git a/Legacy/Stores/build.gradle b/Legacy/Stores/build.gradle index 5e836dfa..5c6fc3e3 100644 --- a/Legacy/Stores/build.gradle +++ b/Legacy/Stores/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - implementation project(path: ':Core:Legacy') + implementation project(':Core:Legacy') api 'androidx.datastore:datastore-preferences:1.1.2' diff --git a/Legacy/src/main/java/com/infomaniak/lib/core/networking/AccessTokenUsageInterceptor.kt b/Legacy/src/main/java/com/infomaniak/lib/core/networking/AccessTokenUsageInterceptor.kt index 2ed463f0..41820a9c 100644 --- a/Legacy/src/main/java/com/infomaniak/lib/core/networking/AccessTokenUsageInterceptor.kt +++ b/Legacy/src/main/java/com/infomaniak/lib/core/networking/AccessTokenUsageInterceptor.kt @@ -106,7 +106,8 @@ class AccessTokenUsageInterceptor( data class ApiCallRecord(val accessToken: String, val date: Long, val responseCode: Int) companion object { - private const val SIX_MONTHS = 60 * 60 * 24 * 182L // In seconds + private const val SECONDS_IN_A_DAY = 86_400L + private const val SIX_MONTHS = SECONDS_IN_A_DAY * 182L // In seconds private const val TEN_SECONDS = 10 // In seconds } } diff --git a/src/main/kotlin/com/infomaniak/core/DateUtils.kt b/src/main/kotlin/com/infomaniak/core/DateUtils.kt deleted file mode 100644 index 1affc63d..00000000 --- a/src/main/kotlin/com/infomaniak/core/DateUtils.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Infomaniak Core - Android - * Copyright (C) 2024 Infomaniak Network SA - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.infomaniak.core - -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale - -const val FORMAT_DATE_DEFAULT = "dd.MM.yy" -const val FORMAT_DATE_TITLE = "E d MMMM" -const val FORMAT_DATE_SIMPLE = "dd/MM/yyyy" -const val FORMAT_DATE_FULL = "EEEE d MMMM" - -fun Date.format(pattern: String = FORMAT_DATE_DEFAULT): String = SimpleDateFormat(pattern, Locale.getDefault()).format(this) diff --git a/Legacy/src/main/java/com/infomaniak/lib/core/utils/DateUtils.kt b/src/main/kotlin/com/infomaniak/core/utils/DateUtils.kt similarity index 90% rename from Legacy/src/main/java/com/infomaniak/lib/core/utils/DateUtils.kt rename to src/main/kotlin/com/infomaniak/core/utils/DateUtils.kt index b7f89919..840cd0a4 100644 --- a/Legacy/src/main/java/com/infomaniak/lib/core/utils/DateUtils.kt +++ b/src/main/kotlin/com/infomaniak/core/utils/DateUtils.kt @@ -15,9 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.lib.core.utils +package com.infomaniak.core.utils -import android.os.Build import androidx.annotation.RequiresApi import java.text.SimpleDateFormat import java.time.ZoneId @@ -27,22 +26,27 @@ import java.util.Calendar import java.util.Date import java.util.Locale -const val FORMAT_DATE_CLEAR_MONTH = "dd MMM yyyy" const val FORMAT_DATE_CLEAR_FULL_MONTH = "EEEE d MMMM yyyy" -const val FORMAT_DATE_DAY_MONTH = "EEE d MMM" -const val FORMAT_DATE_DAY_MONTH_YEAR = "EEE d MMM yyyy" +const val FORMAT_DATE_CLEAR_MONTH = "dd MMM yyyy" +const val FORMAT_DATE_CLEAR_MONTH_DAY_ONE_CHAR = "d MMM yyyy" const val FORMAT_DATE_DAY_FULL_MONTH_WITH_TIME = "EEEE d MMMM HH:mm" const val FORMAT_DATE_DAY_FULL_MONTH_YEAR_WITH_TIME = "EEEE d MMMM yyyy HH:mm" -const val FORMAT_DATE_CLEAR_MONTH_DAY_ONE_CHAR = "d MMM yyyy" +const val FORMAT_DATE_DAY_MONTH = "EEE d MMM" +const val FORMAT_DATE_DAY_MONTH_YEAR = "EEE d MMM yyyy" const val FORMAT_DATE_DEFAULT = "dd.MM.yy" -const val FORMAT_DATE_HOUR_MINUTE = "HH:mm" +const val FORMAT_DATE_FULL = "EEEE d MMMM" const val FORMAT_DATE_SHORT_DAY_ONE_CHAR = "d MMM" -const val FORMAT_SCHEDULE_MAIL = "yyyy-MM-dd'T'HH:mm:ssXXX" +const val FORMAT_DATE_SIMPLE = "dd/MM/yyyy" +const val FORMAT_DATE_TITLE = "E d MMMM" const val FORMAT_DATE_WITH_TIMEZONE = "yyyy-MM-dd'T'HH:mm:ssZ" const val FORMAT_EVENT_DATE = "dd/MM/yyyy HH:mm" const val FORMAT_FULL_DATE = "EEEE dd MMMM yyyy" const val FORMAT_FULL_DATE_WITH_HOUR = "EEEE MMM d yyyy HH:mm:ss" +const val FORMAT_HOUR_MINUTES = "HH:mm" const val FORMAT_NEW_FILE = "yyyyMMdd_HHmmss" +const val FORMAT_SCHEDULE_MAIL = "yyyy-MM-dd'T'HH:mm:ssXXX" + +const val SECONDS_IN_A_DAY = 86_400L //region Format Dates enum class FormatData { @@ -51,12 +55,9 @@ enum class FormatData { BOTH, } -fun Date.format(pattern: String = FORMAT_DATE_DEFAULT): String { - val simpleDateFormat = SimpleDateFormat(pattern, Locale.getDefault()) - return simpleDateFormat.format(this) -} +fun Date.format(pattern: String = FORMAT_DATE_DEFAULT): String = SimpleDateFormat(pattern, Locale.getDefault()).format(this) -@RequiresApi(Build.VERSION_CODES.O) +@RequiresApi(26) fun Date.formatWithLocal(formatData: FormatData, formatStyle: FormatStyle, formatStyleSecondary: FormatStyle? = null): String { val formatter = when (formatData) { FormatData.DATE -> DateTimeFormatter.ofLocalizedDate(formatStyle) @@ -69,6 +70,10 @@ fun Date.formatWithLocal(formatData: FormatData, formatStyle: FormatStyle, forma //endregion //region Get a new Date relatively to a given Date +fun Date.yesterday(): Date = addDays(-1) + +fun Date.tomorrow(): Date = addDays(1) + fun Date.startOfTheDay(): Date = Calendar.getInstance().apply { time = this@startOfTheDay set(Calendar.HOUR_OF_DAY, 0) @@ -83,11 +88,6 @@ fun Date.endOfTheDay(): Date = Calendar.getInstance().apply { set(Calendar.SECOND, 59) }.time -fun Date.tomorrow(): Date = Calendar.getInstance().apply { - time = this@tomorrow - add(Calendar.DATE, 1) -}.time - fun Date.startOfTomorrow(): Date = tomorrow().startOfTheDay() fun Date.endOfTomorrow(): Date = tomorrow().endOfTheDay() @@ -212,17 +212,11 @@ fun Date.isSameDayAs(targetDate: Date): Boolean { day() == targetDate.day() } +fun Date.isYesterday(): Boolean = isSameDayAs(Date().yesterday()) + fun Date.isToday(): Boolean = isSameDayAs(Date()) -fun Date.isYesterday(): Boolean { - val yesterday = Date().addDays(-1) - return isSameDayAs(yesterday) -} - -fun Date.isThisWeek(): Boolean { - val now = Date() - return this in now.startOfTheWeek()..now.endOfTheWeek() -} +fun Date.isTomorrow(): Boolean = isSameDayAs(Date().tomorrow()) fun Date.isWeekend(): Boolean { val calendar = Calendar.getInstance().apply { @@ -232,6 +226,8 @@ fun Date.isWeekend(): Boolean { return day == 1 || day == 7 } +fun Date.isThisWeek(): Boolean = Date().let { now -> this in now.startOfTheWeek()..now.endOfTheWeek() } + fun Date.isThisMonth(): Boolean = Date().let { now -> year() == now.year() && month() == now.month() } fun Date.isThisYear(): Boolean = Date().let { now -> year() == now.year() } diff --git a/src/main/kotlin/com/infomaniak/core/DownloadManagerUtils.kt b/src/main/kotlin/com/infomaniak/core/utils/DownloadManagerUtils.kt similarity index 96% rename from src/main/kotlin/com/infomaniak/core/DownloadManagerUtils.kt rename to src/main/kotlin/com/infomaniak/core/utils/DownloadManagerUtils.kt index 2e276aaa..cb9725e2 100644 --- a/src/main/kotlin/com/infomaniak/core/DownloadManagerUtils.kt +++ b/src/main/kotlin/com/infomaniak/core/utils/DownloadManagerUtils.kt @@ -1,6 +1,6 @@ /* * Infomaniak Core - Android - * Copyright (C) 2024 Infomaniak Network SA + * Copyright (C) 2024-2025 Infomaniak Network SA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.core +package com.infomaniak.core.utils import android.app.DownloadManager.Request import android.net.Uri diff --git a/src/main/kotlin/com/infomaniak/core/EmailUtils.kt b/src/main/kotlin/com/infomaniak/core/utils/EmailUtils.kt similarity index 96% rename from src/main/kotlin/com/infomaniak/core/EmailUtils.kt rename to src/main/kotlin/com/infomaniak/core/utils/EmailUtils.kt index 6b848610..6d4b1193 100644 --- a/src/main/kotlin/com/infomaniak/core/EmailUtils.kt +++ b/src/main/kotlin/com/infomaniak/core/utils/EmailUtils.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.core +package com.infomaniak.core.utils import android.util.Patterns diff --git a/src/main/kotlin/com/infomaniak/core/EnumUtils.kt b/src/main/kotlin/com/infomaniak/core/utils/EnumUtils.kt similarity index 97% rename from src/main/kotlin/com/infomaniak/core/EnumUtils.kt rename to src/main/kotlin/com/infomaniak/core/utils/EnumUtils.kt index 3bbc96c8..0f1be401 100644 --- a/src/main/kotlin/com/infomaniak/core/EnumUtils.kt +++ b/src/main/kotlin/com/infomaniak/core/utils/EnumUtils.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.core +package com.infomaniak.core.utils inline fun > enumValueOfOrNull(value: String?): T? { return value?.let { runCatching { enumValueOf(it) }.getOrNull() } diff --git a/src/main/kotlin/com/infomaniak/core/NumberUtils.kt b/src/main/kotlin/com/infomaniak/core/utils/NumberUtils.kt similarity index 96% rename from src/main/kotlin/com/infomaniak/core/NumberUtils.kt rename to src/main/kotlin/com/infomaniak/core/utils/NumberUtils.kt index ca87605a..465dd432 100644 --- a/src/main/kotlin/com/infomaniak/core/NumberUtils.kt +++ b/src/main/kotlin/com/infomaniak/core/utils/NumberUtils.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.core +package com.infomaniak.core.utils import java.util.Locale diff --git a/src/main/kotlin/com/infomaniak/core/UserAgentUtils.kt b/src/main/kotlin/com/infomaniak/core/utils/UserAgentUtils.kt similarity index 96% rename from src/main/kotlin/com/infomaniak/core/UserAgentUtils.kt rename to src/main/kotlin/com/infomaniak/core/utils/UserAgentUtils.kt index 7829f325..52b94494 100644 --- a/src/main/kotlin/com/infomaniak/core/UserAgentUtils.kt +++ b/src/main/kotlin/com/infomaniak/core/utils/UserAgentUtils.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.core +package com.infomaniak.core.utils import android.os.Build