diff --git a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt index 6efc996a..b0dd176f 100644 --- a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt +++ b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt @@ -1,6 +1,8 @@ package chat.revolt.screens.chat.views.channel +import android.app.Activity import android.content.ContentValues +import android.content.res.Configuration import android.net.Uri import android.os.Environment import android.provider.MediaStore @@ -20,6 +22,7 @@ import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutVertically +import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -44,12 +47,16 @@ import androidx.compose.foundation.layout.requiredHeight import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.text.InlineTextContent +import androidx.compose.foundation.text.appendInlineContent import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.filled.Menu import androidx.compose.material3.AssistChip +import androidx.compose.material3.Button +import androidx.compose.material3.Card import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem @@ -63,6 +70,7 @@ import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.Scaffold import androidx.compose.material3.SmallFloatingActionButton import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable @@ -84,11 +92,16 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.Placeholder +import androidx.compose.ui.text.PlaceholderVerticalAlign +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.LineHeightStyle import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp import androidx.documentfile.provider.DocumentFile import androidx.hilt.navigation.compose.hiltViewModel @@ -224,6 +237,12 @@ fun ChannelScreen( imeInTransition = false } } + + LaunchedEffect(Unit) { + if (context.resources.configuration.keyboard and Configuration.KEYBOARD_QWERTY != 0) { + viewModel.usesPhysicalKeyboard() + } + } // // val processFileUri: (Uri, String?) -> Unit = remember { @@ -831,6 +850,76 @@ fun ChannelScreen( ) } } + + if (viewModel.showPhysicalKeyboardSpark) { + Card( + modifier = Modifier + .align(Alignment.TopCenter) + .padding(8.dp) + ) { + Column( + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = Modifier.padding(16.dp) + ) { + Text( + stringResource(R.string.spark_keyboard_shortcuts), + style = MaterialTheme.typography.bodyLarge, + fontWeight = FontWeight.SemiBold + ) + Text( + buildAnnotatedString { + val raw = + stringResource(R.string.spark_keyboard_shortcuts_description) + val before = raw.substringBefore("%1\$s") + val after = raw.substringAfter("%1\$s") + + append(before) + appendInlineContent("metaKey", "Meta") + append(" + /") + append(after) + }, + inlineContent = mapOf( + "metaKey" to InlineTextContent( + placeholder = Placeholder( + width = 1.em, + height = 1.em, + placeholderVerticalAlign = PlaceholderVerticalAlign.Center + ) + ) { + with(LocalDensity.current) { + Image( + painterResource(R.drawable.ic_meta_key_24dp), + contentDescription = null, + /*modifier = Modifier.size(1.em.toDp())*/ + ) + } + } + ), + style = MaterialTheme.typography.bodyLarge + ) + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Button( + onClick = { + viewModel.dismissPhysicalKeyboardSpark() + }, + modifier = Modifier.weight(1f) + ) { + Text(stringResource(R.string.spark_keyboard_shortcuts_dismiss)) + } + TextButton( + onClick = { + (context as Activity).requestShowKeyboardShortcuts() + }, + modifier = Modifier.weight(1f) + ) { + Text(stringResource(R.string.spark_keyboard_shortcuts_cta)) + } + } + } + } + } } Column( diff --git a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt index f2be0d30..09556fde 100644 --- a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt +++ b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt @@ -872,4 +872,20 @@ class ChannelScreenViewModel @Inject constructor( items.addAll(groupedItems) } } + + var showPhysicalKeyboardSpark by mutableStateOf(false) + fun usesPhysicalKeyboard() { + viewModelScope.launch { + if (kvStorage.getBoolean("spark/physicalKeyboard/dismissed") != true) { + showPhysicalKeyboardSpark = true + } + } + } + + fun dismissPhysicalKeyboardSpark() { + viewModelScope.launch { + kvStorage.set("spark/physicalKeyboard/dismissed", true) + showPhysicalKeyboardSpark = false + } + } } \ No newline at end of file diff --git a/app/src/main/java/chat/revolt/screens/settings/DebugSettingsScreen.kt b/app/src/main/java/chat/revolt/screens/settings/DebugSettingsScreen.kt index 4a90eeb7..9473330f 100644 --- a/app/src/main/java/chat/revolt/screens/settings/DebugSettingsScreen.kt +++ b/app/src/main/java/chat/revolt/screens/settings/DebugSettingsScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Button import androidx.compose.material3.ElevatedButton import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider @@ -66,8 +67,13 @@ class DebugSettingsScreenViewModel @Inject constructor( private val kvStorage: KVStorage ) : ViewModel() { fun forgetAllSparks() { - // No op because there are no active sparks - // psst, notifications will be the next one + forgetPhysicalKeyboardSpark() + } + + fun forgetPhysicalKeyboardSpark() { + viewModelScope.launch { + kvStorage.remove("spark/physicalKeyboard/dismissed") + } } fun forgetLatestChangelog() { @@ -209,10 +215,11 @@ fun DebugSettingsScreen( Row( modifier = Modifier.horizontalScroll(rememberScrollState()) ) { - - Text("There are no active sparks, but you can still try to ") - ElevatedButton(onClick = { viewModel.forgetAllSparks() }) { - Text("forget all sparks") + ElevatedButton(onClick = { viewModel.forgetPhysicalKeyboardSpark() }) { + Text("Forget physical keyboard spark") + } + Button(onClick = { viewModel.forgetAllSparks() }) { + Text("Forget all sparks") } } diff --git a/app/src/main/res/drawable/ic_meta_key_24dp.xml b/app/src/main/res/drawable/ic_meta_key_24dp.xml new file mode 100644 index 00000000..a5733ab2 --- /dev/null +++ b/app/src/main/res/drawable/ic_meta_key_24dp.xml @@ -0,0 +1,34 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cec0043f..8b808e16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -577,6 +577,7 @@ Using a keyboard? Revolt has keyboard shortcuts! Press %1$s to see them. Open shortcuts + Alright Important notice regarding your account You have received an important notice regarding your account from our moderation team. Please read it carefully.