-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add warning dialog at startup if a newer data version is used with an…
… old app version
- Loading branch information
1 parent
7bcbc72
commit bf0d6ef
Showing
10 changed files
with
308 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...kotlin/com/sunnychung/application/multiplatform/hellohttp/document/OperationalDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.sunnychung.application.multiplatform.hellohttp.document | ||
|
||
import com.sunnychung.application.multiplatform.hellohttp.annotation.DocumentRoot | ||
import com.sunnychung.application.multiplatform.hellohttp.annotation.Persisted | ||
import com.sunnychung.application.multiplatform.hellohttp.model.OperationalInfo | ||
import kotlinx.serialization.Serializable | ||
|
||
@DocumentRoot | ||
@Persisted | ||
@Serializable | ||
data class OperationalDocument(override val id: OperationalDI, var data: OperationalInfo) : Document<OperationalDI> | ||
|
||
@Persisted | ||
@Serializable | ||
class OperationalDI : DocumentIdentifier(type = PersistenceDocumentType.Operational) { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return javaClass.hashCode() | ||
} | ||
|
||
override fun toString(): String { | ||
return "OperationalDI()" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...vmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/model/OperationalInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.sunnychung.application.multiplatform.hellohttp.model | ||
|
||
import com.sunnychung.application.multiplatform.hellohttp.annotation.Persisted | ||
import kotlinx.serialization.Serializable | ||
|
||
@Persisted | ||
@Serializable | ||
data class OperationalInfo( | ||
var appVersion: String, | ||
var installationId: String, | ||
) |
29 changes: 29 additions & 0 deletions
29
src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/model/Version.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.sunnychung.application.multiplatform.hellohttp.model | ||
|
||
class Version(val versionName: String) : Comparable<Version> { | ||
private val components = versionName.split("[\\.-]+".toRegex()) | ||
override operator fun compareTo(other: Version): Int { | ||
(0 .. maxOf(components.lastIndex, other.components.lastIndex)).forEach { i -> | ||
val compareResult = this.numericComponent(i).compareTo(other.numericComponent(i)) | ||
if (compareResult != 0) { | ||
return compareResult | ||
} | ||
} | ||
return 0 | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (other !is Version) return false | ||
return compareTo(other) == 0 | ||
} | ||
|
||
fun numericComponent(index: Int): Int { | ||
return if (index > components.lastIndex) { | ||
0 | ||
} else { | ||
components[index].toIntOrNull() ?: -1 | ||
} | ||
} | ||
|
||
override fun toString(): String = versionName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...in/com/sunnychung/application/multiplatform/hellohttp/repository/OperationalRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sunnychung.application.multiplatform.hellohttp.repository | ||
|
||
import com.sunnychung.application.multiplatform.hellohttp.document.OperationalDI | ||
import com.sunnychung.application.multiplatform.hellohttp.document.OperationalDocument | ||
import kotlinx.serialization.serializer | ||
|
||
class OperationalRepository : BaseCollectionRepository<OperationalDocument, OperationalDI>(serializer()) { | ||
override fun relativeFilePath(id: OperationalDI): String = "operational.db" | ||
} |
Oops, something went wrong.