Skip to content

Commit

Permalink
Merge pull request #310 from mbakgun/feature/offline-mode-improvements
Browse files Browse the repository at this point in the history
feature/offline-mode-improvements
  • Loading branch information
mbakgun authored Oct 18, 2024
2 parents aa0e878 + e6c389e commit 4a32bc6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 35 deletions.
4 changes: 2 additions & 2 deletions shared/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<ID>MagicNumber:MjImagesApp.kt$24f</ID>
<ID>MagicNumber:String0.commonMain.kt$10</ID>
<ID>MagicNumber:String0.commonMain.kt$109</ID>
<ID>MagicNumber:String0.commonMain.kt$84</ID>
<ID>MagicNumber:String0.commonMain.kt$95</ID>
<ID>MagicNumber:String0.commonMain.kt$120</ID>
<ID>MagicNumber:String0.commonMain.kt$131</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val androidInstrumentedTest by getting { dependencies { implementation(libs.androidxUiTestJunit4) implementation(libs.androidxUiTestManifest) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jsMain by getting { dependencies { implementation(compose.runtime) implementation(compose.foundation) implementation(project(":shared")) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmMain by getting { dependencies { implementation(project(":shared")) implementation(compose.desktop.currentOs) } }</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MjImagesScreenTest {
}

composeTestRule
.onNodeWithText("offline", substring = true)
.onNodeWithText("offline", substring = true, ignoreCase = true)
.assertIsDisplayed()
}

Expand Down
2 changes: 1 addition & 1 deletion shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<string name="snack_message">1) Click image to open in browser\n2) Long click to preview image</string>
<string name="failed_fetch_message">Failed to fetch images, using offline mode</string>
<string name="failed_fetch_message">Offline mode is being utilised as latest photos cannot be collected..</string>
</resources>
6 changes: 5 additions & 1 deletion shared/src/commonMain/kotlin/domain/model/MjImage.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package domain.model

data class MjImage(
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid

data class MjImage @OptIn(ExperimentalUuidApi::class) constructor(
val id: String = Uuid.random().toString(),
val date: String,
val imageUrl: String,
val hqImageUrl: String,
Expand Down
8 changes: 4 additions & 4 deletions shared/src/commonMain/kotlin/domain/model/MjImages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ data class MjImages(

fun isEmpty() = images.isEmpty()

operator fun plus(images: MjImages): MjImages =
operator fun plus(other: MjImages): MjImages =
MjImages(
currentPage = images.currentPage,
images = (this.images + images.images).distinct(),
totalPages = images.totalPages
currentPage = other.currentPage,
images = (this.images + other.images).distinctBy(MjImage::imageUrl),
totalPages = other.totalPages
)
}
2 changes: 1 addition & 1 deletion shared/src/commonMain/kotlin/ui/MjImagesApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fun MjImagesList(
) {
items(
items = images.images,
key = MjImage::imageUrl
key = MjImage::id,
) { image ->
MjImageItem(
image = image,
Expand Down
28 changes: 3 additions & 25 deletions shared/src/commonTest/kotlin/domain/mapper/MjImagesMapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package domain.mapper

import data.source.remote.model.MjImageResponse
import data.source.remote.model.MjImagesResponse
import domain.model.MjImage
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -133,15 +132,8 @@ class MjImagesMapperTest {

// then
assertEquals(
listOf(
MjImage(
date = "2023-21-04",
imageUrl = "https://mj.akgns.com",
ratio = 1.0,
hqImageUrl = "https://mj.akgns.com/hq",
)
),
result.images
1,
result.images.size
)
}

Expand Down Expand Up @@ -169,21 +161,7 @@ class MjImagesMapperTest {

// then
assertEquals(
listOf(
MjImage(
date = "2024-21-04",
imageUrl = "https://mj.akgns.com",
ratio = 1.0,
hqImageUrl = "https://mj.akgns.com/hq",
),
MjImage(
date = "2023-21-04",
imageUrl = "https://mj.akgns.com/images",
hqImageUrl = "https://mj.akgns.com/hq",
ratio = 1.0
)
),
result.images
result.images.size, 2
)
}

Expand Down

0 comments on commit 4a32bc6

Please sign in to comment.