Skip to content

Commit

Permalink
prepare bs connection
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 10, 2024
1 parent de0e775 commit 9a1d42f
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class App : MultiDexApplication(), DIAware {
StrictMode.ThreadPolicy.Builder()
.detectAll()
.permitDiskReads()
.permitDiskWrites()
.penaltyLog()
.penaltyDialog()
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import androidx.core.database.getStringOrNull
import dev.datlag.tooling.scopeCatching
import io.github.aakira.napier.Napier

Expand Down Expand Up @@ -69,8 +70,9 @@ actual class BurningSeriesResolver(
progress = progress,
length = length,
number = number,
series = Episode.Series(
title = seriesHref
series = Series(
title = seriesHref,
href = seriesHref
)
)
)
Expand All @@ -83,12 +85,12 @@ actual class BurningSeriesResolver(
return episodes
}

actual fun resolveByName(english: String?, romaji: String?) {
actual fun resolveByName(english: String?, romaji: String?): Set<Series> {
val englishTrimmed = english?.trim()?.ifBlank { null }?.replace("'", "")
val romajiTrimmed = romaji?.trim()?.ifBlank { null }?.replace("'", "")

if (seriesClient == null || (englishTrimmed == null && romajiTrimmed == null)) {
return
return emptySet()
}

val selection = if (englishTrimmed != null && romajiTrimmed != null) {
Expand All @@ -104,26 +106,36 @@ actual class BurningSeriesResolver(
selection,
null,
null
) ?: return
) ?: return emptySet()

val series = mutableSetOf<Series>()

if (seriesCursor.moveToFirst()) {
while (!seriesCursor.isAfterLast) {
val titleIndex = seriesCursor.getColumnIndex("title")
val hrefIndex = seriesCursor.getColumnIndex("hrefPrimary")

if (titleIndex == -1) {
if (hrefIndex == -1) {
seriesCursor.moveToNext()
continue
}

val title = seriesCursor.getString(titleIndex)
Napier.e("Series matching name: $title")
val title = seriesCursor.getStringOrNull(titleIndex)
val href = seriesCursor.getString(hrefIndex)

series.add(
Series(
title = title ?: href,
href = href
)
)

seriesCursor.moveToNext()
}
}

seriesCursor.close()
return
return series
}

actual fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.datlag.aniflow.other
expect class BurningSeriesResolver {
val isAvailable: Boolean
fun resolveWatchedEpisodes(): Set<Episode>
fun resolveByName(english: String?, romaji: String?)
fun resolveByName(english: String?, romaji: String?): Set<Series>

fun close()
}
Expand All @@ -13,8 +13,9 @@ data class Episode(
val length: Long,
val number: String,
val series: Series
) {
data class Series(
val title: String
)
}
)

data class Series(
val title: String,
val href: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ 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.datlag.tooling.compose.withDefaultContext
import dev.datlag.tooling.compose.withIOContext
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.delay

@Composable
fun EditFAB(
Expand All @@ -35,25 +38,24 @@ fun EditFAB(
horizontalAlignment = Alignment.End,
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)
) {
var showOtherFABs by remember { mutableStateOf(false) }
var showOtherFABs by remember(expanded) { mutableStateOf(expanded) }

AnimatedVisibility(
visible = showOtherFABs,
enter = scaleIn(
enter = slideInVertically(
animationSpec = bouncySpring(),
transformOrigin = TransformOrigin(1F, 0.5F)
initialOffsetY = { -(-it / 2) }
) + fadeIn(
animationSpec = bouncySpring()
),
exit = scaleOut(
transformOrigin = TransformOrigin(1F, 0.5F)
exit = slideOutVertically(
animationSpec = bouncySpring(),
targetOffsetY = { -(-it / 2) }
) + fadeOut(
animationSpec = bouncySpring()
)
) {
LabelFAB(
label = "Progress",
expanded = expanded,
onClick = {
showOtherFABs = false
onProgress()
Expand All @@ -67,21 +69,20 @@ fun EditFAB(
}
AnimatedVisibility(
visible = showOtherFABs,
enter = scaleIn(
enter = slideInVertically(
animationSpec = bouncySpring(),
transformOrigin = TransformOrigin(1F, 0.5F)
initialOffsetY = { -(-it / 2) }
) + fadeIn(
animationSpec = bouncySpring()
),
exit = scaleOut(
transformOrigin = TransformOrigin(1F, 0.5F)
exit = slideOutVertically(
animationSpec = bouncySpring(),
targetOffsetY = { -(-it / 2) }
) + fadeOut(
animationSpec = bouncySpring()
)
) {
LabelFAB(
label = "Rating",
expanded = expanded,
onClick = {
showOtherFABs = false
onRate()
Expand All @@ -95,21 +96,20 @@ fun EditFAB(
}
AnimatedVisibility(
visible = showOtherFABs && bsAvailable,
enter = scaleIn(
enter = slideInVertically(
animationSpec = bouncySpring(),
transformOrigin = TransformOrigin(1F, 0.5F)
initialOffsetY = { -(-it / 2) }
) + fadeIn(
animationSpec = bouncySpring()
),
exit = scaleOut(
transformOrigin = TransformOrigin(1F, 0.5F)
exit = slideOutVertically(
animationSpec = bouncySpring(),
targetOffsetY = { -(-it / 2) }
) + fadeOut(
animationSpec = bouncySpring()
)
) {
LabelFAB(
label = stringResource(SharedRes.strings.bs),
expanded = expanded,
onClick = {
showOtherFABs = false
onBS()
Expand Down Expand Up @@ -156,41 +156,34 @@ fun EditFAB(

@Composable
private fun LabelFAB(
label: String,
expanded: Boolean,
onClick: () -> Unit,
icon: @Composable () -> Unit
) {
var showLabel by remember { mutableStateOf(false) }

LaunchedEffect(showLabel) {
if (!showLabel) {
showLabel = true
}
}

Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
AnimatedVisibility(
visible = expanded,
enter = fadeIn(),
exit = fadeOut()
) {
Surface(
onClick = onClick,
tonalElevation = 8.dp,
shadowElevation = 4.dp,
shape = RoundedCornerShape(4.dp)
) {
Text(
modifier = Modifier.padding(4.dp),
text = label,
maxLines = 1
)
}
}

SmallFloatingActionButton(
modifier = Modifier.padding(end = 4.dp),
onClick = onClick
) {
icon()
}
}

DisposableEffect(showLabel) {
onDispose {
showLabel = false
}
}
}

private fun <T> bouncySpring() = spring<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ fun ScheduleOverview(
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.weight(1f))
IconButton(
onClick = onMoreClick,
enabled = state is AiringTodayRepository.State.Success
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowForwardIos,
contentDescription = null
)
}
}

when (val current = state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dev.datlag.aniflow.anilist.model.Character
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.anilist.type.MediaFormat
import dev.datlag.aniflow.anilist.type.MediaStatus
import dev.datlag.aniflow.other.Series
import dev.datlag.aniflow.settings.model.AppSettings
import dev.datlag.aniflow.ui.navigation.Component
import dev.datlag.aniflow.ui.navigation.ContentHolderComponent
Expand Down Expand Up @@ -50,6 +51,7 @@ interface MediumComponent : ContentHolderComponent {
val siteUrl: Flow<String>

val bsAvailable: Boolean
val bsOptions: Flow<Collection<Series>>

val dialog: Value<ChildSlot<DialogConfig, DialogComponent>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import com.arkivanov.decompose.extensions.compose.subscribeAsState
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.IconSource
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.maxkeppeler.sheets.option.OptionDialog
import com.maxkeppeler.sheets.option.models.DisplayMode
import com.maxkeppeler.sheets.option.models.Option
import com.maxkeppeler.sheets.option.models.OptionConfig
import com.maxkeppeler.sheets.option.models.OptionSelection
import com.maxkeppeler.sheets.rating.RatingDialog
import com.maxkeppeler.sheets.rating.models.RatingBody
import com.maxkeppeler.sheets.rating.models.RatingConfig
Expand All @@ -40,6 +45,8 @@ import dev.datlag.aniflow.other.UserHelper
import dev.datlag.aniflow.ui.custom.EditFAB
import dev.datlag.aniflow.ui.navigation.screen.medium.component.*
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import dev.icerock.moko.resources.compose.painterResource
import io.github.aakira.napier.Napier
import kotlinx.coroutines.launch
import org.kodein.di.instance

Expand Down Expand Up @@ -87,6 +94,9 @@ fun MediumScreen(component: MediumComponent) {
floatingActionButton = {
val userRating by component.rating.collectAsStateWithLifecycle(-1)
val ratingState = rememberUseCaseState()
val bsState = rememberUseCaseState()

val bsOptions by component.bsOptions.collectAsStateWithLifecycle(emptySet())

val alreadyAdded by component.alreadyAdded.collectAsStateWithLifecycle(
component.initialMedium.entry != null
Expand Down Expand Up @@ -116,6 +126,29 @@ fun MediumScreen(component: MediumComponent) {
)
)

OptionDialog(
state = bsState,
selection = OptionSelection.Single(
options = bsOptions.map {
Option(
titleText = it.title
)
},
onSelectOption = { option, _ ->
Napier.e("Selected: ${bsOptions.toList()[option]}")
}
),
header = Header.Default(
icon = IconSource(
painter = painterResource(SharedRes.images.bs)
),
title = "Connect with BS"
),
config = OptionConfig(
mode = DisplayMode.LIST
)
)

if (!notReleased) {
val uriHandler = LocalUriHandler.current
val userHelper by LocalDI.current.instance<UserHelper>()
Expand All @@ -125,7 +158,7 @@ fun MediumScreen(component: MediumComponent) {
bsAvailable = component.bsAvailable,
expanded = listState.isScrollingUp(),
onBS = {

bsState.show()
},
onRate = {
uriHandler.openUri(userHelper.loginUrl)
Expand Down
Loading

0 comments on commit 9a1d42f

Please sign in to comment.