all: commonize theming

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2021-06-04 15:46:45 +05:30
parent d63a331325
commit 090c3c2017
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
5 changed files with 38 additions and 24 deletions

View file

@ -3,27 +3,16 @@ package dev.msfjarvis.claw.android
import android.os.Bundle import android.os.Bundle
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import dev.msfjarvis.claw.android.theme.LobstersTheme import androidx.compose.foundation.isSystemInDarkTheme
import dev.msfjarvis.claw.common.posts.LobstersItem import dev.msfjarvis.claw.common.posts.LobstersItem
import dev.msfjarvis.lobsters.data.local.SavedPost import dev.msfjarvis.claw.common.posts.TEST_POST
import dev.msfjarvis.claw.common.theme.LobstersTheme
val TEST_POST =
SavedPost(
shortId = "zqyydb",
title = "k2k20 hackathon report: Bob Beck on LibreSSL progress",
url = "https://undeadly.org/cgi?action=article;sid=20200921105847",
createdAt = "2020-09-21T07:11:14.000-05:00",
commentsUrl = "https://lobste.rs/s/zqyydb/k2k20_hackathon_report_bob_beck_on",
submitterName = "Vigdis",
submitterAvatarUrl = "/404.html",
tags = listOf("openbsd", "linux", "containers", "hack the planet", "no thanks"),
)
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
LobstersTheme { LobstersTheme(darkTheme = isSystemInDarkTheme()) {
LobstersItem( LobstersItem(
post = TEST_POST, post = TEST_POST,
isSaved = false, isSaved = false,

View file

@ -22,14 +22,26 @@ import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.google.accompanist.flowlayout.FlowRow import com.google.accompanist.flowlayout.FlowRow
import dev.msfjarvis.claw.common.theme.titleColor
import dev.msfjarvis.lobsters.data.local.SavedPost import dev.msfjarvis.lobsters.data.local.SavedPost
import io.kamel.image.KamelImage import io.kamel.image.KamelImage
import io.kamel.image.lazyImageResource import io.kamel.image.lazyImageResource
val TEST_POST =
SavedPost(
shortId = "zqyydb",
title = "k2k20 hackathon report: Bob Beck on LibreSSL progress",
url = "https://undeadly.org/cgi?action=article;sid=20200921105847",
createdAt = "2020-09-21T07:11:14.000-05:00",
commentsUrl = "https://lobste.rs/s/zqyydb/k2k20_hackathon_report_bob_beck_on",
submitterName = "Vigdis",
submitterAvatarUrl = "/404.html",
tags = listOf("openbsd", "linux", "containers", "hack the planet", "no thanks"),
)
@Composable @Composable
fun LobstersItem( fun LobstersItem(
post: SavedPost, post: SavedPost,
@ -84,7 +96,7 @@ fun PostTitle(
) { ) {
Text( Text(
text = title, text = title,
color = Color.Black, color = titleColor,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
modifier = Modifier.then(modifier), modifier = Modifier.then(modifier),
) )

View file

@ -1,6 +1,5 @@
package dev.msfjarvis.claw.android.theme package dev.msfjarvis.claw.common.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors import androidx.compose.material.darkColors
import androidx.compose.material.lightColors import androidx.compose.material.lightColors
@ -34,9 +33,9 @@ val darkColors =
) )
@Composable @Composable
fun LobstersTheme(children: @Composable () -> Unit) { fun LobstersTheme(darkTheme: Boolean, children: @Composable () -> Unit) {
MaterialTheme( MaterialTheme(
colors = if (isSystemInDarkTheme()) darkColors else lightColors, colors = if (darkTheme) darkColors else lightColors,
content = children, content = children,
) )
} }

View file

@ -14,7 +14,9 @@ kotlin {
dependencies { implementation(libs.thirdparty.sqldelight.androidDriver) } dependencies { implementation(libs.thirdparty.sqldelight.androidDriver) }
} }
val androidTest by getting val androidTest by getting
val desktopMain by getting { dependencies { implementation(libs.thirdparty.sqldelight.jvmDriver) } } val desktopMain by getting {
dependencies { implementation(libs.thirdparty.sqldelight.jvmDriver) }
}
val desktopTest by getting { val desktopTest by getting {
dependencies { dependencies {
implementation(libs.kotlin.coroutines.core) implementation(libs.kotlin.coroutines.core)

View file

@ -1,4 +1,16 @@
import androidx.compose.desktop.Window import androidx.compose.desktop.Window
import dev.msfjarvis.claw.common.App import dev.msfjarvis.claw.common.posts.LobstersItem
import dev.msfjarvis.claw.common.posts.TEST_POST
import dev.msfjarvis.claw.common.theme.LobstersTheme
fun main() = Window { App() } fun main() = Window {
LobstersTheme(darkTheme = true) {
LobstersItem(
post = TEST_POST,
isSaved = false,
{},
{},
{},
)
}
}