-
Notifications
You must be signed in to change notification settings - Fork 1
/
zmanimSS.lua
268 lines (251 loc) · 9.49 KB
/
zmanimSS.lua
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
local Blitbuffer = require("ffi/blitbuffer")
local Device = require("device")
--local Event = require("ui/event")
local Font = require("ui/font")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local CenterContainer = require("ui/widget/container/centercontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local HorizontalGroup = require("ui/widget/horizontalgroup")
--local HorizontalSpan = require("ui/widget/horizontalspan")
local InputContainer = require("ui/widget/container/inputcontainer")
--local LeftContainer = require("ui/widget/container/leftcontainer")
local LineWidget = require("ui/widget/linewidget")
local OverlapGroup = require("ui/widget/overlapgroup")
local RightContainer = require("ui/widget/container/rightcontainer")
local Size = require("ui/size")
local TextBoxWidget = require("ui/widget/textboxwidget")
local TextWidget = require("ui/widget/textwidget")
local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local ZmanimUtil = require("zmanimutil")
local Screen = Device.screen
local ffi = require("ffi")
local libzmanim = require("libzmanim_load")
local cchar = ffi.typeof("char[?]")
local FACE_NAME = "ezra"
local ZmanimSS = InputContainer:extend{
name = "ZmanimSS",
covers_fullscreen = true,
modal = true,
content = nil,
widget = nil,
background = Blitbuffer.COLOR_LIGHT_GRAY,
face = nil,
}
function ZmanimSS:init()
if Device:hasKeys() then
self.key_events.Close = { {Device.input.group.Back} }
end
if Device:isTouchDevice() then
local range = Geom:new{
x = 0, y = 0,
w = Screen:getWidth(),
h = Screen:getHeight(),
}
self.ges_events.Tap = { GestureRange:new{ ges = "tap", range = range } }
end
self.height = Screen:getHeight()
self.width = Screen:getWidth()
self:genContent()
self:genWidget()
self:update()
end
function ZmanimSS:getZman(hdate, zman, text, round)
local result = libzmanim[zman](hdate, ZmanimUtil:getLocation())
if round then
libzmanim.hdateaddsecond(result, 60-result.sec)
end
local zf = os.date("%l:%M", tonumber(libzmanim.hdatetime_t(result)))
return {zf, text}
end
function ZmanimSS:getShuir(hdate, shuir)
local cshuir = cchar(100)
libzmanim[shuir](hdate, cshuir)
local result = ffi.string(cshuir)
local sub, _
if shuir ~= "chumash" then
sub, _ = string.gsub(result, "[^\n]-\n", "", 1)
end
local sub2, _ = string.gsub(sub or result, "\n", " - ")
return sub2
end
function ZmanimSS:genContent()
self.content = {}
local round = ZmanimUtil:getRound()
local hdate = ZmanimUtil:tsToHdate(os.time())
local day_string = ""
if libzmanim.hdatecompare(hdate, ZmanimUtil:getNightfall(hdate)) <= 0 then
libzmanim.hdateaddday(hdate, 1)
day_string = "ליל "
elseif libzmanim.hdatecompare(hdate, libzmanim.getalosbaalhatanya(hdate, ZmanimUtil:getLocation())) > 0 then
day_string = "ליל "
end
local zl = {}
table.insert(zl, self:getZman(hdate, "getalosbaalhatanya", "עלות"))
table.insert(zl, self:getZman(hdate, "getmisheyakir10p2degrees", "משיכיר", round))
table.insert(zl, self:getZman(hdate, "getsunrise", "נץ החמה", round))
table.insert(zl, self:getZman(hdate, "getshmabaalhatanya", "קריאת שמע"))
table.insert(zl, self:getZman(hdate, "gettefilabaalhatanya", "תפלה"))
table.insert(zl, self:getZman(hdate, "getchatzosbaalhatanya", "חצות"))
table.insert(zl, self:getZman(hdate, "getminchagedolabaalhatanya", "מנחה גדולה", round))
table.insert(zl, self:getZman(hdate, "getminchaketanabaalhatanya", "מנחה קטנה", round))
table.insert(zl, self:getZman(hdate, "getplagbaalhatanya", "פלג המנחה", round))
if libzmanim.iscandlelighting(hdate) == 1 then
table.insert(zl, self:getZman(hdate, "getcandlelighting", "הדלקת נרות"))
end
table.insert(zl, self:getZman(hdate, "getsunset", "שקיעה"))
if libzmanim.iscandlelighting(hdate) == 2 then
table.insert(zl, self:getZman(hdate, "gettzais8p5", "הדלקת נרות"))
table.insert(zl, self:getZman(hdate, "gettzais8p5", "צאת", round))
elseif libzmanim.isassurbemelachah(hdate) and hdate.wday ~= 6 then
if hdate.wday == 0 then
table.insert(zl, self:getZman(hdate, "gettzais8p5", "יציאת השבת", round))
else
table.insert(zl, self:getZman(hdate, "gettzais8p5", "יציאת החג", round))
end
else
table.insert(zl, self:getZman(hdate, "gettzaisbaalhatanya", "צאת", round))
end
if #zl %2 == 1 then --odd
table.insert(zl, self:getShuir(hdate, "tehillim"))
end
day_string = day_string .. ZmanimUtil:getDateString(hdate)
local yt = ZmanimUtil:getYomtov(hdate)
if yt ~= "" then
day_string = day_string .." - " .. yt
end
table.insert(self.content, day_string)
local ziterator = #zl/2
for k =1,ziterator do
table.insert(self.content, {zl[ziterator+k], zl[k]})
end
table.insert(self.content, self:getShuir(hdate, "chumash"))
table.insert(self.content, self:getShuir(hdate, "tanya"))
table.insert(self.content, self:getShuir(hdate, "rambam"))
end
function ZmanimSS:genWidget()
local items = #self.content
local item_height = math.floor((self.height - ((Size.line.thick * (items - 1))+ (Size.padding.default*2))) / items)
local half_width = math.floor((self.width - Size.line.thick) /2)
-- Font size is already `scaleBySize` in `Font`
self.face = Font:getFace(FACE_NAME, 40) or Font:getFace("cfont", 40)
local vg = VerticalGroup:new{}
table.insert(vg, VerticalSpan:new{width = Size.padding.default})
for k, v in ipairs(self.content) do
if k ~= 1 then
table.insert(vg,
LineWidget:new{
dimen = Geom:new{ w = self.width, h = Size.line.thick },
})
end
local hg = HorizontalGroup:new{}
if type(v) == "table" then
for k1, v1 in ipairs(v) do
if k1 ~= 1 then
table.insert(hg,
LineWidget:new{
dimen = Geom:new{ w = Size.line.thick, h = item_height },
})
end
local hg1
if type(v1) == "table" then
hg1 = HorizontalGroup:new{}
table.insert(hg1, RightContainer:new{
dimen = Geom:new{ w = math.floor(half_width * .25), h = item_height },
TextWidget:new{
text = v1[1],
face = self.face,
max_width = half_width,
}
})
table.insert(hg1, RightContainer:new{
dimen = Geom:new{ w = math.floor(half_width * .65), h = item_height },
TextWidget:new{
text = v1[2],
face = self.face,
max_width = half_width,
}
})
else
hg1 = TextWidget:new{
text = v1,
face = self.face,
max_width = half_width,
}
end
table.insert(hg, CenterContainer:new{
dimen = Geom:new{
w = half_width,
h = item_height,
},
hg1
})
end
else
--table.insert(hg, VerticalSpan:new{width = item_height})
table.insert(hg,
TextBoxWidget:new{
text = v,
lang = "he",
para_direction_rtl = true,
face = self.face,
width = self.width,
alignment = "center",
bgcolor = self.background,
height = item_height,
height_adjust = true,
})
end
table.insert(vg, hg)
end
table.insert(vg, VerticalSpan:new{width = Size.padding.default})
local dimen = Geom:new{w = self.width, h = self.height,}
self.widget = OverlapGroup:new{
dimen = dimen,
CenterContainer:new{
dimen = dimen,
vg
},
TextWidget:new{
text = 'ב"ה ', --.. os.date("%T", os.time()),
face = Font:getFace(FACE_NAME, 10) or Font:getFace("cfont", 10) ,
overlap_align = "right",
padding = Size.padding.tiny
}
}
end
function ZmanimSS:update()
self.region = Geom:new{
x = 0, y = 0,
w = self.width,
h = self.height,
}
self.main_frame = FrameContainer:new{
radius = 0,
bordersize = 0,
padding = 0,
margin = 0,
background = self.background,
width = self.width,
height = self.height,
self.widget,
}
self[1] = self.main_frame
end
function ZmanimSS:onTap(_, ges)
if ges.pos:intersectWith(self.main_frame.dimen) then
self:onClose()
end
return true
end
function ZmanimSS:onClose()
UIManager:close(self)
return true
end
function ZmanimSS:onAnyKeyPressed()
self:onClose()
return true
end
return ZmanimSS