-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added tests to ModelsViewModel
- Loading branch information
Showing
26 changed files
with
1,228 additions
and
503 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
60 changes: 60 additions & 0 deletions
60
composeApp/src/commonMain/kotlin/org/cyanotic/olpaka/core/DownloadStatsCalculator.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,60 @@ | ||
package org.cyanotic.olpaka.core | ||
|
||
import kotlinx.datetime.Clock | ||
|
||
interface DownloadStatsCalculator { | ||
|
||
fun calculateDownloadSpeed( | ||
downloadedBytes: Long, | ||
previousBytesDownloaded: Long, | ||
previousUpdateTime: Long | ||
): Long? | ||
|
||
fun calculateRemainingTime( | ||
totalBytes: Long, | ||
downloadedBytes: Long, | ||
previousBytesDownloaded: Long, | ||
previousUpdateTime: Long | ||
): Long? | ||
} | ||
|
||
class DownloadStatsCalculatorDefault : DownloadStatsCalculator { | ||
|
||
override fun calculateDownloadSpeed( | ||
downloadedBytes: Long, | ||
previousBytesDownloaded: Long, | ||
previousUpdateTime: Long | ||
): Long? { | ||
val timeElapsed = Clock.System.now().toEpochMilliseconds() - previousUpdateTime | ||
if (timeElapsed == 0L || downloadedBytes == previousBytesDownloaded) { | ||
return null | ||
} | ||
|
||
val speedBytesPerMillisecond = (downloadedBytes - previousBytesDownloaded) / timeElapsed | ||
return speedBytesPerMillisecond * 1000 | ||
} | ||
|
||
override fun calculateRemainingTime( | ||
totalBytes: Long, | ||
downloadedBytes: Long, | ||
previousBytesDownloaded: Long, | ||
previousUpdateTime: Long | ||
): Long? { | ||
|
||
val timeElapsed = Clock.System.now().toEpochMilliseconds() - previousUpdateTime | ||
if (timeElapsed == 0L || downloadedBytes == previousBytesDownloaded) { | ||
return null | ||
} | ||
|
||
val speedBytesPerMillisecond = (downloadedBytes - previousBytesDownloaded) / timeElapsed | ||
val speedBytesPerSecond = speedBytesPerMillisecond * 1000 | ||
|
||
val remainingBytes = totalBytes - downloadedBytes | ||
if(speedBytesPerSecond == 0L){ | ||
return null | ||
} | ||
val timeLeftSeconds = remainingBytes / speedBytesPerSecond | ||
return timeLeftSeconds | ||
} | ||
|
||
} |
32 changes: 0 additions & 32 deletions
32
composeApp/src/commonMain/kotlin/org/cyanotic/olpaka/core/ModelDownloadState.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
composeApp/src/commonMain/kotlin/org/cyanotic/olpaka/core/OlpakaAntilog.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,23 @@ | ||
package org.cyanotic.olpaka.core | ||
|
||
import io.github.aakira.napier.Antilog | ||
import io.github.aakira.napier.DebugAntilog | ||
import io.github.aakira.napier.LogLevel | ||
|
||
class OlpakaAntilog : Antilog() { | ||
|
||
private val logger = DebugAntilog() | ||
var currentLevel = LogLevel.INFO | ||
|
||
override fun performLog( | ||
priority: LogLevel, | ||
tag: String?, | ||
throwable: Throwable?, | ||
message: String? | ||
) { | ||
if(priority.ordinal >= currentLevel.ordinal){ | ||
logger.log(priority, tag, throwable, message) | ||
} | ||
} | ||
|
||
} |
27 changes: 0 additions & 27 deletions
27
composeApp/src/commonMain/kotlin/org/cyanotic/olpaka/core/Utils.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.