From 071b9f603649897c9e9802c510fc8118e996f2aa Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 17 May 2022 16:07:29 -0700 Subject: [PATCH 1/3] Move the read now button, add a pending state This drops the button down a bit so we have more space, also allows for pending state if tapped before save has completed. --- .../Sources/Views/ShareExtensionView.swift | 75 ++++++++++++++----- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift b/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift index badcc27dc..7dd30d07f 100644 --- a/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift +++ b/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift @@ -111,6 +111,22 @@ public struct ShareExtensionChildView: View { @State var reminderTime: ReminderTime? @State var hideUntilReminded = false + @State var readNowPending = false + + private func waitForReadNow() { + readNowPending = true + + DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300)) { + switch status { + case .successfullySaved: + readNowButtonAction() + case .failed(error: _): + readNowPending = false + case .saving, .processing: + waitForReadNow() + } + } + } private func handleReminderTimeSelection(_ selectedTime: ReminderTime) { if selectedTime == reminderTime { @@ -141,18 +157,16 @@ public struct ShareExtensionChildView: View { Spacer() if case ShareExtensionStatus.successfullySaved = status { - HStack { - Spacer() - IconButtonView( - title: "Read Now", - systemIconName: "book", - action: { - readNowButtonAction() - } - ) - Spacer() + HStack(spacing: 4) { + Text("Saved to Omnivore") + .font(.appTitleThree) + .foregroundColor(.appGrayText) + .padding(.trailing, 16) + .multilineTextAlignment(.center) + .fixedSize(horizontal: false, vertical: true) + .lineLimit(nil) } - .padding(.horizontal, 8) + .padding() } else if case let ShareExtensionStatus.failed(error) = status { HStack { Spacer() @@ -207,16 +221,37 @@ public struct ShareExtensionChildView: View { } .padding(.horizontal) - Button( - action: { - dismissButtonTappedAction(reminderTime, hideUntilReminded) - }, - label: { - Text("Dismiss") - .frame(maxWidth: .infinity) + HStack { + if case ShareExtensionStatus.successfullySaved = status { + Button( + action: { + if case ShareExtensionStatus.successfullySaved = status { + readNowButtonAction() + } else { + waitForReadNow() + } + }, + label: { + if readNowPending { + ProgressView().frame(maxWidth: .infinity) + } else { + Text("Read Now").frame(maxWidth: .infinity) + } + } + ) + .buttonStyle(RoundedRectButtonStyle()) } - ) - .buttonStyle(RoundedRectButtonStyle()) + Button( + action: { + dismissButtonTappedAction(reminderTime, hideUntilReminded) + }, + label: { + Text("Dismiss") + .frame(maxWidth: .infinity) + } + ) + .buttonStyle(RoundedRectButtonStyle()) + } .padding(.horizontal) .padding(.bottom) } From 2d4ec9d45daac9fa55895a6095d4c22aa29333b2 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Wed, 18 May 2022 08:49:50 -0700 Subject: [PATCH 2/3] share extension starts with a .processing status --- .../Share/ShareExtensionScene.swift | 4 +- .../OmnivoreKit/Sources/Views/LocalText.swift | 1 - .../Sources/Views/ShareExtensionView.swift | 47 ++++--------------- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionScene.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionScene.swift index a51dbb871..b525b5a97 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionScene.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionScene.swift @@ -22,7 +22,7 @@ public extension PlatformViewController { final class ShareExtensionViewModel: ObservableObject { @Published var title: String? - @Published var status = ShareExtensionStatus.successfullySaved + @Published var status = ShareExtensionStatus.processing @Published var debugText: String? var subscriptions = Set() @@ -75,7 +75,7 @@ final class ShareExtensionViewModel: ObservableObject { self?.debugText = "saveArticleError: \(error)" self?.status = .failed(error: error) } receiveValue: { [weak self] _ in - self?.status = .successfullySaved + self?.status = .success } .store(in: &subscriptions) diff --git a/apple/OmnivoreKit/Sources/Views/LocalText.swift b/apple/OmnivoreKit/Sources/Views/LocalText.swift index 3e7b9d015..861532879 100644 --- a/apple/OmnivoreKit/Sources/Views/LocalText.swift +++ b/apple/OmnivoreKit/Sources/Views/LocalText.swift @@ -13,7 +13,6 @@ public enum LocalText { static let networkError = localText(key: "error.network") static let genericError = localText(key: "error.generic") static let invalidCredsLoginError = localText(key: "loginError.invalidCreds") - static let saveArticleSavingState = localText(key: "saveArticleSavingState") static let saveArticleSavedState = localText(key: "saveArticleSavedState") static let saveArticleProcessingState = localText(key: "saveArticleProcessingState") static let extensionAppUnauthorized = localText(key: "extensionAppUnauthorized") diff --git a/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift b/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift index 7dd30d07f..44109b86f 100644 --- a/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift +++ b/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift @@ -3,16 +3,13 @@ import SwiftUI import Utils public enum ShareExtensionStatus { - case saving case processing - case successfullySaved + case success case failed(error: SaveArticleError) var displayMessage: String { switch self { - case .saving: - return LocalText.saveArticleSavingState - case .successfullySaved: + case .success: return LocalText.saveArticleSavedState case let .failed(error: error): return error.displayMessage @@ -111,22 +108,6 @@ public struct ShareExtensionChildView: View { @State var reminderTime: ReminderTime? @State var hideUntilReminded = false - @State var readNowPending = false - - private func waitForReadNow() { - readNowPending = true - - DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300)) { - switch status { - case .successfullySaved: - readNowButtonAction() - case .failed(error: _): - readNowPending = false - case .saving, .processing: - waitForReadNow() - } - } - } private func handleReminderTimeSelection(_ selectedTime: ReminderTime) { if selectedTime == reminderTime { @@ -156,7 +137,7 @@ public struct ShareExtensionChildView: View { Spacer() - if case ShareExtensionStatus.successfullySaved = status { + if case ShareExtensionStatus.success = status { HStack(spacing: 4) { Text("Saved to Omnivore") .font(.appTitleThree) @@ -222,25 +203,17 @@ public struct ShareExtensionChildView: View { .padding(.horizontal) HStack { - if case ShareExtensionStatus.successfullySaved = status { + if case ShareExtensionStatus.success = status { Button( - action: { - if case ShareExtensionStatus.successfullySaved = status { - readNowButtonAction() - } else { - waitForReadNow() - } - }, - label: { - if readNowPending { - ProgressView().frame(maxWidth: .infinity) - } else { - Text("Read Now").frame(maxWidth: .infinity) - } - } + action: { readNowButtonAction() }, + label: { Text("Read Now").frame(maxWidth: .infinity) } ) .buttonStyle(RoundedRectButtonStyle()) } + if case ShareExtensionStatus.processing = status { + Button(action: {}, label: { ProgressView().frame(maxWidth: .infinity) }) + .buttonStyle(RoundedRectButtonStyle()) + } Button( action: { dismissButtonTappedAction(reminderTime, hideUntilReminded) From 65640d7b044256cb3afada5c6e66100e2e9bed99 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Wed, 18 May 2022 09:13:26 -0700 Subject: [PATCH 3/3] add feature flag for read now button --- apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift | 1 + apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift index 7b5d0f704..5642e89eb 100644 --- a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift +++ b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift @@ -10,6 +10,7 @@ public enum FeatureFlag { public static let showAccountDeletion = false public static let enableSnoozeFromShareExtension = false public static let enableRemindersFromShareExtension = false + public static let enableReadNow = false public static let enablePushNotifications = false public static let enableShareButton = false public static let enableSnooze = false diff --git a/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift b/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift index 44109b86f..8cfa95fbb 100644 --- a/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift +++ b/apple/OmnivoreKit/Sources/Views/ShareExtensionView.swift @@ -203,14 +203,14 @@ public struct ShareExtensionChildView: View { .padding(.horizontal) HStack { - if case ShareExtensionStatus.success = status { + if case ShareExtensionStatus.success = status, FeatureFlag.enableReadNow { Button( action: { readNowButtonAction() }, label: { Text("Read Now").frame(maxWidth: .infinity) } ) .buttonStyle(RoundedRectButtonStyle()) } - if case ShareExtensionStatus.processing = status { + if case ShareExtensionStatus.processing = status, FeatureFlag.enableReadNow { Button(action: {}, label: { ProgressView().frame(maxWidth: .infinity) }) .buttonStyle(RoundedRectButtonStyle()) }