Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.15 #1

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 49 additions & 30 deletions Cami.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cami.xcodeproj/xcshareddata/xcschemes/Cami.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1520"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
13 changes: 5 additions & 8 deletions Cami/CamiApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ struct CamiApp: App {

var body: some Scene {
WindowGroup {
ContentView(
model: model,
perms: perms
)
.environment(model)
.environmentObject(model)
.environment(perms)
.environmentObject(perms)
ContentView()
.environment(model)
.environmentObject(model)
.environment(perms)
.environmentObject(perms)
}
}
}
105 changes: 80 additions & 25 deletions Cami/Model/FAQInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,66 @@ struct FAQInformation: Hashable, Identifiable {
var title: String
var description: String

public func search(
text: String,
exact: Bool = true,
anyInsteadOfAll: Bool = true
) -> Int {
public func lookForString(_ text: String, _ weight: Int = 0) -> Int {

if text == "" {
return 0
return 0 + weight
}

let newText = text.lowercased()
let title = self.title.lowercased()
let description = self.description.lowercased()

if title.lowercased().contains(newText) || description.lowercased().contains(newText) {
return 1
}
if exact {
return -1
return 0 + weight
}

return -1
}

public func lookForPart(_ text: String, _ weight: Int = 0, all: Bool = false) -> Int {
let text = text.lowercased()

var isInTitle: Bool = true
var isInDescription: Bool = true
var isInAnyAtSomePoint = false
for textPart in newText.split(separator: " ") {

var isInAnyAtSomePoint: Bool = false

for textPart in text.split(separator: " ") {

let isInTitleLocal = title.contains(textPart)
let isInDescriptionLocal = description.contains(textPart)

isInTitle = isInTitle && isInTitleLocal
isInDescription = isInDescription && isInDescriptionLocal

if !isInAnyAtSomePoint {
isInAnyAtSomePoint = isInTitleLocal || isInDescriptionLocal
}

if !all && isInAnyAtSomePoint {
return 0 + weight
}

}

if isInTitle || isInDescription {
return 2
return 0 + weight
}
if !anyInsteadOfAll {
return -1
}
if isInAnyAtSomePoint {
return 3
}
var newTitle = title
var newDesc = description
isInTitle = true
isInDescription = true
for char in newText {

return -1
}

public func lookForCharsInOrder(_ text: String, _ weight: Int = 0) -> Int {
let text = text.lowercased()

var newTitle = self.title
var newDesc = self.description

var isInTitle: Bool = true
var isInDescription: Bool = true

for char in text {
if isInTitle, let newTitleIndex = newTitle.firstIndex(of: char) {
newTitle = String(newTitle[newTitle.index(after: newTitleIndex)...])
} else {
Expand All @@ -71,9 +88,47 @@ struct FAQInformation: Hashable, Identifiable {
}
}
return if isInTitle || isInDescription {
4
0 + weight
} else {
-1
}
}

public func lookFor(
text: String,
exact: Bool = false,
all: Bool = false
) -> Int {

if text == "" {
return 0
}

let text = text.lowercased()

let exactLookupResult: Int = self.lookForString(text, 1)

if exactLookupResult >= 0 {
return exactLookupResult
} else if exact {
return -1
}

let allLookupResult: Int = self.lookForPart(text, 2, all: true)

if allLookupResult >= 0 {
return allLookupResult
} else if all {
return -1
}

let partLookupResult: Int = self.lookForPart(text, 3, all: false)

if partLookupResult >= 0 {
return partLookupResult
}

return self.lookForCharsInOrder(text, 4)

}
}
3 changes: 2 additions & 1 deletion Cami/Model/FAQInformationModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
//
// Created by Guillaume Coquard on 09/02/24.
//
// swiftlint:disable line_length

import Foundation

class FAQInformationModel {

static let shared: FAQInformationModel = .init()

// swiftlint:disable line_length
public let list: [FAQInformation] = [
.init(title: "Why does Cami request full access to Calendars?", description: "iOS requires applications to either request access to calendars in order to be able to edit events OR read and edit events. We need to read every events from every calendars, hence the request for \"Full Access\"."),
.init(title: "Why does Cami request access to Contacts?", description: "Cami presents by default the next birthday from your contacts in the top right corner of the widget, therefore Cami needs to access your contacts. If you disable contact access, next birthday won't be displayed."),
.init(title: "Why does my widget content seem outdated?", description: "Cami relies completely on iOS features and mechanisms. According to documentation provided by Apple, a widget can be updated every five minutes at most. If you want to force the update of your actual widgets, you just have to open the app and close it right after. This automatically refreshes widgets. If it does not work, you can try long pressing the \"Everything is fine.\" green box on the welcome screen of Cami and then tap on \"Refresh widgets\".")
]
// swiftlint:enable line_length

private init() {}
}
12 changes: 6 additions & 6 deletions Cami/Model/PermissionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ final class PermissionModel: ObservableObject {

private let center: NotificationCenter = .default

private var events: AuthorizationSet = .none {
private var events: PermissionSet = .none {
didSet {
self.center.post(name: .eventsAccessUpdated, object: nil)
}
}
private var contacts: AuthorizationSet = .none {
private var contacts: PermissionSet = .none {
didSet {
self.center.post(name: .contactsAccessUpdated, object: nil)
}
}
private var reminders: AuthorizationSet = .none {
private var reminders: PermissionSet = .none {
didSet {
self.center.post(name: .remindersAccessUpdated, object: nil)
}
}

var global: AuthorizationSet = .none {
var global: PermissionSet = .none {
didSet {
self.center.post(name: .accessUpdated, object: nil)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ final class PermissionModel: ObservableObject {
AuthSet.restrictedReminders
}

self.global = AuthorizationSet([
self.global = PermissionSet([
self.events,
self.contacts,
self.reminders
Expand Down Expand Up @@ -110,7 +110,7 @@ extension PermissionModel {
}

@objc private func updateAccess() {
self.global = AuthorizationSet([
self.global = PermissionSet([
self.events,
self.contacts,
self.reminders
Expand Down
19 changes: 6 additions & 13 deletions Cami/View/Calendar/CalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ struct CalendarView: View {
@State
private var wasNotAuthorized: Bool = true

@State
private var isSettingsViewPresented: Bool = !Bool(PermissionModel.shared.global.status)
@Binding
var areSettingsPresented: Bool

@State
private var isCalendarSelectionViewPresented: Bool = false
Expand All @@ -40,15 +40,8 @@ struct CalendarView: View {
.scrollIndicators(.hidden)
.scrollPosition(id: $model.position)
.sheet(isPresented: $isCalendarSelectionViewPresented) {
CalendarSelectionView().presentationDragIndicator(.visible)
}
.sheet(isPresented: $isSettingsViewPresented) {
SettingsView()
.environmentObject(model)
.environmentObject(perms)
.presentationDragIndicator(Bool(perms.global.status) ? .visible : .hidden)
.presentationDetents([.medium])
.interactiveDismissDisabled(!Bool(perms.global.status))
CalendarSelectionView()
.presentationDragIndicator(.visible)
}
.toolbar {
ToolbarItemGroup(placement: .navigation) {
Expand Down Expand Up @@ -89,7 +82,7 @@ struct CalendarView: View {
.labelStyle(.iconOnly)
}
Button {
isSettingsViewPresented.toggle()
areSettingsPresented.toggle()
} label: {
Label("Settings", systemImage: "gear")
.labelStyle(.iconOnly)
Expand All @@ -107,7 +100,7 @@ struct CalendarView: View {
.labelStyle(.iconOnly)
}
Button {
isSettingsViewPresented.toggle()
areSettingsPresented.toggle()
} label: {
Label("Settings", systemImage: "gear")
.labelStyle(.iconOnly)
Expand Down
22 changes: 18 additions & 4 deletions Cami/View/Calendar/MonthDayCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ struct MonthDayCell: View {
@Environment(ViewModel.self)
private var model: ViewModel

@EnvironmentObject
private var perms: PermissionModel

@State
private var colors: [Generic<Color>]?

private func updateColors() async {
let calendars: Set<String> = await day.lazyInitCalendars()
self.colors = Array(model.calendars.intersection( calendars ))
.asEKCalendars()
.map { Generic<Color>(Color(cgColor: $0.cgColor)) }
}

let day: Day

var body: some View {
Expand Down Expand Up @@ -51,10 +61,14 @@ struct MonthDayCell: View {
.onAppear {
DispatchQueue.main.async {
Task {
let calendars: Set<String> = await day.lazyInitCalendars()
colors = Array(model.calendars.intersection( calendars ))
.asEKCalendars()
.map { Generic<Color>(Color(cgColor: $0.cgColor)) }
await self.updateColors()
}
}
}
.onChange(of: perms.global) { _, _ in
DispatchQueue.main.async {
Task {
await self.updateColors()
}
}
}
Expand Down
Loading