-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathAppGroup.qml
444 lines (397 loc) · 18.5 KB
/
AppGroup.qml
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import QtQuick 2.12
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
import QtQuick.Controls.Universal 2.12
import QtGraphicalEffects 1.12
import Qt.labs.settings 1.0
import AndroidNative 1.0 as AN
import FileIO 1.0
Item {
id: groupItem
width: parent.width
implicitHeight: groupColumn.height
property string groupLabel
property var messageApp
property string phoneApp
property string textInput: ""
property double innerSpacing
property double componentSpacing
property double labelPointSize
property double headerPointSize
property double backgroundOpacity
property double desaturation: 1.0
property int groupIndex: 0
property int selectedGroupIndex: 1
property int columnCount: Screen.desktopAvailableWidth < 521 ? 4 : Screen.desktopAvailableWidth > 800 ? 8 : 5
property bool unreadMessages: false
property bool newCalls: false
property bool isHeaderVisible: groupIndex !== selectedGroupIndex
property bool isHeader2Visible: groupIndex === selectedGroupIndex && groupIndex > 0 && groupLabel.toLowerCase()
property bool isGridVisible: groupIndex === selectedGroupIndex
property var accentColor
property var notificationData:""
property var iconMap: ({})
property var labelMap: ({})
property var apps: []
property var pinnedShortcuts: []
Component.onCompleted: {
console.debug("AppGroup | Screen width: " + Screen.desktopAvailableWidth)
columnCount = Screen.desktopAvailableWidth < 446 ? 4 : Screen.desktopAvailableWidth > 800 ? 8 : 5
}
onWidthChanged: {
console.log("AppGroup | Width changed to " + width)
if (width > 820) {
columnCount = 8
} else {
columnCount = 5
}
}
onTextInputChanged: {
console.log("AppGroup " + groupIndex + " | onTextInputChanged")
groupModel.update(groupItem.textInput)
}
onAppsChanged: {
console.log("AppGroup " + groupIndex + " | onAppsChanged: " + groupItem.apps.length)
groupModel.prepareModel()
}
onPinnedShortcutsChanged: {
console.log("AppGroup " + groupIndex + " | onPinnedShortcutsChanged")
console.debug("AppGroup " + groupIndex + " | Number of pinned shortcuts: " + groupItem.pinnedShortcuts.length)
groupModel.prepareModel()
}
onDesaturationChanged: {
console.log("AppGroup " + groupIndex + " | onDesaturationChanged to " + desaturation)
groupGrid.forceLayout()
}
onBackgroundOpacityChanged: {
groupGrid.forceLayout()
}
onSelectedGroupIndexChanged: {
console.log("AppGroup " + groupIndex + " | Selected group changed to " + selectedGroupIndex)
groupColumn.topPadding = groupItem.groupIndex === 0 ? 0 : groupItem.groupIndex === 1 && groupItem.selectedGroupIndex === 0 ? groupItem.innerSpacing / 2 : groupItem.innerSpacing
}
function showApps(appsShouldBeVisible) {
groupGrid.visible = appsShouldBeVisible
groupHeader.visible = !appsShouldBeVisible
}
function removePinnedShortcut(shortcutId) {
if (groupItem.groupIndex === 0) {
groupItem.pinnedShortcuts = groupItem.pinnedShortcuts.filter(function(item) {
return item.shortcutId !== shortcutId
})
}
}
Column {
id: groupColumn
width: parent.width
topPadding: groupItem.groupIndex === 0 ? 0 : groupItem.groupIndex === 1 && groupItem.selectedGroupIndex === 0 ?
groupItem.componentSpacing / 2 : groupItem.componentSpacing
Button {
id: groupHeader
visible: groupItem.isHeaderVisible
anchors.horizontalCenter: parent.horizontalCenter
flat: true
text: groupItem.groupLabel
contentItem: Label {
text: groupHeader.text
padding: groupItem.innerSpacing / 2
color: Universal.foreground
opacity: 0.5
font.pointSize: groupItem.headerPointSize
}
background: Rectangle {
color: "transparent"
border.color: Universal.foreground
opacity: 0.5
radius: height / 2
}
onClicked: {
groupItem.parent.showGroup(groupItem.groupIndex)
}
}
Label {
id: groupHeader2
visible: groupItem.isHeader2Visible
anchors.horizontalCenter: parent.horizontalCenter
topPadding: groupItem.componentSpacing / 2
bottomPadding: groupItem.componentSpacing / 2
leftPadding: groupItem.innerSpacing / 2
rightPadding: groupItem.innerSpacing / 2
text: groupHeader.text
color: Universal.foreground
opacity: 0.5
font.pointSize: groupItem.labelPointSize
background: Rectangle {
color: "transparent"
border.color: "transparent"
}
}
GridView {
id: groupGrid
width: parent.width
height: contentHeight
cellHeight: parent.width / groupItem.columnCount * 1.28
cellWidth: parent.width / groupItem.columnCount
visible: groupItem.isGridVisible
interactive: false
model: groupModel
currentIndex: -1
delegate: Rectangle {
id: gridCell
width: groupGrid.cellWidth
height: groupGrid.cellHeight
color: "transparent"
property var gradientColor: Universal.background
property var overlayColor: Universal.foreground
Rectangle {
id: gridCircle
anchors.top: gridButton.top
anchors.horizontalCenter: parent.horizontalCenter
height: parent.width * 0.55
width: parent.width * 0.55
color: Universal.foreground
opacity: Universal.theme === Universal.Light ? 0.1 : 0.2
radius: width * 0.5
}
Button {
id: gridButton
anchors.top: parent.top
anchors.centerIn: gridCell
topPadding: (gridCircle.height - buttonIcon.height) / 2 //groupItem.innerSpacing / 2
width: parent.width
text: model.label
contentItem: Column {
spacing: gridCell.width * 0.25
Image {
id: buttonIcon
anchors.horizontalCenter: parent.horizontalCenter
//anchors.left: parent.left
//anchors.leftMargin: gridCell.width * 0.25
source: model.package in groupItem.iconMap && (model.shortcutId === undefined || model.shortcutId.length === 0) && desaturation === 1.0
? Qt.resolvedUrl(groupItem.iconMap[model.package]) : "data:image/png;base64," + model.icon
width: gridButton.width * 0.35
height: gridButton.width * 0.35
cache: false
ColorOverlay {
anchors.fill: buttonIcon
source: buttonIcon
color: gridCell.overlayColor
visible: (model.package in groupItem.iconMap) && model.shortcutId === undefined && desaturation === 1.0
}
}
Label {
id: buttonLabel
anchors.horizontalCenter: parent.horizontalCenter
width: gridButton.width - groupItem.innerSpacing
horizontalAlignment: contentWidth > gridButton.width - groupItem.innerSpacing ? Text.AlignLeft
: Text.AlignHCenter
text: gridButton.text
font.pointSize: groupItem.labelPointSize
clip: groupItem.backgroundOpacity === 1.0 ? true : false
elide: groupItem.backgroundOpacity === 1.0 ? Text.ElideNone : Text.ElideRight
}
}
flat:true
background: Rectangle {
color: "transparent"
border.color: "transparent"
}
onClicked: {
if (groupGrid.currentIndex > -1) {
groupItem.parent.closeContextMenu()
groupGrid.currentIndex = -1
} else if (model.package.length > 0) {
console.log("App Group | App " + model.label + " selected")
// As a workaround for a missing feature in the phone app
if (model.package === groupItem.phoneApp) {
if (groupItem.newCalls) {
AN.SystemDispatcher.dispatch("volla.launcher.dialerAction", {"app": groupItem.phoneApp, "action": "log"})
AN.SystemDispatcher.dispatch("volla.launcher.updateCallsAsRead", { })
} else {
AN.SystemDispatcher.dispatch("volla.launcher.dialerAction", {"app": groupItem.phoneApp})
}
} else if (model.shortcutId !== undefined && model.shortcutId.length > 0) {
AN.SystemDispatcher.dispatch("volla.launcher.launchShortcut",
{"shortcutId": model.shortcutId, "package": model.package})
} else {
AN.SystemDispatcher.dispatch("volla.launcher.runAppAction", {"appId": model.package})
}
AN.SystemDispatcher.dispatch("volla.launcher.clearRedDot", {"package": model.package})
}
}
onPressAndHold: {
groupGrid.currentIndex = index
groupItem.parent.openContextMenu(model, gridCell, groupGrid)
}
}
Desaturate {
anchors.fill: gridButton
source: gridButton
desaturation: groupItem.desaturation
}
LinearGradient {
id: labelTruncator
height: parent.height
width: parent.width
start: Qt.point(parent.width - groupItem.innerSpacing, 0)
end: Qt.point(parent.width,0)
gradient: Gradient {
GradientStop {
position: 0.0
color: "#00000000"
}
GradientStop {
position: 1.0
color: gridCell.gradientColor
}
}
visible: groupItem.backgroundOpacity === 1.0
}
Rectangle {
id: notificationBadge
visible: groupItem.messageApp.includes(model.package) ? groupItem.unreadMessages
: model.package === groupItem.phoneApp ? groupItem.newCalls
: groupItem.notificationData.hasOwnProperty(model.package) ? true : false
anchors.top: parent.top
anchors.left: parent.left
anchors.topMargin: 6.0
anchors.leftMargin: (parent.width - parent.width * 0.6) * 0.5
width: parent.width * 0.15
height: parent.width * 0.15
radius: height * 0.5
color: accentColor
}
}
Behavior on contentHeight {
NumberAnimation {
duration: 250.0
}
}
}
WorkerScript {
id: groupModelWorker
source: "scripts/apps.mjs"
property bool isReady: false
onMessage: {
console.debug("AppGroup " + groupIndex + " | Worker message received")
groupModel.modelArr = messageObject.apps
groupHeader.text = groupLabel.toLowerCase() === "apps" ? "+" + groupModel.count + " " + groupLabel : groupLabel
groupItem.visible = groupModel.count > 0
}
Component.onCompleted: {
console.debug("AppGroup " + groupIndex + " | Workerscript established" );
isReady = true
if (groupModel.pendingMessage !== undefined) {
console.debug("AppGroup " + groupIndex + " | Will send message to Workerscript" );
sendMessage(groupModel.pendingMessage)
}
}
}
ListModel {
id: groupModel
property var modelArr: new Array
property var pendingMessage
onCountChanged: {
console.log("AppGroup " + groupIndex + " | Number of grid itens changed: " + count)
}
// Call this method, if apps or shortcuts have been changed
function prepareModel() {
console.debug("AppGroup " + groupIndex + " | Will prepare model")
if (groupModelWorker.isReady) {
console.debug("AppGroup " + groupIndex + " | Will send worker message")
groupModelWorker.sendMessage({
"apps": groupItem.pinnedShortcuts.concat(groupItem.apps),
"labelMap" : groupItem.labelMap,
"model" : groupModel,
"text" : groupItem.textInput
})
} else {
console.debug("AppGroup " + groupIndex + " | Will define pending message for script status " + groupModelWorker.status)
pendingMessage = {
"apps": groupItem.pinnedShortcuts.concat(groupItem.apps),
"labelMap" : groupItem.labelMap,
"model" : groupModel,
"text" : groupItem.textInput
}
}
}
// Call this method to update the grid content
function update(text) {
console.log("AppGroup " + groupIndex + " | Update model with text input: " + text)
var filteredGridDict = new Object
var filteredGridItem
var gridItem
var found
var i
console.log("AppGroup " + groupIndex + " | Model '" + groupItem.groupLabel + "' has " + modelArr.length + " elements")
console.log("AppGroup " + groupIndex + " | Model '" + groupItem.groupLabel + "' has " + count + " elements")
// filter model
for (i = 0; i < modelArr.length; i++) {
filteredGridItem = modelArr[i]
var modelItemName = modelArr[i].label
var modelItemId = modelArr[i].itemId
if (text.length === 0 || modelItemName.toLowerCase().includes(text.toLowerCase())) {
filteredGridDict[modelItemId] = filteredGridItem
}
}
var existingGridDict = new Object
for (i = 0; i < count; ++i) {
modelItemId = get(i).itemId
existingGridDict[modelItemId] = true
}
// remove items no longer in filtered set
i = 0
while (i < count) {
modelItemId = get(i).itemId
found = filteredGridDict.hasOwnProperty(modelItemId)
if (!found) {
console.log("AppGrop | Remove " + modelItemId)
remove(i)
} else {
i++
}
}
// add new items
var keys = Object.keys(filteredGridDict)
keys.forEach(function(key) {
found = existingGridDict.hasOwnProperty(key)
if (!found) {
// for simplicity, just adding to end instead of corresponding position in original list
filteredGridItem = filteredGridDict[key]
console.debug("AppGroup " + groupIndex + " | * Will append " + key)
append(filteredGridItem)
}
})
groupHeader.text = groupLabel.toLowerCase() === "apps" ? "+" + count + " " + groupLabel : groupLabel
groupItem.visible = count > 0
sortModel()
}
function sortModel() {
var n;
var i;
for (n = 0; n < count; n++) {
for (i=n+1; i < count; i++) {
if (get(n).label.toLowerCase() > get(i).label.toLowerCase()) {
move(i, n, 1);
n = 0;
}
}
}
}
}
Connections {
target: AN.SystemDispatcher
onDispatched: {
if (type === "volla.launcher.callCountResponse") {
console.log("AppGroup " + groupIndex + " | Missed calls: " + message["callsCount"])
groupItem.newCalls = message["callsCount"] > 0
} else if (type === "volla.launcher.threadsCountResponse") {
console.log("AppGroup " + groupIndex + " | Unread messages: " + message["threadsCount"])
groupItem.unreadMessages = message["threadsCount"] > 0
} else if(type === "volla.launcher.otherAppNotificationResponce") {
groupItem.notificationData = message["Notification"]
}
}
}
}
}