Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding light and dark theme options. Fixes #254 #259

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.sp
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand Down Expand Up @@ -102,8 +101,7 @@ class MainActivity : ComponentActivity() {
val appSettings by appSettingsViewModel.appSettings.observeAsState()

JerboaTheme(
themeMode = ThemeMode.values()[appSettings?.theme ?: 0],
fontSize = (appSettings?.fontSize ?: 13).sp
appSettings = appSettings
) {
val navController = rememberNavController()
val ctx = LocalContext.current
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,16 @@ fun Context.findActivity(): Activity? = when (this) {
enum class ThemeMode {
System,
Light,
Dark,
DarkBlue,
Dark
}

enum class LightTheme {
Green,
Pink
}

enum class DarkTheme {
Gray,
Blue,
Black
}
30 changes: 24 additions & 6 deletions app/src/main/java/com/jerboa/db/AppDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import kotlinx.coroutines.launch
import java.util.concurrent.Executors

const val DEFAULT_FONT_SIZE = 14

@Entity
data class Account(
@PrimaryKey val id: Int,
Expand All @@ -38,14 +40,24 @@ data class AppSettings(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(
name = "font_size",
defaultValue = "13"
defaultValue = DEFAULT_FONT_SIZE.toString()
)
val fontSize: Int,
@ColumnInfo(
name = "theme",
defaultValue = "0"
)
val theme: Int
val theme: Int,
@ColumnInfo(
name = "light_theme",
defaultValue = "0"
)
val lightTheme: Int,
@ColumnInfo(
name = "dark_theme",
defaultValue = "0"
)
val darkTheme: Int
)

@Dao
Expand Down Expand Up @@ -145,9 +157,13 @@ val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"""
CREATE TABLE IF NOT EXISTS AppSettings (id INTEGER PRIMARY KEY
AUTOINCREMENT NOT NULL, font_size INTEGER NOT NULL DEFAULT 13, theme INTEGER
NOT NULL DEFAULT 0)
CREATE TABLE IF NOT EXISTS AppSettings (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
font_size INTEGER NOT NULL DEFAULT $DEFAULT_FONT_SIZE,
theme INTEGER NOT NULL DEFAULT 0,
light_theme INTEGER NOT NULL DEFAULT 0,
dark_theme INTEGER NOT NULL DEFAULT 0
)
"""
)
}
Expand Down Expand Up @@ -189,8 +205,10 @@ abstract class AppDB : RoomDatabase() {
CONFLICT_IGNORE, // Ensures it won't overwrite the existing data
ContentValues(2).apply {
put("id", 1)
put("font_size", 13)
put("font_size", DEFAULT_FONT_SIZE)
put("theme", 0)
put("light_theme", 0)
put("dark_theme", 0)
}
)
}
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/java/com/jerboa/ui/components/common/AppBars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -207,7 +208,7 @@ fun CommentOrPostNodeHeader(
contentDescription = "TODO",
tint = MaterialTheme.colors.error
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
}

PersonProfileLink(
Expand All @@ -229,7 +230,7 @@ fun CommentOrPostNodeHeader(
color = scoreColor(myVote = myVote),
fontSize = MaterialTheme.typography.body1.fontSize.times(1.1)
)
DotSpacer(0.dp)
DotSpacer(0.dp, MaterialTheme.typography.body2)
TimeAgo(published = published, updated = updated)
}
}
Expand Down Expand Up @@ -292,9 +293,14 @@ fun ActionBarButton(
}

@Composable
fun DotSpacer(padding: Dp = SMALL_PADDING) {
fun DotSpacer(
padding: Dp = SMALL_PADDING,
style: TextStyle = MaterialTheme.typography.body2
) {
Text(
text = "·",
style = style,
color = MaterialTheme.colors.onBackground.muted,
modifier = Modifier.padding(horizontal = padding)
)
}
Expand Down Expand Up @@ -443,27 +449,27 @@ fun CommentsAndPosts(
text = "${siFormat(usersActiveDay)} users / day",
color = MaterialTheme.colors.onBackground.muted
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
Text(
text = "${siFormat(usersActiveWeek)} users / week",
color = MaterialTheme.colors.onBackground.muted
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
Text(
text = "${siFormat(usersActiveMonth)} users / month",
color = MaterialTheme.colors.onBackground.muted
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
Text(
text = "${siFormat(usersActiveHalfYear)} users / 6 months",
color = MaterialTheme.colors.onBackground.muted
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
Text(
text = "${siFormat(postCount)} posts",
color = MaterialTheme.colors.onBackground.muted
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
Text(
text = "${siFormat(commentCount)} comments",
color = MaterialTheme.colors.onBackground.muted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ fun TimeAgo(
Row {
Text(
text = afterPreceding,
color = MaterialTheme.colors.onBackground.muted
color = MaterialTheme.colors.onBackground.muted,
style = MaterialTheme.typography.body2
)

updated?.also {
val updatedPretty = dateStringToPretty(it, includeAgo)

DotSpacer(SMALL_PADDING)
DotSpacer(
padding = SMALL_PADDING,
style = MaterialTheme.typography.body2
)
Text(
text = "($updatedPretty)",
style = MaterialTheme.typography.body2,
color = MaterialTheme.colors.onBackground.muted,
fontStyle = FontStyle.Italic
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import com.jerboa.ui.theme.SMALL_PADDING
fun CommunityName(
community: CommunitySafe,
color: Color = MaterialTheme.colors.primary,
style: TextStyle = MaterialTheme.typography.body1
style: TextStyle = MaterialTheme.typography.body2
) {
Text(
text = communityNameShown(community),
Expand All @@ -57,7 +57,7 @@ fun CommunityLink(
spacing: Dp = SMALL_PADDING,
size: Dp = ICON_SIZE,
thumbnailSize: Int = ICON_THUMBNAIL_SIZE,
style: TextStyle = MaterialTheme.typography.body1,
style: TextStyle = MaterialTheme.typography.body2,
onClick: (community: CommunitySafe) -> Unit
) {
Row(
Expand Down Expand Up @@ -92,6 +92,7 @@ fun CommunityLinkLarger(
CommunityLink(
community = community,
color = MaterialTheme.colors.onSurface,
style = MaterialTheme.typography.h6,
size = LINK_ICON_SIZE,
thumbnailSize = LARGER_ICON_THUMBNAIL_SIZE,
spacing = DRAWER_ITEM_SPACING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fun CommentsAndPosts(personView: PersonViewSafe) {
text = "${personView.counts.post_count} posts",
color = MaterialTheme.colors.onBackground.muted
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
Text(
text = "${personView.counts.comment_count} comments",
color = MaterialTheme.colors.onBackground.muted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun PersonName(
isPostCreator: Boolean = false
) {
val name = person?.let { personNameShown(it) } ?: run { "Anonymous" }
val style = MaterialTheme.typography.body1
val style = MaterialTheme.typography.body2

if (isPostCreator) {
Badge(
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/com/jerboa/ui/components/post/PostListing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,30 @@ fun PostHeaderLine(
contentDescription = "TODO",
tint = MaterialTheme.colors.onBackground.muted
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
}
if (postView.post.locked) {
Icon(
imageVector = Icons.Default.Lock,
contentDescription = "TODO",
tint = MaterialTheme.colors.error
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
}
if (postView.post.deleted) {
Icon(
imageVector = Icons.Default.Delete,
contentDescription = "TODO",
tint = MaterialTheme.colors.error
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
}
if (showCommunityName) {
CommunityLink(
community = postView.community,
onClick = onCommunityClick
)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
}
PersonProfileLink(
person = postView.creator,
Expand All @@ -136,11 +136,15 @@ fun PostHeaderLine(
isCommunityBanned = postView.creator_banned_from_community

)
DotSpacer()
DotSpacer(style = MaterialTheme.typography.body2)
if (!isSameInstance) {
postView.post.url?.also {
Text(text = hostName(it), color = MaterialTheme.colors.onBackground.muted)
DotSpacer()
Text(
text = hostName(it),
color = MaterialTheme.colors.onBackground.muted,
style = MaterialTheme.typography.body2
)
DotSpacer(style = MaterialTheme.typography.body2)
}
}

Expand Down
Loading