Skip to content

Commit

Permalink
ContactTrick
Browse files Browse the repository at this point in the history
  • Loading branch information
mountrcg committed May 8, 2024
1 parent 593bfe8 commit 12a8ecd
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 123 deletions.
280 changes: 159 additions & 121 deletions FreeAPS/Sources/Modules/ContactTrick/View/ContactTrickRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ extension ContactTrick {
let resolver: Resolver
@StateObject var state = StateModel()

@Environment(\.colorScheme) var colorScheme
private var color: LinearGradient {
colorScheme == .dark ? LinearGradient(
gradient: Gradient(colors: [
Color.bgDarkBlue,
Color.bgDarkerDarkBlue
]),
startPoint: .top,
endPoint: .bottom
)
:
LinearGradient(
gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
startPoint: .top,
endPoint: .bottom
)
}

@State private var contactStore = CNContactStore()
@State private var authorization = CNContactStore.authorizationStatus(for: .contacts)

Expand Down Expand Up @@ -72,7 +90,7 @@ extension ContactTrick {
}
}
}
.dynamicTypeSize(...DynamicTypeSize.xxLarge)
.scrollContentBackground(.hidden).background(color)
.onAppear(perform: configureView)
.navigationTitle("Contact Trick")
.navigationBarTitleDisplayMode(.automatic)
Expand Down Expand Up @@ -176,173 +194,193 @@ extension ContactTrick {
struct EntryView: View {
@Binding var entry: ContactTrickEntry
@State private var availableFonts: [String]? = nil
@Environment(\.colorScheme) var colorScheme
private var color: LinearGradient {
colorScheme == .dark ? LinearGradient(
gradient: Gradient(colors: [
Color.bgDarkBlue,
Color.bgDarkerDarkBlue
]),
startPoint: .top,
endPoint: .bottom
)
:
LinearGradient(
gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
startPoint: .top,
endPoint: .bottom
)
}

private let fontSizes: [Int] = [100, 120, 130, 140, 160, 180, 200, 225, 250, 275, 300, 350, 400]
private let ringWidths: [Int] = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
private let ringGaps: [Int] = [0, 1, 2, 3, 4, 5]

var body: some View {
Section {
HStack {
ZStack {
Image(uiImage: ContactPicture.getImage(contact: entry, state: RootView.previewState))
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(width: 64, height: 64)
.clipShape(Circle())
Circle()
.stroke(lineWidth: 2)
.foregroundColor(.white)
}
.frame(width: 64, height: 64)
}
}
Form {
VStack {
Section {
Picker(
selection: $entry.layout,
label: Text("Layout")
) {
ForEach(ContactTrickLayout.allCases) { v in
Text(v.displayName).tag(v)
HStack {
ZStack {
Image(uiImage: ContactPicture.getImage(contact: entry, state: RootView.previewState))
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(width: 64, height: 64)
.clipShape(Circle())
Circle()
.stroke(lineWidth: 2)
.foregroundColor(.white)
}
.frame(width: 64, height: 64)
}
}
Section {
switch entry.layout {
case .single:
Form {
Section {
Picker(
selection: $entry.primary,
label: Text("Primary")
selection: $entry.layout,
label: Text("Layout")
) {
ForEach(ContactTrickValue.allCases) { v in
ForEach(ContactTrickLayout.allCases) { v in
Text(v.displayName).tag(v)
}
}
Picker(
selection: $entry.top,
label: Text("Top")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
}
Section {
switch entry.layout {
case .single:
Picker(
selection: $entry.primary,
label: Text("Primary")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
}
}
Picker(
selection: $entry.top,
label: Text("Top")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
}
}
Picker(
selection: $entry.bottom,
label: Text("Bottom")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
}
}
case .split:
Picker(
selection: $entry.top,
label: Text("Top")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
}
}
Picker(
selection: $entry.bottom,
label: Text("Bottom")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
}
}
}
}

Section(header: Text("Ring")) {
Picker(
selection: $entry.bottom,
label: Text("Bottom")
selection: $entry.ring1,
label: Text("Outer")
) {
ForEach(ContactTrickValue.allCases) { v in
ForEach(ContactTrickLargeRing.allCases) { v in
Text(v.displayName).tag(v)
}
}
case .split:
Picker(
selection: $entry.top,
label: Text("Top")
selection: $entry.ringWidth,
label: Text("Width")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
ForEach(ringWidths, id: \.self) { s in
Text("\(s)").tag(s)
}
}
Picker(
selection: $entry.bottom,
label: Text("Bottom")
selection: $entry.ringGap,
label: Text("Gap")
) {
ForEach(ContactTrickValue.allCases) { v in
Text(v.displayName).tag(v)
ForEach(ringGaps, id: \.self) { s in
Text("\(s)").tag(s)
}
}
}
}

Section(header: Text("Ring")) {
Picker(
selection: $entry.ring1,
label: Text("Outer")
) {
ForEach(ContactTrickLargeRing.allCases) { v in
Text(v.displayName).tag(v)
}
}
Picker(
selection: $entry.ringWidth,
label: Text("Width")
) {
ForEach(ringWidths, id: \.self) { s in
Text("\(s)").tag(s)
}
}
Picker(
selection: $entry.ringGap,
label: Text("Gap")
) {
ForEach(ringGaps, id: \.self) { s in
Text("\(s)").tag(s)
}
}
}

Section(header: Text("Font")) {
if availableFonts == nil {
HStack {
Spacer()
Button {
loadFonts()
} label: {
Text(entry.fontName)
Section(header: Text("Font")) {
if availableFonts == nil {
HStack {
Spacer()
Button {
loadFonts()
} label: {
Text(entry.fontName)
}
}
} else {
Picker(
selection: $entry.fontName,
label: EmptyView()
) {
ForEach(availableFonts!, id: \.self) { f in
Text(f).tag(f)
}
}
.pickerStyle(.navigationLink)
.labelsHidden()
}
} else {
Picker(
selection: $entry.fontName,
label: EmptyView()
selection: $entry.fontSize,
label: Text("Size")
) {
ForEach(availableFonts!, id: \.self) { f in
Text(f).tag(f)
ForEach(fontSizes, id: \.self) { s in
Text("\(s)").tag(s)
}
}
.pickerStyle(.navigationLink)
.labelsHidden()
}
Picker(
selection: $entry.fontSize,
label: Text("Size")
) {
ForEach(fontSizes, id: \.self) { s in
Text("\(s)").tag(s)
}
}
Picker(
selection: $entry.secondaryFontSize,
label: Text("Secondary size")
) {
ForEach(fontSizes, id: \.self) { s in
Text("\(s)").tag(s)
}
}
Picker(
selection: $entry.fontTracking,
label: Text("Tracking")
) {
ForEach(FontTracking.allCases) { w in
Text(w.displayName).tag(w)
Picker(
selection: $entry.secondaryFontSize,
label: Text("Secondary size")
) {
ForEach(fontSizes, id: \.self) { s in
Text("\(s)").tag(s)
}
}
}
if entry.isDefaultFont() {
Picker(
selection: $entry.fontWeight,
label: Text("Weight")
selection: $entry.fontTracking,
label: Text("Tracking")
) {
ForEach(FontWeight.allCases) { w in
ForEach(FontTracking.allCases) { w in
Text(w.displayName).tag(w)
}
}
if entry.isDefaultFont() {
Picker(
selection: $entry.fontWeight,
label: Text("Weight")
) {
ForEach(FontWeight.allCases) { w in
Text(w.displayName).tag(w)
}
}
}
}
Section {
Toggle("Dark mode", isOn: $entry.darkMode)
}
}
Section {
Toggle("Dark mode", isOn: $entry.darkMode)
}
}
.scrollContentBackground(.hidden).background(color)
}

private func loadFonts() {
Expand Down
4 changes: 2 additions & 2 deletions FreeAPS/Sources/Services/ContactTrick/ContactPicture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ struct ContactPicture: View {
drawProgressBar(
rect: rect,
progress: Double(iob) / Double(state.maxIOB),
colors: [contact.darkMode ? .blue : .blue, contact.darkMode ? .pink : .red],
colors: [.insulin, Color(red: 0.7215686275, green: 0.3411764706, blue: 1)],
strokeWidth: strokeWidth
)
}
Expand All @@ -401,7 +401,7 @@ struct ContactPicture: View {
rect: rect,
progress1: state.iob.map { Double($0) / Double(state.maxIOB) },
progress2: state.cob.map { Double($0) / Double(state.maxCOB) },
colors1: [contact.darkMode ? .blue : .blue, contact.darkMode ? .pink : .red],
colors1: [.insulin, Color(red: 0.7215686275, green: 0.3411764706, blue: 1)],
colors2: [.loopYellow, .red],
strokeWidth: strokeWidth
)
Expand Down

0 comments on commit 12a8ecd

Please sign in to comment.