[CHANGE] UI fixes and SwiftUI previews for easier development

This commit is contained in:
Fabian Thies
2023-02-19 14:30:21 +01:00
parent f206ee1406
commit 2211013e57
12 changed files with 171 additions and 62 deletions

View File

@@ -36,3 +36,26 @@ extension AppIconView: Equatable {
lhs.iconUrl == rhs.iconUrl && lhs.cornerRadius == rhs.cornerRadius
}
}
import AltStoreCore
struct AppIconView_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static var previews: some View {
HStack {
AppIconView(iconUrl: app.iconURL)
VStack(alignment: .leading) {
Text(app.name)
.bold()
Text(app.developerName)
.font(.callout)
.foregroundColor(.secondary)
}
}
}
}

View File

@@ -100,8 +100,45 @@ struct AppPillButton: View {
}
}
//struct AppPillButton_Previews: PreviewProvider {
// static var previews: some View {
// AppPillButton()
// }
//}
struct AppPillButton_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static let installedApp = InstalledApp.fetchAltStore(in: context)
static var previews: some View {
VStack {
self.preview(for: app)
self.preview(for: installedApp!)
self.preview(for: installedApp!, showRemainingDays: true)
}
.padding()
}
@ViewBuilder
static func preview(for app: AppProtocol, showRemainingDays: Bool = false) -> some View {
HintView(backgroundColor: Color(UIColor.secondarySystemBackground)) {
HStack {
AppIconView(iconUrl: self.app.iconURL)
VStack(alignment: .leading) {
Text(app is StoreApp ? "Store App" : "Installed App")
.bold()
Text(
app is StoreApp ?
"Can be installed" :
showRemainingDays ? "Can be refreshed" : "Can be opened"
)
.font(.callout)
.foregroundColor(.secondary)
}
Spacer()
AppPillButton(app: app, showRemainingDays: showRemainingDays)
}
}
}
}

View File

@@ -41,9 +41,15 @@ extension AppScreenshot {
}
import AltStoreCore
struct AppScreenshot_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static var previews: some View {
AppScreenshot(url: URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/browse-dark.png")!)
AppScreenshot(url: app.screenshotURLs[0])
.padding()
}
}

View File

@@ -14,6 +14,16 @@ struct ModalNavigationLink<Label: View, Modal: View>: View {
@State var isPresentingModal: Bool = false
init(@ViewBuilder modal: @escaping () -> Modal, @ViewBuilder label: @escaping () -> Label) {
self.modal = modal
self.label = label
}
init(_ title: String, @ViewBuilder modal: @escaping () -> Modal) where Label == Text {
self.modal = modal
self.label = { Text(title) }
}
var body: some View {
SwiftUI.Button {
self.isPresentingModal = true
@@ -26,8 +36,10 @@ struct ModalNavigationLink<Label: View, Modal: View>: View {
}
}
//struct ModalNavigationLink_Previews: PreviewProvider {
// static var previews: some View {
// ModalNavigationLink()
// }
//}
struct ModalNavigationLink_Previews: PreviewProvider {
static var previews: some View {
ModalNavigationLink("Present Modal") {
Text("Modal")
}
}
}

View File

@@ -10,7 +10,7 @@ import SwiftUI
extension View {
@ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
@ViewBuilder func `if`<Content: View>(_ condition: Bool, @ViewBuilder transform: (Self) -> Content) -> some View {
if condition {
transform(self)
} else {

View File

@@ -418,3 +418,16 @@ struct AppDetailView: View {
}
}
}
struct AppDetailView_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static var previews: some View {
NavigationView {
AppDetailView(storeApp: app)
}
}
}

View File

@@ -55,8 +55,17 @@ extension AppScreenshotsPreview: Equatable {
}
}
//struct AppScreenshotsPreview_Previews: PreviewProvider {
// static var previews: some View {
// AppScreenshotsPreview()
// }
//}
struct AppScreenshotsPreview_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static var previews: some View {
Color.clear
.sheet(isPresented: .constant(true)) {
NavigationView {
AppScreenshotsPreview(urls: app.screenshotURLs)
}
}
}
}

View File

@@ -56,3 +56,16 @@ extension Int: Identifiable {
self
}
}
import AltStoreCore
struct AppScreenshotsScrollView_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static var previews: some View {
AppScreenshotsScrollView(urls: app.screenshotURLs)
}
}

View File

@@ -42,8 +42,14 @@ struct AppVersionHistoryView: View {
}
}
//struct AppVersionHistoryView_Previews: PreviewProvider {
// static var previews: some View {
// AppVersionHistoryView(storeApp: )
// }
//}
struct AppVersionHistoryView_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static var previews: some View {
NavigationView {
AppVersionHistoryView(storeApp: app)
}
}
}

View File

@@ -41,8 +41,6 @@ struct MyAppsView: View {
@State var isRefreshingAllApps: Bool = false
@State var selectedSideloadingIpaURL: URL?
@State var isShowingAppIDsView: Bool = false
var remainingAppIDs: Int {
guard let team = DatabaseManager.shared.activeTeam() else {
return 0
@@ -91,7 +89,7 @@ struct MyAppsView: View {
.bold()
Spacer()
if !self.isRefreshingAllApps {
SwiftUI.Button(L10n.MyAppsView.refreshAll, action: self.refreshAllApps)
} else {
@@ -121,12 +119,7 @@ struct MyAppsView: View {
.foregroundColor(.secondary)
}
SwiftUI.Button {
self.isShowingAppIDsView = true
} label: {
Text(L10n.MyAppsView.viewAppIDs)
}
.sheet(isPresented: self.$isShowingAppIDsView) {
ModalNavigationLink(L10n.MyAppsView.viewAppIDs) {
NavigationView {
AppIDsView()
}
@@ -140,16 +133,13 @@ struct MyAppsView: View {
.navigationTitle(L10n.MyAppsView.myApps)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
SwiftUI.Button {
self.isShowingFilePicker = true
ModalNavigationLink {
DocumentPicker(selectedUrl: $selectedSideloadingIpaURL, supportedTypes: sideloadFileTypes)
.ignoresSafeArea()
} label: {
Image(systemSymbol: .plus)
.imageScale(.large)
}
.sheet(isPresented: self.$isShowingFilePicker) {
DocumentPicker(selectedUrl: $selectedSideloadingIpaURL, supportedTypes: sideloadFileTypes)
.ignoresSafeArea()
}
.onChange(of: self.selectedSideloadingIpaURL) { newValue in
guard let url = newValue else {
return
@@ -208,7 +198,7 @@ struct MyAppsView: View {
func refreshAllApps() {
let installedApps = InstalledApp.fetchAppsForRefreshingAll(in: DatabaseManager.shared.viewContext)
self.isRefreshingAllApps = true
self.refresh(installedApps) { result in
self.isRefreshingAllApps = false
@@ -254,9 +244,9 @@ extension MyAppsView {
NotificationManager.shared.showNotification(title: title, detailText: message)
}
self.viewModel.refreshGroup = nil
completionHandler(results)
self.viewModel.refreshGroup = nil
completionHandler(results)
}
}
@@ -435,6 +425,10 @@ extension MyAppsView {
}
struct MyAppsView_Previews: PreviewProvider {
static let context = DatabaseManager.shared.viewContext
static let app = StoreApp.makeAltStoreApp(in: context)
static var previews: some View {
NavigationView {
MyAppsView()

View File

@@ -27,13 +27,11 @@ struct SettingsView: View {
var isBackgroundRefreshEnabled: Bool = true
@State var isShowingConnectAppleIDView = false
@State var isShowingAddShortcutView = false
@State var isShowingFeedbackMailView = false
@State var isShowingResetPairingFileConfirmation = false
@State var externalURLToShow: URL?
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown Version"
var body: some View {
List {
@@ -93,13 +91,8 @@ struct SettingsView: View {
Toggle(isOn: self.$isBackgroundRefreshEnabled, label: {
Text(L10n.SettingsView.backgroundRefresh)
})
SwiftUI.Button {
self.isShowingAddShortcutView = true
} label: {
Text(L10n.SettingsView.addToSiri)
}
.sheet(isPresented: self.$isShowingAddShortcutView) {
ModalNavigationLink(L10n.SettingsView.addToSiri) {
if let shortcut = INShortcut(intent: INInteraction.refreshAllApps().intent) {
SiriShortcutSetupView(shortcut: shortcut)
}
@@ -163,10 +156,7 @@ struct SettingsView: View {
}
if MailComposeView.canSendMail {
SwiftUI.Button("Send Feedback") {
self.isShowingFeedbackMailView = true
}
.sheet(isPresented: self.$isShowingFeedbackMailView) {
ModalNavigationLink("Send Feedback") {
MailComposeView(recipients: ["support@sidestore.io"],
subject: "SideStore Beta \(appVersion) Feedback") {
NotificationManager.shared.showNotification(title: "Thank you for your feedback!")

View File

@@ -342,25 +342,31 @@ public extension StoreApp
class func makeAltStoreApp(in context: NSManagedObjectContext) -> StoreApp
{
let app = StoreApp(context: context)
app.source = Source.makeAltStoreSource(in: context)
app.name = "SideStore"
app.bundleIdentifier = StoreApp.altstoreAppID
app.developerName = "Side Team"
app.localizedDescription = "SideStore is an alternative App Store."
app.iconURL = URL(string: "https://user-images.githubusercontent.com/705880/63392210-540c5980-c37b-11e9-968c-8742fc68ab2e.png")!
app.screenshotURLs = []
app.sourceIdentifier = Source.altStoreIdentifier
app.iconURL = URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/icon.png")!
app.screenshotURLs = [
URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/browse-dark.png")!,
URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/apps-dark.png")!,
URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/news-dark.png")!,
URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/browse-light.png")!,
URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/apps-light.png")!,
URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/news-light.png")!,
]
app.tintColor = UIColor(named: "AccentColor")
let appVersion = AppVersion.makeAppVersion(version: "0.3.0",
let appVersion = AppVersion.makeAppVersion(version: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown",
date: Date(),
downloadURL: URL(string: "http://rileytestut.com")!,
downloadURL: URL(string: "https://github.com/SideStore/SideStore/releases/download/0.1.1/SideStore.ipa")!,
size: 0,
appBundleID: app.bundleIdentifier,
sourceID: Source.altStoreIdentifier,
in: context)
app.setVersions([appVersion])
print("makeAltStoreApp StoreApp: \(String(describing: app))")
#if BETA
app.isBeta = true
#endif