Skip to content

Commit 01c142a

Browse files
sentinelwebsentinelweb
authored andcommitted
#496 - save length to db
1 parent 9f52df2 commit 01c142a

File tree

8 files changed

+17
-19
lines changed

8 files changed

+17
-19
lines changed

database/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ plugins {
22
kotlin("multiplatform")
33
kotlin("native.cocoapods")
44
id("com.android.library")
5-
// kotlin("com.android.application")
65
id("com.squareup.sqldelight")
76
kotlin("plugin.serialization")
87
}
98

109
group = "uk.co.sentinelweb.cuer"
1110
version = "1.0"
1211

13-
//val ver_jvm: String by project
1412
val ver_coroutines: String by project
1513
val ver_kotlinx_serialization_core: String by project
1614
val ver_sqldelight: String by project
@@ -19,7 +17,6 @@ val ver_koin: String by project
1917
val ver_turbine: String by project
2018
val ver_kotlin_fixture: String by project
2119
val ver_mockk: String by project
22-
2320
val ver_swift_tools: String by project
2421
val ver_ios_deploy_target: String by project
2522

database/src/androidUnitTest/kotlin/uk/co/sentinelweb/cuer/db/repository/SqldelightMediaDatabaseRepositoryTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import org.koin.test.inject
1414
import uk.co.sentinelweb.cuer.app.db.Database
1515
import uk.co.sentinelweb.cuer.app.db.repository.ChannelDatabaseRepository
1616
import uk.co.sentinelweb.cuer.app.db.repository.ConflictException
17-
import uk.co.sentinelweb.cuer.app.db.repository.MediaDatabaseRepository
1817
import uk.co.sentinelweb.cuer.app.db.repository.DbResult
18+
import uk.co.sentinelweb.cuer.app.db.repository.MediaDatabaseRepository
1919
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Filter.*
2020
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Operation.DELETE
2121
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Operation.FULL
@@ -148,6 +148,7 @@ class SqldelightMediaDatabaseRepositoryTest : KoinTest {
148148
channelData = initialSaved.channelData,
149149
thumbNail = initialSaved.thumbNail,
150150
image = initialSaved.image,
151+
length = initialSaved.length,
151152
broadcastDate = null,
152153
)
153154
val updated = sut.save(changed, emit = true, flat = false).data!!
@@ -178,6 +179,7 @@ class SqldelightMediaDatabaseRepositoryTest : KoinTest {
178179
),
179180
thumbNail = media.thumbNail?.copy(id = saved[i].thumbNail?.id),
180181
image = media.image?.copy(id = saved[i].image?.id),
182+
length = media.length,
181183
)
182184
}
183185

@@ -207,6 +209,7 @@ class SqldelightMediaDatabaseRepositoryTest : KoinTest {
207209
thumbNail = it.thumbNail,
208210
image = it.image,
209211
broadcastDate = null,
212+
length = it.length,
210213
)
211214
}
212215
val updated = sut.save(changed, emit = true, flat = false).data!!

database/src/commonMain/kotlin/uk/co/sentinelweb/cuer/db/factory/DatabaseFactory.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,10 @@ class DatabaseFactory(
4747
)
4848
).apply {
4949
log.d("Database.Schema.version ${Database.Schema.version} prefs.dbVersion ${prefs.dbVersion}")
50-
// }.apply {
51-
// Database.Schema.migrate(
52-
// driver = driver,
53-
// oldVersion = prefs.dbVersion,
54-
// newVersion = Database.Schema.version,
55-
// )
5650
}.also {
5751
prefs.dbVersion = Database.Schema.version
5852
}.apply {
5953
log.d("Database.Schema.version ${Database.Schema.version} prefs.dbVersion ${prefs.dbVersion}")
6054
}
6155
}
62-
}
56+
}

database/src/commonMain/kotlin/uk/co/sentinelweb/cuer/db/mapper/MediaMapper.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class MediaMapper(
3939
isLiveBroadcast = entity.flags.hasFlag(FLAG_LIVE),
4040
isLiveBroadcastUpcoming = entity.flags.hasFlag(FLAG_LIVE_UPCOMING),
4141
playFromStart = entity.flags.hasFlag(FLAG_PLAY_FROM_START),
42-
broadcastDate = entity.broadcast_date
42+
broadcastDate = entity.broadcast_date,
43+
length = entity.length
4344
)
4445

4546
fun map(domain: MediaDomain): Media = Media(
@@ -58,7 +59,8 @@ class MediaMapper(
5859
thumb_id = domain.thumbNail?.id?.id?.value,
5960
image_id = domain.image?.id?.id?.value,
6061
flags = mapFlags(domain),
61-
broadcast_date = domain.broadcastDate
62+
broadcast_date = domain.broadcastDate,
63+
length = domain.length
6264
)
6365

6466
private fun mapFlags(domain: MediaDomain):Long =
@@ -69,4 +71,4 @@ class MediaMapper(
6971
FLAG_LIVE_UPCOMING to domain.isLiveBroadcastUpcoming,
7072
FLAG_PLAY_FROM_START to domain.playFromStart
7173
)
72-
}
74+
}

database/src/commonMain/sqldelight/uk/co/sentinelweb/cuer/database/entity/MediaEntity.sq

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CREATE TABLE media (
1717
thumb_id TEXT,
1818
image_id TEXT,
1919
broadcast_date TEXT AS kotlinx.datetime.LocalDateTime DEFAULT NULL,
20+
length INTEGER,
2021
FOREIGN KEY (channel_id) REFERENCES channel(id)
2122
);
2223

@@ -34,7 +35,7 @@ CREATE INDEX media_description_index ON media(description);
3435

3536
create:
3637
INSERT INTO media ( id, flags, type, url, title, duration, position, date_last_played, description, platform, platform_id,
37-
published, channel_id, thumb_id, image_id, broadcast_date ) VALUES ?
38+
published, channel_id, thumb_id, image_id, broadcast_date, length ) VALUES ?
3839
--ON CONFLICT (platform, platform_id) DO NOTHING
3940
;
4041

@@ -43,7 +44,7 @@ published, channel_id, thumb_id, image_id, broadcast_date ) VALUES ?
4344

4445
update:
4546
REPLACE INTO media ( id, flags, type, url, title, duration, position, date_last_played, description, platform, platform_id,
46-
published, channel_id, thumb_id, image_id, broadcast_date ) VALUES ?
47+
published, channel_id, thumb_id, image_id, broadcast_date, length ) VALUES ?
4748
-- ON CONFLICT (platform, platform_id) DO NOTHING
4849
;
4950

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE media ADD COLUMN length INTEGER DEFAULT NULL;
-132 KB
Binary file not shown.

domain/src/androidUnitTest/kotlin/uk/co/sentinelweb/cuer/core/mappers/TimeSinceFormatterTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TimeSinceFormatterTest {
5353

5454
@Test
5555
fun formatTimeSince_months() {
56-
assertEquals("6mth", sut.formatTimeSince(baseTime - 1000L * 60 * 60 * 24 * 200))
56+
assertEquals("6mo", sut.formatTimeSince(baseTime - 1000L * 60 * 60 * 24 * 200))
5757
}
5858

5959
@Test
@@ -89,7 +89,7 @@ class TimeSinceFormatterTest {
8989

9090
@Test
9191
fun formatTimeShort_months() {
92-
assertEquals("6mth", sut.formatTimeShort(1000L * 60 * 60 * 24 * 200))
92+
assertEquals("6mo", sut.formatTimeShort(1000L * 60 * 60 * 24 * 200))
9393
}
9494

9595
@Test
@@ -102,4 +102,4 @@ class TimeSinceFormatterTest {
102102
assertEquals("--", sut.formatTimeShort(1000L * 60 * 60 * 24 * 365 * 21))
103103
}
104104

105-
}
105+
}

0 commit comments

Comments
 (0)