Skip to content

Commit

Permalink
Include isNext and also include a glow for the current salat time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aamir Jawaid committed Jan 6, 2024
1 parent 4dad4b1 commit b91140e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
4 changes: 4 additions & 0 deletions SalatTimeBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
37D25ADE2A7B095A00FFA2C2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37D25ADD2A7B095A00FFA2C2 /* Assets.xcassets */; };
37D25AE12A7B095A00FFA2C2 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37D25AE02A7B095A00FFA2C2 /* Preview Assets.xcassets */; };
37F3ADF32B47AAAE005D0A61 /* Visualizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F3ADF22B47AAAE005D0A61 /* Visualizer.swift */; };
37F3ADF52B49C245005D0A61 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37F3ADF42B49C245005D0A61 /* View.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -47,6 +48,7 @@
37D25AE02A7B095A00FFA2C2 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
37D25AE22A7B095A00FFA2C2 /* SalatTimeBar.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SalatTimeBar.entitlements; sourceTree = "<group>"; };
37F3ADF22B47AAAE005D0A61 /* Visualizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Visualizer.swift; sourceTree = "<group>"; };
37F3ADF42B49C245005D0A61 /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -80,6 +82,7 @@
children = (
376679AA2ADB9D6300CF583F /* Date.swift */,
372E24862B268C9500A05199 /* Color.swift */,
37F3ADF42B49C245005D0A61 /* View.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -205,6 +208,7 @@
files = (
37C686A02A7F210F00771C45 /* SalatTimeData.swift in Sources */,
376679AB2ADB9D6300CF583F /* Date.swift in Sources */,
37F3ADF52B49C245005D0A61 /* View.swift in Sources */,
372E247C2B1CD7FA00A05199 /* SampleData.swift in Sources */,
372E24872B268C9500A05199 /* Color.swift in Sources */,
372E24812B2113A000A05199 /* SampleTestData.swift in Sources */,
Expand Down
Binary file not shown.
17 changes: 17 additions & 0 deletions SalatTimeBar/Extensions/View.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// View.swift
// SalatTimeBar
//
// Created by Aamir Jawaid on 1/6/24.
//

import SwiftUI

extension View {
func glow(color: Color = .white, radius: CGFloat = 12) -> some View {
self
.shadow(color: color, radius: radius / 3)
.shadow(color: color, radius: radius / 3)
.shadow(color: color, radius: radius / 3)
}
}
2 changes: 1 addition & 1 deletion SalatTimeBar/PopupWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct PopupWindow: View {
}
if let salatsForToday = currentSalatTimes.salatsForToday {
Visualizer(points: salatsForToday.map({ time in
VisualizerPoint(time: time.time, icon: time.type.icon, hasPassed: time.time.timeIntervalSinceNow < 0, isActive: currentSalatTimes.recentlyPassedSalatTime?.type == time.type)
VisualizerPoint(time: time.time, icon: time.type.icon, hasPassed: time.time.timeIntervalSinceNow < 0, isActive: currentSalatTimes.recentlyPassedSalatTime?.type == time.type, isNext: currentSalatTimes.currentSalatTime?.type == time.type)
}))
}
} else {
Expand Down
24 changes: 16 additions & 8 deletions SalatTimeBar/Visualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct VisualizerPoint: Identifiable {
var icon: String?
var hasPassed: Bool?
var isActive: Bool?
var isNext: Bool?
}

struct Position: Identifiable {
Expand All @@ -30,6 +31,7 @@ struct Position: Identifiable {
var icon: String?
var hasPassed: Bool
var isActive: Bool
var isNext: Bool
}

struct Visualizer: View {
Expand All @@ -51,9 +53,15 @@ struct Visualizer: View {
path.addLine(to: CGPoint(x: position.end, y: height / 2.0))
path.closeSubpath()
}
.stroke(position.hasPassed ? Color.accentColor : Color.primary, lineWidth: position.hasPassed ? 2.0 : 1.0)
.stroke(position.hasPassed ? Color.accentColor : Color.secondary, lineWidth: 1.0)
if let icon = position.icon {
Image(systemName: icon).position(x: position.end + PADDING / 2.0, y: height / 2.0).bold(position.isActive).foregroundColor(position.isActive ? Color.accentColor : Color.secondary)
Image(systemName: icon)
.position(x: position.end + PADDING / 2.0, y: height / 2.0)
.bold(position.isActive || position.isNext)
.foregroundColor(position.isActive ? Color.accentColor : position.isNext ? Color.primary : Color.secondary)
.opacity(position.isActive || position.isNext ? 1.0 : 0.2)
.font(.system(size: 8))
.glow(radius: position.isActive ? 20 : 0)
}
}
}
Expand All @@ -69,17 +77,17 @@ struct Visualizer: View {
let n = (point.time.timeIntervalSince1970 - firstTime) / totalTime
let nextX = n * totalWidth
x = nextX + PADDING
return Position(start: firstX, end: nextX, icon: point.icon, hasPassed: point.hasPassed ?? false, isActive: point.isActive ?? false)
return Position(start: firstX, end: nextX, icon: point.icon, hasPassed: point.hasPassed ?? false, isActive: point.isActive ?? false, isNext: point.isNext ?? false)
}
}
}

#Preview {
Visualizer(points: [
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 7), icon: "sun.max", hasPassed: true),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 4), icon: "sun.max"),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 1), icon: "sun.max", hasPassed: true),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 12), icon: "sun.max"),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 24), icon: "sun.max")
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 7), icon: "sun.haze", hasPassed: true, isActive: true),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 4), icon: "sun.max", hasPassed: true),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 1), icon: "sun.horizon.fill", hasPassed: true),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 12), icon: "sun.horizon", isNext: true),
VisualizerPoint(time: Date.now.computeDate(byAdding: .hour, value: 24), icon: "moon.fill")
])
}

0 comments on commit b91140e

Please sign in to comment.