Skip to content

Commit

Permalink
display bs to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 21, 2024
1 parent eb2701a commit aefeea5
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@ package dev.datlag.aniflow.other
import android.content.ContentProviderClient
import android.content.ContentResolver
import android.content.Context
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import dev.datlag.tooling.scopeCatching
import io.github.aakira.napier.Napier

actual class BurningSeriesResolver(
private val packageManager: PackageManager,
private val episodeClient: ContentProviderClient?,
private val seriesClient: ContentProviderClient?
) {

constructor(contentResolver: ContentResolver) : this(
constructor(packageManager: PackageManager, contentResolver: ContentResolver) : this(
packageManager = packageManager,
episodeClient = contentResolver.acquireContentProviderClient(episodesContentUri),
seriesClient = contentResolver.acquireContentProviderClient(seriesContentUri)
)

constructor(context: Context) : this(context.contentResolver)
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))
} else {
packageManager.getApplicationInfo(packageName, 0)
}
true
}.getOrNull() ?: false

actual fun resolveWatchedEpisodes(): Set<Episode> {
if (episodeClient == null) {
Expand Down Expand Up @@ -118,6 +132,7 @@ actual class BurningSeriesResolver(
}

companion object {
val packageName = "dev.datlag.burningseries"
val seriesContentUri = Uri.parse("content://dev.datlag.burningseries.provider/series")
val episodesContentUri = Uri.parse("content://dev.datlag.burningseries.provider/episodes")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.datlag.aniflow.other

expect class BurningSeriesResolver {
val isAvailable: Boolean
fun resolveWatchedEpisodes(): Set<Episode>
fun resolveByName(english: String?, romaji: String?)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package dev.datlag.aniflow.ui.custom
import androidx.compose.animation.*
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
Expand All @@ -17,12 +15,18 @@ import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.unit.dp
import dev.datlag.aniflow.SharedRes
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource

@Composable
fun EditFAB(
displayAdd: Boolean = false,
bsAvailable: Boolean = false,
onBS: () -> Unit,
onRate: () -> Unit,
onProgress: () -> Unit
) {
Expand Down Expand Up @@ -86,6 +90,35 @@ fun EditFAB(
)
}
}
AnimatedVisibility(
visible = showOtherFABs && bsAvailable,
enter = scaleIn(
animationSpec = bouncySpring(),
transformOrigin = TransformOrigin(1F, 0.5F)
) + fadeIn(
animationSpec = bouncySpring()
),
exit = scaleOut(
transformOrigin = TransformOrigin(1F, 0.5F)
) + fadeOut(
animationSpec = bouncySpring()
)
) {
LabelFAB(
label = stringResource(SharedRes.strings.bs),
onClick = {
showOtherFABs = false
onBS()
}
) {
Image(
modifier = Modifier.size(24.dp),
painter = painterResource(SharedRes.images.bs),
contentDescription = stringResource(SharedRes.strings.bs),
colorFilter = ColorFilter.tint(LocalContentColor.current)
)
}
}

FloatingActionButton(
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface MediumComponent : ContentHolderComponent {
val alreadyAdded: StateFlow<Boolean>
val trailer: StateFlow<Medium.Full.Trailer?>

val bsAvailable: Boolean

fun back()
override fun dismissContent() {
back()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ fun MediumScreen(component: MediumComponent) {
if (!notReleased) {
EditFAB(
displayAdd = !alreadyAdded,
bsAvailable = component.bsAvailable,
onBS = {

},
onRate = {
component.rate {
ratingState.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ class MediumScreenComponent(
private val characterStateMachine by di.instance<CharacterStateMachine>()
private val burningSeriesResolver by di.instance<BurningSeriesResolver>()

override val bsAvailable: Boolean
get() = burningSeriesResolver.isAvailable

init {
launchIO {
title.mapNotNull { it.english to it.romaji }.collect { (english, romaji) ->
Expand Down
1 change: 1 addition & 0 deletions composeApp/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
<string name="score">Score</string>
<string name="translate">Translate</string>
<string name="description">Description</string>
<string name="bs">Burning-Series</string>
</resources>
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/moko-resources/images/bs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package dev.datlag.aniflow.other

actual class BurningSeriesResolver {

actual val isAvailable: Boolean
get() = false

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

0 comments on commit aefeea5

Please sign in to comment.