Files
LLeMbas-Android/app/src/main/java/eu/llembas/android/LembasApp.kt
T
HomerandClaude Fable 5.2 5d1e36868c
CI / check (push) Canceled after 0s
Files is a file manager, and the viewer draws a file by what it is
Files listed and showed text. It now does what the web's explorer does,
through the server's /api/v2/files routes: upload (the system picker,
several at once, each streamed from where it is with its progress, one
request a file so a 413 for one does not take the others), new folder, new
text file (never over one that is there), rename, move and copy through a
folder picker that is walked rather than typed into, delete to the trash,
a long press to choose and a bar that moves, copies, downloads, shares or
deletes all that is chosen through /files/batch -- which answers path by
path, and what it refused is said in its own sentences. The trash: list,
restore, remove for good, empty. A file's versions: list, restore.

Leaving the instance: a download goes into a document the person chose
(ACTION_CREATE_DOCUMENT), streamed, several things or a folder as the
server's zip. Open with and Share hand another app a copy in the private
cache through the FileProvider the camera already uses (one more
cache-path, read-only, per grant); the copies go when Files is left, when
the app starts and at sign-out. No permission is added.

The viewer goes by file_kind. Text kinds as before, now editable up to the
server's 1 MB: a save says the sha it opened, a 409 shows the server's
sentence with Reload and Save anyway, and leaving with unsaved text asks.
The text being edited lives in a ViewModel: a megabyte does not fit a saved
instance state. A picture is copied to the cache, decoded with its edge and
pixel count capped whatever the file claims, and zooms and pans. A PDF is
drawn page by page by the platform's PdfRenderer from a cache copy. Sound
and video are played by the platform's MediaPlayer through a
MediaDataSource that asks the app's own HTTP client for each piece with a
Range request: the token stays in the Authorization header and the player
is never given an address, so no player library is added. CSV and TSV are a
grid with a row and column cap; a notebook is its cells' text, outputs as
plain text only. Archives, 3D models and binaries are their details with
Download, Open with and Share. An SVG is its source: the app has no WebView
and draws nothing a file could script. Nothing is rendered as HTML.

The share sheet has a third place to send to: Save to Files, into a folder
chosen with the same picker; shared text is kept as a note.

Strings: 61 new keys, 49 worded as the server's explorer words them and
translated from its catalogues at the pinned commit, 12 the app's own in
all eight languages.

An instance without these routes still lists and shows text; what it
cannot do says so.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 21:24:39 +00:00

90 lines
4.5 KiB
Kotlin

package eu.llembas.android
import android.app.Activity
import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.os.Bundle
import eu.llembas.android.api.EventsHub
import eu.llembas.android.api.Frame
import eu.llembas.android.api.StreamClient
import eu.llembas.android.auth.InstanceStore
import eu.llembas.android.wake.AppVisibility
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.Flow
/** The process: one store of instances, and the notification channels, made once. */
class LembasApp : Application() {
lateinit var instances: InstanceStore
private set
/** The one connection to the person's events route, shared by all that watch it. */
val events = EventsHub(CoroutineScope(SupervisorJob() + Dispatchers.Default))
/** The events route of the instance in use, as its frames; null when not signed in. */
suspend fun eventFrames(): Flow<Frame>? {
val instance = instances.current() ?: return null
val api = instances.clientFor(instance)
return events.frames(instance.id) { StreamClient(api).watch { api.events() } }
}
override fun onCreate() {
super.onCreate()
instances = InstanceStore(this)
// Copies of the account's files a viewer or another app was handed, left by a process that was killed.
eu.llembas.android.ui.files.FileCache.clear(this)
// Whether the app is on screen: the wake word may open the assistant's sheet as an
// activity only then (Android blocks one started from the background, silently).
registerActivityLifecycleCallbacks(
object : ActivityLifecycleCallbacks {
override fun onActivityStarted(activity: Activity) = AppVisibility.activityStarted()
override fun onActivityStopped(activity: Activity) = AppVisibility.activityStopped()
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit
override fun onActivityResumed(activity: Activity) = Unit
override fun onActivityPaused(activity: Activity) = Unit
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit
override fun onActivityDestroyed(activity: Activity) = Unit
},
)
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannels(
listOf(
NotificationChannel(CHANNEL_REPLIES, getString(R.string.channel_replies), NotificationManager.IMPORTANCE_DEFAULT),
NotificationChannel(CHANNEL_ASKS, getString(R.string.channel_asks), NotificationManager.IMPORTANCE_HIGH),
NotificationChannel(CHANNEL_SCHEDULED, getString(R.string.channel_scheduled), NotificationManager.IMPORTANCE_DEFAULT),
NotificationChannel(CHANNEL_SCHEDULED_FAILURES, getString(R.string.channel_scheduled_failures), NotificationManager.IMPORTANCE_HIGH),
NotificationChannel(CHANNEL_REPORTS, getString(R.string.channel_reports), NotificationManager.IMPORTANCE_DEFAULT),
NotificationChannel(CHANNEL_REPORTS_HIGH, getString(R.string.channel_reports_high), NotificationManager.IMPORTANCE_HIGH),
).onEach { it.lockscreenVisibility = android.app.Notification.VISIBILITY_PRIVATE } +
// A new version of the app says nothing about the account.
NotificationChannel(CHANNEL_UPDATES, getString(R.string.channel_updates), NotificationManager.IMPORTANCE_LOW),
)
// 0.1's channel for its reports goes rather than sit empty in the system's settings;
// the reports of LLeMbas 2.0 have a channel of their own (CHANNEL_REPORTS).
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)
eu.llembas.android.widget.AskWidget.refresh(this)
}
companion object {
const val CHANNEL_REPLIES = "replies"
const val CHANNEL_ASKS = "asks"
const val CHANNEL_SCHEDULED = "scheduled_results"
const val CHANNEL_SCHEDULED_FAILURES = "scheduled_failures"
const val CHANNEL_REPORTS = "reports_filed"
const val CHANNEL_REPORTS_HIGH = "reports_important"
const val CHANNEL_UPDATES = "updates"
}
}
val android.content.Context.lembas: LembasApp get() = applicationContext as LembasApp