mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-23 19:26:18 +02:00
Merge branch 'vitorpamplona:main' into configurable-media-compression
This commit is contained in:
@@ -26,10 +26,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.google.accompanist.adaptive.calculateDisplayFeatures
|
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.screen.SharedPreferencesViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.AmethystTheme
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
|
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -53,16 +50,3 @@ fun prepareSharedViewModel(act: MainActivity): SharedPreferencesViewModel {
|
|||||||
|
|
||||||
return sharedPreferencesViewModel
|
return sharedPreferencesViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun AppScreen(sharedPreferencesViewModel: SharedPreferencesViewModel) {
|
|
||||||
AmethystTheme(sharedPreferencesViewModel) {
|
|
||||||
val accountStateViewModel: AccountStateViewModel = viewModel()
|
|
||||||
|
|
||||||
LaunchedEffect(key1 = Unit) {
|
|
||||||
accountStateViewModel.tryLoginExistingAccountAsync()
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountScreen(accountStateViewModel, sharedPreferencesViewModel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -34,7 +34,9 @@ import androidx.activity.enableEdgeToEdge
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.vitorpamplona.amethyst.Amethyst
|
import com.vitorpamplona.amethyst.Amethyst
|
||||||
import com.vitorpamplona.amethyst.LocalPreferences
|
import com.vitorpamplona.amethyst.LocalPreferences
|
||||||
import com.vitorpamplona.amethyst.debugState
|
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.DEFAULT_MUTED_SETTING
|
||||||
import com.vitorpamplona.amethyst.ui.components.keepPlayingMutex
|
import com.vitorpamplona.amethyst.ui.components.keepPlayingMutex
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.Route
|
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.ammolite.service.HttpClientManager
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.Nip47WalletConnect
|
import com.vitorpamplona.quartz.encoders.Nip47WalletConnect
|
||||||
@@ -78,7 +83,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val sharedPreferencesViewModel = prepareSharedViewModel(act = this)
|
val sharedPreferencesViewModel = prepareSharedViewModel(act = this)
|
||||||
AppScreen(sharedPreferencesViewModel = sharedPreferencesViewModel)
|
|
||||||
|
AmethystTheme(sharedPreferencesViewModel) {
|
||||||
|
val accountStateViewModel: AccountStateViewModel = viewModel()
|
||||||
|
|
||||||
|
LaunchedEffect(key1 = Unit) {
|
||||||
|
accountStateViewModel.tryLoginExistingAccountAsync()
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountScreen(accountStateViewModel, sharedPreferencesViewModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,9 +24,12 @@ import androidx.compose.foundation.ExperimentalFoundationApi
|
|||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.systemBarsPadding
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
import androidx.compose.foundation.pager.PagerState
|
import androidx.compose.foundation.pager.PagerState
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
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.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.DisappearingScaffold
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.DisappearingScaffold
|
||||||
import com.vitorpamplona.amethyst.ui.stringRes
|
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.TabRowHeight
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -183,39 +187,60 @@ fun ChatroomListTwoPane(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TwoPane(
|
DisappearingScaffold(
|
||||||
first = {
|
isInvertedLayout = false,
|
||||||
ChatroomListScreenOnlyList(
|
topBar = {
|
||||||
knownFeedContentState,
|
Column {
|
||||||
newFeedContentState,
|
MainTopBar(accountViewModel, nav)
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
strategy = strategy,
|
bottomBar = {
|
||||||
displayFeatures = accountViewModel.settings.displayFeatures.value,
|
AppBottomBar(Route.Message, accountViewModel) { route, _ ->
|
||||||
foldAwareConfiguration = FoldAwareConfiguration.VerticalFoldsOnly,
|
nav.newStack(route.base)
|
||||||
modifier = Modifier.fillMaxSize(),
|
}
|
||||||
)
|
},
|
||||||
|
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)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@@ -244,20 +269,22 @@ fun ChatroomListScreenOnlyList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatroomListOnlyTabs(
|
Column {
|
||||||
pagerState,
|
ChatroomListOnlyTabs(
|
||||||
tabs,
|
pagerState,
|
||||||
{ markKnownAsRead.value = true },
|
tabs,
|
||||||
{ markNewAsRead.value = true },
|
{ markKnownAsRead.value = true },
|
||||||
)
|
{ markNewAsRead.value = true },
|
||||||
|
)
|
||||||
|
|
||||||
ChatroomListTabs(
|
ChatroomListTabs(
|
||||||
pagerState,
|
pagerState,
|
||||||
tabs,
|
tabs,
|
||||||
PaddingValues(0.dp),
|
PaddingValues(0.dp),
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.theme
|
package com.vitorpamplona.amethyst.ui.theme
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.app.UiModeManager
|
||||||
|
import android.content.Context
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
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.RectangleShape
|
||||||
import androidx.compose.ui.graphics.compositeOver
|
import androidx.compose.ui.graphics.compositeOver
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalView
|
import androidx.compose.ui.platform.LocalView
|
||||||
import androidx.compose.ui.text.SpanStyle
|
import androidx.compose.ui.text.SpanStyle
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.core.content.ContextCompat.getSystemService
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.halilibo.richtext.ui.RichTextStyle
|
import com.halilibo.richtext.ui.RichTextStyle
|
||||||
@@ -451,10 +455,19 @@ fun AmethystTheme(
|
|||||||
sharedPrefsViewModel: SharedPreferencesViewModel,
|
sharedPrefsViewModel: SharedPreferencesViewModel,
|
||||||
content: @Composable () -> Unit,
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
val darkTheme =
|
val darkTheme =
|
||||||
when (sharedPrefsViewModel.sharedPrefs.theme) {
|
when (sharedPrefsViewModel.sharedPrefs.theme) {
|
||||||
ThemeType.DARK -> true
|
ThemeType.DARK -> {
|
||||||
ThemeType.LIGHT -> false
|
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()
|
else -> isSystemInDarkTheme()
|
||||||
}
|
}
|
||||||
val colors = if (darkTheme) DarkColorPalette else LightColorPalette
|
val colors = if (darkTheme) DarkColorPalette else LightColorPalette
|
||||||
@@ -477,6 +490,8 @@ fun AmethystTheme(
|
|||||||
|
|
||||||
window.statusBarColor = colors.transparentBackground.toArgb()
|
window.statusBarColor = colors.transparentBackground.toArgb()
|
||||||
window.navigationBarColor = colors.transparentBackground.toArgb()
|
window.navigationBarColor = colors.transparentBackground.toArgb()
|
||||||
|
|
||||||
|
view.setBackgroundColor(colors.background.toArgb())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user