Skip to content

Commit

Permalink
added sponsor screen
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Mar 16, 2024
1 parent f63a30f commit 86c15b3
Show file tree
Hide file tree
Showing 26 changed files with 514 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.datlag.burningseries.shared.common

import android.content.Context
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.ui.Modifier
Expand All @@ -12,6 +13,8 @@ import com.arkivanov.decompose.extensions.compose.stack.animation.predictiveback
import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimation
import com.arkivanov.essenty.backhandler.BackHandler
import com.vanniktech.blurhash.BlurHash
import org.kodein.di.DI
import org.kodein.di.instance
import com.vanniktech.blurhash.BlurHash.decode as defaultDecode

@OptIn(ExperimentalFoundationApi::class)
Expand Down Expand Up @@ -42,4 +45,10 @@ actual fun <C : Any, T : Any> backAnimation(
actual fun BlurHash.decode(hash: String, width: Int, height: Int): ImageBitmap? {
val bitmap = defaultDecode(hash, width, height)
return bitmap?.asImageBitmap()
}

actual fun String.openInBrowser(di: DI) {
val context by di.instance<Context>()

this.openInBrowser(context)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.datlag.burningseries.shared.ui.custom

import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import dev.datlag.burningseries.shared.common.isPackageInstalled
import dev.datlag.burningseries.shared.common.openInBrowser
import dev.datlag.burningseries.shared.other.Project
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource

@Composable
actual fun ProjectCard(project: Project, modifier: Modifier) {
val context = LocalContext.current

if (context.isPackageInstalled(project.`package`)) {
Card(
modifier = modifier,
onClick = {
(project.googlePlay ?: project.github)?.openInBrowser(context)
}
) {
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
project.icon?.let {
Image(
modifier = Modifier.size(64.dp),
painter = painterResource(it),
contentDescription = stringResource(project.title)
)
}
Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
text = stringResource(project.title),
fontWeight = FontWeight.Bold,
style = MaterialTheme.typography.titleLarge
)
Text(text = stringResource(project.subTitle))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,8 @@ actual fun LazyGridScope.DeviceContent(release: StateFlow<Release?>, onDeviceRea
Text(text = stringResource(SharedRes.strings.github))
}
}
} else {
val context = LocalContext.current

if (!context.isPackageInstalled(Constants.PULZ_PACKAGE)) {
Card(
modifier = Modifier.padding(top = 16.dp).fillMaxWidth(),
onClick = {
Constants.GOOGLE_PLAY_PULZ.openInBrowser(context)
},
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary,
)
) {
Row(
modifier = Modifier.fillMaxWidth().padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
modifier = Modifier.weight(1F),
text = stringResource(SharedRes.strings.google_play_pulz)
)
FilledTonalButton(
onClick = {
Constants.GOOGLE_PLAY_PULZ.openInBrowser(context)
}
) {
Text(text = stringResource(SharedRes.strings.yes))
}
}
}
} else if (!reachable) {
Text(text = stringResource(SharedRes.strings.enable_custom_dns))
}
} else if (!reachable) {
Text(text = stringResource(SharedRes.strings.enable_custom_dns))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
Expand All @@ -28,6 +30,7 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.*
import dev.datlag.burningseries.model.common.collectSafe
import dev.datlag.burningseries.shared.LocalDarkMode
import dev.datlag.burningseries.shared.LocalPaddingValues
import dev.datlag.burningseries.shared.ui.theme.shape.DiagonalShape
import kotlin.math.max
Expand Down Expand Up @@ -285,3 +288,49 @@ fun Modifier.bottomShadowBrush(color: Color, alpha: Float = 1F): Modifier {
)
)
}

@Composable
fun ButtonDefaults.githubColors(): ButtonColors {
return if (LocalDarkMode.current) {
ButtonDefaults.buttonColors(
containerColor = Color.White,
contentColor = Color(0xFF121212)
)
} else {
ButtonDefaults.buttonColors(
containerColor = Color.Black,
contentColor = Color(0xFFFAFAFA)
)
}
}

@Composable
fun ButtonDefaults.polarColors(): ButtonColors {
return ButtonDefaults.buttonColors(
containerColor = Color(0xFF0062FF),
contentColor = Color(0xFFFAFAFA)
)
}

@Composable
fun ButtonDefaults.patreonColors(): ButtonColors {
return ButtonDefaults.buttonColors(
containerColor = Color(0xFFF96854),
contentColor = Color(0xFFFAFAFA)
)
}

@Composable
fun ButtonDefaults.paypalColors(): ButtonColors {
return if (LocalDarkMode.current) {
ButtonDefaults.buttonColors(
containerColor = Color(0xFF009CDE),
contentColor = Color(0xFFFAFAFA)
)
} else {
ButtonDefaults.buttonColors(
containerColor = Color(0xFF003087),
contentColor = Color(0xFFFAFAFA)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.graphics.ImageBitmap
import com.arkivanov.decompose.extensions.compose.stack.animation.StackAnimation
import com.arkivanov.essenty.backhandler.BackHandler
import com.vanniktech.blurhash.BlurHash
import org.kodein.di.DI

expect fun Modifier.onClick(
enabled: Boolean = true,
Expand All @@ -22,4 +23,6 @@ expect fun BlurHash.decode(
hash: String,
width: Int,
height: Int
): ImageBitmap?
): ImageBitmap?

expect fun String.openInBrowser(di: DI)
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package dev.datlag.burningseries.shared.other

data object Constants {
const val PULZ_PACKAGE = "dev.datlag.pulz"
const val GOOGLE_PLAY_PULZ = "https://play.google.com/store/apps/details?id=dev.datlag.pulz"
data object Sponsor {
const val GITHUB = "https://github.com/sponsors/DatL4g"
const val POLAR = "https://polar.sh/DatL4g"
const val PATREON = "https://patreon.com/datlag"
const val PAYPAL = "https://paypal.me/datlag"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.datlag.burningseries.shared.other

import dev.datlag.burningseries.shared.SharedRes
import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.StringResource

sealed interface Project {

val icon: ImageResource?
val title: StringResource
val subTitle: StringResource

val `package`: String
val googlePlay: String?
val github: String?

data object PULZ : Project {
override val icon: ImageResource? = SharedRes.images.PulZ
override val title: StringResource = SharedRes.strings.pulz
override val subTitle: StringResource = SharedRes.strings.pulz_subtitle

override val `package`: String = "dev.datlag.pulz"
override val googlePlay: String? = "https://play.google.com/store/apps/details?id=$`package`"
override val github: String? = "https://github.com/DatL4g/PulZ"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.datlag.burningseries.shared.ui.custom

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import dev.datlag.burningseries.shared.other.Project

@Composable
expect fun ProjectCard(project: Project, modifier: Modifier = Modifier)
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ interface InitialComponent : Component {
@OptIn(ExperimentalDecomposeApi::class)
val pages: Value<ChildPages<*, Component>>

val sponsorScrollEnabled: StateFlow<Boolean>
val homeScrollEnabled: StateFlow<Boolean>
val favoriteScrollEnabled: StateFlow<Boolean>
val searchScrollEnabled: StateFlow<Boolean>

fun selectPage(index: Int)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private fun CompactScreen(
LocalPaddingValues provides it
) {
Box(modifier = Modifier.fillMaxSize()) {
val sponsorScrollEnabled by component.sponsorScrollEnabled.collectAsStateWithLifecycle()
val homeScrollEnabled by component.homeScrollEnabled.collectAsStateWithLifecycle()
val favoriteScrollEnabled by component.favoriteScrollEnabled.collectAsStateWithLifecycle()

Expand All @@ -109,9 +110,10 @@ private fun CompactScreen(
},
pager = { modifier, state, key, pageContent ->
val scrollEnabled = when (state.currentPage) {
0 -> homeScrollEnabled
1 -> favoriteScrollEnabled
else -> homeScrollEnabled && favoriteScrollEnabled
0 -> sponsorScrollEnabled
1 -> homeScrollEnabled
2 -> favoriteScrollEnabled
else -> sponsorScrollEnabled && homeScrollEnabled && favoriteScrollEnabled
}
HorizontalPager(
modifier = modifier,
Expand Down
Loading

1 comment on commit 86c15b3

@Slluxx
Copy link

@Slluxx Slluxx commented on 86c15b3 Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Please sign in to comment.