diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/AppScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/AppScreen.kt index acc04dd505..b231f0bae3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/AppScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/AppScreen.kt @@ -26,10 +26,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.lifecycle.viewmodel.compose.viewModel import com.google.accompanist.adaptive.calculateDisplayFeatures -import com.vitorpamplona.amethyst.ui.screen.AccountScreen -import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel -import com.vitorpamplona.amethyst.ui.theme.AmethystTheme @OptIn(ExperimentalMaterial3WindowSizeClassApi::class) @Composable @@ -53,16 +50,3 @@ fun prepareSharedViewModel(act: MainActivity): SharedPreferencesViewModel { return sharedPreferencesViewModel } - -@Composable -fun AppScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) { - AmethystTheme(sharedPreferencesViewModel) { - val accountStateViewModel: AccountStateViewModel = viewModel() - - LaunchedEffect(key1 = Unit) { - accountStateViewModel.tryLoginExistingAccountAsync() - } - - AccountScreen(accountStateViewModel, sharedPreferencesViewModel) - } -} diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt index fb55177267..7c787222e7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt @@ -34,7 +34,9 @@ import androidx.activity.enableEdgeToEdge import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.mutableStateOf +import androidx.lifecycle.viewmodel.compose.viewModel import com.vitorpamplona.amethyst.Amethyst import com.vitorpamplona.amethyst.LocalPreferences import com.vitorpamplona.amethyst.debugState @@ -44,6 +46,9 @@ import com.vitorpamplona.amethyst.service.notifications.PushNotificationUtils import com.vitorpamplona.amethyst.ui.components.DEFAULT_MUTED_SETTING import com.vitorpamplona.amethyst.ui.components.keepPlayingMutex import com.vitorpamplona.amethyst.ui.navigation.Route +import com.vitorpamplona.amethyst.ui.screen.AccountScreen +import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel +import com.vitorpamplona.amethyst.ui.theme.AmethystTheme import com.vitorpamplona.ammolite.service.HttpClientManager import com.vitorpamplona.quartz.encoders.Nip19Bech32 import com.vitorpamplona.quartz.encoders.Nip47WalletConnect @@ -78,7 +83,16 @@ class MainActivity : AppCompatActivity() { setContent { val sharedPreferencesViewModel = prepareSharedViewModel(act = this) - AppScreen(sharedPreferencesViewModel = sharedPreferencesViewModel) + + AmethystTheme(sharedPreferencesViewModel) { + val accountStateViewModel: AccountStateViewModel = viewModel() + + LaunchedEffect(key1 = Unit) { + accountStateViewModel.tryLoginExistingAccountAsync() + } + + AccountScreen(accountStateViewModel, sharedPreferencesViewModel) + } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chatrooms/ChatroomListScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chatrooms/ChatroomListScreen.kt index e628e09cc6..6669364117 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chatrooms/ChatroomListScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chatrooms/ChatroomListScreen.kt @@ -24,9 +24,12 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.consumeWindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.pager.rememberPagerState @@ -73,6 +76,7 @@ import com.vitorpamplona.amethyst.ui.navigation.Route import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.DisappearingScaffold import com.vitorpamplona.amethyst.ui.stringRes +import com.vitorpamplona.amethyst.ui.theme.Size20dp import com.vitorpamplona.amethyst.ui.theme.TabRowHeight import com.vitorpamplona.amethyst.ui.theme.placeholderText import kotlinx.coroutines.Dispatchers @@ -183,39 +187,60 @@ fun ChatroomListTwoPane( } } - TwoPane( - first = { - ChatroomListScreenOnlyList( - knownFeedContentState, - newFeedContentState, - accountViewModel, - twoPaneNav, - ) - }, - second = { - twoPaneNav.innerNav.value?.let { - if (it.route == "Room") { - Chatroom( - roomId = it.id, - accountViewModel = accountViewModel, - nav = nav, - ) - } - - if (it.route == "Channel") { - Channel( - channelId = it.id, - accountViewModel = accountViewModel, - nav = nav, - ) - } + DisappearingScaffold( + isInvertedLayout = false, + topBar = { + Column { + MainTopBar(accountViewModel, nav) } }, - strategy = strategy, - displayFeatures = accountViewModel.settings.displayFeatures.value, - foldAwareConfiguration = FoldAwareConfiguration.VerticalFoldsOnly, - modifier = Modifier.fillMaxSize(), - ) + bottomBar = { + AppBottomBar(Route.Message, accountViewModel) { route, _ -> + nav.newStack(route.base) + } + }, + accountViewModel = accountViewModel, + ) { + TwoPane( + first = { + Box(Modifier.fillMaxSize().systemBarsPadding(), contentAlignment = Alignment.BottomEnd) { + ChatroomListScreenOnlyList( + knownFeedContentState, + newFeedContentState, + accountViewModel, + twoPaneNav, + ) + + Box(Modifier.padding(Size20dp), contentAlignment = Alignment.Center) { + ChannelFabColumn(accountViewModel, nav) + } + } + }, + second = { + twoPaneNav.innerNav.value?.let { + if (it.route == "Room") { + Chatroom( + roomId = it.id, + accountViewModel = accountViewModel, + nav = nav, + ) + } + + if (it.route == "Channel") { + Channel( + channelId = it.id, + accountViewModel = accountViewModel, + nav = nav, + ) + } + } + }, + strategy = strategy, + displayFeatures = accountViewModel.settings.displayFeatures.value, + foldAwareConfiguration = FoldAwareConfiguration.VerticalFoldsOnly, + modifier = Modifier.padding(it).consumeWindowInsets(it).fillMaxSize(), + ) + } } @OptIn(ExperimentalFoundationApi::class) @@ -244,20 +269,22 @@ fun ChatroomListScreenOnlyList( } } - ChatroomListOnlyTabs( - pagerState, - tabs, - { markKnownAsRead.value = true }, - { markNewAsRead.value = true }, - ) + Column { + ChatroomListOnlyTabs( + pagerState, + tabs, + { markKnownAsRead.value = true }, + { markNewAsRead.value = true }, + ) - ChatroomListTabs( - pagerState, - tabs, - PaddingValues(0.dp), - accountViewModel, - nav, - ) + ChatroomListTabs( + pagerState, + tabs, + PaddingValues(0.dp), + accountViewModel, + nav, + ) + } } @OptIn(ExperimentalFoundationApi::class) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt index 143dcac847..d5ec9cbf95 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt @@ -21,6 +21,8 @@ package com.vitorpamplona.amethyst.ui.theme import android.app.Activity +import android.app.UiModeManager +import android.content.Context import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.isSystemInDarkTheme @@ -45,12 +47,14 @@ import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.compositeOver import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.core.content.ContextCompat.getSystemService import androidx.core.view.WindowCompat import androidx.lifecycle.viewmodel.compose.viewModel import com.halilibo.richtext.ui.RichTextStyle @@ -451,10 +455,19 @@ fun AmethystTheme( sharedPrefsViewModel: SharedPreferencesViewModel, content: @Composable () -> Unit, ) { + val context = LocalContext.current val darkTheme = when (sharedPrefsViewModel.sharedPrefs.theme) { - ThemeType.DARK -> true - ThemeType.LIGHT -> false + ThemeType.DARK -> { + val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager? + uiManager!!.nightMode = UiModeManager.MODE_NIGHT_YES + true + } + ThemeType.LIGHT -> { + val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager? + uiManager!!.nightMode = UiModeManager.MODE_NIGHT_NO + false + } else -> isSystemInDarkTheme() } val colors = if (darkTheme) DarkColorPalette else LightColorPalette @@ -477,6 +490,8 @@ fun AmethystTheme( window.statusBarColor = colors.transparentBackground.toArgb() window.navigationBarColor = colors.transparentBackground.toArgb() + + view.setBackgroundColor(colors.background.toArgb()) } } }