Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import uk.co.sentinelweb.cuer.app.ui.common.ktx.bindFlow
import uk.co.sentinelweb.cuer.app.ui.common.navigation.*
import uk.co.sentinelweb.cuer.app.ui.common.navigation.NavigationModel.Param.BACK_PARAMS
import uk.co.sentinelweb.cuer.app.ui.common.navigation.NavigationModel.Target.NAV_BACK
import uk.co.sentinelweb.cuer.app.ui.filebrowser.FilesContract.Label
import uk.co.sentinelweb.cuer.app.ui.filebrowser.FilesContract.Effect
import uk.co.sentinelweb.cuer.app.ui.play_control.CompactPlayerScroll
import uk.co.sentinelweb.cuer.app.ui.player.PlayerContract
import uk.co.sentinelweb.cuer.app.util.extension.fragmentScopeWithSource
Expand Down Expand Up @@ -90,18 +90,18 @@ class FileBrowserFragment : Fragment(), AndroidScopeComponent {
)
}
statusBarColor.setStatusBarColorResource(R.color.black)
bindFlow(viewModel.labels, ::observeLabels)
bindFlow(viewModel.effects, ::observeLabels)
remoteIdArg?.apply { viewModel.init(this, filePathArg) }
}

private fun observeLabels(label: Label) {
private fun observeLabels(label: Effect) {
when (label) {
Label.Init -> {}
Label.Up -> {
Effect.Init -> {}
Effect.Up -> {
navRouter.navigate(NavigationModel(NAV_BACK, mapOf(BACK_PARAMS to R.id.navigation_remotes)))
}

Label.Settings -> navigationProvider.navigate(R.id.navigation_settings_root)
Effect.Settings -> navigationProvider.navigate(R.id.navigation_settings_root)
else -> Unit
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ class FileBrowserFragment : Fragment(), AndroidScopeComponent {
scope(named<FileBrowserFragment>()) {
viewModel {
FilesViewModel(
state = FilesContract.State(),
initialState = FilesContract.State(),
filesInteractor = get(),
remotesRepository = get(),
mapper = get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class UpcomingVideosCheckWorker(
Result.failure()
}


companion object {
val WORK_NAME = "UpcomingVideosCheck"
val MINS_CHECK = 30
}
}
}
3 changes: 0 additions & 3 deletions database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
// kotlin("com.android.application")
id("com.squareup.sqldelight")
kotlin("plugin.serialization")
}

group = "uk.co.sentinelweb.cuer"
version = "1.0"

//val ver_jvm: String by project
val ver_coroutines: String by project
val ver_kotlinx_serialization_core: String by project
val ver_sqldelight: String by project
Expand All @@ -19,7 +17,6 @@ val ver_koin: String by project
val ver_turbine: String by project
val ver_kotlin_fixture: String by project
val ver_mockk: String by project

val ver_swift_tools: String by project
val ver_ios_deploy_target: String by project

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import org.koin.test.inject
import uk.co.sentinelweb.cuer.app.db.Database
import uk.co.sentinelweb.cuer.app.db.repository.ChannelDatabaseRepository
import uk.co.sentinelweb.cuer.app.db.repository.ConflictException
import uk.co.sentinelweb.cuer.app.db.repository.MediaDatabaseRepository
import uk.co.sentinelweb.cuer.app.db.repository.DbResult
import uk.co.sentinelweb.cuer.app.db.repository.MediaDatabaseRepository
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Filter.*
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Operation.DELETE
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Operation.FULL
Expand Down Expand Up @@ -148,6 +148,7 @@ class SqldelightMediaDatabaseRepositoryTest : KoinTest {
channelData = initialSaved.channelData,
thumbNail = initialSaved.thumbNail,
image = initialSaved.image,
length = initialSaved.length,
broadcastDate = null,
)
val updated = sut.save(changed, emit = true, flat = false).data!!
Expand Down Expand Up @@ -178,6 +179,7 @@ class SqldelightMediaDatabaseRepositoryTest : KoinTest {
),
thumbNail = media.thumbNail?.copy(id = saved[i].thumbNail?.id),
image = media.image?.copy(id = saved[i].image?.id),
length = media.length,
)
}

Expand Down Expand Up @@ -207,6 +209,7 @@ class SqldelightMediaDatabaseRepositoryTest : KoinTest {
thumbNail = it.thumbNail,
image = it.image,
broadcastDate = null,
length = it.length,
)
}
val updated = sut.save(changed, emit = true, flat = false).data!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,10 @@ class DatabaseFactory(
)
).apply {
log.d("Database.Schema.version ${Database.Schema.version} prefs.dbVersion ${prefs.dbVersion}")
// }.apply {
// Database.Schema.migrate(
// driver = driver,
// oldVersion = prefs.dbVersion,
// newVersion = Database.Schema.version,
// )
}.also {
prefs.dbVersion = Database.Schema.version
}.apply {
log.d("Database.Schema.version ${Database.Schema.version} prefs.dbVersion ${prefs.dbVersion}")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class MediaMapper(
isLiveBroadcast = entity.flags.hasFlag(FLAG_LIVE),
isLiveBroadcastUpcoming = entity.flags.hasFlag(FLAG_LIVE_UPCOMING),
playFromStart = entity.flags.hasFlag(FLAG_PLAY_FROM_START),
broadcastDate = entity.broadcast_date
broadcastDate = entity.broadcast_date,
length = entity.length
)

fun map(domain: MediaDomain): Media = Media(
Expand All @@ -58,7 +59,8 @@ class MediaMapper(
thumb_id = domain.thumbNail?.id?.id?.value,
image_id = domain.image?.id?.id?.value,
flags = mapFlags(domain),
broadcast_date = domain.broadcastDate
broadcast_date = domain.broadcastDate,
length = domain.length
)

private fun mapFlags(domain: MediaDomain):Long =
Expand All @@ -69,4 +71,4 @@ class MediaMapper(
FLAG_LIVE_UPCOMING to domain.isLiveBroadcastUpcoming,
FLAG_PLAY_FROM_START to domain.playFromStart
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE media (
thumb_id TEXT,
image_id TEXT,
broadcast_date TEXT AS kotlinx.datetime.LocalDateTime DEFAULT NULL,
length INTEGER,
FOREIGN KEY (channel_id) REFERENCES channel(id)
);

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE media ADD COLUMN length INTEGER;
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.co.sentinelweb.cuer.core.mappers

actual class FileSizeMapper {
actual fun formatFileSize(sizeBytes: Long): String =
formatFileSize(bytes = sizeBytes)
}

/**
* Formats file size in bytes to a human-readable string with appropriate unit (G, M, K).
* @param bytes The file size in bytes
* @param decimalPlaces Number of decimal places to include (default: 1)
* @return Formatted string representation of the file size
*/
fun formatFileSize(bytes: Long, decimalPlaces: Int = 1): String {
if (bytes <= 0) return "-"

val units = arrayOf("", "K", "M", "G", "T")
val digitGroups = (Math.log10(bytes.toDouble()) / Math.log10(1024.0)).toInt()

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

val format = if (decimalPlaces > 0) "%.${decimalPlaces}f %s" else "%.0f %s"

return String.format(
format,
bytes / Math.pow(1024.0, digitGroups.toDouble()),

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
units[digitGroups.coerceAtMost(units.size - 1)]
).trim()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package uk.co.sentinelweb.cuer.core.mappers

import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test

class FileSizeMapperTest {
private val sut = FileSizeMapper()

@Before
fun setUp() {

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

}

@Test
fun formatFileSize() {
assertEquals("1.0", sut.formatFileSize(1))
assertEquals("1.0 K", sut.formatFileSize(1024))

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
assertEquals("1.0 M", sut.formatFileSize(1024 * 1024))

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
assertEquals("1.0 G", sut.formatFileSize(1024 * 1024 * 1024))

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

@Test
fun formatTimeSince_months() {
assertEquals("6mth", sut.formatTimeSince(baseTime - 1000L * 60 * 60 * 24 * 200))
assertEquals("6mo", sut.formatTimeSince(baseTime - 1000L * 60 * 60 * 24 * 200))

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
}

@Test
Expand Down Expand Up @@ -89,7 +89,7 @@

@Test
fun formatTimeShort_months() {
assertEquals("6mth", sut.formatTimeShort(1000L * 60 * 60 * 24 * 200))
assertEquals("6mo", sut.formatTimeShort(1000L * 60 * 60 * 24 * 200))

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
}

@Test
Expand All @@ -102,4 +102,4 @@
assertEquals("--", sut.formatTimeShort(1000L * 60 * 60 * 24 * 365 * 21))
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ expect class DateTimeFormatter() {
fun formatDateTimeNullable(dateTime: LocalDateTime?): String
}

expect class FileSizeMapper {
fun formatFileSize(sizeBytes: Long): String
}

fun String.strip00() = this.let {
var formatted = it
while (formatted.startsWith("00:")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TimeSinceFormatter(
differenceSeconds < SEC_TO_HOURS -> "${differenceSeconds / SEC_TO_MIN}m"
differenceSeconds < SEC_TO_DAYS -> "${differenceSeconds / SEC_TO_HOURS}h"
differenceSeconds < SEC_TO_MONTHS -> "${differenceSeconds / SEC_TO_DAYS}d"
differenceSeconds < SEC_TO_YEARS -> "${differenceSeconds / SEC_TO_MONTHS}mth"
differenceSeconds < SEC_TO_YEARS -> "${differenceSeconds / SEC_TO_MONTHS}mo"
differenceSeconds < SEC_TO_YEARS * 20 -> "${differenceSeconds / SEC_TO_YEARS}y"
else -> "--"
}
Expand All @@ -37,7 +37,7 @@ class TimeSinceFormatter(
positiveSeconds < SEC_TO_HOURS -> "$sign${positiveSeconds / SEC_TO_MIN}m"
positiveSeconds < SEC_TO_DAYS -> "$sign${positiveSeconds / SEC_TO_HOURS}h"
positiveSeconds < SEC_TO_MONTHS -> "$sign${positiveSeconds / SEC_TO_DAYS}d"
positiveSeconds < SEC_TO_YEARS -> "$sign${positiveSeconds / SEC_TO_MONTHS}mth"
positiveSeconds < SEC_TO_YEARS -> "$sign${positiveSeconds / SEC_TO_MONTHS}mo"
positiveSeconds < SEC_TO_YEARS * 20 -> "$sign${positiveSeconds / SEC_TO_YEARS}y"
else -> "--"
}
Expand All @@ -50,4 +50,4 @@ class TimeSinceFormatter(
private val SEC_TO_MONTHS = 60 * 60 * 24 * 30
private val SEC_TO_YEARS = 60 * 60 * 24 * 365
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package uk.co.sentinelweb.cuer.di

import org.koin.dsl.module
import uk.co.sentinelweb.cuer.core.mappers.DateTimeFormatter
import uk.co.sentinelweb.cuer.core.mappers.FileSizeMapper
import uk.co.sentinelweb.cuer.core.mappers.TimeFormatter
import uk.co.sentinelweb.cuer.core.mappers.TimeSinceFormatter
import uk.co.sentinelweb.cuer.core.providers.CoroutineContextProvider
Expand All @@ -18,6 +19,7 @@ object DomainModule {
factory<TimeProvider> { TimeProviderImpl() }
factory { TimeSinceFormatter(get(), get()) }
factory { TimeFormatter() }
factory<FileSizeMapper> { FileSizeMapper() }
factory { DateTimeFormatter() }
}

Expand All @@ -29,4 +31,4 @@ object DomainModule {
}

val allModules = listOf(coreModule, domainModule)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data class MediaDomain(
val isLiveBroadcastUpcoming: Boolean = false,
val playFromStart: Boolean = false,
@Contextual val broadcastDate: LocalDateTime? = null, // todo https://github.com/sentinelweb/cuer/issues/196
val length: Long? = null,
) : Domain {

enum class MediaTypeDomain {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package uk.co.sentinelweb.cuer.core.mappers

actual class FileSizeMapper {
actual fun formatFileSize(sizeBytes: Long): String {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package uk.co.sentinelweb.cuer.core.mappers

actual class FileSizeMapper {
actual fun formatFileSize(sizeBytes: Long): String {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.co.sentinelweb.cuer.core.mappers

@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
actual class FileSizeMapper {
actual fun formatFileSize(sizeBytes: Long): String =
formatFileSize(bytes = sizeBytes)
}

/**
* Formats file size in bytes to a human-readable string with appropriate unit (G, M, K).
* @param bytes The file size in bytes
* @param decimalPlaces Number of decimal places to include (default: 1)
* @return Formatted string representation of the file size
*/
fun formatFileSize(bytes: Long, decimalPlaces: Int = 1): String {
if (bytes <= 0) return "0"

val units = arrayOf("", "K", "M", "G", "T")
val digitGroups = (Math.log10(bytes.toDouble()) / Math.log10(1024.0)).toInt()

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

val format = if (decimalPlaces > 0) "%.${decimalPlaces}f %s" else "%.0f %s"

return String.format(
format,
bytes / Math.pow(1024.0, digitGroups.toDouble()),

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
units[digitGroups.coerceAtMost(units.size - 1)]
).trim()
}
Loading
Loading