Skip to content

Commit

Permalink
added bs info
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 25, 2024
1 parent f9d7675 commit 6402213
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ fun <V> Optional.Companion.presentIfNot(predicate: Boolean, value: V) = if (pred
present(value)
}

fun <V> Optional.Companion.presentAsList(vararg value: V) = present(persistentListOf(*value))
fun <V> Optional.Companion.presentAsList(vararg value: V) = if (value.isEmpty()) {
absent()
} else {
present(persistentListOf(*value))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.datlag.aniflow.other
import android.content.ContentProviderClient
import android.content.ContentResolver
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
Expand All @@ -26,15 +27,28 @@ actual class BurningSeriesResolver(

constructor(context: Context) : this(context.packageManager, context.contentResolver)

actual val isAvailable: Boolean
get() = scopeCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getApplicationInfo(packageName, PackageManager.ApplicationInfoFlags.of(0))
private val packageInfo: PackageInfo? = scopeCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
} else {
packageManager.getPackageInfo(packageName, 0)
}
}.getOrNull()

@Suppress("DEPRECATION")
actual val versionCode: Int
get() {
return (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo?.longVersionCode?.toInt() ?: packageInfo?.versionCode
} else {
packageManager.getApplicationInfo(packageName, 0)
}
true
}.getOrNull() ?: false
packageInfo?.versionCode
}) ?: -1
}

actual val versionName: String? = packageInfo?.versionName?.ifBlank { null }

actual val isAvailable: Boolean
get() = packageInfo != null

actual fun resolveWatchedEpisodes(): ImmutableSet<Episode> {
if (episodeClient == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import kotlinx.collections.immutable.ImmutableSet

expect class BurningSeriesResolver {
val isAvailable: Boolean
val versionCode: Int
val versionName: String?

fun resolveWatchedEpisodes(): ImmutableSet<Episode>
fun resolveByName(english: String?, romaji: String?): ImmutableSet<Series>
fun resolveByName(value: String): ImmutableSet<Series>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.material.icons.automirrored.filled.MenuBook
import androidx.compose.material.icons.automirrored.rounded.MenuBook
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.PlayCircleFilled
import androidx.compose.material.icons.rounded.PlayCircleFilled
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -154,7 +155,7 @@ fun CollapsingToolbar(
enabled = isManga
) {
Icon(
imageVector = Icons.Filled.PlayCircleFilled,
imageVector = Icons.Rounded.PlayCircleFilled,
contentDescription = null,
tint = if (isManga) {
LocalContentColor.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ interface MediumComponent : ContentHolderComponent {
val dialog: Value<ChildSlot<DialogConfig, DialogComponent>>

val bsAvailable: Boolean
val bsVersionCode: Int
val bsVersionName: String?
val bsOptions: Flow<ImmutableCollection<Series>>

fun back()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ class MediumScreenComponent(
override val bsAvailable: Boolean
get() = burningSeriesResolver.isAvailable

override val bsVersionCode: Int
get() = burningSeriesResolver.versionCode

override val bsVersionName: String?
get() = burningSeriesResolver.versionName

@OptIn(ExperimentalCoroutinesApi::class)
private val bsDefaultOptions = title.mapLatest {
burningSeriesResolver.resolveByName(it.english, it.romaji)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.datlag.aniflow.ui.navigation.screen.medium.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.*
Expand All @@ -26,6 +28,8 @@ import kotlinx.coroutines.flow.StateFlow
@Composable
fun BSDialog(
state: UseCaseState,
bsVersionCode: Int,
bsVersionName: String?,
bsOptions: ImmutableCollection<Series>,
onSearch: suspend (String) -> Unit
) {
Expand Down Expand Up @@ -58,20 +62,28 @@ fun BSDialog(
onSearch(value)
}

OutlinedTextField(
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp),
value = value,
onValueChange = { value = it },
placeholder = {
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(SharedRes.strings.search),
textAlign = TextAlign.Center
)
},
shape = MaterialTheme.shapes.medium,
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center)
)
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = value,
onValueChange = { value = it },
placeholder = {
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(SharedRes.strings.search),
textAlign = TextAlign.Center
)
},
shape = MaterialTheme.shapes.medium,
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center)
)
if (bsVersionCode < 600) {
Text(text = stringResource(SharedRes.strings.bs_version_requirement))
}
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ fun FABContent(

BSDialog(
state = bsState,
bsVersionCode = component.bsVersionCode,
bsVersionName = component.bsVersionName,
bsOptions = bsOptions,
onSearch = component::searchBS
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayCircleFilled
import androidx.compose.material.icons.rounded.PlayCircleFilled
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -76,7 +77,7 @@ fun TrailerSection(
} else {
Icon(
modifier = Modifier.size(48.dp),
imageVector = Icons.Filled.PlayCircleFilled,
imageVector = Icons.Rounded.PlayCircleFilled,
contentDescription = null
)
}
Expand Down
3 changes: 1 addition & 2 deletions composeApp/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@
<string name="read_chapter">Read Chapter</string>
<string name="search_anime">Search Anime</string>
<string name="search_manga">Search Manga</string>
<string name="top_100">Top 100</string>
<string name="top_movies">Top Movies</string>
<string name="spring">Spring</string>
<string name="summer">Summer</string>
<string name="fall">Fall</string>
<string name="winter">Winter</string>
<string name="recommendation">Recommendation</string>
<string name="bs_version_requirement">This feature will be supported with Burning-Series version 6.0.0 and upwards.</string>
</resources>
6 changes: 6 additions & 0 deletions composeApp/src/commonMain/moko-resources/de-DE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@
<string name="read_chapter">Gelesenes Kapitel</string>
<string name="search_anime">Anime suchen</string>
<string name="search_manga">Manga suchen</string>
<string name="spring">Frühling</string>
<string name="summer">Sommer</string>
<string name="fall">Herbst</string>
<string name="winter">Winter</string>
<string name="recommendation">Empfehlung</string>
<string name="bs_version_requirement">Diese Option wird mit Burning-Series Version 6.0.0 und höher unterstützt.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ actual class BurningSeriesResolver {
actual val isAvailable: Boolean
get() = false

actual val versionCode: Int = -1
actual val versionName: String? = null

actual fun resolveWatchedEpisodes(): ImmutableSet<Episode> {
// ToDo("Check if something like content provider exists")
return persistentSetOf()
Expand Down

0 comments on commit 6402213

Please sign in to comment.