office: live rename propagation (poll) + Offline page Scaffold/TopAppBar
- Commit
ad86e0bbd4e7113f8fbab35f4b4e4621b87ce9e7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-06 18:58 UTC (5 months ago)
- Parents
5d6bc6b
Diff
office/src/main/java/com/vayunmathur/office/MainActivity.kt
diff --git a/office/src/main/java/com/vayunmathur/office/MainActivity.kt b/office/src/main/java/com/vayunmathur/office/MainActivity.ktindex 16c442c710..ec13c6d23f 100644--- a/office/src/main/java/com/vayunmathur/office/MainActivity.kt+++ b/office/src/main/java/com/vayunmathur/office/MainActivity.kt@@ -243,25 +243,26 @@ class MainActivity : ComponentActivity() { } } +@OptIn(ExperimentalMaterial3Api::class) @Composable fun InitialScreen(viewModel: OfficeViewModel, onOpenDocument: () -> Unit, onNavigateEditor: () -> Unit) {- Column(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background).padding(24.dp), horizontalAlignment = Alignment.CenterHorizontally) {- Spacer(Modifier.height(48.dp))- Text("Office", style = MaterialTheme.typography.headlineLarge, fontWeight = FontWeight.Bold)- Spacer(Modifier.height(8.dp))- Text("Open Document Format Viewer & Editor", style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)- Spacer(Modifier.height(32.dp))+ Scaffold(topBar = { TopAppBar(title = { Text("Office") }) }) { pad ->+ Column(Modifier.fillMaxSize().padding(pad).background(MaterialTheme.colorScheme.background).padding(24.dp), horizontalAlignment = Alignment.CenterHorizontally) {+ Spacer(Modifier.height(24.dp))+ Text("Open Document Format Viewer & Editor", style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Spacer(Modifier.height(32.dp)) - Button(onClick = onOpenDocument, modifier = Modifier.fillMaxWidth()) { Text(stringResource(R.string.open_document)) }- Spacer(Modifier.height(4.dp))- Text("Opens ODF, Word/Excel/PowerPoint, CSV, TSV, Markdown & text files",- style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center)- Spacer(Modifier.height(16.dp))+ Button(onClick = onOpenDocument, modifier = Modifier.fillMaxWidth()) { Text(stringResource(R.string.open_document)) }+ Spacer(Modifier.height(4.dp))+ Text("Opens ODF, Word/Excel/PowerPoint, CSV, TSV, Markdown & text files",+ style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center)+ Spacer(Modifier.height(16.dp)) - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {- OutlinedButton(onClick = { viewModel.createNewTextDocument(); onNavigateEditor() }, Modifier.weight(1f)) { Text("New Doc") }- OutlinedButton(onClick = { viewModel.createNewSpreadsheet(); onNavigateEditor() }, Modifier.weight(1f)) { Text("New Sheet") }- OutlinedButton(onClick = { viewModel.createNewPresentation(); onNavigateEditor() }, Modifier.weight(1f)) { Text("New Slides") }+ Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ OutlinedButton(onClick = { viewModel.createNewTextDocument(); onNavigateEditor() }, Modifier.weight(1f)) { Text("New Doc") }+ OutlinedButton(onClick = { viewModel.createNewSpreadsheet(); onNavigateEditor() }, Modifier.weight(1f)) { Text("New Sheet") }+ OutlinedButton(onClick = { viewModel.createNewPresentation(); onNavigateEditor() }, Modifier.weight(1f)) { Text("New Slides") }+ } } } }
office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt
diff --git a/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt b/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.ktindex 1d0b911a59..dcfcefbac5 100644--- a/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt+++ b/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt@@ -2073,6 +2073,7 @@ class OfficeViewModel(application: Application) : AndroidViewModel(application) while (isActive) { kotlinx.coroutines.delay(1200) runCatching { syncDoc(docId, key) }+ runCatching { pollTitle(docId, key) } // pick up an owner rename ~live } } // Presence upkeep: clear a peer's "typing…" a few seconds after they stop, and drop the whole@@ -2519,6 +2520,22 @@ class OfficeViewModel(application: Application) : AndroidViewModel(application) return latest } + /** Applies an owner rename to the currently-open document (title bar + index) if it changed. */+ private suspend fun pollTitle(docId: String, key: ByteArray) {+ if (currentDocId != docId) return+ val t = fetchTitle(docId, key, currentOwnerKey) ?: return+ val cur = (_state.value as? ViewState.Loaded)?.document ?: return+ if (cur.title == t) return+ withContext(Dispatchers.Main) {+ (_state.value as? ViewState.Loaded)?.document?.let { if (it.title != t) _state.value = ViewState.Loaded(withTitle(it, t)) }+ }+ val ds = DataStoreUtils.getInstance(getApplication())+ indexMutex.withLock {+ val index = loadIndex(ds).associateBy { it.docId }.toMutableMap()+ index[docId]?.let { if (it.title != t) { index[docId] = it.copy(title = t); saveIndex(ds, index.values.toList()) } }+ }+ }+ /** Owner renames the open online document; the new name is published (signed) to all members. */ fun renameDocument(newName: String, onResult: (Boolean) -> Unit = {}) { val docId = currentDocId; val key = currentDocKey