Skip to content

Commit

Permalink
Merge pull request #382 from dominik-masson/amoled
Browse files Browse the repository at this point in the history
Amoled Theme and SMS begin from bottom
  • Loading branch information
SuhasDissa authored Mar 28, 2024
2 parents d098c41 + 41fef6f commit e89dd80
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/bnyro/contacts/enums/ThemeMode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.bnyro.contacts.enums
enum class ThemeMode {
SYSTEM,
LIGHT,
DARK;
DARK,
AMOLED;

companion object {
fun fromInt(value: Int) = ThemeMode.values().first { it.ordinal == value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,15 @@ package com.bnyro.contacts.ui.components.conversation

import android.provider.Telephony
import android.text.format.DateUtils
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.ClickableText
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.DismissValue
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.SwipeToDismiss
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDismissState
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -52,6 +30,10 @@ fun ColumnScope.Messages(
scrollState: LazyListState,
smsModel: SmsModel
) {
LaunchedEffect(Unit) {
scrollState.scrollToItem(messages.size + 5)
}

val timestamped = messages.groupBy {
DateUtils.getRelativeDateTimeString(
LocalContext.current,
Expand All @@ -61,6 +43,7 @@ fun ColumnScope.Messages(
DateUtils.FORMAT_ABBREV_ALL
).split(", ").first()
}

LazyColumn(
state = scrollState,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
Expand All @@ -40,8 +39,6 @@ fun SettingsScreen(onDismissRequest: () -> Unit) {
val themeModel: ThemeModel = viewModel()
val smsModel: SmsModel = viewModel()

val context = LocalContext.current

FullScreenDialog(onClose = onDismissRequest) {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
rememberTopAppBarState()
Expand Down Expand Up @@ -78,7 +75,7 @@ fun SettingsScreen(onDismissRequest: () -> Unit) {
Text(stringResource(R.string.theme))
BlockPreference(
preferenceKey = Preferences.themeKey,
entries = listOf(R.string.system, R.string.light, R.string.dark).map {
entries = listOf(R.string.system, R.string.light, R.string.dark, R.string.amoled).map {
stringResource(it)
}
) {
Expand Down
21 changes: 13 additions & 8 deletions app/src/main/java/com/bnyro/contacts/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package com.bnyro.contacts.ui.theme
import android.app.Activity
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.material3.surfaceColorAtElevation
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
Expand Down Expand Up @@ -40,15 +36,24 @@ fun ConnectYouTheme(
val darkTheme = when (themeMode) {
ThemeMode.LIGHT -> false
ThemeMode.DARK -> true
ThemeMode.AMOLED -> false
else -> isSystemInDarkTheme()
}

val amoledDark = themeMode == ThemeMode.AMOLED

val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
if (darkTheme) dynamicDarkColorScheme(context)
else if (amoledDark) dynamicDarkColorScheme(context).copy(
background = Color.Black,
surface = Color.Black
) else dynamicLightColorScheme(context)
}

darkTheme -> DarkColorScheme
amoledDark -> DarkColorScheme.copy(background = Color.Black, surface = Color.Black)
else -> LightColorScheme
}

Expand All @@ -62,7 +67,7 @@ fun ConnectYouTheme(
WindowCompat.getInsetsController(
activity.window,
view
).isAppearanceLightStatusBars = !darkTheme
).isAppearanceLightStatusBars = !darkTheme && !amoledDark
WindowCompat.getInsetsController(
activity.window,
view
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@
<string name="add_note">Add Note</string>
<string name="add_event">Add Event</string>
<string name="date">Date</string>
<string name="amoled">Amoled</string>
</resources>

0 comments on commit e89dd80

Please sign in to comment.