mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Sort & format subtitle download options (#88)
Sorts the subtitle download options by community rating and downloads. Also abbreviates the download count if it's large (eg 5133->5.1k).
This commit is contained in:
parent
af0e853c21
commit
1db48334ab
3 changed files with 32 additions and 5 deletions
|
|
@ -42,6 +42,7 @@ import com.github.damontecres.wholphin.ui.components.EditTextBox
|
||||||
import com.github.damontecres.wholphin.ui.components.ErrorMessage
|
import com.github.damontecres.wholphin.ui.components.ErrorMessage
|
||||||
import com.github.damontecres.wholphin.ui.ifElse
|
import com.github.damontecres.wholphin.ui.ifElse
|
||||||
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
||||||
|
import com.github.damontecres.wholphin.util.abbreviateNumber
|
||||||
import org.jellyfin.sdk.model.api.RemoteSubtitleInfo
|
import org.jellyfin.sdk.model.api.RemoteSubtitleInfo
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -200,7 +201,7 @@ fun convertRemoteSubtitles(
|
||||||
if (op.forced == true) {
|
if (op.forced == true) {
|
||||||
add("Forced")
|
add("Forced")
|
||||||
}
|
}
|
||||||
add("${op.downloadCount ?: 0} downloads")
|
add("${abbreviateNumber(op.downloadCount ?: 0)} downloads")
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = strings.joinToString(" - "),
|
text = strings.joinToString(" - "),
|
||||||
|
|
|
||||||
|
|
@ -836,10 +836,17 @@ class PlaybackViewModel
|
||||||
try {
|
try {
|
||||||
currentItemPlayback.value?.itemId?.let {
|
currentItemPlayback.value?.itemId?.let {
|
||||||
Timber.v("Searching for remote subtitles for %s", it)
|
Timber.v("Searching for remote subtitles for %s", it)
|
||||||
val results by api.subtitleApi.searchRemoteSubtitles(
|
val results =
|
||||||
itemId = it,
|
api.subtitleApi
|
||||||
language = language,
|
.searchRemoteSubtitles(
|
||||||
)
|
itemId = it,
|
||||||
|
language = language,
|
||||||
|
).content
|
||||||
|
.sortedWith(
|
||||||
|
compareByDescending<RemoteSubtitleInfo> { it.communityRating }
|
||||||
|
.thenByDescending { it.downloadCount },
|
||||||
|
)
|
||||||
|
|
||||||
subtitleSearch.setValueOnMain(SubtitleSearch.Success(results))
|
subtitleSearch.setValueOnMain(SubtitleSearch.Success(results))
|
||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import org.jellyfin.sdk.model.api.MediaStream
|
||||||
import org.jellyfin.sdk.model.api.MediaStreamType
|
import org.jellyfin.sdk.model.api.MediaStreamType
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a [LocalDateTime] as `Aug 24, 2000`
|
* Format a [LocalDateTime] as `Aug 24, 2000`
|
||||||
|
|
@ -108,3 +109,21 @@ fun getSubtitleDisplay(
|
||||||
formatSubtitleLang(it.mediaStreams)
|
formatSubtitleLang(it.mediaStreams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val abbrevSuffixes = listOf("", "K", "M", "B")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a number by abbreviation, eg 5533 => 5.5K
|
||||||
|
*/
|
||||||
|
fun abbreviateNumber(number: Int): String {
|
||||||
|
if (number < 1000) {
|
||||||
|
return number.toString()
|
||||||
|
}
|
||||||
|
var unit = 0
|
||||||
|
var count = number.toDouble()
|
||||||
|
while (count >= 1000 && unit + 1 < abbrevSuffixes.size) {
|
||||||
|
count /= 1000
|
||||||
|
unit++
|
||||||
|
}
|
||||||
|
return String.format(Locale.getDefault(), "%.1f%s", count, abbrevSuffixes[unit])
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue