From 6260c3fc063d49df1c92ced4c2acec27fc18968d Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 17 Aug 2022 10:43:56 +0200 Subject: [PATCH] Fixes and drone build should work. --- .drone.yml | 5 ++- androidApp/build.gradle.kts | 10 +++++ .../readerforselfoss/utils/DateUtilsTest.kt | 32 --------------- .../android/themes/AppColors.kt | 8 ++-- gradle.properties | 2 + shared/build.gradle.kts | 4 ++ .../amine/apps/readerforselfossv2/Platform.kt | 5 --- .../readerforselfossv2/utils/DateUtils.kt | 35 ++++++++++++++++ .../amine/apps/readerforselfossv2/Greeting.kt | 7 ---- .../amine/apps/readerforselfossv2/Platform.kt | 5 --- .../readerforselfossv2/rest/SelfossModel.kt | 4 +- .../readerforselfossv2/utils/DateUtils.kt | 40 ++++--------------- .../amine/apps/readerforselfossv2/Platform.kt | 7 ---- 13 files changed, 66 insertions(+), 98 deletions(-) delete mode 100644 androidApp/src/androidTest/java/apps/amine/bou/readerforselfoss/utils/DateUtilsTest.kt delete mode 100644 shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt create mode 100644 shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt delete mode 100644 shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Greeting.kt delete mode 100644 shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt delete mode 100644 shared/src/iosMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt diff --git a/.drone.yml b/.drone.yml index 4ee64e9..107dc9f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,18 +1,19 @@ kind: pipeline type: docker +name: android steps: - name: build image: mingc/android-build-box:latest commands: - - ./gradlew build + - ./gradlew :androidApp:build -PignoreGitVersion=true - name: code-analysis image: mingc/android-build-box:latest failure: ignore commands: - ls -la - - ./gradlew sonarqube -Dsonar.projectKey=RFS2 -Dsonar.sources=. -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN + - ./gradlew sonarqube -Dsonar.projectKey=RFS2 -Dsonar.sources=. -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN -PignoreGitVersion=true environment: SONAR_HOST_URL: from_secret: sonarScannerHostUrl diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index d4a17f7..e48be33 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -1,5 +1,7 @@ import java.io.ByteArrayOutputStream +val ignoreGitVersion: String by project + plugins { id("com.android.application") kotlin("android") @@ -32,11 +34,19 @@ fun gitVersion(): String { } fun versionCodeFromGit(): Int { + if (ignoreGitVersion == "true") { + // don't care + return 1 + } println("version code " + gitVersion()) return gitVersion().toInt() } fun versionNameFromGit(): String { + if (ignoreGitVersion == "true") { + // don't care + return "1" + } println("version name " + gitVersion()) return gitVersion() } diff --git a/androidApp/src/androidTest/java/apps/amine/bou/readerforselfoss/utils/DateUtilsTest.kt b/androidApp/src/androidTest/java/apps/amine/bou/readerforselfoss/utils/DateUtilsTest.kt deleted file mode 100644 index 2a73d65..0000000 --- a/androidApp/src/androidTest/java/apps/amine/bou/readerforselfoss/utils/DateUtilsTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -// TODO -//package bou.amine.apps.readerforselfossv2.android.utils -// -//import bou.amine.apps.readerforselfossv2.android.utils.Config -//import bou.amine.apps.readerforselfossv2.android.utils.parseDate -//import org.junit.Test -// -//class DateUtilsTest { -// -// @Test -// fun parseDateV4() { -// -// Config.apiVersion = 4 -// val dateString = "2013-04-07T13:43:00+01:00" -// -// val milliseconds = parseDate(dateString).toEpochMilli() -// val correctMilliseconds : Long = 1365338580000 -// -// assert(milliseconds == correctMilliseconds) -// } -// -// @Test -// fun parseDateV1() { -// Config.apiVersion = 0 -// val dateString = "2013-04-07 13:43:00" -// -// val milliseconds = parseDate(dateString).toEpochMilli() -// val correctMilliseconds = 1365342180000 -// -// assert(milliseconds == correctMilliseconds) -// } -//} \ No newline at end of file diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt index 9c10e52..78db5a6 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt @@ -46,16 +46,16 @@ class AppColors(a: Activity) { colorBackground = if (isDarkTheme) { a.setTheme(R.style.NoBarDark) - R.color.darkBackground + a.resources.getColor(R.color.darkBackground) } else { a.setTheme(R.style.NoBar) - R.color.grey_50 + a.resources.getColor(R.color.grey_50) } textColor = if (isDarkTheme) { - R.color.white + a.resources.getColor(R.color.white) } else { - R.color.grey_900 + a.resources.getColor(R.color.grey_900) } } } diff --git a/gradle.properties b/gradle.properties index cab4d3d..5322fc7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,3 +18,5 @@ kotlin.native.enableDependencyPropagation=false android.useAndroidX=true android.enableJetifier=true kotlin.mpp.enableGranularSourceSetsMetadata=true +org.gradle.parallel=true +ignoreGitVersion=false diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index d5062d4..ec4c4b3 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -86,4 +86,8 @@ android { minSdk = 21 targetSdk = 31 } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } } \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt deleted file mode 100644 index 04329a6..0000000 --- a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt +++ /dev/null @@ -1,5 +0,0 @@ -package bou.amine.apps.readerforselfossv2 - -actual class Platform actual constructor() { - actual val platform: String = "Android ${android.os.Build.VERSION.SDK_INT}" -} \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt new file mode 100644 index 0000000..e5fe1d2 --- /dev/null +++ b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -0,0 +1,35 @@ +package bou.amine.apps.readerforselfossv2.utils + +import android.annotation.SuppressLint +import android.text.format.DateUtils +import java.time.Instant +import java.time.LocalDateTime +import java.time.OffsetDateTime +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter + +actual class DateUtils actual constructor(private val apiMajorVersion: Int) { + actual fun parseDate(dateString: String): Long { + + val FORMATTERV1 = "yyyy-MM-dd HH:mm:ss" + + return if (apiMajorVersion >= 4) { + OffsetDateTime.parse(dateString).toInstant().toEpochMilli() + } else { + LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(FORMATTERV1)).toInstant( + ZoneOffset.UTC).toEpochMilli() + } + } + + actual fun parseRelativeDate(dateString: String): String { + + val date = parseDate(dateString) + + return " " + DateUtils.getRelativeTimeSpanString( + date, + Instant.now().toEpochMilli(), + DateUtils.MINUTE_IN_MILLIS, + DateUtils.FORMAT_ABBREV_RELATIVE + ) + } +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Greeting.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Greeting.kt deleted file mode 100644 index b7391b7..0000000 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Greeting.kt +++ /dev/null @@ -1,7 +0,0 @@ -package bou.amine.apps.readerforselfossv2 - -class Greeting { - fun greeting(): String { - return "Hello, ${Platform().platform}!" - } -} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt deleted file mode 100644 index 6ae0e8c..0000000 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt +++ /dev/null @@ -1,5 +0,0 @@ -package bou.amine.apps.readerforselfossv2 - -expect class Platform() { - val platform: String -} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt index d620f1d..b4aa311 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt @@ -1,7 +1,5 @@ package bou.amine.apps.readerforselfossv2.rest -import android.os.Parcelable -import android.text.Html import kotlinx.serialization.Serializable class SelfossModel { @@ -13,7 +11,7 @@ class SelfossModel { val unread: Int ) { fun getTitleDecoded(): String { - return Html.fromHtml(tag).toString() + return tag // TODO Html.fromHtml(tag).toString() } } diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index 305b5b5..16b95c2 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -1,42 +1,16 @@ package bou.amine.apps.readerforselfossv2.utils -//import android.text.format.DateUtils import bou.amine.apps.readerforselfossv2.rest.SelfossModel -import java.time.Instant -import java.time.LocalDateTime -import java.time.OffsetDateTime -import java.time.ZoneOffset -import java.time.format.DateTimeFormatter -fun SelfossModel.Item.parseDate(dateUtils: bou.amine.apps.readerforselfossv2.utils.DateUtils): Instant = + +fun SelfossModel.Item.parseDate(dateUtils: DateUtils): Long = dateUtils.parseDate(this.datetime) -fun SelfossModel.Item.parseRelativeDate(dateUtils: bou.amine.apps.readerforselfossv2.utils.DateUtils): String = +fun SelfossModel.Item.parseRelativeDate(dateUtils: DateUtils): String = dateUtils.parseRelativeDate(this.datetime) -class DateUtils(private val apiMajorVersion: Int) { - fun parseDate(dateString: String): Instant { +expect class DateUtils(apiMajorVersion: Int) { + fun parseDate(dateString: String): Long - val FORMATTERV1 = "yyyy-MM-dd HH:mm:ss" - - return if (apiMajorVersion >= 4) { - OffsetDateTime.parse(dateString).toInstant() - } else { - LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(FORMATTERV1)).toInstant(ZoneOffset.UTC) - } - } - - fun parseRelativeDate(dateString: String): String { - - val date = parseDate(dateString) - - // TODO: -// return " " + DateUtils.getRelativeTimeSpanString( -// date.toEpochMilli(), -// Instant.now().toEpochMilli(), -// 60000L, // DateUtils.MINUTE_IN_MILLIS, -// 262144 // DateUtils.FORMAT_ABBREV_RELATIVE -// ) - return dateString - } -} \ No newline at end of file + fun parseRelativeDate(dateString: String): String +} diff --git a/shared/src/iosMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt b/shared/src/iosMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt deleted file mode 100644 index 6ed3dca..0000000 --- a/shared/src/iosMain/kotlin/bou/amine/apps/readerforselfossv2/Platform.kt +++ /dev/null @@ -1,7 +0,0 @@ -package bou.amine.apps.readerforselfossv2 - -import platform.UIKit.UIDevice - -actual class Platform actual constructor() { - actual val platform: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion -} \ No newline at end of file