-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.github.libretube.ui.compose | ||
|
||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.github.libretube.R | ||
import com.github.libretube.api.SubscriptionHelper | ||
import com.github.libretube.constants.PreferenceKeys | ||
import com.github.libretube.helpers.PreferenceHelper | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun SubscribeButton(channelId: String) { | ||
Check failure on line 25 in app/src/main/java/com/github/libretube/ui/compose/SubscribeButton.kt
|
||
val scope = rememberCoroutineScope() | ||
var isSubscribed by rememberSaveable { mutableStateOf(false) } | ||
var shouldNotify by rememberSaveable { mutableStateOf(false) } | ||
|
||
LaunchedEffect(true) { | ||
isSubscribed = SubscriptionHelper.isSubscribed(channelId) ?: false | ||
shouldNotify = PreferenceHelper.isChannelNotificationIgnorable(channelId) | ||
} | ||
|
||
Row { | ||
if (isSubscribed && PreferenceHelper.getBoolean(PreferenceKeys.NOTIFICATION_ENABLED, true)) { | ||
IconButton(onClick = { | ||
shouldNotify = !shouldNotify | ||
PreferenceHelper.toggleIgnorableNotificationChannel(channelId) | ||
}) { | ||
val icon = if (shouldNotify) R.drawable.ic_bell else R.drawable.ic_notification | ||
Icon(painter = painterResource(icon), contentDescription = null) | ||
} | ||
} | ||
Button(onClick = { | ||
scope.launch { | ||
if (isSubscribed) { | ||
SubscriptionHelper.unsubscribe(channelId) | ||
} else { | ||
SubscriptionHelper.subscribe(channelId) | ||
} | ||
isSubscribed = !isSubscribed | ||
} | ||
}) { | ||
Text(stringResource(if (isSubscribed) R.string.unsubscribe else R.string.subscribe)) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun PreviewSubscribeButton() { | ||
Check failure on line 62 in app/src/main/java/com/github/libretube/ui/compose/SubscribeButton.kt
|
||
SubscribeButton("@CNN") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.libretube.ui.theme | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
val Purple80 = Color(0xFFD0BCFF) | ||
val PurpleGrey80 = Color(0xFFCCC2DC) | ||
val Pink80 = Color(0xFFEFB8C8) | ||
|
||
val Purple40 = Color(0xFF6650a4) | ||
val PurpleGrey40 = Color(0xFF625b71) | ||
val Pink40 = Color(0xFF7D5260) | ||
Check failure on line 11 in app/src/main/java/com/github/libretube/ui/theme/Color.kt
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.libretube.ui.theme | ||
|
||
import android.app.Activity | ||
Check failure on line 3 in app/src/main/java/com/github/libretube/ui/theme/Theme.kt
|
||
import android.os.Build | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.darkColorScheme | ||
import androidx.compose.material3.dynamicDarkColorScheme | ||
import androidx.compose.material3.dynamicLightColorScheme | ||
import androidx.compose.material3.lightColorScheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalContext | ||
|
||
private val DarkColorScheme = darkColorScheme( | ||
Check failure on line 14 in app/src/main/java/com/github/libretube/ui/theme/Theme.kt
|
||
primary = Purple80, | ||
secondary = PurpleGrey80, | ||
tertiary = Pink80 | ||
Check failure on line 17 in app/src/main/java/com/github/libretube/ui/theme/Theme.kt
|
||
) | ||
|
||
private val LightColorScheme = lightColorScheme( | ||
Check failure on line 20 in app/src/main/java/com/github/libretube/ui/theme/Theme.kt
|
||
primary = Purple40, | ||
secondary = PurpleGrey40, | ||
tertiary = Pink40 | ||
Check failure on line 23 in app/src/main/java/com/github/libretube/ui/theme/Theme.kt
|
||
|
||
Check failure on line 24 in app/src/main/java/com/github/libretube/ui/theme/Theme.kt
|
||
/* Other default colors to override | ||
background = Color(0xFFFFFBFE), | ||
surface = Color(0xFFFFFBFE), | ||
onPrimary = Color.White, | ||
onSecondary = Color.White, | ||
onTertiary = Color.White, | ||
onBackground = Color(0xFF1C1B1F), | ||
onSurface = Color(0xFF1C1B1F), | ||
*/ | ||
) | ||
|
||
@Composable | ||
fun LibreTubeTheme( | ||
darkTheme: Boolean = isSystemInDarkTheme(), | ||
// Dynamic color is available on Android 12+ | ||
dynamicColor: Boolean = true, | ||
content: @Composable () -> Unit | ||
) { | ||
val colorScheme = when { | ||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { | ||
val context = LocalContext.current | ||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) | ||
} | ||
|
||
darkTheme -> DarkColorScheme | ||
else -> LightColorScheme | ||
} | ||
|
||
MaterialTheme( | ||
colorScheme = colorScheme, | ||
typography = Typography, | ||
content = content | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.libretube.ui.theme | ||
|
||
import androidx.compose.material3.Typography | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.sp | ||
|
||
// Set of Material typography styles to start with | ||
val Typography = Typography( | ||
bodyLarge = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 16.sp, | ||
lineHeight = 24.sp, | ||
letterSpacing = 0.5.sp | ||
) | ||
/* Other default text styles to override | ||
titleLarge = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 22.sp, | ||
lineHeight = 28.sp, | ||
letterSpacing = 0.sp | ||
), | ||
labelSmall = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 11.sp, | ||
lineHeight = 16.sp, | ||
letterSpacing = 0.5.sp | ||
) | ||
*/ | ||
) |