Repository navigation
fix: resolve deprecation warnings in ExportModels, GitHubAppUpdater, and LocalClipboard #38
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
Changes from 3 commits
ea82f46
e6f1a43
983014f
d728dcf
f3880de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,9 @@ import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.graphics.vector.ImageVector | ||
| import androidx.compose.ui.platform.LocalClipboardManager | ||
| import kotlinx.coroutines.launch | ||
| import androidx.compose.runtime.rememberCoroutineScope | ||
| import androidx.compose.ui.platform.LocalClipboard | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.style.TextAlign | ||
|
|
@@ -83,7 +85,8 @@ fun ImportScreen( | |
| val vm = LocalImportViewModel.current | ||
| val soundPlayer = LocalSoundPlayer.current | ||
| val context = LocalContext.current | ||
| val clipboardManager = LocalClipboardManager.current | ||
| val clipboardManager = LocalClipboard.current | ||
| val scope = rememberCoroutineScope() | ||
| val maxImportSizeLabel = remember { formatBytesAsMb(MAX_IMPORT_SIZE_BYTES.toLong()) } | ||
| val uiState by vm.uiState.collectAsStateWithLifecycle() | ||
|
|
||
|
|
@@ -196,17 +199,19 @@ fun ImportScreen( | |
| error = uiState.error, | ||
| onOpenFile = { vm.onOpenFileRequest() }, | ||
| onPaste = { | ||
| scope.launch { | ||
| try { | ||
| clipboardManager.getText()?.let { | ||
| if (exceedsImportLimit(it.text, MAX_IMPORT_SIZE_BYTES)) { | ||
| clipboardManager.getClipEntry()?.let { | ||
| val text = it.clipData.getItemAt(0).text.toString() | ||
| if (exceedsImportLimit(text, MAX_IMPORT_SIZE_BYTES)) { | ||
| soundPlayer.playBeep() | ||
| Toast.makeText( | ||
| context, | ||
| context.getString(R.string.toast_import_too_large, maxImportSizeLabel), | ||
| Toast.LENGTH_LONG | ||
| ).show() | ||
| } else { | ||
| vm.onPasteContent(it.text) | ||
| vm.onPasteContent(text) | ||
| } | ||
| } ?: Toast.makeText(context, R.string.toast_clipboard_empty, Toast.LENGTH_SHORT).show() | ||
|
Comment on lines
+202
to
216
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. 🧩 Analysis chain🌐 Web query:
💡 Result: Yes, according to the official Android documentation, ClipData.Item can represent Uri and Intent clipboard content. Constructors exist for Item(Uri uri) and Item(Intent intent), and items can combine text, Intent, and/or URI. The types an individual item can contain explicitly include Text (CharSequence), Intent (arbitrary Intent object), and Uri (URI reference, often content: URI). Yes, ClipData.Item.coerceToText(Context) is the recommended way to convert arbitrary clipboard content into text. The API reference describes it as turning the item into text regardless of its type, with a fallback algorithm: prioritize getText if available; for Uri, attempt to retrieve text stream from content provider or return URI string; for Intent, convert to intent: URI string; otherwise empty string. The Copy and Paste guide explicitly states: "Even if your application only handles text, you can copy non-text data from the clipboard by converting it with the ClipData.Item.coerceToText(android.content.Context) method." The ClipData reference also notes: "If all you want is the textual representation of the clipped data, you can use the convenience method Item.coerceToText." This is presented as the standard convenience approach for text conversion without needing to handle specific MIME types manually. Citations:
Use
Suggested fix- clipboardManager.getClipEntry()?.let {
- val text = it.clipData.getItemAt(0).text.toString()
- if (exceedsImportLimit(text, MAX_IMPORT_SIZE_BYTES)) {
+ clipboardManager.getClipEntry()?.let { entry ->
+ val item = entry.clipData
+ .takeIf { it.itemCount > 0 }
+ ?.getItemAt(0)
+ val text = item?.coerceToText(context)?.toString().orEmpty()
+
+ if (text.isBlank()) {
+ Toast.makeText(
+ context,
+ R.string.toast_clipboard_empty,
+ Toast.LENGTH_SHORT
+ ).show()
+ } else if (exceedsImportLimit(text, MAX_IMPORT_SIZE_BYTES)) {
soundPlayer.playBeep()
Toast.makeText(
context,
context.getString(R.string.toast_import_too_large, maxImportSizeLabel),
Toast.LENGTH_LONG
).show()
} else {
vm.onPasteContent(text)
}
} ?: Toast.makeText(context, R.string.toast_clipboard_empty, Toast.LENGTH_SHORT).show()🤖 Prompt for AI Agents |
||
| } catch (e: SecurityException) { | ||
|
|
@@ -215,6 +220,7 @@ fun ImportScreen( | |
| Toast.makeText(context, R.string.toast_cannot_access_clipboard, Toast.LENGTH_SHORT).show() | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| is ImportStep.Validated -> { | ||
|
|
||
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.
ClipData.Item.textmay be null for URI/intent clipboard entries, and callingtoString()here turns that into the literal string"null". That value is then passed tovm.onPasteContent(...), causing a misleading JSON import error path instead of treating the clipboard as non-text/empty. This regression is user-visible when pasting content copied from apps that publish URI-only clip data.Useful? React with 👍 / 👎.