Skip to content

Commit

Permalink
Use text as progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BPerlakiH committed Oct 2, 2024
1 parent f9750f1 commit 00fe1ef
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 24 deletions.
13 changes: 11 additions & 2 deletions Kiwix/SplashScreenKiwix.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" image="YES" notEnabled="YES"/>
</accessibility>
<constraints>
<constraint firstAttribute="height" constant="140" id="vtl-H0-fnU"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loading Application..." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qEE-oI-yVD">
<rect key="frame" x="114.66666666666669" y="553.66666666666663" width="164" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="gOr-0c-AYj" firstAttribute="width" relation="lessThanOrEqual" secondItem="Ze5-6b-2t3" secondAttribute="width" multiplier="0.618" id="G29-6Y-oWb"/>
<constraint firstItem="qEE-oI-yVD" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="HVV-dV-2mF"/>
<constraint firstItem="gOr-0c-AYj" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="MYi-uf-geF"/>
<constraint firstItem="qEE-oI-yVD" firstAttribute="centerY" secondItem="gOr-0c-AYj" secondAttribute="centerY" constant="138" id="Yh8-Xe-erv"/>
<constraint firstItem="gOr-0c-AYj" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="ohB-Hm-56e"/>
<constraint firstItem="gOr-0c-AYj" firstAttribute="height" relation="lessThanOrEqual" secondItem="Ze5-6b-2t3" secondAttribute="height" multiplier="0.382" id="zTu-F5-CRx"/>
</constraints>
</view>
</viewController>
Expand Down
1 change: 1 addition & 0 deletions Support/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
"welcome.main_page.title" = "Main Page";
"welcome.grid.bookmarks.title" = "Bookmarks";
"welcome.actions.open_file" = "Open File";
"welcome.loading.data.text" = "Loading Data...";
"welcome.button.status.fetching_catalog.text" = "Fetching Catalog...";
"welcome.button.status.fetch_catalog.text" = "Fetch Catalog";

Expand Down
7 changes: 6 additions & 1 deletion ViewModel/LibraryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import os

enum LibraryState {
case initial
case initialProgress // fresh installs first progress only
case inProgress
case complete
case error
Expand Down Expand Up @@ -65,7 +66,11 @@ final class LibraryViewModel: ObservableObject {
self.process = processFactory()
state = process.state
process.$state.sink { [weak self] newState in
self?.state = newState
if self?.state == .initial && newState == .inProgress {
self?.state = .initialProgress
} else {
self?.state = newState
}
}.store(in: &cancellables)
}

Expand Down
18 changes: 15 additions & 3 deletions Views/BuildingBlocks/LoadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ struct LogoView: View {
var body: some View {
GeometryReader { geometry in
Image(Brand.loadingLogoImage)
.frame(maxWidth: geometry.size.width * 0.618,
maxHeight: geometry.size.height * 0.3820)
.frame(height: 140)
.aspectRatio(contentMode: .fit)
.position(
x: geometry.size.width * 0.5,
Expand All @@ -30,6 +29,19 @@ struct LogoView: View {
}
}

struct LoadingMessageView: View {
let message: String
var body: some View {
GeometryReader { geometry in
Text(message)
.position(
x: geometry.size.width * 0.5,
y: geometry.size.height * 0.5 + 138
)
}
}
}

struct LoadingProgressView: View {
var body: some View {
GeometryReader { geometry in
Expand All @@ -52,7 +64,7 @@ struct LoadingView: View {
var body: some View {
ZStack {
LogoView()
LoadingProgressView()
LoadingMessageView(message: "welcome.loading.data.text".localized)
}.ignoresSafeArea()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Views/Library/ZimFilesCategories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private struct CategoryGrid: View {
Group {
if sections.isEmpty {
switch viewModel.state {
case .inProgress:
case .inProgress, .initialProgress:
Message(text: "zim_file_catalog.fetching.message".localized)
case .error:
Message(text: "library_refresh_error.retrieve.description".localized, color: .red)
Expand Down Expand Up @@ -228,7 +228,7 @@ private struct CategoryList: View {
Group {
if zimFiles.isEmpty {
switch viewModel.state {
case .inProgress:
case .inProgress, .initialProgress:
Message(text: "zim_file_catalog.fetching.message".localized)
case .error:
Message(text: "library_refresh_error.retrieve.description".localized, color: .red)
Expand Down
2 changes: 1 addition & 1 deletion Views/Library/ZimFilesNew.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct ZimFilesNew: View {
.overlay {
if zimFiles.isEmpty {
switch viewModel.state {
case .inProgress:
case .inProgress, .initialProgress:
Message(text: "zim_file_catalog.fetching.message".localized)
case .error:
Message(text: "library_refresh_error.retrieve.description".localized, color: .red)
Expand Down
34 changes: 19 additions & 15 deletions Views/Welcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ struct Welcome: View {
ZStack {
LogoView()
welcomeContent
if library.state == .initialProgress {
LoadingMessageView(message: "welcome.button.status.fetching_catalog.text".localized)
}
if library.state == .inProgress {
LoadingView()
LoadingProgressView()
}
}.ignoresSafeArea()
} else {
Expand Down Expand Up @@ -80,18 +83,13 @@ struct Welcome: View {

private var welcomeContent: some View {
GeometryReader { geometry in
HStack {
Spacer()
VStack(spacing: 20) {
Spacer()
.frame(height: geometry.size.height * 0.618)
actions
Text("library_refresh_error.retrieve.description".localized)
.foregroundColor(.red)
.opacity(library.state == .error ? 1 : 0)
Spacer()
}
.padding()
actions
.position(
x: geometry.size.width * 0.5,
y: geometry.size.height * 0.5 + 138
// (140 logo height + 96 buttons height ) / 2 + 20 distance
)
.opacity( [.initial, .initialProgress].contains(library.state) ? 0 : 1 )
#if os(macOS)
.frame(maxWidth: 300)
#elseif os(iOS)
Expand All @@ -109,8 +107,14 @@ struct Welcome: View {
}
#endif
}
Spacer()
}
Text("library_refresh_error.retrieve.description".localized)
.foregroundColor(.red)
.opacity(library.state == .error ? 1 : 0)
.position(
x: geometry.size.width * 0.5,
y: geometry.size.height * 0.5 + 138 + 96 / 2 + 20
)

}
}

Expand Down

0 comments on commit 00fe1ef

Please sign in to comment.