Skip to content
Snippets Groups Projects
Commit 62b4bcf7 authored by Aleksandras Kostarevas's avatar Aleksandras Kostarevas
Browse files

Add BugViewer action

parent 9dde4679
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<string name="text_edit_action_title">Text Editor</string> <string name="text_edit_action_title">Text Editor</string>
<string name="mem_debug_action_title">Debug Info</string> <string name="mem_debug_action_title">Debug Info</string>
<string name="more_actions_action_title">All Actions</string> <string name="more_actions_action_title">All Actions</string>
<string name="bug_viewer_action_title">Bug Viewer</string>
<string name="action_kind_action_key">Action Key</string> <string name="action_kind_action_key">Action Key</string>
<string name="action_kind_pinned_key">Pinned Action(s)</string> <string name="action_kind_pinned_key">Pinned Action(s)</string>
......
package org.futo.inputmethod.latin.uix.actions
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.util.Log
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.futo.inputmethod.latin.BuildConfig
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.Action
import org.futo.inputmethod.latin.uix.ActionWindow
import org.futo.inputmethod.latin.uix.settings.ScrollableList
import org.futo.inputmethod.updates.openURI
data class BugInfo(val name: String, val details: String)
public object BugViewerState {
val bugs = mutableListOf<BugInfo>()
public fun pushBug(bug: BugInfo) {
Log.e("BugViewerState", "Bug pushed: $bug")
bugs.add(0, bug)
}
}
val BugViewerAction = Action(
icon = R.drawable.code,
name = R.string.bug_viewer_action_title,
simplePressImpl = null,
canShowKeyboard = true,
windowImpl = { manager, _ ->
val latinIme = manager.getLatinIMEForDebug()
object : ActionWindow {
@Composable
override fun windowName(): String {
return stringResource(R.string.bug_viewer_action_title)
}
@Composable
override fun WindowContents(keyboardShown: Boolean) {
ScrollableList {
if(BugViewerState.bugs.isEmpty()) {
Text("No errors have been reported yet", style = DebugLabel)
}
BugViewerState.bugs.forEach {
val name = "Bug in ${it.name} (${BuildConfig.VERSION_NAME})"
Text(name, style = DebugTitle)
Row {
TextButton(onClick = {
val clipboardManager = manager.getContext()
.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip =
ClipData.newPlainText("label", "$name\n\n${it.details}")
clipboardManager.setPrimaryClip(clip)
}) {
Text("Copy to clipboard")
}
TextButton(onClick = {
manager.getContext().openURI("mailto:keyboard@futo.org", newTask = true)
}) {
Text("Email us (include the copy)")
}
}
Text(it.details, style = DebugLabel)
Spacer(modifier = Modifier.height(8.dp))
}
}
}
override fun close() {
}
}
},
shownInEditor = false
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment