Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions manager/src/main/kotlin/org/matrix/vector/manager/ui/VectorApp.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.matrix.vector.manager.ui

import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -14,6 +17,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
import androidx.navigation3.runtime.EntryProviderScope
Expand Down Expand Up @@ -77,6 +81,7 @@ import org.matrix.vector.ui.store.RepoScreen
@Composable
fun VectorApp() {
val navigator = rememberNavigator(VectorNavPanelStore, TOP_LEVEL_DESTINATIONS)
val context = LocalContext.current

// Where the launch intent asked to open. The activity has no back stack to act on, so it leaves
// the destination here and this is the first place there is one — on a cold start the splash is
Expand Down Expand Up @@ -163,7 +168,7 @@ fun VectorApp() {
rememberSaveableStateHolderNavEntryDecorator(),
rememberViewModelStoreNavEntryDecorator(),
),
entryProvider = entryProvider { registerRoutes(navigator) },
entryProvider = entryProvider { registerRoutes(navigator, context) },
)
// Last child of the Box so it draws over the destination, and inside the app window
// rather than in one of its own: parasitically this app is com.android.shell, which
Expand Down Expand Up @@ -195,11 +200,11 @@ fun VectorApp() {
* its keys by class, and entryProvider throws for one it was never given, so dropping the
* registration of a hidden panel would turn a stale saved stack into a crash.
*/
private fun EntryProviderScope<NavKey>.registerRoutes(navigator: Navigator) {
private fun EntryProviderScope<NavKey>.registerRoutes(navigator: Navigator, context: Context) {
entry<TopLevelRoute.Home> {
HomeScreen(
onOpenStatus = { navigator.go(SystemStatus) },
onOpenUrl = { url -> navigator.go(Web(url)) },
onOpenUrl = { url -> openLink(context, navigator, url) },
onOpenCanary = { navigator.go(Canary) },
onOpenReport = { navigator.go(Troubleshoot) },
onOpenUpdate = { navigator.go(FrameworkUpdate()) },
Expand Down Expand Up @@ -234,7 +239,7 @@ private fun EntryProviderScope<NavKey>.registerRoutes(navigator: Navigator) {
RepoDetailsScreen(
packageName = route.packageName,
onNavigateBack = { navigator.back() },
onOpenUrl = { url -> navigator.go(Web(url)) },
onOpenUrl = { url -> openLink(context, navigator, url) },
dataSource = ServiceLocator.store,
settings = ServiceLocator.settings,
host = remember(route.packageName) { VectorStoreInstallHost(route.packageName) },
Expand All @@ -255,14 +260,14 @@ private fun EntryProviderScope<NavKey>.registerRoutes(navigator: Navigator) {
entry<Troubleshoot> {
TroubleshootScreen(
onNavigateBack = { navigator.back() },
onOpenUrl = { url -> navigator.go(Web(url)) },
onOpenUrl = { url -> openLink(context, navigator, url) },
onOpenCanary = { navigator.go(Canary) },
)
}
entry<Canary> {
CanaryScreen(
onNavigateBack = { navigator.back() },
onOpenUrl = { url -> navigator.go(Web(url)) },
onOpenUrl = { url -> openLink(context, navigator, url) },
onInstall = { versionCode -> navigator.go(FrameworkUpdate(versionCode)) },
onOpenReport = { navigator.go(Troubleshoot) },
)
Expand All @@ -271,8 +276,26 @@ private fun EntryProviderScope<NavKey>.registerRoutes(navigator: Navigator) {
FrameworkUpdateScreen(
openOnVersionCode = route.versionCode.takeIf { it > 0 },
onNavigateBack = { navigator.back() },
onOpenUrl = { url -> navigator.go(Web(url)) },
onOpenUrl = { url -> openLink(context, navigator, url) },
)
}
entry<Web> { route -> WebScreen(url = route.url, onNavigateBack = { navigator.back() }) }
}

/**
* Opens a link in the in-app viewer, or in a browser with "Open links in a browser" on. Every
* screen's `onOpenUrl` lands here, so the setting is asked in one place, and read at the tap.
*/
private fun openLink(context: Context, navigator: Navigator, url: String) {
if (ServiceLocator.settings.openLinksExternally.value) {
try {
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
return
} catch (_: Exception) {
// No app took it, or it was refused (a file:// URI): the viewer beats a dead tap.
}
}
navigator.go(Web(url))
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ LocalizedOverlay {
ToggleRow(
title = stringResource(R.string.settings_open_externally),
icon = Icons.Rounded.OpenInBrowser,
subtitle = stringResource(R.string.settings_open_externally_summary),
subtitle =
if (openExternally) stringResource(R.string.settings_open_externally_summary_on)
else stringResource(R.string.settings_open_externally_summary),
checked = openExternally,
onCheckedChange = settings::setOpenLinksExternally,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.matrix.vector.manager.ui.screens.home

import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down Expand Up @@ -145,7 +142,6 @@ fun HomeScreen(
val status by viewModel.status.collectAsStateWithLifecycle()
val feed by viewModel.feed.collectAsStateWithLifecycle()
val refreshing by viewModel.refreshing.collectAsStateWithLifecycle()
val openExternally by viewModel.openLinksExternally.collectAsStateWithLifecycle()
val feedItems by viewModel.feedItems.collectAsStateWithLifecycle()
val loadingHistory by viewModel.loadingHistory.collectAsStateWithLifecycle()
val historyStalled by viewModel.historyStalled.collectAsStateWithLifecycle()
Expand All @@ -156,7 +152,6 @@ fun HomeScreen(
val presence by viewModel.presence.collectAsStateWithLifecycle()
val promptDismissed by viewModel.launcherPromptDismissed.collectAsStateWithLifecycle()
val hintStatus by viewModel.statusBadgeHint.collectAsStateWithLifecycle()
val context = LocalContext.current
var showSplash by rememberSaveable { mutableStateOf(false) }
var showAppearance by rememberSaveable { mutableStateOf(false) }
var showLanguage by rememberSaveable { mutableStateOf(false) }
Expand Down Expand Up @@ -203,25 +198,6 @@ fun HomeScreen(
}
}

// Every GitHub link goes through the in-app viewer by default; the setting sends them to a
// browser instead for users who would rather stay in one.
fun open(url: String) {
if (openExternally) {
try {
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(url))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
} catch (_: ActivityNotFoundException) {
// Nothing on the device took the intent. Falling back to the built-in viewer beats
// a link tap that does nothing at all.
onOpenUrl(url)
}
} else {
onOpenUrl(url)
}
}

Scaffold(
// The header draws its own status-bar inset so it can run under the bar; letting the
// Scaffold consume it here would leave a band of plain background above the pane. The
Expand Down Expand Up @@ -284,12 +260,12 @@ fun HomeScreen(
// is effectively unreachable without a long scroll.
item {
TakePartSection(
onOpen = ::open,
onOpen = onOpenUrl,
onCanary = onOpenCanary,
onReport = onOpenReport,
)
Spacer(Modifier.height(14.dp))
ProjectFooter(feed = feed, onClick = { open(GitHubRepository.REPO_URL) })
ProjectFooter(feed, onClick = { onOpenUrl(GitHubRepository.REPO_URL) })
Spacer(Modifier.height(26.dp))
}

Expand All @@ -303,9 +279,9 @@ fun HomeScreen(
onLoadMoreHistory = viewModel::loadMoreHistory,
onToggleAuthor = viewModel::toggleAuthorFilter,
onClearAuthors = viewModel::clearAuthorFilter,
onOpenCommit = { c -> open(c.htmlUrl ?: GitHubRepository.REPO_URL) },
onOpenPullRequest = { pr -> open("${GitHubRepository.REPO_URL}/pull/$pr") },
onOpenProfile = { c -> open(c.profileUrl ?: GitHubRepository.REPO_URL) },
onOpenCommit = { onOpenUrl(it.htmlUrl ?: GitHubRepository.REPO_URL) },
onOpenPullRequest = { onOpenUrl("${GitHubRepository.REPO_URL}/pull/$it") },
onOpenProfile = { onOpenUrl(it.profileUrl ?: GitHubRepository.REPO_URL) },
)

item { Spacer(Modifier.height(24.dp)) }
Expand Down Expand Up @@ -377,8 +353,8 @@ fun HomeScreen(
LanguageSheet(
controller = VectorLocaleController,
onDismiss = { showLanguage = false },
onHelpTranslate = { open(CROWDIN_URL) },
onOpenUrl = ::open,
onHelpTranslate = { onOpenUrl(CROWDIN_URL) },
onOpenUrl = onOpenUrl,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ class HomeViewModel(
private val github: GitHubRepository,
) : ViewModel() {

val openLinksExternally: StateFlow<Boolean> = ServiceLocator.settings.openLinksExternally

val headerAmbience: StateFlow<String> = ServiceLocator.settings.headerAmbience

private val _status = MutableStateFlow(FrameworkStatus())
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
</plurals>
<string name="settings_open_externally">فتح الروابط في المتصفح</string>
<string name="settings_open_externally_summary">عند الإيقاف: تُفتح صفحات GitHub داخل Vector.</string>
<string name="settings_open_externally_summary_on">عند التشغيل: تُفتح صفحات GitHub في المتصفح.</string>

<string name="scope_use_recommended">استخدام ما تطلبه الوحدة</string>
<string name="scope_select_visible">تحديد كل ما هو ظاهر</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">Links im Browser öffnen</string>
<string name="settings_open_externally_summary">Aus: GitHub-Seiten öffnen sich in Vector.</string>
<string name="settings_open_externally_summary_on">An: GitHub-Seiten öffnen sich im Browser.</string>

<string name="scope_use_recommended">Nehmen, was das Modul verlangt</string>
<string name="scope_select_visible">Alles Angezeigte auswählen</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">Abrir los enlaces en un navegador</string>
<string name="settings_open_externally_summary">Desactivado: las páginas de GitHub se abren dentro de Vector.</string>
<string name="settings_open_externally_summary_on">Activado: las páginas de GitHub se abren en el navegador.</string>

<string name="scope_use_recommended">Usar lo que el módulo pide</string>
<string name="scope_select_visible">Seleccionar todo lo que se muestra</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">باز کردن پیوندها در مرورگر</string>
<string name="settings_open_externally_summary">خاموش: صفحه‌های GitHub درون Vector باز می‌شوند.</string>
<string name="settings_open_externally_summary_on">روشن: صفحه‌های GitHub در مرورگر باز می‌شوند.</string>

<string name="scope_use_recommended">همان چیزی که ماژول می‌خواهد</string>
<string name="scope_select_visible">گزینش همهٔ موارد نمایان</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">Ouvrir les liens dans un navigateur</string>
<string name="settings_open_externally_summary">Désactivé : les pages GitHub s\'ouvrent dans Vector.</string>
<string name="settings_open_externally_summary_on">Activé : les pages GitHub s\'ouvrent dans le navigateur.</string>

<string name="scope_use_recommended">Prendre ce que le module demande</string>
<string name="scope_select_visible">Tout sélectionner à l\'écran</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
</plurals>
<string name="settings_open_externally">Buka tautan di peramban</string>
<string name="settings_open_externally_summary">Mati: halaman GitHub dibuka di dalam Vector.</string>
<string name="settings_open_externally_summary_on">Hidup: halaman GitHub dibuka di peramban.</string>

<string name="scope_use_recommended">Pakai yang diminta modul</string>
<string name="scope_select_visible">Pilih semua yang tampil</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">Apri i link in un browser</string>
<string name="settings_open_externally_summary">Disattivato: le pagine GitHub si aprono dentro Vector.</string>
<string name="settings_open_externally_summary_on">Attivato: le pagine GitHub si aprono nel browser.</string>

<string name="scope_use_recommended">Usa quello che chiede il modulo</string>
<string name="scope_select_visible">Seleziona tutto ciò che è mostrato</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
</plurals>
<string name="settings_open_externally">פתיחת קישורים בדפדפן</string>
<string name="settings_open_externally_summary">כבוי: דפי GitHub נפתחים בתוך Vector.</string>
<string name="settings_open_externally_summary_on">מופעל: דפי GitHub נפתחים בדפדפן.</string>

<string name="scope_use_recommended">להשתמש במה שהמודול מבקש</string>
<string name="scope_select_visible">בחירת כל מה שמוצג</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
</plurals>
<string name="settings_open_externally">リンクをブラウザで開く</string>
<string name="settings_open_externally_summary">オフのとき、GitHub のページは Vector 内で開きます。</string>
<string name="settings_open_externally_summary_on">オンのとき、GitHub のページはブラウザで開きます。</string>

<string name="scope_use_recommended">モジュールの要求どおりにする</string>
<string name="scope_select_visible">表示中のすべてを選択</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
</plurals>
<string name="settings_open_externally">링크를 브라우저에서 열기</string>
<string name="settings_open_externally_summary">꺼두면 GitHub 페이지가 Vector 안에서 열립니다.</string>
<string name="settings_open_externally_summary_on">켜두면 GitHub 페이지가 브라우저에서 열립니다.</string>

<string name="scope_use_recommended">모듈이 요청한 대로 두기</string>
<string name="scope_select_visible">표시된 항목 모두 선택</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
</plurals>
<string name="settings_open_externally">Otwieraj linki w przeglądarce</string>
<string name="settings_open_externally_summary">Wyłączone: strony GitHuba otwierają się wewnątrz Vectora.</string>
<string name="settings_open_externally_summary_on">Włączone: strony GitHuba otwierają się w przeglądarce.</string>
<!-- Scope editor -->
<string name="scope_use_recommended">Użyj tego, czego wymaga moduł</string>
<string name="scope_select_visible">Zaznacz wszystko, co jest pokazane</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">Abrir links em um navegador</string>
<string name="settings_open_externally_summary">Desligado: as páginas do GitHub abrem dentro do Vector.</string>
<string name="settings_open_externally_summary_on">Ligado: as páginas do GitHub abrem no navegador.</string>

<string name="scope_use_recommended">Usar o que o módulo pede</string>
<string name="scope_select_visible">Selecionar tudo que está à mostra</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">Открывать ссылки в браузере</string>
<string name="settings_open_externally_summary">Выключено: страницы GitHub открываются внутри Vector.</string>
<string name="settings_open_externally_summary_on">Включено: страницы GitHub открываются в браузере.</string>
<string name="scope_use_recommended">Взять то, что просит модуль</string>
<string name="scope_select_visible">Выбрать всё показанное</string>
<string name="scope_clear_visible">Снять со всего показанного</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</plurals>
<string name="settings_open_externally">Bağlantıları tarayıcıda aç</string>
<string name="settings_open_externally_summary">Kapalı: GitHub sayfaları Vector içinde açılır.</string>
<string name="settings_open_externally_summary_on">Açık: GitHub sayfaları tarayıcıda açılır.</string>

<string name="scope_use_recommended">Modülün istediğini kullan</string>
<string name="scope_select_visible">Görünenlerin tümünü seç</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
</plurals>
<string name="settings_open_externally">Відкривати посилання в браузері</string>
<string name="settings_open_externally_summary">Вимкнено: сторінки GitHub відкриваються всередині Vector.</string>
<string name="settings_open_externally_summary_on">Увімкнено: сторінки GitHub відкриваються в браузері.</string>

<string name="scope_use_recommended">Узяти те, що просить модуль</string>
<string name="scope_select_visible">Вибрати все показане</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
</plurals>
<string name="settings_open_externally">Mở liên kết bằng trình duyệt</string>
<string name="settings_open_externally_summary">Tắt: các trang GitHub mở ngay trong Vector.</string>
<string name="settings_open_externally_summary_on">Bật: các trang GitHub mở bằng trình duyệt.</string>

<string name="scope_use_recommended">Dùng đúng những gì mô-đun yêu cầu</string>
<string name="scope_select_visible">Chọn hết những mục đang hiện</string>
Expand Down
1 change: 1 addition & 0 deletions manager/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
</plurals>
<string name="settings_open_externally">用浏览器打开链接</string>
<string name="settings_open_externally_summary">关闭时:GitHub 页面在 Vector 内打开。</string>
<string name="settings_open_externally_summary_on">开启时:GitHub 页面在浏览器中打开。</string>

<string name="scope_use_recommended">使用模块建议的范围</string>
<string name="scope_select_visible">选中当前显示的全部</string>
Expand Down
Loading