-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrayerTimeView.swift
277 lines (245 loc) · 12.5 KB
/
PrayerTimeView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//
// PrayerTimeViewModel.swift
// Salaam
//
// Created by Muhammad Shah on 20/01/2023.
//
import SwiftUI
import CoreLocation
import Adhan
import WidgetKit
struct PrayerView: View{
@ObservedObject var pray: PrayerTimeViewModel
@ObservedObject var model: PrayerTimeViewModel
@Environment(\.presentationMode) var presetationMode
@State var isPrayer = true
@State var dates : String
@State var month : String
@State var currentYear : String
@State var scale = 1.0
func getIslamicDate(){
let dateFor = DateFormatter()
let hijriCalendar = Calendar.init(identifier: Calendar.Identifier.islamicCivil)
dateFor.locale = Locale.init(identifier: "en")
dateFor.calendar = hijriCalendar
dateFor.dateFormat = "d"
//dateFor.dateFormat = "LLLL"
let islamic_date = dateFor.string(from: Date())
self.dates = islamic_date
}
func getMonth(){
let dateFor = DateFormatter()
let hijriCalendar = Calendar.init(identifier: Calendar.Identifier.islamicCivil)
dateFor.locale = Locale.init(identifier: "en")
dateFor.calendar = hijriCalendar
dateFor.dateFormat = "dd/mm/yyyy"
dateFor.dateFormat = "LLLL"
let nameOfMonth = dateFor.string(from: Date())
self.month = nameOfMonth
}
func getYear(){
let dateFor = DateFormatter()
let hijriCalendar = Calendar.init(identifier: Calendar.Identifier.islamicCivil)
dateFor.locale = Locale.init(identifier: "en")
dateFor.calendar = hijriCalendar
dateFor.dateFormat = "yyyy"
let yearnumber = dateFor.string(from: Date())
self.currentYear = yearnumber
}
@State private var bouncing = false
var body: some View{
GeometryReader{ geometry in
ZStack{
VStack{
CloudShape()
.fill(.thinMaterial)
.frame(width: 160, height: 100)
.padding(.top, 40)
.padding(.leading, 40)
}
.frame(maxHeight: 160, alignment: bouncing ? .bottom : .topTrailing)
.animation(Animation.easeInOut(duration: 3.0).repeatForever(autoreverses: true), value: bouncing)
VStack{
CloudShape()
.fill(.thinMaterial)
.frame(width: 160, height: 100)
.padding(.top, 45)
.padding(.leading, -30)
}
.frame(maxHeight: 160, alignment: bouncing ? .bottom : .topTrailing)
.animation(Animation.easeInOut(duration: 2.0).repeatForever(autoreverses: true), value: bouncing)
}
.onAppear {
self.bouncing.toggle()
}
ZStack{
Circle()
.fill(.ultraThinMaterial)
.frame(width: 260, height: 130)
.scaleEffect(scale)
.onAppear {
let baseAnimation = Animation.easeInOut(duration: 1)
let repeated = baseAnimation.repeatForever(autoreverses: true)
withAnimation(repeated) {
scale = 1.2
}
}
Circle()
.fill(.ultraThinMaterial)
.frame(width: 200, height: 100)
.scaleEffect(scale)
.onAppear {
let baseAnimation = Animation.easeInOut(duration: 1.2)
let repeated = baseAnimation.repeatForever(autoreverses: true)
withAnimation(repeated) {
scale = 1.2
}
}
Circle()
.fill(Color.init("sun"))
.frame(width: 140, height: 70)
Circle()
.fill(Color.init("moon"))
.frame(width: 15, height: 7.5)
.offset(x: -21, y: -6)
Circle()
.fill(Color.init("moon"))
.frame(width: 15, height: 7.5)
.offset(x: -25, y: 6)
Circle()
.fill(Color.init("moon"))
.frame(width: 20, height: 10)
.offset(x: -22, y: -2)
Circle()
.fill(Color.init("moon"))
.frame(width: 30, height: 15)
.offset(x: -12, y: -18)
Circle()
.fill(Color.init("moon"))
.frame(width: 10, height: 5)
.offset(x: -10, y: -6)
}
.padding(.top, 10)
.padding(.trailing, -40)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topTrailing)
VStack{
VStack{
VStack{
Text("\(dates) \(month) \(currentYear)")
.fontWeight(.bold)
.frame(alignment: .leading)
.font(.system(size:15))
.onAppear {
self.getIslamicDate()
self.getMonth()
self.getYear()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
VStack{
Text("السلام عليكم")
.font(.system(size: 40))
.fontWeight(.bold)
}
.frame(maxWidth: .infinity, maxHeight: 40, alignment: .bottomLeading)
.padding(.top, 10)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
.padding(15)
ZStack{
VStack{
HStack{
Text("Fajr")
Spacer()
Text(pray.fajr)
}
.padding()
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 15))
.onAppear {
model.getPrayerTime(CLLocationManager(), didUpdateHeading: CLHeading.init())
WidgetCenter.shared.reloadAllTimelines()
}
HStack{
Text("Sunrise")
Spacer()
Text(pray.sunrise)
}
.padding()
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 15))
HStack{
Text("Zuhr")
Spacer()
Text(pray.zuhr)
}
.padding()
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 15))
HStack{
Text("Asr")
Spacer()
Text(pray.asr)
}
.padding()
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 15))
HStack{
Text("Maghrib")
Spacer()
Text(pray.maghrib)
}
.padding()
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 15))
HStack{
Text("Isha")
Spacer()
Text(pray.isha)
}
.padding()
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 15))
}
.padding(10)
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 15))
}
.padding(10)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
}
}
.background(LinearGradient(gradient: Gradient(colors: [.init("GD2").opacity(0.6), .init("GD1")]), startPoint: .bottom, endPoint: .top))
}
}
struct CloudShape: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: CGPoint(x: rect.minX + 0.81028 * rect.width, y: rect.minY + 0.39009 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.77271 * rect.width, y: rect.minY + 0.39612 * rect.height), control1: CGPoint(x: rect.minX + 0.79766 * rect.width, y: rect.minY + 0.39009 * rect.height), control2: CGPoint(x: rect.minX + 0.78507 * rect.width, y: rect.minY + 0.39210 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.69093 * rect.width, y: rect.minY + 0.22300 * rect.height), control1: CGPoint(x: rect.minX + 0.76339 * rect.width, y: rect.minY + 0.32133 * rect.height), control2: CGPoint(x: rect.minX + 0.73325 * rect.width, y: rect.minY + 0.25753 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.55572 * rect.width, y: rect.minY + 0.21906 * rect.height), control1: CGPoint(x: rect.minX + 0.64862 * rect.width, y: rect.minY + 0.18847 * rect.height), control2: CGPoint(x: rect.minX + 0.59879 * rect.width, y: rect.minY + 0.18702 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.29076 * rect.width, y: rect.minY + 0.02004 * rect.height), control1: CGPoint(x: rect.minX + 0.51674 * rect.width, y: rect.minY + 0.04650 * rect.height), control2: CGPoint(x: rect.minX + 0.39812 * rect.width, y: rect.minY + -0.04260 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.16694 * rect.width, y: rect.minY + 0.44594 * rect.height), control1: CGPoint(x: rect.minX + 0.18340 * rect.width, y: rect.minY + 0.08269 * rect.height), control2: CGPoint(x: rect.minX + 0.12797 * rect.width, y: rect.minY + 0.27339 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.00002 * rect.width, y: rect.minY + 0.72706 * rect.height), control1: CGPoint(x: rect.minX + 0.07290 * rect.width, y: rect.minY + 0.45072 * rect.height), control2: CGPoint(x: rect.minX + -0.00139 * rect.width, y: rect.minY + 0.57584 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.17212 * rect.width, y: rect.minY + 1.00000 * rect.height), control1: CGPoint(x: rect.minX + 0.00143 * rect.width, y: rect.minY + 0.87829 * rect.height), control2: CGPoint(x: rect.minX + 0.07803 * rect.width, y: rect.minY + 0.99976 * rect.height))
path.addLine(to: CGPoint(x: rect.minX + 0.81028 * rect.width, y: rect.minY + 1.00000 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 1.00000 * rect.width, y: rect.minY + 0.69504 * rect.height), control1: CGPoint(x: rect.minX + 0.91505 * rect.width, y: rect.minY + 1.00000 * rect.height), control2: CGPoint(x: rect.minX + 1.00000 * rect.width, y: rect.minY + 0.86347 * rect.height))
path.addCurve(to: CGPoint(x: rect.minX + 0.81028 * rect.width, y: rect.minY + 0.39009 * rect.height), control1: CGPoint(x: rect.minX + 1.00000 * rect.width, y: rect.minY + 0.52662 * rect.height), control2: CGPoint(x: rect.minX + 0.91505 * rect.width, y: rect.minY + 0.39009 * rect.height))
path.closeSubpath()
return path
}
}
extension View {
/// Sets the text color for a navigation bar title.
/// - Parameter color: Color the title should be
///
/// Supports both regular and large titles.
func navigationBarTitleTextColor(_ color: Color) -> some View {
let uiColor = UIColor(color)
UITableView.appearance().separatorStyle = .none
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: uiColor ]
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: uiColor ]
return self
}
}