Skip to content

Commit

Permalink
[CI] Stop ignoring ktlint check/format failures on CI checks (gdg-ber…
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobodemann authored Jul 5, 2024
2 parents cc21044 + 2c0cbc7 commit 675f5c7
Show file tree
Hide file tree
Showing 38 changed files with 171 additions and 145 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
name: Debug APK
path: zeapp/android/build/outputs/apk/debug/android-debug.apk

format:
ktlint:
runs-on: ubuntu-latest
steps:
- name: "Checkout Repo"
Expand All @@ -48,8 +48,8 @@ jobs:
uses: gradle/actions/setup-gradle@v3
- name: "Validate Gradle wrapper"
uses: gradle/actions/wrapper-validation@v3
- name: "Lint"
run: ./gradlew ktlintFormat --no-daemon
- name: "ktLint"
run: ./gradlew ktlintCheck --no-daemon

lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions zeapp/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ android {
"pt-rBR",
"pl",
"et",
"ru"
"ru",
),
)

Expand Down Expand Up @@ -213,7 +213,7 @@ ktlint {
android.set(true)
outputToConsole.set(true)
outputColorName.set("RED")
ignoreFailures.set(true)
ignoreFailures.set(false)
reporters {
reporter(ReporterType.PLAIN)
reporter(ReporterType.CHECKSTYLE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package de.berlindroid.zeapp

import androidx.compose.ui.test.*
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.rules.ActivityScenarioRule
import org.junit.Rule
import org.junit.Test

class ZeMainActivityTest {
class ZeMainActivityTests {

@get:Rule
val composeTestRule = createAndroidComposeRule<ZeMainActivity>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun AutoSizeTextField(
errorContainerColor = Color.Red,
errorLabelColor = Color.Red,
focusedSupportingTextColor = ZeBlack,
unfocusedSupportingTextColor = ZeBlack
unfocusedSupportingTextColor = ZeBlack,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import android.widget.LinearLayout
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.core.graphics.scale
import de.berlindroid.zekompanion.BADGE_HEIGHT
import de.berlindroid.zekompanion.BADGE_WIDTH
import de.berlindroid.zeapp.zeui.zepages.BarCodePage
import de.berlindroid.zeapp.zeui.zepages.QRCodePage
import de.berlindroid.zekompanion.BADGE_HEIGHT
import de.berlindroid.zekompanion.BADGE_WIDTH
import de.berlindroid.zekompanion.forEach
import de.berlindroid.zekompanion.forEachIndexed
import de.berlindroid.zekompanion.isBinary
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.berlindroid.zeapp.zemodels

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

data class WeatherData(
val day: String?,
val temperature: Double,
) {

val formattedTemperature: String
get() = "${temperature}C"

fun formattedDate(): String {
return if (day == null) {
"N/A"
} else {
val dateTime = LocalDateTime.parse(day, DateTimeFormatter.ISO_DATE_TIME)
dateTime.format(DateTimeFormatter.ofPattern("d MMM uuuu"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ private val CONFIG_REGEX = Regex("""([^\s]+?)=([^\s]+?)(?:\s+|$)""")
* ```
*/
class ZeBadgeConfigParser
@Inject
constructor() {
fun parse(configString: String): ParseResult {
val configMap =
CONFIG_REGEX.findAll(configString)
.map { it.groupValues }
.associate { it[1] to it[2] }
.mapValues { it.value.replace(SPACE_ESCAPED, " ") }
@Inject
constructor() {
fun parse(configString: String): ParseResult {
val configMap =
CONFIG_REGEX.findAll(configString)
.map { it.groupValues }
.associate { it[1] to it[2] }
.mapValues { it.value.replace(SPACE_ESCAPED, " ") }

val userId = configMap["user.uuid"]?.let { UUID.fromString(it) }
val userName = configMap["user.name"]
val userDescription = configMap["user.description"]
val userProfilePhoto = configMap["user.iconB64"]?.let { Base64.decode(it, Base64.DEFAULT) }
val userId = configMap["user.uuid"]?.let { UUID.fromString(it) }
val userName = configMap["user.name"]
val userDescription = configMap["user.description"]
val userProfilePhoto = configMap["user.iconB64"]?.let { Base64.decode(it, Base64.DEFAULT) }

val isWiFiAttached = configMap["wifi_attached"]?.toBoolean() ?: false
val isDeveloperMode = configMap["developer_mode"]?.toBoolean() ?: false
val isWiFiAttached = configMap["wifi_attached"]?.toBoolean() ?: false
val isDeveloperMode = configMap["developer_mode"]?.toBoolean() ?: false

val userInfo =
if (
userId != null && userName != null && userDescription != null && userProfilePhoto != null
) {
UserInfo(userId, userName, userDescription, userProfilePhoto)
} else {
null
}
val userInfo =
if (
userId != null && userName != null && userDescription != null && userProfilePhoto != null
) {
UserInfo(userId, userName, userDescription, userProfilePhoto)
} else {
null
}

return ParseResult(
userInfo,
isWiFiAttached,
isDeveloperMode,
)
}
return ParseResult(
userInfo,
isWiFiAttached,
isDeveloperMode,
)
}
}

data class ParseResult(
val userInfo: UserInfo?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import android.content.Context
import android.graphics.Bitmap
import dagger.hilt.android.qualifiers.ApplicationContext
import de.berlindroid.zeapp.zeui.pixelBuffer
import de.berlindroid.zekompanion.*
import de.berlindroid.zekompanion.BadgePayload.*
import de.berlindroid.zekompanion.BadgePayload
import de.berlindroid.zekompanion.Environment
import de.berlindroid.zekompanion.base64
import de.berlindroid.zekompanion.buildBadgeManager
import de.berlindroid.zekompanion.toBinary
import de.berlindroid.zekompanion.zipit
import kotlinx.coroutines.delay
import timber.log.Timber
import javax.inject.Inject
Expand All @@ -31,7 +35,7 @@ class ZeBadgeManager @Inject constructor(
.zipit()
.base64()

val payload = PreviewPayload(
val payload = BadgePayload.PreviewPayload(
payload = binaryPayload,
)

Expand All @@ -51,7 +55,7 @@ class ZeBadgeManager @Inject constructor(
.zipit()
.base64()

val payload = StorePayload(
val payload = BadgePayload.StorePayload(
filename = name,
payload = binaryPayload,
)
Expand All @@ -65,8 +69,8 @@ class ZeBadgeManager @Inject constructor(
* @param name a file name on the badge to be shown
*/
suspend fun showPage(name: String): Result<Int> {
val payload = ShowPayload(
filename = name
val payload = BadgePayload.ShowPayload(
filename = name,
)

return badgeManager.sendPayload(payload)
Expand All @@ -76,7 +80,7 @@ class ZeBadgeManager @Inject constructor(
* Return the name of the pages stored on the badge.
*/
suspend fun requestPagesStored(): Result<String> {
val payload = ListPayload()
val payload = BadgePayload.ListPayload()

return if (badgeManager.sendPayload(payload).isSuccess) {
badgeManager.readResponse()
Expand All @@ -90,13 +94,13 @@ class ZeBadgeManager @Inject constructor(
*/
suspend fun listConfiguration(): Result<Map<String, Any?>> {
badgeManager.sendPayload(
ConfigLoadPayload(),
BadgePayload.ConfigLoadPayload(),
)

badgeManager.readResponse()
delay(300)

val payload = ConfigListPayload()
val payload = BadgePayload.ConfigListPayload()

if (badgeManager.sendPayload(payload).isSuccess) {
val response = badgeManager.readResponse()
Expand All @@ -106,7 +110,7 @@ class ZeBadgeManager @Inject constructor(
val config = response.getOrDefault("").replace("\r\n", "")
Timber.v(
"Badge sent response: successfully received configuration: " +
"'${config.replace("\n", "\\n")}'.",
"'${config.replace("\n", "\\n")}'.",
)

val parseResult = badgeConfigParser.parse(config)
Expand All @@ -124,15 +128,14 @@ class ZeBadgeManager @Inject constructor(
* Update configuration on badge..
*/
suspend fun updateConfiguration(configuration: Map<String, Any?>): Result<Any> {

val detypedConfig: Map<String, String> = configuration.map { e ->
val (k, v) = e
k to kotlinToPython(v)
}.toMap()

val config = detypedConfig.entries.joinToString(separator = " ")

val payload = ConfigUpdatePayload(
val payload = BadgePayload.ConfigUpdatePayload(
config = config,
)

Expand All @@ -141,7 +144,7 @@ class ZeBadgeManager @Inject constructor(
delay(300)

return if (badgeManager.sendPayload(
ConfigSavePayload(),
BadgePayload.ConfigSavePayload(),
).isSuccess
) {
Result.success(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import javax.inject.Inject

class ZeContributorsService @Inject constructor() {
fun contributors(): Flow<List<Contributor>> = flow {

val contributors = githubApiService.getContributors()

emit(
contributors.map { Contributor(it.login, it.url, it.imageUrl, it.contributions) }
contributors.map { Contributor(it.login, it.url, it.imageUrl, it.contributions) },
)
}.flowOn(Dispatchers.IO)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.annotation.DrawableRes
import dagger.hilt.android.qualifiers.ApplicationContext
import de.berlindroid.zekompanion.BADGE_HEIGHT
import de.berlindroid.zekompanion.BADGE_WIDTH
import de.berlindroid.zeapp.R
import de.berlindroid.zeapp.zebits.scaleIfNeeded
import de.berlindroid.zekompanion.BADGE_HEIGHT
import de.berlindroid.zekompanion.BADGE_WIDTH
import javax.inject.Inject

class ZeImageProviderService @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import dagger.hilt.android.qualifiers.ApplicationContext
import de.berlindroid.zekompanion.BADGE_HEIGHT
import de.berlindroid.zekompanion.BADGE_WIDTH
import de.berlindroid.zeapp.zebits.toBitmap
import de.berlindroid.zeapp.zemodels.ZeBadgeType
import de.berlindroid.zeapp.zemodels.ZeConfiguration
import de.berlindroid.zeapp.zemodels.ZeSlot
import de.berlindroid.zeapp.zeui.pixelBuffer
import de.berlindroid.zekompanion.BADGE_HEIGHT
import de.berlindroid.zekompanion.BADGE_WIDTH
import de.berlindroid.zekompanion.base64
import de.berlindroid.zekompanion.debase64
import de.berlindroid.zekompanion.toBinary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package de.berlindroid.zeapp.zeservices

import de.berlindroid.zeapp.zemodels.WeatherData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import retrofit2.http.GET
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

internal suspend fun fetchWeather(date: String): WeatherData {
try {
Expand Down Expand Up @@ -68,21 +67,3 @@ private interface WeatherApi {
@GET("v1/forecast?latitude=52.5244&longitude=13.4105&hourly=temperature_2m&forecast_days=16")
suspend fun getWeather(): Weather
}

data class WeatherData(
val day: String?,
val temperature: Double,
) {

val formattedTemperature: String
get() = "${temperature}C"

fun formattedDate(): String {
return if (day == null) {
"N/A"
} else {
val dateTime = LocalDateTime.parse(day, DateTimeFormatter.ISO_DATE_TIME)
dateTime.format(DateTimeFormatter.ofPattern("d MMM uuuu"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ fun BarCodeEditorDialog(
Text(text = stringResource(id = android.R.string.ok))
}
},
title = { Text(
color = ZeBlack,
text = stringResource(id = R.string.add_barcode_url)
) },
title = {
Text(
color = ZeBlack,
text = stringResource(id = R.string.add_barcode_url),
)
},
properties = DialogProperties(),
text = {
LazyColumn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -67,10 +66,12 @@ fun CustomPhraseEditorDialog(
Text(text = stringResource(id = android.R.string.cancel))
}
},
title = { Text(
color = ZeBlack,
text = stringResource(R.string.add_your_phrase_here)
) },
title = {
Text(
color = ZeBlack,
text = stringResource(R.string.add_your_phrase_here),
)
},
properties = DialogProperties(),
text = {
Column {
Expand Down
Loading

0 comments on commit 675f5c7

Please sign in to comment.