Skip to content

Commit 80dc7f3

Browse files
authored
Merge pull request #1139 from kiwix/donation-button-ipad
Re-arrange donation button on iPad
2 parents 2cb1087 + e2cf585 commit 80dc7f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+220
-173
lines changed

App/App_iOS.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
1515

16+
#if os(iOS)
1617
import SwiftUI
18+
import Combine
1719
import UserNotifications
1820

19-
#if os(iOS)
2021
@main
2122
struct Kiwix: App {
23+
2224
@Environment(\.scenePhase) private var scenePhase
2325
@StateObject private var library = LibraryViewModel()
2426
@StateObject private var navigation = NavigationViewModel()
2527
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
26-
2728
private let fileMonitor: DirectoryMonitor
2829
private let activityService: ActivityService?
29-
30+
3031
init() {
3132
fileMonitor = DirectoryMonitor(url: URL.documentDirectory) { LibraryOperations.scanDirectory($0) }
3233
// MARK: - live activities
@@ -99,6 +100,8 @@ struct Kiwix: App {
99100
navigation.navigateToMostRecentTab()
100101
}
101102
}
103+
.modifier(DonationViewModifier())
104+
102105
}
103106
.commands {
104107
CommandGroup(replacing: .undoRedo) {

App/App_macOS.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ struct RootView: View {
167167
@Environment(\.openWindow) var openWindow
168168
@Environment(\.controlActiveState) var controlActiveState
169169
@StateObject private var navigation = NavigationViewModel()
170-
@State private var currentNavItem: NavigationItem?
170+
@State private var currentNavItem: MenuItem?
171171
@StateObject private var windowTracker = WindowTracker()
172172
@State private var paymentButtonLabel: PayWithApplePayButtonLabel?
173173

174-
private let primaryItems: [NavigationItem] = [.bookmarks]
175-
private let libraryItems: [NavigationItem] = [.opened, .categories, .downloads, .new]
174+
private let primaryItems: [MenuItem] = [.bookmarks]
175+
private let libraryItems: [MenuItem] = [.opened, .categories, .downloads, .new]
176176
private let openURL = NotificationCenter.default.publisher(for: .openURL)
177177
private let appTerminates = NotificationCenter.default.publisher(for: NSApplication.willTerminateNotification)
178178
private let tabCloses = NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)
@@ -183,15 +183,15 @@ struct RootView: View {
183183
NavigationSplitView {
184184
List(selection: $currentNavItem) {
185185
ForEach(
186-
[NavigationItem.tab(objectID: navigation.currentTabId)] + primaryItems,
186+
[MenuItem.tab(objectID: navigation.currentTabId)] + primaryItems,
187187
id: \.self
188-
) { navigationItem in
189-
Label(navigationItem.name, systemImage: navigationItem.icon)
188+
) { menuItem in
189+
Label(menuItem.name, systemImage: menuItem.icon)
190190
}
191191
if FeatureFlags.hasLibrary {
192192
Section(LocalString.app_macos_navigation_button_library) {
193-
ForEach(libraryItems, id: \.self) { navigationItem in
194-
Label(navigationItem.name, systemImage: navigationItem.icon)
193+
ForEach(libraryItems, id: \.self) { menuItem in
194+
Label(menuItem.name, systemImage: menuItem.icon)
195195
}
196196
}
197197
}
@@ -232,7 +232,7 @@ struct RootView: View {
232232
.modifier(SaveContentHandler())
233233
.environmentObject(navigation)
234234
.onChange(of: currentNavItem) { newValue in
235-
navigation.currentItem = newValue
235+
navigation.currentItem = newValue?.navigationItem
236236
}
237237
.onOpenURL { url in
238238
if url.isFileURL {

App/SidebarViewController.swift

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import CoreData
1818
import SwiftUI
1919
import UIKit
2020

21-
class SidebarViewController: UICollectionViewController, NSFetchedResultsControllerDelegate {
21+
final class SidebarViewController: UICollectionViewController, NSFetchedResultsControllerDelegate {
2222
private lazy var dataSource = {
23-
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, NavigationItem> {
23+
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, MenuItem> {
2424
[unowned self] cell, indexPath, item in
2525
configureCell(cell: cell, indexPath: indexPath, item: item)
2626
}
@@ -29,7 +29,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
2929
) { [unowned self] headerView, elementKind, indexPath in
3030
configureHeader(headerView: headerView, elementKind: elementKind, indexPath: indexPath)
3131
}
32-
let dataSource = UICollectionViewDiffableDataSource<Section, NavigationItem>(collectionView: collectionView) {
32+
let dataSource = UICollectionViewDiffableDataSource<Section, MenuItem>(collectionView: collectionView) {
3333
collectionView, indexPath, item in
3434
collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: item)
3535
}
@@ -50,16 +50,22 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
5050
}
5151

5252
enum Section: String, CaseIterable {
53-
case primary
5453
case tabs
54+
case primary
5555
case library
5656
case settings
57+
case donation
5758

5859
static var allSections: [Section] {
59-
if FeatureFlags.hasLibrary {
60+
switch (FeatureFlags.hasLibrary, Brand.hideDonation) {
61+
case (true, true):
62+
allCases.filter { [.donation].contains($0) }
63+
case (false, true):
64+
allCases.filter { [.donation, .library].contains($0) }
65+
case (true, false):
6066
allCases
61-
} else {
62-
allCases.filter { $0 != .library }
67+
case (false, false):
68+
allCases.filter { [.library].contains($0) }
6369
}
6470
}
6571
}
@@ -84,7 +90,8 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
8490
func updateSelection() {
8591
guard let navigationViewModel,
8692
let currentItem = navigationViewModel.currentItem,
87-
let indexPath = dataSource.indexPath(for: currentItem),
93+
let currentMenuItem = MenuItem(from: currentItem),
94+
let indexPath = dataSource.indexPath(for: currentMenuItem),
8895
collectionView.indexPathsForSelectedItems?.first != indexPath else { return }
8996
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
9097
}
@@ -124,13 +131,16 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
124131
)
125132

126133
// apply initial snapshot
127-
var snapshot = NSDiffableDataSourceSnapshot<Section, NavigationItem>()
134+
var snapshot = NSDiffableDataSourceSnapshot<Section, MenuItem>()
128135
snapshot.appendSections(Section.allSections)
129136
snapshot.appendItems([.bookmarks], toSection: .primary)
130-
if FeatureFlags.hasLibrary {
137+
if snapshot.sectionIdentifiers.contains(.library) {
131138
snapshot.appendItems([.opened, .categories, .downloads, .new], toSection: .library)
132139
}
133140
snapshot.appendItems([.settings], toSection: .settings)
141+
if snapshot.sectionIdentifiers.contains(.donation) {
142+
snapshot.appendItems([.donation], toSection: .donation)
143+
}
134144
dataSource.apply(snapshot, animatingDifferences: false)
135145
try? fetchedResultController.performFetch()
136146
}
@@ -153,8 +163,8 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
153163
) {
154164
let tabIds = snapshot.itemIdentifiers
155165
.compactMap { $0 as? NSManagedObjectID }
156-
let tabs = tabIds.map { NavigationItem.tab(objectID: $0) }
157-
var tabsSnapshot = NSDiffableDataSourceSectionSnapshot<NavigationItem>()
166+
let tabs = tabIds.map { MenuItem.tab(objectID: $0) }
167+
var tabsSnapshot = NSDiffableDataSourceSectionSnapshot<MenuItem>()
158168
tabsSnapshot.append(tabs)
159169
Task { [tabsSnapshot] in
160170
await MainActor.run { [tabsSnapshot] in
@@ -173,11 +183,20 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
173183
}
174184
}
175185
}
186+
187+
override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
188+
guard dataSource.itemIdentifier(for: indexPath) != .donation else {
189+
// trigger the donation pop-up, but do not select the menu item itself
190+
NotificationCenter.openDonations()
191+
return false
192+
}
193+
return true
194+
}
176195

177196
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
178197
guard let splitViewController,
179198
let navigationViewModel,
180-
let navigationItem = dataSource.itemIdentifier(for: indexPath) else { return }
199+
let navigationItem = dataSource.itemIdentifier(for: indexPath)?.navigationItem else { return }
181200
if navigationViewModel.currentItem != navigationItem {
182201
navigationViewModel.currentItem = navigationItem
183202
}
@@ -192,7 +211,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
192211

193212
// MARK: - Collection View Configuration
194213

195-
private func configureCell(cell: UICollectionViewListCell, indexPath: IndexPath, item: NavigationItem) {
214+
private func configureCell(cell: UICollectionViewListCell, indexPath: IndexPath, item: MenuItem) {
196215
if case let .tab(objectID) = item,
197216
let tab = try? Database.shared.viewContext.existingObject(with: objectID) as? Tab {
198217
var config = cell.defaultContentConfiguration()
@@ -214,9 +233,9 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
214233
var config = cell.defaultContentConfiguration()
215234
config.text = item.name
216235
config.image = UIImage(systemName: item.icon)
236+
config.imageProperties.tintColor = item.iconForegroundColor
217237
cell.contentConfiguration = config
218238
}
219-
220239
}
221240

222241
private func configureHeader(headerView: UICollectionViewListCell, elementKind: String, indexPath: IndexPath) {

Support/br.lproj/Localizable.strings

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@
163163
"enum.libray_tab_item.categories" = "Rummadoù";
164164
"enum.libray_tab_item.downloads" = "Pellgargadurioù";
165165
"enum.libray_tab_item.new" = "Nevez";
166-
"enum.navigation_item.loading" = "O kargañ";
167166
"enum.navigation_item.bookmarks" = "Sinedoù";
168-
"enum.navigation_item.map" = "Kartenn";
169167
"enum.navigation_item.new_tab" = "Steudenn nevez";
170168
"enum.navigation_item.opened" = "Digor";
171169
"enum.navigation_item.categories" = "Rummadoù";

Support/dag.lproj/Localizable.strings

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,8 @@
191191
"enum.libray_tab_item.categories" = "Pubu nima";
192192
"enum.libray_tab_item.downloads" = "Deebu";
193193
"enum.libray_tab_item.new" = "Palli";
194-
"enum.navigation_item.loading" = "Ʒili";
195194
"enum.navigation_item.reading" = "Kariŋ";
196195
"enum.navigation_item.bookmarks" = "Buku'dalima";
197-
"enum.navigation_item.map" = "Tiŋgbani";
198196
"enum.navigation_item.new_tab" = "Binshɛɣ'kam palli";
199197
"enum.navigation_item.opened" = "Yooma";
200198
"enum.navigation_item.categories" = "Pubu nima";

Support/de.lproj/Localizable.strings

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,8 @@
216216
"enum.libray_tab_item.categories" = "Kategorien";
217217
"enum.libray_tab_item.downloads" = "Downloads";
218218
"enum.libray_tab_item.new" = "Neu";
219-
"enum.navigation_item.loading" = "Lade …";
220219
"enum.navigation_item.reading" = "Lese …";
221220
"enum.navigation_item.bookmarks" = "Lesezeichen";
222-
"enum.navigation_item.map" = "Karte";
223221
"enum.navigation_item.new_tab" = "Neuer Tab";
224222
"enum.navigation_item.opened" = "Geöffnet";
225223
"enum.navigation_item.categories" = "Kategorien";

Support/en.lproj/Localizable.strings

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,8 @@
261261
"enum.libray_tab_item.downloads" = "Downloads";
262262
"enum.libray_tab_item.new" = "New";
263263

264-
"enum.navigation_item.loading" = "Loading";
265264
"enum.navigation_item.reading" = "Reading";
266265
"enum.navigation_item.bookmarks" = "Bookmarks";
267-
"enum.navigation_item.map" = "Map";
268266
"enum.navigation_item.new_tab" = "New Tab";
269267
"enum.navigation_item.opened" = "Opened";
270268
"enum.navigation_item.categories" = "Categories";

Support/es.lproj/Localizable.strings

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,8 @@
216216
"enum.libray_tab_item.categories" = "Categorías";
217217
"enum.libray_tab_item.downloads" = "Descargas";
218218
"enum.libray_tab_item.new" = "Nuevo";
219-
"enum.navigation_item.loading" = "Cargando…";
220219
"enum.navigation_item.reading" = "Lectura";
221220
"enum.navigation_item.bookmarks" = "Marcadores";
222-
"enum.navigation_item.map" = "Mapa";
223221
"enum.navigation_item.new_tab" = "Pestaña nueva";
224222
"enum.navigation_item.opened" = "Abierto";
225223
"enum.navigation_item.categories" = "Categorías";

Support/fi.lproj/Localizable.strings

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
"enum.external_link_loading_policy.never_load" = "Älä koskaan lataa";
124124
"enum.library_language_sorting_model.a-z" = "A-Ö";
125125
"enum.libray_tab_item.new" = "Uusi";
126-
"enum.navigation_item.loading" = "Ladataan";
127126
"enum.navigation_item.bookmarks" = "Kirjanmerkit";
128127
"enum.navigation_item.new_tab" = "Uusi välilehti";
129128
"enum.navigation_item.opened" = "Avattu";

Support/fr.lproj/Localizable.strings

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,8 @@
226226
"enum.libray_tab_item.categories" = "Catégories";
227227
"enum.libray_tab_item.downloads" = "Téléchargements";
228228
"enum.libray_tab_item.new" = "Nouveau";
229-
"enum.navigation_item.loading" = "Chargement";
230229
"enum.navigation_item.reading" = "Lecture";
231230
"enum.navigation_item.bookmarks" = "Signets";
232-
"enum.navigation_item.map" = "Carte";
233231
"enum.navigation_item.new_tab" = "Nouvel onglet";
234232
"enum.navigation_item.opened" = "Ouvert";
235233
"enum.navigation_item.categories" = "Catégories";

0 commit comments

Comments
 (0)