-
-
Notifications
You must be signed in to change notification settings - Fork 63
DIY Action To Change Default Keyboard #809
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
Draft
thekrdev
wants to merge
10
commits into
sameerasw:develop
Choose a base branch
from
thekrdev:feature/diy/set-keyboard
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d9056d
refactor: re-ordered clickable modifier, "by dev" badge
thekrdev 6ec29c6
feat: added keyboard change action in diy
thekrdev 5f3ed3b
refactor: corrected permission name for keyboard change
thekrdev 90ecccf
refactor: ensure permission for setting default keyboard on action tr…
thekrdev 358a17b
refactor(editor/global): ensure permission is granted before setting …
thekrdev f269521
refactor: added strings and renamed variables
thekrdev b4c4da1
refactor: fixed design system & component styling by using pre-made c…
thekrdev ff14868
refactor: fixed hardcoded user-facing string in action executor (2)
thekrdev 1451a93
refactor: fixed missing isActionConfigured validation for Action.Keyb…
thekrdev bee40a4
refactor: fixed reactive state handling for selectedIme in editor (4)
thekrdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
app/src/main/java/com/sameerasw/essentials/ui/features/apps/sheets/KeyboardSelectionSheet.kt
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 High Severity Issues (Must Fix Before Merge)1. Design System & Component Styling Violations in
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| package com.sameerasw.essentials.ui.features.apps.sheets | ||
|
|
||
| import android.content.Context | ||
| import android.os.Build | ||
| import android.provider.Settings | ||
| import android.util.Log | ||
| import android.view.inputmethod.InputMethodInfo | ||
| import android.view.inputmethod.InputMethodManager | ||
| import android.widget.Toast | ||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.ListItem | ||
| import androidx.compose.material3.ListItemDefaults | ||
| import androidx.compose.material3.LoadingIndicator | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.RadioButton | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.graphics.asImageBitmap | ||
| import androidx.compose.ui.layout.ContentScale | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.platform.LocalView | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.core.graphics.drawable.toBitmap | ||
| import com.sameerasw.essentials.R | ||
| import com.sameerasw.essentials.ui.core.sheets.EssentialsBottomSheet | ||
| import com.sameerasw.essentials.utils.HapticUtil | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.withContext | ||
|
|
||
| @Composable | ||
| fun KeyboardSelectionSheet( | ||
| onDismissRequest: (ime: String?) -> Unit, | ||
| selectedIme: String?, | ||
| context: Context = LocalContext.current | ||
| ) { | ||
| var isLoadingKeyboards by remember { mutableStateOf(true) } | ||
| var defaultInputMethod by remember { mutableStateOf<String?>(null) } | ||
| var imesList by remember { mutableStateOf<List<InputMethodInfo>>(emptyList()) } | ||
| val view = LocalView.current | ||
| val isDeprecated = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE | ||
|
|
||
| LaunchedEffect(Unit) { | ||
| isLoadingKeyboards = true | ||
| try { | ||
| val list = withContext(Dispatchers.IO) { | ||
| val imes = | ||
| context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
| val defaultIme = | ||
| if (isDeprecated) | ||
| imes.currentInputMethodInfo?.id | ||
| else | ||
| Settings.Secure.getString( | ||
| context.contentResolver, | ||
| Settings.Secure.DEFAULT_INPUT_METHOD | ||
| ) | ||
| defaultIme to imes | ||
| } | ||
| defaultInputMethod = selectedIme ?: (list.first ?: "") | ||
| imesList = list.second.inputMethodList | ||
| } catch (e: Exception) { | ||
| Log.e( | ||
| "KeyboardSelectionSheet", "Error loading input methods list: ${e.message ?: ""}" | ||
| ) | ||
| } finally { | ||
| isLoadingKeyboards = false | ||
| } | ||
| } | ||
|
|
||
| EssentialsBottomSheet( | ||
| onDismissRequest = { onDismissRequest(defaultInputMethod) }, | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .padding(start = 16.dp, end = 16.dp, bottom = 16.dp), | ||
| verticalArrangement = Arrangement.spacedBy(16.dp) | ||
| ) { | ||
| Row( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text( | ||
| text = stringResource(R.string.diy_set_keyboard_sheet_title), | ||
| style = MaterialTheme.typography.headlineSmall, | ||
| fontWeight = FontWeight.SemiBold | ||
| ) | ||
| } | ||
|
|
||
| if (isLoadingKeyboards) { | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .padding(vertical = 32.dp), | ||
| horizontalArrangement = Arrangement.Center | ||
| ) { | ||
| LoadingIndicator() | ||
| } | ||
| } else { | ||
| LazyColumn( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .weight(1f, fill = false) | ||
| .clip(RoundedCornerShape(24.dp)), | ||
| verticalArrangement = Arrangement.spacedBy(2.dp) | ||
| ) { | ||
| items(imesList, key = { it.id }) { ime -> | ||
| val isEnabled = ime.serviceInfo.enabled | ||
| val isSelected = defaultInputMethod == ime.id | ||
|
|
||
| ListItem( | ||
| checked = isSelected, | ||
| onCheckedChange = { | ||
| if (isEnabled) { | ||
| HapticUtil.performVirtualKeyHaptic(view) | ||
| defaultInputMethod = ime.id | ||
| } else { | ||
| HapticUtil.performVirtualKeyHaptic(view) | ||
| Toast.makeText( | ||
| context, | ||
| R.string.diy_set_keyboard_input_method_disabled, | ||
| Toast.LENGTH_SHORT | ||
| ).show() | ||
| } | ||
| }, | ||
| onLongClick = null, | ||
| enabled = isEnabled, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| leadingContent = { | ||
| Image( | ||
| bitmap = ime.loadIcon(context.packageManager).toBitmap() | ||
| .asImageBitmap(), | ||
| contentDescription = ime.serviceInfo.name, | ||
| modifier = Modifier.size(24.dp), | ||
| contentScale = ContentScale.Fit | ||
| ) | ||
| }, | ||
| supportingContent = null, | ||
| trailingContent = { | ||
| RadioButton( | ||
| selected = if (isEnabled) isSelected else false, | ||
| onClick = null, | ||
| enabled = isEnabled | ||
| ) | ||
| }, | ||
| colors = ListItemDefaults.colors( | ||
| containerColor = MaterialTheme.colorScheme.surfaceBright | ||
| ), | ||
| contentPadding = androidx.compose.foundation.layout.PaddingValues( | ||
| horizontal = 16.dp, | ||
| vertical = 16.dp | ||
| ), | ||
| content = { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.spacedBy(4.dp) | ||
| ) { | ||
| Text( | ||
| text = ime.loadLabel(context.packageManager).toString(), | ||
| style = MaterialTheme.typography.bodyMedium, | ||
| color = MaterialTheme.colorScheme.onSurface | ||
| ) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Missing
isActionConfiguredValidation forAction.Keyboardapp/src/main/java/com/sameerasw/essentials/ui/activities/AutomationEditorActivity.ktisActionConfigureddoes not validateAction.Keyboard. If a user adds the "Set Keyboard" action without opening the settings sheet,action.inputMethodIdremainsnull. When triggered, it will execute withnull, which can clear the user's default keyboard in Android settings or fail.action.inputMethodId != null && action.inputMethodId.isNotBlank().