Assistant entry points: share sheet (new or last chat), widget, shortcuts, headset button
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
- Share: a sheet over the sharing app shows what came in, takes an optional request, and sends
to a new chat or the last assistant chat; files uploaded first; a new chat becomes the last.
- Home-screen widget (RemoteViews, nothing from the account): Ask, Speak, last chat.
- Launcher shortcuts published from code (the debug build's package differs): Ask, Speak, Last.
- ACTION_VOICE_COMMAND / VOICE_SEARCH_HANDS_FREE open the sheet listening; locked: unlock first.
- Quick Settings tile: STATE_INACTIVE (never greyed out), TOGGLEABLE_TILE false.
- fetch-tokens.py also writes values{,-night}/tokens.xml for what Compose cannot draw.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
38 files changed
+964
-135
No files matched your search
@@ -3,6 +3,24 @@
|
||||
What changed in each release of LLeMbas for Android. Versions follow SemVer; until 1.0.0 the app
|
||||
is in alpha and releases come off `main`.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- **Share to LLeMbas, with a say in it.** *Ask LLeMbas* in any app's share menu now opens a
|
||||
sheet over that app: what came in (the text or link, the files by name), a line for what to do
|
||||
with it (optional), and where it goes -- a **new chat** or the **last assistant chat**. Files
|
||||
are uploaded and go with the message; the chat then opens in the app.
|
||||
- **A home-screen widget**: *Ask anything* opens the assistant, the microphone opens it
|
||||
listening, and the clock opens the last assistant chat. It shows nothing from your account.
|
||||
- **Launcher shortcuts** (long-press the icon): Ask LLeMbas, Speak, Last chat.
|
||||
- **A headset's voice button** opens the assistant listening, when LLeMbas answers it; over the
|
||||
lock screen it asks to unlock first.
|
||||
|
||||
### Changed
|
||||
|
||||
- The Quick Settings tile always shows as ready, never greyed out.
|
||||
|
||||
## [1.0.0-beta.6] — 2026-11-10
|
||||
|
||||
For LLeMbas server 2.0 (2.0.0-beta.9 or later for schedules on a computer, the update check through the instance, pinning, folders, memory and search).
|
||||
|
||||
@@ -38,11 +38,11 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
|
||||
<!-- The assistant's sheet as an activity: the tile, the shortcut, ACTION_ASSIST, and
|
||||
the lock-screen path (it asks to unlock before sending anything). -->
|
||||
<!-- The assistant's sheet as an activity: the tile, the widget, the shortcuts,
|
||||
ACTION_ASSIST, a headset's voice button, and the lock-screen path (it asks to
|
||||
unlock before sending anything). -->
|
||||
<activity
|
||||
android:name=".assist.AssistActivity"
|
||||
android:exported="true"
|
||||
@@ -55,6 +55,15 @@
|
||||
<action android:name="android.intent.action.ASSIST" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<!-- A headset's voice button: the sheet opens listening. -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VOICE_COMMAND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.speech.action.VOICE_SEARCH_HANDS_FREE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
@@ -62,7 +71,9 @@
|
||||
android:exported="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:label="@string/share_label"
|
||||
android:taskAffinity="">
|
||||
android:taskAffinity=""
|
||||
android:theme="@style/Theme.Lembas.Sheet"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
@@ -78,6 +89,17 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- The home-screen widget: Ask, the microphone, the last assistant chat. -->
|
||||
<receiver
|
||||
android:name=".widget.AskWidget"
|
||||
android:exported="true"
|
||||
android:label="@string/tile_ask">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_ask" />
|
||||
</receiver>
|
||||
|
||||
<!-- The digital assistant: Settings › Default apps › Digital assistant app. -->
|
||||
<service
|
||||
android:name=".assist.LembasAssistService"
|
||||
@@ -112,6 +134,8 @@
|
||||
android:icon="@drawable/ic_notification"
|
||||
android:label="@string/tile_ask"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<!-- A button, not a switch. -->
|
||||
<meta-data android:name="android.service.quicksettings.TOGGLEABLE_TILE" android:value="false" />
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
|
||||
@@ -27,6 +27,8 @@ class LembasApp : Application() {
|
||||
// LLeMbas 2.0 has no reports, so 0.1's channel for them goes rather than sit empty in
|
||||
// the system's settings.
|
||||
manager.deleteNotificationChannel("reports")
|
||||
// The launcher's long-press shortcuts, in the app's language as it is now.
|
||||
eu.llembas.android.widget.Shortcuts.publish(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -3,17 +3,36 @@ package eu.llembas.android.assist
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.service.quicksettings.Tile
|
||||
import android.service.quicksettings.TileService
|
||||
import eu.llembas.android.R
|
||||
|
||||
/** A Quick Settings tile that opens the assistant's sheet: one more way in besides the power button. */
|
||||
/**
|
||||
* A Quick Settings tile that opens the assistant's sheet: one more way in besides the power
|
||||
* button. It is a button, not a switch -- always shown as ready (`STATE_INACTIVE`), never as
|
||||
* "on", and the system's default (`STATE_UNAVAILABLE` on some phones until the first update)
|
||||
* would grey it out. Over the lock screen the sheet opens there and asks to unlock before it
|
||||
* sends anything, as from any other way in.
|
||||
*/
|
||||
class AskTileService : TileService() {
|
||||
override fun onStartListening() {
|
||||
super.onStartListening()
|
||||
qsTile?.apply {
|
||||
state = Tile.STATE_INACTIVE
|
||||
label = getString(R.string.tile_ask)
|
||||
updateTile()
|
||||
}
|
||||
}
|
||||
|
||||
@android.annotation.SuppressLint("StartActivityAndCollapseDeprecated")
|
||||
override fun onClick() {
|
||||
super.onClick()
|
||||
val intent = Intent(this, AssistActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
if (Build.VERSION.SDK_INT >= 34) {
|
||||
// Android 14 refuses the Intent overload; the PendingIntent one is the way now.
|
||||
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
|
||||
startActivityAndCollapse(
|
||||
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT),
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
startActivityAndCollapse(intent)
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.llembas.android.assist
|
||||
import android.Manifest
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
@@ -17,6 +18,33 @@ import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.ui.theme.LembasTheme
|
||||
|
||||
/** What a way into the sheet asks for. */
|
||||
enum class Opening {
|
||||
Sheet,
|
||||
Listen,
|
||||
Continue,
|
||||
;
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* A headset's voice button sends `VOICE_COMMAND` (or, locked, `VOICE_SEARCH_HANDS_FREE`):
|
||||
* the person means to speak, so the sheet opens listening whatever Settings says.
|
||||
*/
|
||||
fun of(intent: Intent): Opening = when {
|
||||
intent.getBooleanExtra(AssistActivity.EXTRA_LISTEN, false) -> Listen
|
||||
intent.action == AssistActivity.ACTION_CONTINUE -> Continue
|
||||
intent.action in LISTENING -> Listen
|
||||
else -> Sheet
|
||||
}
|
||||
|
||||
private val LISTENING = setOf(
|
||||
AssistActivity.ACTION_LISTEN,
|
||||
Intent.ACTION_VOICE_COMMAND,
|
||||
"android.speech.action.VOICE_SEARCH_HANDS_FREE",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The assistant as an activity: what the Quick Settings tile, the "Ask" shortcut and a plain
|
||||
* `ACTION_ASSIST` open, and where the voice-interaction session hands over what needs an
|
||||
@@ -27,6 +55,7 @@ import eu.llembas.android.ui.theme.LembasTheme
|
||||
*/
|
||||
class AssistActivity : ComponentActivity() {
|
||||
private lateinit var controller: AssistController
|
||||
private lateinit var keyguard: KeyguardManager
|
||||
|
||||
/** Whether the phone is locked: the sheet shows nothing from the account until it is not. */
|
||||
private val locked = mutableStateOf(false)
|
||||
@@ -41,31 +70,9 @@ class AssistActivity : ComponentActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setShowWhenLocked(true)
|
||||
controller = AssistController(this, lifecycleScope)
|
||||
val keyguard = getSystemService(KeyguardManager::class.java)
|
||||
keyguard = getSystemService(KeyguardManager::class.java)
|
||||
locked.value = keyguard.isKeyguardLocked
|
||||
val waiting = intent.getStringExtra(EXTRA_QUESTION).orEmpty()
|
||||
val wantsMic = intent.getBooleanExtra(EXTRA_LISTEN, false)
|
||||
if (keyguard.isKeyguardLocked) {
|
||||
keyguard.requestDismissKeyguard(
|
||||
this,
|
||||
object : KeyguardManager.KeyguardDismissCallback() {
|
||||
override fun onDismissSucceeded() {
|
||||
locked.value = false
|
||||
if (waiting.isNotBlank()) controller.ask(waiting) else controller.opened(locked = false)
|
||||
}
|
||||
|
||||
override fun onDismissCancelled() = finish()
|
||||
|
||||
override fun onDismissError() = finish()
|
||||
},
|
||||
)
|
||||
} else if (waiting.isNotBlank()) {
|
||||
controller.ask(waiting)
|
||||
} else if (wantsMic && !controller.micAllowed()) {
|
||||
mic.launch(Manifest.permission.RECORD_AUDIO)
|
||||
} else {
|
||||
controller.opened(locked = false)
|
||||
}
|
||||
take(intent)
|
||||
setContent {
|
||||
val prefs by lembas.instances.prefs.collectAsState(initial = Prefs())
|
||||
LembasTheme(prefs.theme) {
|
||||
@@ -94,6 +101,50 @@ class AssistActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Opened again while it is up -- the headset's button pressed twice, the tile again. */
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
setIntent(intent)
|
||||
take(intent)
|
||||
}
|
||||
|
||||
/**
|
||||
* What the way in asked for: a question handed over by the session, listening (the headset's
|
||||
* voice button, the widget's microphone, the Speak shortcut), the last assistant chat (the
|
||||
* widget, the shortcut), or just the sheet. Over the lock screen each waits for Android to
|
||||
* unlock first.
|
||||
*/
|
||||
private fun take(intent: Intent) {
|
||||
val opening = Opening.of(intent)
|
||||
val waiting = intent.getStringExtra(EXTRA_QUESTION).orEmpty()
|
||||
val go = {
|
||||
when {
|
||||
waiting.isNotBlank() -> controller.ask(waiting)
|
||||
opening == Opening.Continue -> controller.continueWhenReady()
|
||||
opening == Opening.Listen && !controller.micAllowed() -> mic.launch(Manifest.permission.RECORD_AUDIO)
|
||||
opening == Opening.Listen -> controller.opened(locked = false, listen = true)
|
||||
else -> controller.opened(locked = false)
|
||||
}
|
||||
}
|
||||
if (keyguard.isKeyguardLocked) {
|
||||
keyguard.requestDismissKeyguard(
|
||||
this,
|
||||
object : KeyguardManager.KeyguardDismissCallback() {
|
||||
override fun onDismissSucceeded() {
|
||||
locked.value = false
|
||||
go()
|
||||
}
|
||||
|
||||
override fun onDismissCancelled() = finish()
|
||||
|
||||
override fun onDismissError() = finish()
|
||||
},
|
||||
)
|
||||
} else {
|
||||
go()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
controller.close()
|
||||
super.onDestroy()
|
||||
@@ -104,5 +155,17 @@ class AssistActivity : ComponentActivity() {
|
||||
|
||||
/** Handed over by the session: ask for the microphone, then listen. */
|
||||
const val EXTRA_LISTEN = "eu.llembas.android.LISTEN"
|
||||
|
||||
/** Open listening: the widget's microphone and the Speak shortcut. */
|
||||
const val ACTION_LISTEN = "eu.llembas.android.action.LISTEN"
|
||||
|
||||
/** Open at the last chat the assistant made: the widget and the shortcut. */
|
||||
const val ACTION_CONTINUE = "eu.llembas.android.action.CONTINUE"
|
||||
|
||||
/** The sheet, listening. */
|
||||
fun listening(context: Context): Intent = Intent(context, AssistActivity::class.java).setAction(ACTION_LISTEN)
|
||||
|
||||
/** The sheet, at the last assistant chat. */
|
||||
fun continuing(context: Context): Intent = Intent(context, AssistActivity::class.java).setAction(ACTION_CONTINUE)
|
||||
}
|
||||
}
|
||||
@@ -168,14 +168,25 @@ class AssistController(private val context: Context, private val scope: Coroutin
|
||||
/**
|
||||
* The sheet came up. It starts listening at once -- the microphone first, as an assistant
|
||||
* opens -- unless Settings says not to, the phone is locked (nothing is sent from the lock
|
||||
* screen), or the microphone is not allowed yet (that needs an activity to ask).
|
||||
* screen), or the microphone is not allowed yet (that needs an activity to ask). [listen]
|
||||
* is a way in that means to speak -- a headset's voice button -- and listens regardless.
|
||||
*/
|
||||
fun opened(locked: Boolean) {
|
||||
fun opened(locked: Boolean, listen: Boolean = false) {
|
||||
scope.launch {
|
||||
ready.join()
|
||||
val prefs = context.lembas.instances.prefs.first()
|
||||
val s = _state.value
|
||||
if (s.signedIn && !locked && prefs.assistantListens && s.canListen && s.empty && !s.listening && micAllowed()) listen()
|
||||
if (s.signedIn && !locked && (listen || prefs.assistantListens) && s.canListen && !s.listening && micAllowed()) {
|
||||
if (listen || s.empty) listen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Open at the last assistant chat, once it is known which that is. */
|
||||
fun continueWhenReady() {
|
||||
scope.launch {
|
||||
ready.join()
|
||||
if (_state.value.last != null) continueLast() else opened(locked = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,108 +7,131 @@ import android.os.Bundle
|
||||
import android.provider.OpenableColumns
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.core.content.IntentCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import eu.llembas.android.AppLanguage
|
||||
import eu.llembas.android.MainActivity
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.api.ApiException
|
||||
import eu.llembas.android.assist.AssistSheetFrame
|
||||
import eu.llembas.android.assist.LastAssist
|
||||
import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.push.Notifications
|
||||
import eu.llembas.android.ui.explain
|
||||
import eu.llembas.android.ui.theme.LembasTheme
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* "Share to LLeMbas": text, a link, a picture or a file from any app starts a new chat with it.
|
||||
* Files are uploaded first and bound to the first message, as the composer's are.
|
||||
* "Ask LLeMbas" in any app's share menu: text, a link, a picture or files. A sheet over the app
|
||||
* it came from says what came in, takes a line of what to do with it, and sends it to a new chat
|
||||
* or to the last chat the assistant made; files are uploaded first and bound to that message, as
|
||||
* the composer's are. The chat then opens in the app. A new chat made here becomes the
|
||||
* assistant's last chat, so the next share can follow it.
|
||||
*/
|
||||
class ShareActivity : ComponentActivity() {
|
||||
private val failure = mutableStateOf<String?>(null)
|
||||
class ShareActivity :
|
||||
ComponentActivity(),
|
||||
ShareActions {
|
||||
private val state = MutableStateFlow(ShareState())
|
||||
private var uris: List<Uri> = emptyList()
|
||||
|
||||
override fun attachBaseContext(newBase: Context) = super.attachBaseContext(AppLanguage.wrap(newBase))
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
uris = when (intent.action) {
|
||||
Intent.ACTION_SEND -> listOfNotNull(IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java))
|
||||
Intent.ACTION_SEND_MULTIPLE -> IntentCompat.getParcelableArrayListExtra(intent, Intent.EXTRA_STREAM, Uri::class.java).orEmpty()
|
||||
else -> emptyList()
|
||||
}
|
||||
val text = listOfNotNull(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getCharSequenceExtra(Intent.EXTRA_TEXT)?.toString())
|
||||
.filter { it.isNotBlank() }
|
||||
.distinct()
|
||||
.joinToString("\n\n")
|
||||
.trim()
|
||||
state.update { it.copy(text = text, files = uris.map { uri -> SharedFile(nameOf(uri), (contentResolver.getType(uri) ?: "").startsWith("image/")) }) }
|
||||
lifecycleScope.launch {
|
||||
val store = lembas.instances
|
||||
val prefs = store.prefs.first()
|
||||
state.update {
|
||||
it.copy(
|
||||
signedIn = store.current() != null,
|
||||
last = prefs.lastAssistChat.takeIf { id -> id.isNotBlank() && !prefs.assistantTemporary }
|
||||
?.let { id -> LastAssist(id, prefs.lastAssistTitle, prefs.lastAssistAt) },
|
||||
)
|
||||
}
|
||||
}
|
||||
setContent {
|
||||
LembasTheme {
|
||||
Surface(Modifier.fillMaxSize()) {
|
||||
Column(
|
||||
Modifier.fillMaxSize().padding(24.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
val error = failure.value
|
||||
if (error == null) {
|
||||
CircularProgressIndicator()
|
||||
Text(stringResource(R.string.share_sending))
|
||||
} else {
|
||||
Text(error, color = MaterialTheme.colorScheme.error)
|
||||
TextButton(onClick = { finish() }) { Text(stringResource(R.string.close)) }
|
||||
}
|
||||
val prefs by lembas.instances.prefs.collectAsState(initial = Prefs())
|
||||
val shown by state.collectAsState()
|
||||
LembasTheme(prefs.theme) {
|
||||
AssistSheetFrame(onDismiss = ::cancel) { handle, _ -> ShareSheetContent(shown, this@ShareActivity, handle) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun cancel() = finish()
|
||||
|
||||
override fun send(ask: String, toLast: Boolean) {
|
||||
if (state.value.sending) return
|
||||
state.update { it.copy(sending = true, error = null) }
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val store = lembas.instances
|
||||
val api = store.client() ?: run {
|
||||
startActivity(Intent(this@ShareActivity, MainActivity::class.java))
|
||||
finish()
|
||||
return@launch
|
||||
}
|
||||
val now = state.value
|
||||
val into = if (toLast) now.last?.chatId else null
|
||||
val files = uris.map { uri ->
|
||||
val bytes = withContext(Dispatchers.IO) { contentResolver.openInputStream(uri)?.use { it.readBytes() } ?: ByteArray(0) }
|
||||
api.upload(nameOf(uri), contentResolver.getType(uri) ?: "application/octet-stream", bytes, into).id
|
||||
}
|
||||
val message = shareMessage(ask, now.text, getString(R.string.share_default_prompt))
|
||||
val chatId = if (into != null) {
|
||||
api.sendMessage(into, message, files)
|
||||
into
|
||||
} else {
|
||||
val prefs = store.prefs.first()
|
||||
val made = api.createChat(message, files, model = prefs.assistantModel.ifBlank { null })
|
||||
store.savePrefs {
|
||||
it.copy(
|
||||
lastAssistChat = made.chat.id,
|
||||
lastAssistTitle = ask.ifBlank { now.text.ifBlank { now.files.firstOrNull()?.name.orEmpty() } }.take(120),
|
||||
lastAssistAt = System.currentTimeMillis(),
|
||||
)
|
||||
}
|
||||
made.chat.id
|
||||
}
|
||||
startActivity(
|
||||
Intent(this@ShareActivity, MainActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.putExtra(Notifications.EXTRA_CHAT, chatId),
|
||||
)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
// The last chat deleted since: it is not offered again.
|
||||
if (e is ApiException && e.status == 404 && toLast) {
|
||||
lembas.instances.savePrefs { it.copy(lastAssistChat = "", lastAssistTitle = "", lastAssistAt = 0) }
|
||||
state.update { it.copy(last = null) }
|
||||
}
|
||||
state.update { it.copy(sending = false, error = explain(e)) }
|
||||
}
|
||||
}
|
||||
lifecycleScope.launch { share(intent) }
|
||||
}
|
||||
|
||||
private suspend fun share(intent: Intent) {
|
||||
try {
|
||||
val api = lembas.instances.client() ?: run {
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val text = listOfNotNull(
|
||||
intent.getStringExtra(Intent.EXTRA_SUBJECT),
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT),
|
||||
).joinToString("\n\n").trim()
|
||||
val uris = when (intent.action) {
|
||||
Intent.ACTION_SEND -> listOfNotNull(IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java))
|
||||
|
||||
Intent.ACTION_SEND_MULTIPLE ->
|
||||
IntentCompat.getParcelableArrayListExtra(intent, Intent.EXTRA_STREAM, Uri::class.java).orEmpty()
|
||||
|
||||
else -> emptyList()
|
||||
}
|
||||
val files = uris.map { uri ->
|
||||
val (name, bytes) = withContext(Dispatchers.IO) {
|
||||
val name = contentResolver.query(uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null)?.use { c ->
|
||||
if (c.moveToFirst()) c.getString(0) else null
|
||||
} ?: "shared"
|
||||
name to (contentResolver.openInputStream(uri)?.use { it.readBytes() } ?: ByteArray(0))
|
||||
}
|
||||
api.upload(name, contentResolver.getType(uri) ?: "application/octet-stream", bytes).id
|
||||
}
|
||||
if (text.isBlank() && files.isEmpty()) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val made = api.createChat(text.ifBlank { getString(R.string.share_default_prompt) }, files)
|
||||
startActivity(
|
||||
Intent(this, MainActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.putExtra(Notifications.EXTRA_CHAT, made.chat.id),
|
||||
)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
failure.value = explain(e)
|
||||
}
|
||||
}
|
||||
private fun nameOf(uri: Uri): String = runCatching {
|
||||
contentResolver.query(uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null)?.use { c -> if (c.moveToFirst()) c.getString(0) else null }
|
||||
}.getOrNull() ?: uri.lastPathSegment ?: "shared"
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
package eu.llembas.android.share
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
|
||||
import androidx.compose.material.icons.filled.EditNote
|
||||
import androidx.compose.material.icons.filled.History
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.assist.LastAssist
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
|
||||
/** One shared file, as the sheet names it. */
|
||||
data class SharedFile(val name: String, val image: Boolean)
|
||||
|
||||
/** What was shared, where it may go, and how sending it went. */
|
||||
data class ShareState(
|
||||
val signedIn: Boolean = true,
|
||||
val text: String = "",
|
||||
val files: List<SharedFile> = emptyList(),
|
||||
/** The last chat the assistant made, offered as the other place to send it. */
|
||||
val last: LastAssist? = null,
|
||||
val sending: Boolean = false,
|
||||
val error: String? = null,
|
||||
)
|
||||
|
||||
/** What the share sheet can do; nothing by default, for the screenshot tests. */
|
||||
interface ShareActions {
|
||||
/** Send it with [ask] (empty: the default request) to a new chat, or [toLast] to the last assistant chat. */
|
||||
fun send(ask: String, toLast: Boolean) {}
|
||||
|
||||
fun cancel() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* The share sheet's contents, from [state] alone: what came in (the text, the files by name),
|
||||
* what to do with it (a line of the person's own, optional), where it goes -- a new chat, or the
|
||||
* last chat the assistant made -- and Send. Rows of unknown height stack; the two choices are
|
||||
* whole-row tap targets of at least 56 dp.
|
||||
*/
|
||||
@Composable
|
||||
fun ColumnScope.ShareSheetContent(state: ShareState, actions: ShareActions, handle: Modifier = Modifier) {
|
||||
val palette = LocalPalette.current
|
||||
var ask by remember { mutableStateOf("") }
|
||||
var toLast by remember { mutableStateOf(false) }
|
||||
|
||||
Column(handle.fillMaxWidth()) {
|
||||
Box(Modifier.fillMaxWidth().padding(top = 10.dp, bottom = 6.dp), contentAlignment = Alignment.Center) {
|
||||
Box(Modifier.size(width = 36.dp, height = 4.dp).background(palette.inkFaint, RoundedCornerShape(2.dp)))
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.share_label),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 8.dp),
|
||||
)
|
||||
if (state.sending) {
|
||||
val bar = Modifier.fillMaxWidth().padding(horizontal = 16.dp).height(2.dp)
|
||||
if (LocalInspectionMode.current) LinearProgressIndicator(progress = { 0.4f }, modifier = bar) else LinearProgressIndicator(bar)
|
||||
}
|
||||
}
|
||||
|
||||
if (!state.signedIn) {
|
||||
Column(Modifier.weight(1f).fillMaxWidth().padding(24.dp), verticalArrangement = Arrangement.Center) {
|
||||
Text(stringResource(R.string.assist_signed_out), style = MaterialTheme.typography.bodyLarge)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
// What came in.
|
||||
if (state.text.isNotBlank()) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
color = palette.surfaceRaised,
|
||||
border = BorderStroke(1.dp, palette.border),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Text(
|
||||
state.text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = palette.inkMuted,
|
||||
maxLines = 6,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
state.files.forEach { file ->
|
||||
Row(Modifier.fillMaxWidth().heightIn(min = 40.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(
|
||||
if (file.image) Icons.Filled.Image else Icons.AutoMirrored.Filled.InsertDriveFile,
|
||||
contentDescription = null,
|
||||
tint = palette.accent,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Text(file.name, style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
|
||||
// What to do with it.
|
||||
TextField(
|
||||
value = ask,
|
||||
onValueChange = { ask = it },
|
||||
placeholder = { Text(stringResource(R.string.share_ask_hint)) },
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = TextFieldDefaults.colors(
|
||||
focusedContainerColor = palette.surfaceRaised,
|
||||
unfocusedContainerColor = palette.surfaceRaised,
|
||||
focusedIndicatorColor = Color.Transparent,
|
||||
unfocusedIndicatorColor = Color.Transparent,
|
||||
),
|
||||
maxLines = 4,
|
||||
enabled = !state.sending,
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 52.dp),
|
||||
)
|
||||
|
||||
// Where it goes.
|
||||
val last = state.last
|
||||
if (last != null) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
color = palette.surfaceRaised,
|
||||
border = BorderStroke(1.dp, palette.border),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Column {
|
||||
Destination(Icons.Filled.EditNote, stringResource(R.string.new_chat), null, selected = !toLast, enabled = !state.sending) { toLast = false }
|
||||
Destination(Icons.Filled.History, stringResource(R.string.assist_continue), last.title, selected = toLast, enabled = !state.sending) {
|
||||
toLast =
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
state.error?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = palette.danger) }
|
||||
}
|
||||
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(start = 12.dp, end = 16.dp, top = 4.dp, bottom = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.End,
|
||||
) {
|
||||
TextButton(onClick = actions::cancel, modifier = Modifier.heightIn(min = 48.dp)) { Text(stringResource(R.string.cancel)) }
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Button(
|
||||
onClick = { actions.send(ask, toLast && last != null) },
|
||||
enabled = !state.sending && (state.text.isNotBlank() || state.files.isNotEmpty()),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = palette.accent, contentColor = palette.accentInk),
|
||||
modifier = Modifier.heightIn(min = 48.dp),
|
||||
) { Text(stringResource(if (state.sending) R.string.share_sending else R.string.send)) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Destination(icon: ImageVector, title: String, detail: String?, selected: Boolean, enabled: Boolean, onClick: () -> Unit) {
|
||||
val palette = LocalPalette.current
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.selectable(selected = selected, enabled = enabled, role = Role.RadioButton, onClick = onClick)
|
||||
.heightIn(min = 56.dp)
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(icon, contentDescription = null, tint = palette.inkMuted, modifier = Modifier.size(24.dp))
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge)
|
||||
detail?.takeIf { it.isNotBlank() }?.let {
|
||||
Text(it, style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted, maxLines = 2, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
RadioButton(selected = selected, onClick = null, enabled = enabled)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The message a share sends: the person's own words (or the default request) first, then what was
|
||||
* shared, so the model reads the request before the material.
|
||||
*/
|
||||
fun shareMessage(ask: String, shared: String, fallback: String): String {
|
||||
val request = ask.trim().ifBlank { fallback }
|
||||
return if (shared.isBlank()) request else "$request\n\n---\n\n${shared.trim()}"
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package eu.llembas.android.widget
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.graphics.drawable.Icon
|
||||
import android.widget.RemoteViews
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.assist.AssistActivity
|
||||
|
||||
/**
|
||||
* The home-screen widget: a bar that opens the assistant's sheet (Ask), the sheet listening (the
|
||||
* microphone), or the sheet at the last chat the assistant made. Nothing on it comes from the
|
||||
* account, so it never needs updating and shows nothing private wherever it is placed.
|
||||
*/
|
||||
class AskWidget : AppWidgetProvider() {
|
||||
override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) {
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_ask).apply {
|
||||
setOnClickPendingIntent(R.id.widget_ask, open(context, REQUEST_ASK, Intent(context, AssistActivity::class.java).setAction(Intent.ACTION_ASSIST)))
|
||||
setOnClickPendingIntent(R.id.widget_mic, open(context, REQUEST_LISTEN, AssistActivity.listening(context)))
|
||||
setOnClickPendingIntent(R.id.widget_last, open(context, REQUEST_CONTINUE, AssistActivity.continuing(context)))
|
||||
}
|
||||
ids.forEach { manager.updateAppWidget(it, views) }
|
||||
}
|
||||
|
||||
private fun open(context: Context, request: Int, intent: Intent): PendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
request,
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||
)
|
||||
|
||||
private companion object {
|
||||
const val REQUEST_ASK = 1
|
||||
const val REQUEST_LISTEN = 2
|
||||
const val REQUEST_CONTINUE = 3
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The launcher icon's long-press shortcuts: Ask, Speak and the last assistant chat. Published from
|
||||
* code rather than `shortcuts.xml`, because a static shortcut names the package, and the test
|
||||
* build's is `….debug`; and so their labels follow the app's language.
|
||||
*/
|
||||
object Shortcuts {
|
||||
fun publish(context: Context) {
|
||||
val manager = context.getSystemService(ShortcutManager::class.java) ?: return
|
||||
val shortcuts = listOf(
|
||||
shortcut(
|
||||
context,
|
||||
"ask",
|
||||
R.string.tile_ask,
|
||||
R.string.tile_ask,
|
||||
R.drawable.ic_shortcut_ask,
|
||||
Intent(context, AssistActivity::class.java).setAction(Intent.ACTION_ASSIST),
|
||||
),
|
||||
shortcut(context, "speak", R.string.widget_speak, R.string.widget_speak, R.drawable.ic_shortcut_mic, AssistActivity.listening(context)),
|
||||
shortcut(context, "continue", R.string.shortcut_last, R.string.assist_continue, R.drawable.ic_shortcut_history, AssistActivity.continuing(context)),
|
||||
)
|
||||
runCatching { manager.dynamicShortcuts = shortcuts }
|
||||
}
|
||||
|
||||
private fun shortcut(context: Context, id: String, short: Int, long: Int, icon: Int, intent: Intent): ShortcutInfo = ShortcutInfo.Builder(context, id)
|
||||
.setShortLabel(context.getString(short))
|
||||
.setLongLabel(context.getString(long))
|
||||
.setIcon(Icon.createWithResource(context, icon))
|
||||
.setIntent(intent)
|
||||
.build()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A launcher shortcut's icon: a Material icon (Apache-2.0) on a disc, in the theme's colours. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="48" android:viewportHeight="48">
|
||||
<path android:fillColor="@color/token_surface_raised" android:pathData="M24,0a24,24 0,1 1,0 48a24,24 0,1 1,0 -48z" />
|
||||
<group android:translateX="12" android:translateY="12">
|
||||
<path android:fillColor="@color/token_accent" android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2z" />
|
||||
</group>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A launcher shortcut's icon: a Material icon (Apache-2.0) on a disc, in the theme's colours. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="48" android:viewportHeight="48">
|
||||
<path android:fillColor="@color/token_surface_raised" android:pathData="M24,0a24,24 0,1 1,0 48a24,24 0,1 1,0 -48z" />
|
||||
<group android:translateX="12" android:translateY="12">
|
||||
<path android:fillColor="@color/token_accent" android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z" />
|
||||
</group>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A launcher shortcut's icon: a Material icon (Apache-2.0) on a disc, in the theme's colours. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp" android:height="48dp"
|
||||
android:viewportWidth="48" android:viewportHeight="48">
|
||||
<path android:fillColor="@color/token_surface_raised" android:pathData="M24,0a24,24 0,1 1,0 48a24,24 0,1 1,0 -48z" />
|
||||
<group android:translateX="12" android:translateY="12">
|
||||
<path android:fillColor="@color/token_accent" android:pathData="M12,14c1.66,0 2.99,-1.34 2.99,-3L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v6c0,1.66 1.34,3 3,3zM17.3,11c0,3 -2.54,5.1 -5.3,5.1S6.7,14 6.7,11L5,11c0,3.41 2.72,6.23 6,6.72L11,21h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z" />
|
||||
</group>
|
||||
</vector>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A Material icon (Apache-2.0) in the theme's colour (values*/tokens.xml). -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp" android:height="24dp"
|
||||
android:viewportWidth="24" android:viewportHeight="24">
|
||||
<path android:fillColor="@color/token_accent" android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A Material icon (Apache-2.0) in the theme's colour (values*/tokens.xml). -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp" android:height="24dp"
|
||||
android:viewportWidth="24" android:viewportHeight="24">
|
||||
<path android:fillColor="@color/token_ink_muted" android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A Material icon (Apache-2.0) in the theme's colour (values*/tokens.xml). -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp" android:height="24dp"
|
||||
android:viewportWidth="24" android:viewportHeight="24">
|
||||
<path android:fillColor="@color/token_accent_ink" android:pathData="M12,14c1.66,0 2.99,-1.34 2.99,-3L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v6c0,1.66 1.34,3 3,3zM17.3,11c0,3 -2.54,5.1 -5.3,5.1S6.7,14 6.7,11L5,11c0,3.41 2.72,6.23 6,6.72L11,21h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- The widget's bar, in the theme's colours (values*/tokens.xml). -->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<solid android:color="@color/token_surface" />
|
||||
<stroke android:width="1dp" android:color="@color/token_border" />
|
||||
<corners android:radius="28dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||
<solid android:color="@color/token_accent" />
|
||||
</shape>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- The home-screen widget: Ask (the sheet), the microphone (the sheet, listening) and the last
|
||||
assistant chat. It shows nothing from the account -- no chat title, no model -- so nothing
|
||||
of it is private wherever the launcher shows it. Every part keeps a fixed size except the
|
||||
Ask label, which gives. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/widget_background"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="56dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_ask"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/ic_widget_ask" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@string/widget_hint"
|
||||
android:textColor="@color/token_ink_muted"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widget_last"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:contentDescription="@string/assist_continue"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/ic_widget_history" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widget_mic"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="2dp"
|
||||
android:background="@drawable/widget_mic_background"
|
||||
android:contentDescription="@string/widget_speak"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/ic_widget_mic" />
|
||||
</LinearLayout>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">Používá ho asistent i mikrofon v konverzaci. S LLeMbas asistent ukazuje slova s malým zpožděním a pauza je odešle, konverzace je zapíše, když přestanete; s rozpoznáváním v telefonu se objevují, jak mluvíte.</string>
|
||||
<string name="share_sending">Odesílá se do LLeMbas…</string>
|
||||
<string name="share_default_prompt">Podívejte se na tohle.</string>
|
||||
<string name="share_ask_hint">Co s tím má LLeMbas udělat? (nepovinné)</string>
|
||||
<string name="widget_hint">Zeptejte se na cokoli</string>
|
||||
<string name="widget_speak">Mluvit</string>
|
||||
<string name="widget_description">Ptejte se hlasem nebo textem, nebo pokračujte v poslední konverzaci s asistentem. Neukazuje nic z vašeho účtu.</string>
|
||||
<string name="shortcut_last">Poslední chat</string>
|
||||
</resources>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">Wird vom Assistenten und vom Mikrofon im Chat genutzt. Mit LLeMbas zeigt der Assistent die Wörter einen Moment später, und eine Pause sendet sie, ein Chat schreibt sie auf, wenn Sie aufhören; mit der Erkennung des Telefons erscheinen sie beim Sprechen.</string>
|
||||
<string name="share_sending">Wird an LLeMbas gesendet…</string>
|
||||
<string name="share_default_prompt">Schauen Sie sich das an.</string>
|
||||
<string name="share_ask_hint">Was soll LLeMbas damit tun? (optional)</string>
|
||||
<string name="widget_hint">Frag mich alles</string>
|
||||
<string name="widget_speak">Sprechen</string>
|
||||
<string name="widget_description">Per Sprache oder Text fragen oder den letzten Assistenten-Chat fortsetzen. Zeigt nichts aus Ihrem Konto.</string>
|
||||
<string name="shortcut_last">Letzter Chat</string>
|
||||
</resources>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">La usan el asistente y el micrófono de un chat. Con LLeMbas el asistente muestra las palabras un momento después y una pausa las envía, y un chat las escribe cuando usted para; con el reconocimiento del teléfono aparecen mientras habla.</string>
|
||||
<string name="share_sending">Enviando a LLeMbas…</string>
|
||||
<string name="share_default_prompt">Échele un vistazo a esto.</string>
|
||||
<string name="share_ask_hint">¿Qué debe hacer LLeMbas con esto? (opcional)</string>
|
||||
<string name="widget_hint">Pregunta lo que quieras</string>
|
||||
<string name="widget_speak">Hablar</string>
|
||||
<string name="widget_description">Pregunta por voz o por texto, o continúa el último chat del asistente. No muestra nada de tu cuenta.</string>
|
||||
<string name="shortcut_last">Último chat</string>
|
||||
</resources>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">Utilisée par l’assistant et par le micro d’une conversation. Avec LLeMbas, l’assistant affiche les mots avec un léger décalage et une pause les envoie, et une conversation les écrit quand vous vous arrêtez ; avec la reconnaissance du téléphone, ils apparaissent pendant que vous parlez.</string>
|
||||
<string name="share_sending">Envoi à LLeMbas…</string>
|
||||
<string name="share_default_prompt">Jetez un œil à ceci.</string>
|
||||
<string name="share_ask_hint">Que doit en faire LLeMbas ? (facultatif)</string>
|
||||
<string name="widget_hint">Posez une question</string>
|
||||
<string name="widget_speak">Parler</string>
|
||||
<string name="widget_description">Demandez à la voix ou par écrit, ou reprenez la dernière discussion de l’assistant. N’affiche rien de votre compte.</string>
|
||||
<string name="shortcut_last">Dernière discussion</string>
|
||||
</resources>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">Az asszisztens és a csevegés mikrofonja használja. LLeMbasszal az asszisztens kis késéssel mutatja a szavakat, és egy szünet elküldi őket, a csevegés pedig akkor írja le őket, amikor abbahagyja; a telefon felismerőjével beszéd közben jelennek meg.</string>
|
||||
<string name="share_sending">Küldés az LLeMbas-nak…</string>
|
||||
<string name="share_default_prompt">Nézze meg ezt.</string>
|
||||
<string name="share_ask_hint">Mit kezdjen vele a LLeMbas? (nem kötelező)</string>
|
||||
<string name="widget_hint">Kérdezz bármit</string>
|
||||
<string name="widget_speak">Beszéd</string>
|
||||
<string name="widget_description">Kérdezz hanggal vagy szöveggel, vagy folytasd az asszisztens legutóbbi csevegését. A fiókodból semmit sem mutat.</string>
|
||||
<string name="shortcut_last">Utolsó csevegés</string>
|
||||
</resources>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">La usano l’assistente e il microfono di una chat. Con LLeMbas l’assistente mostra le parole con un attimo di ritardo e una pausa le invia, e una chat le scrive quando si ferma; con il riconoscimento del telefono appaiono mentre parla.</string>
|
||||
<string name="share_sending">Invio a LLeMbas…</string>
|
||||
<string name="share_default_prompt">Dai un\'occhiata a questo.</string>
|
||||
<string name="share_ask_hint">Cosa deve farne LLeMbas? (facoltativo)</string>
|
||||
<string name="widget_hint">Chiedi qualsiasi cosa</string>
|
||||
<string name="widget_speak">Parla</string>
|
||||
<string name="widget_description">Chiedi a voce o per iscritto, o continua l’ultima chat dell’assistente. Non mostra nulla del tuo account.</string>
|
||||
<string name="shortcut_last">Ultima chat</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.9 (moria). Do not edit. -->
|
||||
<resources>
|
||||
<color name="token_bg">#FF0B0D10</color>
|
||||
<color name="token_surface">#FF11151A</color>
|
||||
<color name="token_surface_raised">#FF171C22</color>
|
||||
<color name="token_border">#FF26303A</color>
|
||||
<color name="token_ink">#FFE2E8EC</color>
|
||||
<color name="token_ink_muted">#FFA6B2BC</color>
|
||||
<color name="token_accent">#FF8FD8E8</color>
|
||||
<color name="token_accent_ink">#FF061418</color>
|
||||
<color name="token_accent_soft">#1F8FD8E8</color>
|
||||
</resources>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">Używa go asystent i mikrofon w czacie. Z LLeMbas asystent pokazuje słowa z lekkim opóźnieniem, a pauza je wysyła, czat zapisuje je, gdy przestaniesz; z rozpoznawaniem telefonu pojawiają się w trakcie mówienia.</string>
|
||||
<string name="share_sending">Wysyłanie do LLeMbas…</string>
|
||||
<string name="share_default_prompt">Zobacz to.</string>
|
||||
<string name="share_ask_hint">Co LLeMbas ma z tym zrobić? (opcjonalnie)</string>
|
||||
<string name="widget_hint">Zapytaj o cokolwiek</string>
|
||||
<string name="widget_speak">Mów</string>
|
||||
<string name="widget_description">Pytaj głosem lub tekstem albo kontynuuj ostatni czat asystenta. Nie pokazuje niczego z Twojego konta.</string>
|
||||
<string name="shortcut_last">Ostatni czat</string>
|
||||
</resources>
|
||||
@@ -401,4 +401,9 @@
|
||||
<string name="voice_input_hint">Používa ho asistent aj mikrofón v konverzácii. S LLeMbas asistent ukazuje slová s malým oneskorením a pauza ich odošle, konverzácia ich zapíše, keď prestanete; s rozpoznávaním v telefóne sa objavujú, ako hovoríte.</string>
|
||||
<string name="share_sending">Odosiela sa do LLeMbas…</string>
|
||||
<string name="share_default_prompt">Pozrite sa na toto.</string>
|
||||
<string name="share_ask_hint">Čo s tým má LLeMbas urobiť? (nepovinné)</string>
|
||||
<string name="widget_hint">Opýtajte sa na čokoľvek</string>
|
||||
<string name="widget_speak">Hovoriť</string>
|
||||
<string name="widget_description">Pýtajte sa hlasom alebo textom, alebo pokračujte v poslednej konverzácii s asistentom. Neukazuje nič z vášho účtu.</string>
|
||||
<string name="shortcut_last">Posledný chat</string>
|
||||
</resources>
|
||||
@@ -403,4 +403,9 @@
|
||||
<string name="voice_input_hint">Used by the assistant and by the microphone in a chat. With LLeMbas the assistant shows the words a moment behind you and a pause sends them, and a chat writes them down when you stop; with the phone\'s recogniser they appear as you speak.</string>
|
||||
<string name="share_sending">Sending to LLeMbas…</string>
|
||||
<string name="share_default_prompt">Have a look at this.</string>
|
||||
<string name="share_ask_hint">What should LLeMbas do with it? (optional)</string>
|
||||
<string name="widget_hint">Ask anything</string>
|
||||
<string name="widget_speak">Speak</string>
|
||||
<string name="widget_description">Ask by voice or text, or carry on the last assistant chat. Shows nothing from your account.</string>
|
||||
<string name="shortcut_last">Last chat</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at v2.0.0-beta.9 (shire). Do not edit. -->
|
||||
<resources>
|
||||
<color name="token_bg">#FFF1EAD6</color>
|
||||
<color name="token_surface">#FFF8F3E5</color>
|
||||
<color name="token_surface_raised">#FFFCF9F0</color>
|
||||
<color name="token_border">#FFCBBF9D</color>
|
||||
<color name="token_ink">#FF1F2418</color>
|
||||
<color name="token_ink_muted">#FF474D3B</color>
|
||||
<color name="token_accent">#FF285F3C</color>
|
||||
<color name="token_accent_ink">#FFF8F3E5</color>
|
||||
<color name="token_accent_soft">#1A285F3C</color>
|
||||
</resources>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<shortcut
|
||||
android:shortcutId="ask"
|
||||
android:enabled="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:shortcutShortLabel="@string/tile_ask">
|
||||
<intent
|
||||
android:action="android.intent.action.ASSIST"
|
||||
android:targetPackage="eu.llembas.android"
|
||||
android:targetClass="eu.llembas.android.assist.AssistActivity" />
|
||||
</shortcut>
|
||||
</shortcuts>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_description"
|
||||
android:initialLayout="@layout/widget_ask"
|
||||
android:minWidth="250dp"
|
||||
android:minHeight="40dp"
|
||||
android:minResizeWidth="180dp"
|
||||
android:previewLayout="@layout/widget_ask"
|
||||
android:resizeMode="horizontal"
|
||||
android:targetCellWidth="4"
|
||||
android:targetCellHeight="1"
|
||||
android:updatePeriodMillis="0"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -10,6 +10,7 @@ import eu.llembas.android.assist.SheetStop
|
||||
import eu.llembas.android.assist.settle
|
||||
import eu.llembas.android.assist.usePhoneRecognizer
|
||||
import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.share.shareMessage
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
@@ -87,4 +88,12 @@ class AssistTest {
|
||||
assertFalse(usePhoneRecognizer(Prefs.VOICE_LEMBAS, phoneHas = true, instanceStt = true))
|
||||
assertTrue(usePhoneRecognizer(Prefs.VOICE_LEMBAS, phoneHas = true, instanceStt = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aShareSendsTheRequestBeforeWhatWasShared() {
|
||||
assertEquals("Summarise it.\n\n---\n\nhttps://example.org", shareMessage(" Summarise it. ", "https://example.org\n", "Have a look."))
|
||||
assertEquals("Have a look.\n\n---\n\nSome text", shareMessage("", "Some text", "Have a look."))
|
||||
// Files only: the request alone, the files go as attachments.
|
||||
assertEquals("Have a look.", shareMessage(" ", "", "Have a look."))
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,8 @@ import eu.llembas.android.assist.Connection
|
||||
import eu.llembas.android.assist.LastAssist
|
||||
import eu.llembas.android.auth.Instance
|
||||
import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.share.ShareState
|
||||
import eu.llembas.android.share.SharedFile
|
||||
import eu.llembas.android.ui.chat.ChatState
|
||||
import eu.llembas.android.ui.chat.Draft
|
||||
import eu.llembas.android.ui.home.ChatsState
|
||||
@@ -411,6 +413,18 @@ object Fakes {
|
||||
error = "Home cannot be reached.",
|
||||
)
|
||||
|
||||
// A share from another app.
|
||||
val shareLink = ShareState(
|
||||
text = "The Long Road: a walker's guide to waybread\nhttps://example.org/waybread",
|
||||
last = LastAssist("c1", "Packing for the road", 0),
|
||||
)
|
||||
|
||||
val shareFiles = ShareState(
|
||||
files = listOf(SharedFile("map-of-the-road.jpg", image = true), SharedFile("provisions.pdf", image = false)),
|
||||
last = LastAssist("c1", "Packing for the road", 0),
|
||||
error = "Home cannot be reached.",
|
||||
)
|
||||
|
||||
// Scheduled: shaped as the server's contract fixtures are (contract/schedule*.json).
|
||||
private fun rule(text: String) = LembasJson.parseToJsonElement(text).jsonObject
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
@file:OptIn(ExperimentalRoborazziApi::class)
|
||||
|
||||
package eu.llembas.android.shots
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -16,10 +20,20 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
|
||||
import com.github.takahirom.roborazzi.RoborazziComposeOptions
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import com.github.takahirom.roborazzi.inspectionMode
|
||||
import com.github.takahirom.roborazzi.size
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.assist.AssistActions
|
||||
import eu.llembas.android.assist.AssistSheetContent
|
||||
import eu.llembas.android.assist.AssistSheetFrame
|
||||
import eu.llembas.android.assist.AssistUiState
|
||||
import eu.llembas.android.share.ShareActions
|
||||
import eu.llembas.android.share.ShareSheetContent
|
||||
import eu.llembas.android.share.ShareState
|
||||
import eu.llembas.android.ui.chat.ActivityActions
|
||||
import eu.llembas.android.ui.chat.ActivityContent
|
||||
import eu.llembas.android.ui.chat.CardSheet
|
||||
@@ -66,6 +80,8 @@ private object NoSettingsActions : SettingsActions
|
||||
|
||||
private object NoAssistActions : AssistActions
|
||||
|
||||
private object NoShareActions : ShareActions
|
||||
|
||||
/**
|
||||
* The app's screens with made-up data ([Fakes]), as a phone shows them: each in Shire and
|
||||
* Moria, at a large phone's size and, where things crowd, a small one's and with large type.
|
||||
@@ -287,6 +303,49 @@ class ScreenShots {
|
||||
shoot("28-memory", Phone.Small, fontScale = 1.5f) { MemoryContent(Fakes.memory, NoMemoryActions) }
|
||||
shoot("28-memory-none") { MemoryContent(MemoryState(), NoMemoryActions) }
|
||||
}
|
||||
|
||||
/** "Ask LLeMbas" from another app's share menu: a link, and a picture with a file. */
|
||||
@Test
|
||||
fun share() {
|
||||
val over: (ShareState) -> @Composable () -> Unit = { state ->
|
||||
{
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ChatContent(Fakes.transcript, NoChatActions, agent = false)
|
||||
AssistSheetFrame(onDismiss = {}) { handle, _ -> ShareSheetContent(state, NoShareActions, handle) }
|
||||
}
|
||||
}
|
||||
}
|
||||
shoot("30-share-link", content = over(Fakes.shareLink))
|
||||
shoot("30-share-link", Phone.Small, fontScale = 1.5f, content = over(Fakes.shareLink))
|
||||
shoot("31-share-files", content = over(Fakes.shareFiles))
|
||||
}
|
||||
|
||||
/** The home-screen widget, as the launcher inflates it (light; [widgetNight] is dark). */
|
||||
@Test
|
||||
fun widget() = shootWidget("light")
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "+night")
|
||||
fun widgetNight() = shootWidget("dark")
|
||||
|
||||
private fun shootWidget(theme: String) {
|
||||
for (phone in listOf(Phone.Large, Phone.Small)) {
|
||||
captureRoboImage(
|
||||
filePath = "build/screenshots/${phone.tag}-32-widget-$theme.png",
|
||||
roborazziComposeOptions = RoborazziComposeOptions {
|
||||
size(phone.widthDp, 120)
|
||||
inspectionMode(true)
|
||||
},
|
||||
) {
|
||||
Box(Modifier.fillMaxSize().padding(16.dp), contentAlignment = Alignment.Center) {
|
||||
AndroidView(
|
||||
factory = { context -> LayoutInflater.from(context).inflate(R.layout.widget_ask, null) },
|
||||
modifier = Modifier.fillMaxWidth().height(64.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+46
-3
@@ -2,14 +2,19 @@
|
||||
"""The server's colours, as the app's Compose theme.
|
||||
|
||||
scripts/fetch-tokens.py <server-ref> read tokens.css at that ref (a tag such as v1.7.0),
|
||||
write Tokens.kt and tokens.lock.json
|
||||
scripts/fetch-tokens.py verify: Tokens.kt matches tokens.lock.json
|
||||
write Tokens.kt, the colour resources and tokens.lock.json
|
||||
scripts/fetch-tokens.py verify: they match tokens.lock.json
|
||||
|
||||
The server is a git checkout, LLeMbas beside this repository by default (LEMBAS_SERVER names
|
||||
another). Only the colour tokens of the two themes are read -- `moria` (declared on `:root`) and
|
||||
`shire` -- and each becomes a `Palette` in Kotlin. The lock records the ref, the commit and the
|
||||
SHA-256 of the generated file, as LLeMbas Desktop's `tokens.lock.json` does: the file in the tree
|
||||
says which server version the look comes from, and CI refuses a copy that drifted.
|
||||
|
||||
What Compose cannot draw -- the home-screen widget, the shortcuts' icons -- takes the same colours
|
||||
as Android resources: `values/tokens.xml` from `shire` and `values-night/tokens.xml` from `moria`,
|
||||
a few of the tokens as `@color/token_<name>`, so a widget follows the phone's dark mode in the
|
||||
app's own colours.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -27,6 +32,10 @@ SERVER = Path(os.environ.get("LEMBAS_SERVER", ROOT.parent / "LLeMbas"))
|
||||
SOURCE = "src/lembas/web/static/css/tokens.css"
|
||||
OUT = ROOT / "app/src/main/java/eu/llembas/android/ui/theme/Tokens.kt"
|
||||
LOCK = ROOT / "tokens.lock.json"
|
||||
RES = ROOT / "app/src/main/res"
|
||||
# The tokens a resource reads, and which theme each folder takes.
|
||||
RES_NAMES = ("bg", "surface", "surface-raised", "border", "ink", "ink-muted", "accent", "accent-ink", "accent-soft")
|
||||
RES_THEMES = {"values": "shire", "values-night": "moria"}
|
||||
|
||||
# The tokens the app uses, in the order they are written. A token missing from a theme is an
|
||||
# error rather than a default: a palette that silently fell back would look right and be wrong.
|
||||
@@ -75,6 +84,32 @@ def camel(name: str) -> str:
|
||||
return head + "".join(p.capitalize() for p in rest)
|
||||
|
||||
|
||||
def android_colour(value: str) -> str:
|
||||
"""#AARRGGBB, as a resource writes it."""
|
||||
return "#" + argb(value)[2:]
|
||||
|
||||
|
||||
def theme_values(css: str, theme: str) -> dict[str, str]:
|
||||
return dict(re.findall(r"--([a-z0-9-]+)\s*:\s*([^;]+);", block(css, THEMES[theme])))
|
||||
|
||||
|
||||
def generate_res(css: str, ref: str, theme: str) -> str:
|
||||
values = theme_values(css, theme)
|
||||
lines = [
|
||||
'<?xml version="1.0" encoding="utf-8"?>',
|
||||
f"<!-- Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at {ref} ({theme}). Do not edit. -->",
|
||||
"<resources>",
|
||||
*[f' <color name="token_{n.replace("-", "_")}">{android_colour(values[n])}</color>' for n in RES_NAMES],
|
||||
"</resources>",
|
||||
"",
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def res_files() -> dict[str, Path]:
|
||||
return {folder: RES / folder / "tokens.xml" for folder in RES_THEMES}
|
||||
|
||||
|
||||
def generate(css: str, ref: str) -> str:
|
||||
lines = [
|
||||
"// Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at "
|
||||
@@ -105,6 +140,9 @@ def main() -> None:
|
||||
lock = json.loads(LOCK.read_text())
|
||||
if sha(OUT) != lock["sha256"]:
|
||||
sys.exit(f"fetch-tokens: {OUT.name} does not match {LOCK.name} (server {lock['tag']})")
|
||||
for folder, path in res_files().items():
|
||||
if not path.exists() or sha(path) != lock.get("res", {}).get(folder):
|
||||
sys.exit(f"fetch-tokens: {folder}/tokens.xml does not match {LOCK.name} (server {lock['tag']})")
|
||||
print(f"fetch-tokens: {OUT.name} matches {LOCK.name} (server {lock['tag']})")
|
||||
return
|
||||
ref = sys.argv[1]
|
||||
@@ -118,8 +156,13 @@ def main() -> None:
|
||||
).stdout
|
||||
OUT.parent.mkdir(parents=True, exist_ok=True)
|
||||
OUT.write_text(generate(css, ref), encoding="utf-8")
|
||||
res = {}
|
||||
for folder, path in res_files().items():
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(generate_res(css, ref, RES_THEMES[folder]), encoding="utf-8")
|
||||
res[folder] = sha(path)
|
||||
LOCK.write_text(
|
||||
json.dumps({"tag": ref, "commit": commit, "sha256": sha(OUT)}, indent=2) + "\n"
|
||||
json.dumps({"tag": ref, "commit": commit, "sha256": sha(OUT), "res": res}, indent=2) + "\n"
|
||||
)
|
||||
print(f"fetch-tokens: wrote {OUT.relative_to(ROOT)} from {ref} ({commit[:12]})")
|
||||
|
||||
|
||||
@@ -429,6 +429,11 @@ STRINGS: dict[str, str] = {
|
||||
# Share
|
||||
"share_sending": "Sending to LLeMbas…",
|
||||
"share_default_prompt": "Have a look at this.",
|
||||
"share_ask_hint": "What should LLeMbas do with it? (optional)",
|
||||
"widget_hint": "Ask anything",
|
||||
"widget_speak": "Speak",
|
||||
"widget_description": "Ask by voice or text, or carry on the last assistant chat. Shows nothing from your account.",
|
||||
"shortcut_last": "Last chat",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -152,9 +152,11 @@
|
||||
"settings_about": "O aplikaci",
|
||||
"settings_assistant": "Asistent",
|
||||
"settings_instances": "Instance",
|
||||
"share_ask_hint": "Co s tím má LLeMbas udělat? (nepovinné)",
|
||||
"share_default_prompt": "Podívejte se na tohle.",
|
||||
"share_label": "Zeptat se LLeMbas",
|
||||
"share_sending": "Odesílá se do LLeMbas…",
|
||||
"shortcut_last": "Poslední chat",
|
||||
"shown": "Zobrazeno",
|
||||
"signin_address": "Adresa instance",
|
||||
"signin_code_intro": "Otevřete instanci v prohlížeči, přihlaste se a schvalte tento kód:",
|
||||
@@ -221,7 +223,10 @@
|
||||
"voice_input_lembas_line": "Převod řeči na text vaší instance, přes server. Nahrávka jde na vaši instanci a nikam jinam.",
|
||||
"voice_input_phone": "Telefon (Google nebo systémový)",
|
||||
"voice_input_phone_line": "Vlastní rozpoznávání řeči v telefonu. Slova se objevují, jak mluvíte; nahrávka jde tam, kam ji to rozpoznávání pošle.",
|
||||
"voice_input_phone_none": "Tento telefon nemá vlastní rozpoznávání řeči."
|
||||
"voice_input_phone_none": "Tento telefon nemá vlastní rozpoznávání řeči.",
|
||||
"widget_description": "Ptejte se hlasem nebo textem, nebo pokračujte v poslední konverzaci s asistentem. Neukazuje nic z vašeho účtu.",
|
||||
"widget_hint": "Zeptejte se na cokoli",
|
||||
"widget_speak": "Mluvit"
|
||||
},
|
||||
"de": {
|
||||
"about_version": "LLeMbas für Android %1$s",
|
||||
@@ -377,9 +382,11 @@
|
||||
"settings_about": "Über",
|
||||
"settings_assistant": "Assistent",
|
||||
"settings_instances": "Instanzen",
|
||||
"share_ask_hint": "Was soll LLeMbas damit tun? (optional)",
|
||||
"share_default_prompt": "Schauen Sie sich das an.",
|
||||
"share_label": "LLeMbas fragen",
|
||||
"share_sending": "Wird an LLeMbas gesendet…",
|
||||
"shortcut_last": "Letzter Chat",
|
||||
"shown": "Angezeigt",
|
||||
"signin_address": "Adresse der Instanz",
|
||||
"signin_code_intro": "Öffnen Sie die Instanz im Browser, melden Sie sich an und bestätigen Sie diesen Code:",
|
||||
@@ -446,7 +453,10 @@
|
||||
"voice_input_lembas_line": "Die Spracherkennung Ihrer Instanz, über den Server. Die Aufnahme geht an Ihre Instanz und nirgendwo sonst hin.",
|
||||
"voice_input_phone": "Telefon (Google oder das System)",
|
||||
"voice_input_phone_line": "Die eigene Spracherkennung des Telefons. Die Wörter erscheinen beim Sprechen; die Aufnahme geht dorthin, wohin diese Erkennung sie schickt.",
|
||||
"voice_input_phone_none": "Dieses Telefon hat keine eigene Spracherkennung."
|
||||
"voice_input_phone_none": "Dieses Telefon hat keine eigene Spracherkennung.",
|
||||
"widget_description": "Per Sprache oder Text fragen oder den letzten Assistenten-Chat fortsetzen. Zeigt nichts aus Ihrem Konto.",
|
||||
"widget_hint": "Frag mich alles",
|
||||
"widget_speak": "Sprechen"
|
||||
},
|
||||
"es": {
|
||||
"about_version": "LLeMbas para Android %1$s",
|
||||
@@ -601,9 +611,11 @@
|
||||
"settings_about": "Acerca de",
|
||||
"settings_assistant": "Asistente",
|
||||
"settings_instances": "Instancias",
|
||||
"share_ask_hint": "¿Qué debe hacer LLeMbas con esto? (opcional)",
|
||||
"share_default_prompt": "Échele un vistazo a esto.",
|
||||
"share_label": "Preguntar a LLeMbas",
|
||||
"share_sending": "Enviando a LLeMbas…",
|
||||
"shortcut_last": "Último chat",
|
||||
"shown": "Mostrado",
|
||||
"signin_address": "Dirección de la instancia",
|
||||
"signin_code_intro": "Abra la instancia en el navegador, inicie sesión y apruebe este código:",
|
||||
@@ -670,7 +682,10 @@
|
||||
"voice_input_lembas_line": "La conversión de voz a texto de su instancia, a través del servidor. La grabación va a su instancia y a ningún otro sitio.",
|
||||
"voice_input_phone": "Teléfono (Google o el del sistema)",
|
||||
"voice_input_phone_line": "El reconocimiento de voz del propio teléfono. Las palabras aparecen mientras habla; la grabación va adonde ese reconocimiento la envíe.",
|
||||
"voice_input_phone_none": "Este teléfono no tiene reconocimiento de voz propio."
|
||||
"voice_input_phone_none": "Este teléfono no tiene reconocimiento de voz propio.",
|
||||
"widget_description": "Pregunta por voz o por texto, o continúa el último chat del asistente. No muestra nada de tu cuenta.",
|
||||
"widget_hint": "Pregunta lo que quieras",
|
||||
"widget_speak": "Hablar"
|
||||
},
|
||||
"fr": {
|
||||
"about_version": "LLeMbas pour Android %1$s",
|
||||
@@ -826,9 +841,11 @@
|
||||
"settings_about": "À propos",
|
||||
"settings_assistant": "Assistant",
|
||||
"settings_instances": "Instances",
|
||||
"share_ask_hint": "Que doit en faire LLeMbas ? (facultatif)",
|
||||
"share_default_prompt": "Jetez un œil à ceci.",
|
||||
"share_label": "Demander à LLeMbas",
|
||||
"share_sending": "Envoi à LLeMbas…",
|
||||
"shortcut_last": "Dernière discussion",
|
||||
"shown": "Affiché",
|
||||
"signin_address": "Adresse de l'instance",
|
||||
"signin_code_intro": "Ouvrez l'instance dans le navigateur, connectez-vous et approuvez ce code :",
|
||||
@@ -895,7 +912,10 @@
|
||||
"voice_input_lembas_line": "La transcription de votre instance, via le serveur. L’enregistrement va à votre instance et nulle part ailleurs.",
|
||||
"voice_input_phone": "Téléphone (Google ou celui du système)",
|
||||
"voice_input_phone_line": "La reconnaissance vocale du téléphone. Les mots apparaissent pendant que vous parlez ; l’enregistrement va là où cette reconnaissance l’envoie.",
|
||||
"voice_input_phone_none": "Ce téléphone n’a pas de reconnaissance vocale propre."
|
||||
"voice_input_phone_none": "Ce téléphone n’a pas de reconnaissance vocale propre.",
|
||||
"widget_description": "Demandez à la voix ou par écrit, ou reprenez la dernière discussion de l’assistant. N’affiche rien de votre compte.",
|
||||
"widget_hint": "Posez une question",
|
||||
"widget_speak": "Parler"
|
||||
},
|
||||
"hu": {
|
||||
"about_version": "LLeMbas Androidra %1$s",
|
||||
@@ -1051,9 +1071,11 @@
|
||||
"settings_about": "Névjegy",
|
||||
"settings_assistant": "Asszisztens",
|
||||
"settings_instances": "Példányok",
|
||||
"share_ask_hint": "Mit kezdjen vele a LLeMbas? (nem kötelező)",
|
||||
"share_default_prompt": "Nézze meg ezt.",
|
||||
"share_label": "Kérdés az LLeMbas-tól",
|
||||
"share_sending": "Küldés az LLeMbas-nak…",
|
||||
"shortcut_last": "Utolsó csevegés",
|
||||
"shown": "Megjelenítve",
|
||||
"signin_address": "A példány címe",
|
||||
"signin_code_intro": "Nyissa meg a példányt a böngészőben, jelentkezzen be, és hagyja jóvá ezt a kódot:",
|
||||
@@ -1120,7 +1142,10 @@
|
||||
"voice_input_lembas_line": "A példánya beszédfelismerése, a szerveren át. A felvétel a példányához megy, máshová nem.",
|
||||
"voice_input_phone": "Telefon (Google vagy a rendszeré)",
|
||||
"voice_input_phone_line": "A telefon saját beszédfelismerője. A szavak beszéd közben jelennek meg; a felvétel oda megy, ahová az a felismerő küldi.",
|
||||
"voice_input_phone_none": "Ennek a telefonnak nincs saját beszédfelismerője."
|
||||
"voice_input_phone_none": "Ennek a telefonnak nincs saját beszédfelismerője.",
|
||||
"widget_description": "Kérdezz hanggal vagy szöveggel, vagy folytasd az asszisztens legutóbbi csevegését. A fiókodból semmit sem mutat.",
|
||||
"widget_hint": "Kérdezz bármit",
|
||||
"widget_speak": "Beszéd"
|
||||
},
|
||||
"it": {
|
||||
"about_version": "LLeMbas per Android %1$s",
|
||||
@@ -1275,9 +1300,11 @@
|
||||
"settings_about": "Informazioni",
|
||||
"settings_assistant": "Assistente",
|
||||
"settings_instances": "Istanze",
|
||||
"share_ask_hint": "Cosa deve farne LLeMbas? (facoltativo)",
|
||||
"share_default_prompt": "Dai un'occhiata a questo.",
|
||||
"share_label": "Chiedi a LLeMbas",
|
||||
"share_sending": "Invio a LLeMbas…",
|
||||
"shortcut_last": "Ultima chat",
|
||||
"shown": "Mostrato",
|
||||
"signin_address": "Indirizzo dell'istanza",
|
||||
"signin_code_intro": "Apri l'istanza nel browser, accedi e approva questo codice:",
|
||||
@@ -1344,7 +1371,10 @@
|
||||
"voice_input_lembas_line": "La trascrizione della sua istanza, tramite il server. La registrazione va alla sua istanza e da nessun’altra parte.",
|
||||
"voice_input_phone": "Telefono (Google o quello di sistema)",
|
||||
"voice_input_phone_line": "Il riconoscimento vocale del telefono. Le parole appaiono mentre parla; la registrazione va dove la manda quel riconoscimento.",
|
||||
"voice_input_phone_none": "Questo telefono non ha un riconoscimento vocale proprio."
|
||||
"voice_input_phone_none": "Questo telefono non ha un riconoscimento vocale proprio.",
|
||||
"widget_description": "Chiedi a voce o per iscritto, o continua l’ultima chat dell’assistente. Non mostra nulla del tuo account.",
|
||||
"widget_hint": "Chiedi qualsiasi cosa",
|
||||
"widget_speak": "Parla"
|
||||
},
|
||||
"pl": {
|
||||
"about_version": "LLeMbas na Androida %1$s",
|
||||
@@ -1499,9 +1529,11 @@
|
||||
"settings_about": "Informacje",
|
||||
"settings_assistant": "Asystent",
|
||||
"settings_instances": "Instancje",
|
||||
"share_ask_hint": "Co LLeMbas ma z tym zrobić? (opcjonalnie)",
|
||||
"share_default_prompt": "Zobacz to.",
|
||||
"share_label": "Zapytaj LLeMbas",
|
||||
"share_sending": "Wysyłanie do LLeMbas…",
|
||||
"shortcut_last": "Ostatni czat",
|
||||
"shown": "Pokazano",
|
||||
"signin_address": "Adres instancji",
|
||||
"signin_code_intro": "Otwórz instancję w przeglądarce, zaloguj się i zatwierdź ten kod:",
|
||||
@@ -1568,7 +1600,10 @@
|
||||
"voice_input_lembas_line": "Zamiana mowy na tekst Twojej instancji, przez serwer. Nagranie trafia do Twojej instancji i nigdzie indziej.",
|
||||
"voice_input_phone": "Telefon (Google lub systemowy)",
|
||||
"voice_input_phone_line": "Własne rozpoznawanie mowy telefonu. Słowa pojawiają się w trakcie mówienia; nagranie trafia tam, dokąd wyśle je to rozpoznawanie.",
|
||||
"voice_input_phone_none": "Ten telefon nie ma własnego rozpoznawania mowy."
|
||||
"voice_input_phone_none": "Ten telefon nie ma własnego rozpoznawania mowy.",
|
||||
"widget_description": "Pytaj głosem lub tekstem albo kontynuuj ostatni czat asystenta. Nie pokazuje niczego z Twojego konta.",
|
||||
"widget_hint": "Zapytaj o cokolwiek",
|
||||
"widget_speak": "Mów"
|
||||
},
|
||||
"sk": {
|
||||
"about_version": "LLeMbas pre Android %1$s",
|
||||
@@ -1723,9 +1758,11 @@
|
||||
"settings_about": "O aplikácii",
|
||||
"settings_assistant": "Asistent",
|
||||
"settings_instances": "Inštancie",
|
||||
"share_ask_hint": "Čo s tým má LLeMbas urobiť? (nepovinné)",
|
||||
"share_default_prompt": "Pozrite sa na toto.",
|
||||
"share_label": "Spýtať sa LLeMbas",
|
||||
"share_sending": "Odosiela sa do LLeMbas…",
|
||||
"shortcut_last": "Posledný chat",
|
||||
"shown": "Zobrazené",
|
||||
"signin_address": "Adresa inštancie",
|
||||
"signin_code_intro": "Otvorte inštanciu v prehliadači, prihláste sa a schváľte tento kód:",
|
||||
@@ -1792,6 +1829,9 @@
|
||||
"voice_input_lembas_line": "Prevod reči na text vašej inštancie, cez server. Nahrávka ide na vašu inštanciu a nikam inam.",
|
||||
"voice_input_phone": "Telefón (Google alebo systémový)",
|
||||
"voice_input_phone_line": "Vlastné rozpoznávanie reči v telefóne. Slová sa objavujú, ako hovoríte; nahrávka ide tam, kam ju to rozpoznávanie pošle.",
|
||||
"voice_input_phone_none": "Tento telefón nemá vlastné rozpoznávanie reči."
|
||||
"voice_input_phone_none": "Tento telefón nemá vlastné rozpoznávanie reči.",
|
||||
"widget_description": "Pýtajte sa hlasom alebo textom, alebo pokračujte v poslednej konverzácii s asistentom. Neukazuje nič z vášho účtu.",
|
||||
"widget_hint": "Opýtajte sa na čokoľvek",
|
||||
"widget_speak": "Hovoriť"
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"tag": "v2.0.0-beta.9",
|
||||
"commit": "3b7da5fc7ac72d5de9229919793dd299c03da6a8",
|
||||
"sha256": "9057a56beb78ef9f3042555841014b9372ac415e70e054f41afcd488a9f14777"
|
||||
"sha256": "9057a56beb78ef9f3042555841014b9372ac415e70e054f41afcd488a9f14777",
|
||||
"res": {
|
||||
"values": "ffa9a947b34431144ba452c64efd3d948547ebe6ec52da8735f9463bfad6ce2d",
|
||||
"values-night": "b8cd01974f9c7fd4a00f681b1c99c839ff5d86b538c1d777e9628e2bcc36b584"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user