From 3a144b7792447997ba6a83227995bae2c9926e76 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Sun, 26 Feb 2023 17:32:09 +0100 Subject: [PATCH] collapse long posts (#1037) close #914 * collapse long posts * initialize user pref setting in init(), remove onAppear and onChange(pref) from view --------- Co-authored-by: Thomas Ricouard --- .../Tabs/Settings/ContentSettingsView.swift | 15 ++++-- .../Localization/be.lproj/Localizable.strings | 3 ++ .../Localization/ca.lproj/Localizable.strings | 3 ++ .../Localization/de.lproj/Localizable.strings | 3 ++ .../en-GB.lproj/Localizable.strings | 3 ++ .../Localization/en.lproj/Localizable.strings | 3 ++ .../Localization/es.lproj/Localizable.strings | 3 ++ .../Localization/eu.lproj/Localizable.strings | 3 ++ .../Localization/fr.lproj/Localizable.strings | 3 ++ .../Localization/it.lproj/Localizable.strings | 3 ++ .../Localization/ja.lproj/Localizable.strings | 3 ++ .../Localization/ko.lproj/Localizable.strings | 3 ++ .../Localization/nb.lproj/Localizable.strings | 3 ++ .../Localization/nl.lproj/Localizable.strings | 3 ++ .../Localization/pl.lproj/Localizable.strings | 3 ++ .../pt-BR.lproj/Localizable.strings | 3 ++ .../Localization/tr.lproj/Localizable.strings | 3 ++ .../Localization/uk.lproj/Localizable.strings | 3 ++ .../zh-Hans.lproj/Localizable.strings | 3 ++ .../DesignSystem/Views/EmojiText.swift | 7 ++- .../Env/Sources/Env/UserPreferences.swift | 2 + .../Status/Row/StatusRowViewModel.swift | 28 ++++++++++ .../Row/Subviews/StatusRowSpoilerView.swift | 1 + .../Row/Subviews/StatusRowTextView.swift | 53 +++++++++++++++---- 24 files changed, 146 insertions(+), 14 deletions(-) diff --git a/IceCubesApp/App/Tabs/Settings/ContentSettingsView.swift b/IceCubesApp/App/Tabs/Settings/ContentSettingsView.swift index 9eaf9a43..eadb43ae 100644 --- a/IceCubesApp/App/Tabs/Settings/ContentSettingsView.swift +++ b/IceCubesApp/App/Tabs/Settings/ContentSettingsView.swift @@ -43,19 +43,28 @@ struct ContentSettingsView: View { } } - Section("settings.content.reading") { + Section { Toggle(isOn: $userPreferences.appAutoExpandSpoilers) { Text("settings.content.expand-spoilers") } .disabled(userPreferences.useInstanceContentSettings) - + Picker("settings.content.expand-media", selection: $userPreferences.appAutoExpandMedia) { ForEach(ServerPreferences.AutoExpandMedia.allCases, id: \.rawValue) { media in Text(media.description).tag(media) } } .disabled(userPreferences.useInstanceContentSettings) - }.listRowBackground(theme.primaryBackgroundColor) + + Toggle(isOn: $userPreferences.collapseLongPosts) { + Text("settings.content.collapse-long-posts") + } + } header: { + Text("settings.content.reading") + } footer: { + Text("settings.content.collapse-long-posts-hint") + } + .listRowBackground(theme.primaryBackgroundColor) Section("settings.content.posting") { Picker("settings.content.default-visibility", selection: $userPreferences.appDefaultPostVisibility) { diff --git a/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings index 2a5ebdf7..024b0140 100644 --- a/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings @@ -112,6 +112,8 @@ "settings.system" = "Сістэмныя налады"; "settings.content.navigation-title" = "Налады змесціву"; "settings.content.boosts" = "Павышэння"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Схаваць паўторныя павышэння"; "settings.content.instance-settings" = "Налады змесціва серверу"; "settings.content.use-instance-settings" = "Ужыць налады серверу"; @@ -462,6 +464,7 @@ "status.row.you-boosted" = "Вы ўзмацнілі"; "status.show-less" = "Паказваць менш"; "status.show-more" = "Паказаць больш"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " а "; "status.summary.edited-time" = "Апошняе рэдагаванне:"; "status.summary.n-boosts %lld" = "%lld павышаных"; diff --git a/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings index fe025591..7b68a83d 100644 --- a/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings @@ -108,6 +108,8 @@ "settings.content.navigation-title" = "Configuració del contacte"; "settings.content.use-instance-settings" = "Utilitza la configuració del servidor"; "settings.content.boosts" = "Impulsos"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Hide repeated boosts"; "settings.content.instance-settings" = "Server Content Settings"; "settings.content.expand-spoilers" = "Mostra'm sempre els espòilers"; @@ -456,6 +458,7 @@ "status.row.you-boosted" = "Heu impulsat"; "status.show-less" = "Mostra'n menys"; "status.show-more" = "Mostra'n més"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " a les "; "status.summary.edited-time" = "Darrera edició: "; "status.summary.n-boosts %lld" = "%lld impulsos"; diff --git a/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings index d81d44a2..e2c68b50 100644 --- a/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings @@ -132,6 +132,8 @@ "settings.system" = "Systemeinstellungen"; "settings.content.navigation-title" = "Inhaltseinstellungen"; "settings.content.boosts" = "Boosts"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Wiederholte Boosts verstecken"; "settings.content.instance-settings" = "Serverinhaltseinstellungen"; "settings.content.use-instance-settings" = "Servereinstellungen verwenden"; @@ -453,6 +455,7 @@ "status.row.you-boosted" = "Du hast geboostet"; "status.show-less" = "Weniger anzeigen"; "status.show-more" = "Mehr anzeigen"; +"status.show-full-post" = "Ganzen Beitrag anzeigen"; "status.summary.at-time" = " um "; "status.summary.n-boosts %lld" = "%lld Boosts"; "status.summary.n-favorites %lld" = "%lld Favoriten"; diff --git a/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings index dcba68be..ba188317 100644 --- a/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings @@ -111,6 +111,8 @@ "settings.general.content" = "Content Settings"; "settings.system" = "System Settings"; "settings.content.boosts" = "Boosts"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.navigation-title" = "Content Settings"; "settings.content.use-instance-settings" = "Use Server Settings"; "settings.content.instance-settings" = "Server Content Settings"; @@ -457,6 +459,7 @@ "status.row.you-boosted" = "You boosted"; "status.show-less" = "Show less"; "status.show-more" = "Show more"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " at "; "status.summary.edited-time" = "Last edited: "; "status.summary.n-boosts %lld" = "%lld boosts"; diff --git a/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings index a2f979f9..de900106 100644 --- a/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings @@ -112,6 +112,8 @@ "settings.system" = "System Settings"; "settings.content.navigation-title" = "Content Settings"; "settings.content.boosts" = "Boosts"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Hide Repeated Boosts"; "settings.content.instance-settings" = "Server Content Settings"; "settings.content.use-instance-settings" = "Use Server Settings"; @@ -458,6 +460,7 @@ "status.row.you-boosted" = "You boosted"; "status.show-less" = "Show less"; "status.show-more" = "Show more"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " at "; "status.summary.edited-time" = "Last edited: "; "status.summary.n-boosts %lld" = "%lld boosts"; diff --git a/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings index 40158ddc..6fc43418 100644 --- a/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings @@ -132,6 +132,8 @@ "settings.system" = "Ajustes del sistema"; "settings.content.navigation-title" = "Ajustes de contenido"; "settings.content.boosts" = "Retoots"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Ocultar retoots repetidos"; "settings.content.instance-settings" = "Ajustes de contenido del servidor"; "settings.content.use-instance-settings" = "Usar ajustes del servidor"; @@ -458,6 +460,7 @@ "status.row.you-boosted" = "Retooteaste"; "status.show-less" = "Mostrar menos"; "status.show-more" = "Mostrar más"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " a las "; "status.summary.edited-time" = "Última edición: "; "status.summary.n-boosts %lld" = "%lld retoots"; diff --git a/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings index 8574c92d..cd9e74ce 100644 --- a/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings @@ -132,6 +132,8 @@ "settings.system" = "Sistemaren ezarpenak"; "settings.content.navigation-title" = "Edukiaren ezarpenak"; "settings.content.boosts" = "Bultzadak"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Ezkutatu errepikatutako bultzadak"; "settings.content.instance-settings" = "Edukiari buruzko ezarpenak"; "settings.content.use-instance-settings" = "Erabili zerbitzariko ezarpenak"; @@ -450,6 +452,7 @@ "status.row.you-boosted" = "Zuk bultzatua"; "status.show-less" = "Ikusi gutxiago"; "status.show-more" = "Ikusi gehiago"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " · "; "status.summary.edited-time" = "Azkenekoz editatua: "; "status.visibility.direct" = "Aipatutakoak"; diff --git a/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings index b6b99a4f..e77c7ed5 100644 --- a/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings @@ -108,6 +108,8 @@ "settings.system" = "Paramètres système"; "settings.content.navigation-title" = "Paramètres de contenu"; "settings.content.boosts" = "Boosts"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Masquer les boosts répétés"; "settings.content.instance-settings" = "Réglages de contenu serveur"; "settings.content.use-instance-settings" = "Utiliser les paramètres du serveur"; @@ -453,6 +455,7 @@ "status.row.you-boosted" = "Vous avez boosté"; "status.show-less" = "Afficher moins"; "status.show-more" = "Afficher plus"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " à "; "status.summary.edited-time" = "Dernière modification : "; "status.summary.n-boosts %lld" = "%lld boosts"; diff --git a/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings index fcc0b628..7b073b16 100644 --- a/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings @@ -133,6 +133,8 @@ "settings.content.navigation-title" = "Impostazioni dei contenuti"; "settings.content.use-instance-settings" = "Utilizza le impostazioni del server"; "settings.content.boosts" = "Condivisioni"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Nascondi le condivisioni ripetute"; "settings.content.instance-settings" = "Configurazione dei contenuti del Server"; "settings.content.expand-spoilers" = "Visualizza sempre i contenuti sensibili"; @@ -458,6 +460,7 @@ "status.row.you-boosted" = "Tu hai condiviso"; "status.show-less" = "Mostra meno"; "status.show-more" = "Mostra di più"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " alle "; "status.summary.edited-time" = "Ultima modifica: "; "status.summary.n-boosts %lld" = "%lld condivisioni"; diff --git a/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings index d9757c36..3b07263f 100644 --- a/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings @@ -112,6 +112,8 @@ "settings.system" = "システム設定"; "settings.content.navigation-title" = "コンテンツ設定"; "settings.content.boosts" = "ブースト"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "度重なるブーストを隠す"; "settings.content.instance-settings" = "サーバーコンテンツ設定"; "settings.content.use-instance-settings" = "サーバー設定を使用する"; @@ -457,6 +459,7 @@ "status.row.you-boosted" = "ブーストしました"; "status.show-less" = "表示項目を減らす"; "status.show-more" = "表示項目を増やす"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " at "; "status.summary.edited-time" = "最新編集日: "; "status.summary.n-boosts %lld" = "%lld ブースト"; diff --git a/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings index 02934133..949935ad 100644 --- a/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings @@ -108,6 +108,8 @@ "settings.system" = "시스템 설정"; "settings.content.navigation-title" = "콘텐츠 설정"; "settings.content.boosts" = "부스트"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "중복으로 부스트된 글 숨기기"; "settings.content.instance-settings" = "인스턴스 콘텐츠 설정"; "settings.content.use-instance-settings" = "인스턴스 설정에 맞추기"; @@ -459,6 +461,7 @@ "status.row.you-boosted" = "내가 부스트함"; "status.show-less" = "간략히 보기"; "status.show-more" = "더 보기"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " "; "status.summary.edited-time" = "마지막 수정: "; "status.summary.n-boosts %lld" = "부스트 %lld회"; diff --git a/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings index a0f8885d..a29be6c8 100644 --- a/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings @@ -112,6 +112,8 @@ "settings.system" = "Systeminnstillinger"; "settings.content.navigation-title" = "Innholdsinnstillinger"; "settings.content.boosts" = "Forsterkninger"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Hide repeated boosts"; "settings.content.instance-settings" = "Server Content Settings"; "settings.content.use-instance-settings" = "Bruk serverinnstillinger"; @@ -457,6 +459,7 @@ "status.row.you-boosted" = "Du forsterket"; "status.show-less" = "Vis mindre"; "status.show-more" = "Vis mer"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = "kl "; "status.summary.edited-time" = "Sist redigert: "; "status.summary.n-boosts %lld" = "%lld forsterkninger"; diff --git a/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings index ae35c9b7..36d27cbd 100644 --- a/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings @@ -132,6 +132,8 @@ "settings.system" = "Systeeminstellingen"; "settings.content.navigation-title" = "Inhoud"; "settings.content.boosts" = "Boosts"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Verberg herhaalde boosts"; "settings.content.instance-settings" = "Serverinstellingen voor inhoud"; "settings.content.use-instance-settings" = "Gebruik serverinstellingen"; @@ -451,6 +453,7 @@ "status.row.you-boosted" = "Je boostte"; "status.show-less" = "Toon minder"; "status.show-more" = "Toon meer"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " om "; "status.summary.edited-time" = "Laatst gewijzigd: "; "status.summary.n-boosts %lld" = "%lld boosts"; diff --git a/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings index 3591088f..ed79cf14 100644 --- a/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings @@ -108,6 +108,8 @@ "settings.system" = "Ustawienia systemowe"; "settings.content.navigation-title" = "Ustawienia treści"; "settings.content.boosts" = "Podbicia"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Ukryj powtórzone podbicia"; "settings.content.instance-settings" = "Ustawienia treści serwera"; "settings.content.use-instance-settings" = "Zastosuj ustawienia serwera"; @@ -451,6 +453,7 @@ "status.row.you-boosted" = "Podbiłeś(aś)"; "status.show-less" = "Pokaż mniej"; "status.show-more" = "Pokaż więcej"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " o "; "status.summary.edited-time" = "Ostatnia edycja: "; "status.visibility.direct" = "Post bezpośredni"; diff --git a/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings index 85496094..ecf4efa1 100644 --- a/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings @@ -108,6 +108,8 @@ "settings.system" = "Ajustes do Sistema"; "settings.content.navigation-title" = "Configurações de Conteúdo"; "settings.content.boosts" = "Boosts"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "Ocultar boosts repetidos"; "settings.content.instance-settings" = "Configurações de conteúdo do servidor"; "settings.content.use-instance-settings" = "Usar configurações do servidor"; @@ -457,6 +459,7 @@ "status.row.you-boosted" = "Você deu boost"; "status.show-less" = "Exibir menos"; "status.show-more" = "Exibir mais"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " as "; "status.summary.edited-time" = "Última edição: "; "status.summary.n-boosts %lld" = "%lld boosts"; diff --git a/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings index 01cd17e6..1e8aa90d 100644 --- a/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings @@ -107,6 +107,8 @@ "settings.general.content" = "Content Settings"; "settings.system" = "System Settings"; "settings.content.navigation-title" = "Content Settings"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.boosts" = "Yükseltmeler"; "settings.content.hide-repeated-boosts" = "Hide repeated boosts"; "settings.content.instance-settings" = "Server Content Settings"; @@ -453,6 +455,7 @@ "status.row.you-boosted" = "Yükselttin"; "status.show-less" = "Daha az göster"; "status.show-more" = "Daha fazla göster"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " de "; "status.summary.edited-time" = "Son düzenleme: "; "status.summary.n-boosts %lld" = "%lld yükseltmeler"; diff --git a/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings index bff13ab0..f8ec7900 100644 --- a/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings @@ -111,6 +111,8 @@ "settings.general.content" = "Налаштування вмісту"; "settings.system" = "Системні налаштування"; "settings.content.navigation-title" = "Налаштування вмісту"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.boosts" = "Поширення"; "settings.content.hide-repeated-boosts" = "Не відображати повторні поширення"; "settings.content.instance-settings" = "Налаштування відображення сервера"; @@ -458,6 +460,7 @@ "status.row.you-boosted" = "Ви поширили"; "status.show-less" = "Показати менше"; "status.show-more" = "Показати більше"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " о "; "status.summary.edited-time" = "Востаннє змінено: "; "status.summary.n-boosts %lld" = "%lld поширень"; diff --git a/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings index a54a16f5..1c3c3e7e 100644 --- a/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings @@ -133,6 +133,8 @@ "settings.system" = "系统设置"; "settings.content.navigation-title" = "内容设置"; "settings.content.boosts" = "转发"; +"settings.content.collapse-long-posts" = "Collapse long posts"; +"settings.content.collapse-long-posts-hint" = "Collapsed posts only display a limited number of lines together with a button to show the full post"; "settings.content.hide-repeated-boosts" = "隐藏重复的转发"; "settings.content.instance-settings" = "服务器内容设置"; "settings.content.use-instance-settings" = "使用服务器设置"; @@ -456,6 +458,7 @@ "status.row.you-boosted" = "你转发了"; "status.show-less" = "显示更少"; "status.show-more" = "显示更多"; +"status.show-full-post" = "Show full post"; "status.summary.at-time" = " 在 "; "status.summary.edited-time" = "上次编辑:"; "status.summary.n-boosts %lld" = "%lld 转发"; diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/EmojiText.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/EmojiText.swift index a43c5c91..975b8fdf 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/EmojiText.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/EmojiText.swift @@ -8,11 +8,13 @@ public struct EmojiTextApp: View { private let emojis: [any CustomEmoji] private let language: String? private let append: (() -> Text)? + private let lineLimit: Int? - public init(_ markdown: HTMLString, emojis: [Emoji], language: String? = nil, append: (() -> Text)? = nil) { + public init(_ markdown: HTMLString, emojis: [Emoji], language: String? = nil, lineLimit: Int? = nil, append: (() -> Text)? = nil) { self.markdown = markdown self.emojis = emojis.map { RemoteEmoji(shortcode: $0.shortcode, url: $0.url) } self.language = language + self.lineLimit = lineLimit self.append = append } @@ -22,11 +24,14 @@ public struct EmojiTextApp: View { .append { append() } + .lineLimit(lineLimit) } else if emojis.isEmpty { Text(markdown.asSafeMarkdownAttributedString) + .lineLimit(lineLimit) .environment(\.layoutDirection, isRTL() ? .rightToLeft : .leftToRight) } else { EmojiText(markdown: markdown.asMarkdown, emojis: emojis) + .lineLimit(lineLimit) .environment(\.layoutDirection, isRTL() ? .rightToLeft : .leftToRight) } } diff --git a/Packages/Env/Sources/Env/UserPreferences.swift b/Packages/Env/Sources/Env/UserPreferences.swift index 3e96933d..887c3739 100644 --- a/Packages/Env/Sources/Env/UserPreferences.swift +++ b/Packages/Env/Sources/Env/UserPreferences.swift @@ -47,6 +47,8 @@ public class UserPreferences: ObservableObject { @AppStorage("swipeactions-icon-style") public var swipeActionsIconStyle: SwipeActionsIconStyle = .iconWithText @AppStorage("requested_review") public var requestedReview = false + + @AppStorage("collapse-long-posts") public var collapseLongPosts = true public enum SwipeActionsIconStyle: String, CaseIterable { case iconWithText, iconOnly diff --git a/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift b/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift index a68ee4b2..f52650ca 100644 --- a/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift +++ b/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift @@ -37,6 +37,31 @@ public class StatusRowViewModel: ObservableObject { @Published var localStatusId: String? @Published var localStatus: Status? + // used by the button to expand a collapsed post + @Published var isCollapsed: Bool = true { + didSet { + recalcCollapse() + } + } + // number of lines to show, nil means show the whole post + @Published var lineLimit: Int? = nil + // post length determining if the post should be collapsed + let collapseThresholdLength : Int = 750 + // number of text lines to show on a collpased post + let collapsedLines: Int = 8 + // user preference, set in init + var collapseLongPosts: Bool = false + + private func recalcCollapse() { + let hasContentWarning = !status.spoilerText.asRawText.isEmpty + let showCollapseButton = collapseLongPosts && isCollapsed && !hasContentWarning + && (status.reblog?.content ?? status.content).asRawText.unicodeScalars.count > collapseThresholdLength + let newlineLimit = showCollapseButton && isCollapsed ? collapsedLines : nil + if newlineLimit != lineLimit { + lineLimit = newlineLimit + } + } + private let theme = Theme.shared private let userMentionned: Bool @@ -112,6 +137,9 @@ public class StatusRowViewModel: ObservableObject { isEmbedLoading = false embeddedStatus = embed } + + collapseLongPosts = UserPreferences.shared.collapseLongPosts + recalcCollapse() } func markSeen() { diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowSpoilerView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowSpoilerView.swift index bfb0232f..b636e1be 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowSpoilerView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowSpoilerView.swift @@ -29,6 +29,7 @@ struct StatusRowSpoilerView: View { .accessibility(label: displaySpoiler ? Text("status.show-more") : Text("status.show-less")) .accessibilityHidden(true) } + .contentShape(Rectangle()) .onTapGesture { // make whole row tapable to make up for smaller button size withAnimation { displaySpoiler.toggle() diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowTextView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowTextView.swift index 125672da..d9bda10d 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowTextView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowTextView.swift @@ -1,22 +1,55 @@ import DesignSystem +import Env import Models import SwiftUI struct StatusRowTextView: View { @EnvironmentObject private var theme: Theme + @EnvironmentObject private var preferences: UserPreferences let status: AnyStatus - let viewModel: StatusRowViewModel - + @ObservedObject var viewModel: StatusRowViewModel + var body: some View { - HStack { - EmojiTextApp(status.content, emojis: status.emojis, language: status.language) - .font(.scaledBody) - .emojiSize(Font.scaledBodyPointSize) - .environment(\.openURL, OpenURLAction { url in - viewModel.routerPath.handleStatus(status: status, url: url) - }) - Spacer() + VStack { + HStack { + EmojiTextApp(status.content, emojis: status.emojis, language: status.language, lineLimit: viewModel.lineLimit) + .font(.scaledBody) + .emojiSize(Font.scaledBodyPointSize) + .environment(\.openURL, OpenURLAction { url in + viewModel.routerPath.handleStatus(status: status, url: url) + }) + Spacer() + } + makeCollapseButton() + } + } + + @ViewBuilder + func makeCollapseButton() -> some View { + if let _ = viewModel.lineLimit { + HStack(alignment: .top) { + Text("status.show-full-post") + .font(.system(.subheadline, weight: .bold)) + .foregroundColor(.secondary) + Spacer() + Button { + withAnimation { + viewModel.isCollapsed.toggle() + } + } label: { + Image(systemName: "chevron.down") + } + .buttonStyle(.bordered) + .accessibility(label: Text("status.show-full-post")) + .accessibilityHidden(true) + } + .contentShape(Rectangle()) + .onTapGesture { // make whole row tapable to make up for smaller button size + withAnimation { + viewModel.isCollapsed.toggle() + } + } } } }