Skip to content

Commit

Permalink
lint warning updates
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbarela committed Dec 19, 2023
1 parent cd886a1 commit 65417b4
Show file tree
Hide file tree
Showing 30 changed files with 522 additions and 311 deletions.
130 changes: 87 additions & 43 deletions Marlin/Marlin/BottomSheet/BottomSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,38 @@ struct MarlinDataBottomSheet: View {
Self._printChanges()
return
Color.clear
.sheet(isPresented: $showBottomSheet, onDismiss: {
NotificationCenter.default.post(name: .FocusMapOnItem, object: FocusMapOnItemNotification(item: nil))
}) {
MarlinBottomSheet(itemList: itemList, focusNotification: .FocusMapOnItem)
.environmentObject(LocationManager.shared())
.presentationDetents([.medium])
}

.sheet(
isPresented: $showBottomSheet,
onDismiss: {
NotificationCenter.default.post(
name: .FocusMapOnItem,
object: FocusMapOnItemNotification(item: nil)
)
},
content: {
MarlinBottomSheet(itemList: itemList, focusNotification: .FocusMapOnItem)
.environmentObject(LocationManager.shared())
.presentationDetents([.medium])
}
)

.onReceive(mapItemsTappedPub) { output in
guard let notification = output.object as? MapItemsTappedNotification else {
return
}
var bottomSheetItems: [BottomSheetItem] = []
bottomSheetItems += self.handleTappedItems(items: notification.items, mapName: notification.mapName, zoom: notification.zoom)
bottomSheetItems += self.handleTappedItems(
items: notification.items,
mapName: notification.mapName,
zoom: notification.zoom
)
if bottomSheetItems.count == 0 {
return
}
itemList.bottomSheetItems = bottomSheetItems
showBottomSheet.toggle()
}
.onReceive(dismissBottomSheetPub) { output in
.onReceive(dismissBottomSheetPub) { _ in
showBottomSheet = false
}
}
Expand All @@ -71,7 +82,11 @@ struct MarlinBottomSheet <Content: View>: View {

let contentBuilder: (_ item: any DataSourceViewBuilder) -> Content

init(itemList: BottomSheetItemList, focusNotification: NSNotification.Name, @ViewBuilder contentBuilder: @escaping (_ item: any DataSourceViewBuilder) -> Content) {
init(
itemList: BottomSheetItemList,
focusNotification: NSNotification.Name,
@ViewBuilder contentBuilder: @escaping (_ item: any DataSourceViewBuilder) -> Content
) {
self.itemList = itemList
self.contentBuilder = contentBuilder
self.focusNotification = focusNotification
Expand All @@ -80,7 +95,8 @@ struct MarlinBottomSheet <Content: View>: View {
init(itemList: BottomSheetItemList, focusNotification: NSNotification.Name) where Content == AnyView {
self.init(itemList: itemList, focusNotification: focusNotification) { item in
AnyView(
// TODO: need a way to specify views for the models, maybe just move the data source view builder stuff to the models
// TODO: need a way to specify views for the models,
// maybe just move the data source view builder stuff to the models
item.summary
.setShowMoreDetails(true)
.setShowSectionHeader(true)
Expand All @@ -89,13 +105,11 @@ struct MarlinBottomSheet <Content: View>: View {
}
}


//action: @escaping () -> Void
@ViewBuilder
private var rectangle: some View {
if let item = itemList.bottomSheetItems?[selectedItem].item {
Rectangle()
.fill(Color(type(of:item).definition.color))
.fill(Color(type(of: item).definition.color))
.frame(maxWidth: 8, maxHeight: .infinity)
}
}
Expand All @@ -108,24 +122,30 @@ struct MarlinBottomSheet <Content: View>: View {
if let bottomSheetItems = itemList.bottomSheetItems, bottomSheetItems.count >= selectedItem + 1 {
let item = bottomSheetItems[selectedItem].item
HStack {
DataSourceCircleImage(dataSource: type(of:item), size: 30)
DataSourceCircleImage(dataSource: type(of: item), size: 30)
Spacer()
}

if bottomSheetItems.count > 1 {
HStack(spacing: 8) {
Button(action: {
withAnimation {
selectedItem = max(0, selectedItem - 1)
}
}) {
Label(
title: {},
icon: { Image(systemName: "chevron.left")
Button(
action: {
withAnimation {
selectedItem = max(0, selectedItem - 1)
}
},
label: {
Label(
title: {},
icon: {
Image(systemName: "chevron.left")
.renderingMode(.template)
.foregroundColor(selectedItem != 0 ? Color.primaryColorVariant : Color.disabledColor)
.foregroundColor(selectedItem != 0
? Color.primaryColorVariant : Color.disabledColor
)
})
}
}
)
.buttonStyle(MaterialButtonStyle())
.accessibilityElement()
.accessibilityLabel("previous")
Expand All @@ -134,18 +154,23 @@ struct MarlinBottomSheet <Content: View>: View {
.font(Font.caption)
.foregroundColor(Color.onSurfaceColor.opacity(0.6))

Button(action: {
withAnimation {
selectedItem = min(pages - 1, selectedItem + 1)
}
}) {
Label(
title: {},
icon: { Image(systemName: "chevron.right")
Button(
action: {
withAnimation {
selectedItem = min(pages - 1, selectedItem + 1)
}
},
label: {
Label(
title: {},
icon: {
Image(systemName: "chevron.right")
.renderingMode(.template)
.foregroundColor(pages - 1 != selectedItem ? Color.primaryColorVariant : Color.disabledColor)
})
}
.foregroundColor(pages - 1 != selectedItem
? Color.primaryColorVariant : Color.disabledColor)
})
}
)
.buttonStyle(MaterialButtonStyle())
.accessibilityElement()
.accessibilityLabel("next")
Expand All @@ -154,7 +179,8 @@ struct MarlinBottomSheet <Content: View>: View {
}
}

if (itemList.bottomSheetItems?.count ?? -1) >= selectedItem + 1, let item = itemList.bottomSheetItems?[selectedItem] {
if (itemList.bottomSheetItems?.count ?? -1) >= selectedItem + 1,
let item = itemList.bottomSheetItems?[selectedItem] {
if let dataSource = item.item as? (any DataSourceViewBuilder) {
contentBuilder(dataSource)
.transition(.opacity)
Expand All @@ -173,15 +199,33 @@ struct MarlinBottomSheet <Content: View>: View {
.ignoresSafeArea()
)
.onChange(of: selectedItem) { item in
if (itemList.bottomSheetItems?.count ?? -1) >= selectedItem + 1, let bottomSheetItem = itemList.bottomSheetItems?[selectedItem], let item = bottomSheetItem.item as? Locatable {
NotificationCenter.default.post(name: focusNotification, object: FocusMapOnItemNotification(item: item, zoom: bottomSheetItem.zoom, mapName: bottomSheetItem.mapName))
if (itemList.bottomSheetItems?.count ?? -1) >= selectedItem + 1,
let bottomSheetItem = itemList.bottomSheetItems?[selectedItem],
let item = bottomSheetItem.item as? Locatable {
NotificationCenter.default.post(
name: focusNotification,
object: FocusMapOnItemNotification(
item: item,
zoom: bottomSheetItem.zoom,
mapName: bottomSheetItem.mapName
)
)
}
}
.onAppear {
if (itemList.bottomSheetItems?.count ?? -1) >= selectedItem + 1, let bottomSheetItem = itemList.bottomSheetItems?[selectedItem], let item = bottomSheetItem.item as? Locatable {
NotificationCenter.default.post(name: focusNotification, object: FocusMapOnItemNotification(item: item, zoom: bottomSheetItem.zoom, mapName: bottomSheetItem.mapName))
if (itemList.bottomSheetItems?.count ?? -1) >= selectedItem + 1,
let bottomSheetItem = itemList.bottomSheetItems?[selectedItem],
let item = bottomSheetItem.item as? Locatable {
NotificationCenter.default.post(
name: focusNotification,
object: FocusMapOnItemNotification(
item: item,
zoom: bottomSheetItem.zoom,
mapName: bottomSheetItem.mapName
)
)
if let dataSource = item as? DataSource {
Metrics.shared.dataSourceBottomSheet(dataSource: type(of:dataSource).definition)
Metrics.shared.dataSourceBottomSheet(dataSource: type(of: dataSource).definition)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Marlin/Marlin/DataSources/ASAM/Asam+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation
import CoreData
import MapKit
import CoreData
import GeoJSON

class Asam: NSManagedObject {
Expand Down
15 changes: 13 additions & 2 deletions Marlin/Marlin/DataSources/ASAM/Asam+MapImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ extension Asam: MapImage {

static var cacheTiles: Bool = true

func mapImage(marker: Bool, zoomLevel: Int, tileBounds3857: MapBoundingBox?, context: CGContext? = nil) -> [UIImage] {
return defaultMapImage(marker: marker, zoomLevel: zoomLevel, tileBounds3857: tileBounds3857, context: context, tileSize: 512.0)
func mapImage(
marker: Bool,
zoomLevel: Int,
tileBounds3857: MapBoundingBox?,
context: CGContext? = nil
) -> [UIImage] {
return defaultMapImage(
marker: marker,
zoomLevel: zoomLevel,
tileBounds3857: tileBounds3857,
context: context,
tileSize: 512.0
)
}
}
3 changes: 2 additions & 1 deletion Marlin/Marlin/DataSources/ASAM/AsamModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ extension AsamModel: DataSource {

static var isMappable: Bool = true
static var dataSourceName: String = NSLocalizedString("ASAM", comment: "ASAM data source display name")
static var fullDataSourceName: String = NSLocalizedString("Anti-Shipping Activity Messages", comment: "ASAM data source full display name")
static var fullDataSourceName: String =
NSLocalizedString("Anti-Shipping Activity Messages", comment: "ASAM data source full display name")
static var key: String = "asam"
static var metricsKey: String = "asams"
static var imageName: String? = "asam"
Expand Down
28 changes: 21 additions & 7 deletions Marlin/Marlin/DataSources/Bookmark/Bookmark+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ protocol Bookmarkable {

extension Bookmarkable {
var bookmark: Bookmark? {
return try? PersistenceController.current.viewContext.fetchFirst(Bookmark.self, predicate: NSPredicate(format: "id == %@ AND dataSource == %@", itemKey, key))
return try? PersistenceController.current.viewContext.fetchFirst(
Bookmark.self,
predicate: NSPredicate(format: "id == %@ AND dataSource == %@", itemKey, key))
}

static func getItem(context: NSManagedObjectContext, itemKey: String?) -> Bookmarkable? {
Expand Down Expand Up @@ -54,9 +56,10 @@ class Bookmark: NSManagedObject, BatchImportable {

}

// disable this check because we have this many data sources
// swiftlint:disable cyclomatic_complexity
func getDataSourceItem(context: NSManagedObjectContext) -> (any Bookmarkable)? {
print("data source is \(dataSource)")
switch(dataSource) {
switch dataSource {
case Asam.key:
return Asam.getItem(context: context, itemKey: self.id)
case Modu.key:
Expand All @@ -82,6 +85,7 @@ class Bookmark: NSManagedObject, BatchImportable {
}
return nil
}
// swiftlint:enable cyclomatic_complexity
}

extension Bookmark: DataSource {
Expand All @@ -98,15 +102,23 @@ extension Bookmark: DataSource {
DataSourceProperty(name: "Date", key: #keyPath(Bookmark.timestamp), type: .date)
]

static var defaultSort: [DataSourceSortParameter] = [DataSourceSortParameter(property:DataSourceProperty(name: "Timestamp", key: #keyPath(Bookmark.timestamp), type: .date), ascending: false)]

static var defaultSort: [DataSourceSortParameter] = [
DataSourceSortParameter(
property: DataSourceProperty(
name: "Timestamp",
key: #keyPath(Bookmark.timestamp),
type: .date
),
ascending: false)
]

static var defaultFilter: [DataSourceFilterParameter] = []

static var isMappable: Bool = false
static var dataSourceName: String = "Bookmarks"
static var fullDataSourceName: String = "Bookmarks"
static var color: UIColor = UIColor(argbValue: 0xFFFF9500)
static var imageName: String? = nil
static var imageName: String?
static var systemImageName: String? = "bookmark.fill"
static var imageScale: CGFloat = 1.0

Expand All @@ -125,7 +137,9 @@ extension Bookmark: DataSourceViewBuilder {
return "Bookmark \(self.id ?? "")"
}
var detailView: AnyView {
if let viewBuilder = getDataSourceItem(context: PersistenceController.current.viewContext) as? (any DataSourceViewBuilder) {
if let viewBuilder = getDataSourceItem(
context: PersistenceController.current.viewContext
) as? (any DataSourceViewBuilder) {
return viewBuilder.detailView
}
return AnyView(Text("Bookmark detail \(self.dataSource ?? "") \(self.id ?? "")"))
Expand Down
39 changes: 23 additions & 16 deletions Marlin/Marlin/DataSources/Bookmark/BookmarkButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ struct BookmarkButton: View {
@ObservedObject var viewModel: BookmarkViewModel

var body: some View {
Button(action: {
withAnimation {
if viewModel.isBookmarked {
viewModel.removeBookmark()
} else {
bookmarkBottomSheet = true
Button(
action: {
withAnimation {
if viewModel.isBookmarked {
viewModel.removeBookmark()
} else {
bookmarkBottomSheet = true
}
}
},
label: {
Label(
title: { },
icon: { Image(systemName: viewModel.isBookmarked ? "bookmark.fill" : "bookmark")
.renderingMode(.template)
.foregroundColor(Color.primaryColorVariant)
})
}
}) {
Label(
title: { },
icon: { Image(systemName: viewModel.isBookmarked ? "bookmark.fill" : "bookmark")
.renderingMode(.template)
.foregroundColor(Color.primaryColorVariant)
})
}
)
.accessibilityElement()
.accessibilityLabel("\(viewModel.isBookmarked ? "remove bookmark \(viewModel.itemKey ?? "")" : "bookmark")")
.animation(.easeOut, value: viewModel.isBookmarked)
Expand All @@ -43,7 +46,11 @@ struct BookmarkButton: View {
}
TextEditor(text: $notes)
.lineLimit(4...)
.overlay(Rectangle().frame(height: 2).foregroundColor(Color.primaryColorVariant), alignment: .bottom)
.overlay(
Rectangle()
.frame(height: 2)
.foregroundColor(Color.primaryColorVariant), alignment: .bottom
)
.scrollContentBackground(.hidden)
.background(Color.backgroundColor)
.tint(Color.primaryColorVariant)
Expand All @@ -57,7 +64,7 @@ struct BookmarkButton: View {
}
bookmarkBottomSheet = false
}
.buttonStyle(MaterialButtonStyle(type:.text))
.buttonStyle(MaterialButtonStyle(type: .text))
.accessibilityElement()
.accessibilityLabel("Bookmark")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct BookmarkListEmptyState: View {
var body: some View {
GeometryReader { geo in
GeometryReader { _ in
VStack(alignment: .center, spacing: 16) {
Spacer()
HStack(alignment: .center, spacing: 0) {
Expand Down
Loading

0 comments on commit 65417b4

Please sign in to comment.