forked from HelloVolla/android-launcher-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collections.qml
1454 lines (1320 loc) · 67.5 KB
/
Collections.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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.XmlListModel 2.12
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
LauncherPage {
id: collectionPage
anchors.fill: parent
property var headline
property var textInputField
property string textInput
property real iconSize: 64.0
property int currentCollectionMode: 3
property var currentCollectionModel: peopleModel
property var threads: new Array
property var calls: new Array
property var threadAge: 86400 * 7 // one week in seconds
property var messageAge: 86400 * 5 * 1000 // one day in milliseconds
property int operationCount: 0 // number of background operations
property int maxCalls: 50
property int maxTextLength: 500
property string c_TITLE: "title" // large main title, bold
property string c_STITLE: "stitle" // small title above the main, grey
property string c_TEXT: "text" // large main text, regular
property string c_STEXT: "stext" // small text beyond the main text, grey
property string c_ICON: "icon" // small icon at the left side
property string c_IMAGE: "image" // preview image
property string c_BADGE: "badge" // red dot for unread content children
property string c_SBADGE: "sbadge" // red dot for unread messages
property string c_PHONE: "phome" // recent phone number
property string c_MOBILE: "mobile" // cell phone number
property string c_EMAIL: "email" // recent email address
property string c_ID: "id" // id of the contact, thread or news
property string c_CHANNEL: "channel" // twitter or news channel
property string c_TSTAMP: "tstamp" // timestamp to sort the list
property string c_TYPE: "type" // rss or atpm feed type
property string c_SIGNAL: "signal" // has a signal account
onTextInputChanged: {
console.log("Collections | text input changed")
currentCollectionModel.update(textInput)
}
function updateCollectionPage (mode) {
console.log("Collections | Update collection model: " + mode)
currentCollectionMode = mode
currentCollectionModel.clear()
currentCollectionModel.modelArr = new Array
switch (mode) {
case mainView.collectionMode.People:
headline.text = qsTr("People")
textInputField.placeholderText = qsTr("Find people ...")
currentCollectionModel = peopleModel
currentCollectionModel.modelArr = new Array
operationCount = mainView.isSignalActive ? 3 : 2
mainView.updateSpinner(true)
collectionPage.loadThreads({"age": threadAge})
collectionPage.loadCalls({"age": threadAge})
break;
case mainView.collectionMode.Threads:
headline.text = qsTr("Threads")
textInputField.placeholderText = qsTr("Find thread ...")
currentCollectionModel = threadModel
currentCollectionModel.modelArr = new Array
operationCount = mainView.isSignalActive ? 2 : 1
mainView.updateSpinner(true)
collectionPage.loadThreads({"age": threadAge})
break;
case mainView.collectionMode.News:
headline.text = qsTr("News")
textInputField.placeholderText = qsTr("Find news ...")
currentCollectionModel = newsModel
currentCollectionModel.modelArr = new Array
collectionPage.threads = new Array
collectionPage.calls = new Array
mainView.updateSpinner(true)
currentCollectionModel.update("")
break;
case mainView.collectionMode.Notes:
headline.text = qsTr("Notes")
textInputField.placeholderText = qsTr("Find note ...")
currentCollectionModel = notesModel
collectionPage.threads = new Array
collectionPage.calls = new Array
mainView.updateSpinner(true)
currentCollectionModel.loadData()
currentCollectionModel.update("")
break;
default:
console.log("Collections | Unknown collection mode")
break;
}
}
function updateListModel() {
console.log("Collections | Operation count is " + operationCount)
operationCount = operationCount - 1
if (operationCount < 1) {
mainView.updateSpinner(false)
collectionPage.currentCollectionModel.loadData()
collectionPage.currentCollectionModel.update(collectionPage.textInput)
}
}
function sortListModel() {
var n;
var i;
for (n = 0; n < currentCollectionModel.count; n++) {
for (i=n+1; i < currentCollectionModel.count; i++) {
if (currentCollectionModel.get(n).c_TSTAMP < currentCollectionModel.get(i).c_TSTAMP) {
currentCollectionModel.move(i, n, 1);
n = 0;
}
}
}
}
function loadThreads(filter) {
console.log("Collections | Will load threads")
collectionPage.threads = new Array
AN.SystemDispatcher.dispatch("volla.launcher.threadAction", filter)
// load threads from further source
// address (phone or contact), body (message), date, type
console.debug("Collections | Signal is active: " + mainView.isSignalActive)
if (mainView.isActiveSignal) AN.SystemDispatcher.dispatch("volla.launcher.signalThreadsAction", filter)
}
function loadCalls(filter) {
console.log("Collections | Will load calls")
collectionPage.calls = new Array
AN.SystemDispatcher.dispatch("volla.launcher.callLogAction", filter)
}
ListView {
id: listView
anchors.fill: parent
headerPositioning: mainView.backgroundOpacity === 1.0 ? ListView.PullBackHeader : ListView.InlineHeader
header: Column {
id: header
width: parent.width
z: 2
Label {
id: headerLabel
topPadding: mainView.innerSpacing * 2
width: parent.width - mainView.innerSpacing
x: mainView.innerSpacing
text: qsTr("People")
font.pointSize: mainView.headerFontSize
font.weight: Font.Black
background: Rectangle {
color: mainView.backgroundOpacity === 1.0 ? Universal.background : "transparent"
border.color: "transparent"
}
Binding {
target: collectionPage
property: "headline"
value: headerLabel
}
}
TextField {
id: textField
padding: mainView.innerSpacing
x: mainView.innerSpacing
width: parent.width -mainView.innerSpacing * 2
placeholderText: qsTr("Filter collections")
color: mainView.fontColor
placeholderTextColor: "darkgrey"
font.pointSize: mainView.largeFontSize
leftPadding: 0.0
rightPadding: 0.0
background: Rectangle {
color: mainView.backgroundOpacity === 1.0 ? mainView.backgroundColor : "transparent"
border.color: "transparent"
}
Binding {
target: collectionPage
property: "textInput"
value: textField.displayText.toLowerCase()
}
Binding {
target: collectionPage
property: "textInputField"
value: textField
}
Button {
id: deleteButton
text: "<font color='#808080'>×</font>"
font.pointSize: mainView.largeFontSize * 2
flat: true
topPadding: 0.0
anchors.top: parent.top
anchors.right: parent.right
visible: textField.displayText !== ""
onClicked: {
textField.text = ""
textField.focus = false
}
}
}
Rectangle {
width: parent.width
height: 1.1
color: mainView.backgroundOpacity === 1.0 ? Universal.background : "transparent"
border.color: "transparent"
}
}
model: currentCollectionModel
delegate: MouseArea {
id: backgroundItem
width: parent.width
implicitHeight: contactBox.height
property var selectedMenuItem: contactBox
property bool isMenuStatus: false
property int indexOfThisDelegate: index
Rectangle {
id: contactBox
color: "transparent"
width: parent.width
implicitHeight: contactMenu.visible ?
contactRow.height + contactMenu.height + mainView.innerSpacing
: contactRow.height + mainView.innerSpacing
Row {
id: contactRow
x: mainView.innerSpacing
spacing: 18.0
topPadding: mainView.innerSpacing / 2
Rectangle {
id: contactInicials
height: collectionPage.iconSize
width: collectionPage.iconSize
radius: height * 0.5
border.color: Universal.foreground
opacity: 0.9
color: "transparent"
visible: model.c_ICON === ""
&& (collectionPage.currentCollectionMode === mainView.collectionMode.People
|| collectionPage.currentCollectionMode === mainView.collectionMode.News)
Label {
text: model.c_TITLE !== undefined ? getInitials() : "?"
height: parent.height
width: parent.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: Universal.foreground
opacity: 0.9
font.pointSize: mainView.largeFontSize
function getInitials() {
const namesArray = model.c_TITLE.split(' ')
if (namesArray.length === 1) return `${namesArray[0].charAt(0)}`
else return `${namesArray[0].charAt(0)}${namesArray[namesArray.length - 1].charAt(0)}`
}
}
}
Image {
id: contactImage
source: model.c_ICON !== undefined ? model.c_ICON : ""
sourceSize: Qt.size(collectionPage.iconSize, collectionPage.iconSize)
smooth: true
visible: false
width: collectionPage.iconSize
height: collectionPage.iconSize
fillMode: collectionPage.currentCollectionMode === mainView.collectionMode.News ? Image.PreserveAspectFit
: Image.PreserveAspectCrop
Desaturate {
anchors.fill: contactImage
source: contactImage
desaturation: 1.0
}
}
Image {
source: "/images/contact-mask.png"
id: contactMask
sourceSize: Qt.size(collectionPage.iconSize, collectionPage.iconSize)
smooth: true
visible: false
}
OpacityMask {
id: iconMask
width: collectionPage.iconSize
height: collectionPage.iconSize
source: contactImage
maskSource: contactMask
visible: model.c_ICON !== ""
}
Column {
id: contactColumn
spacing: 3.0
property real columnWidth: collectionPage.currentCollectionMode === mainView.collectionMode.Threads
|| collectionPage.currentCollectionMode === mainView.collectionMode.Notes ?
contactBox.width - mainView.innerSpacing * 2 - contactRow.spacing
: contactBox.width - mainView.innerSpacing * 2 - collectionPage.iconSize - contactRow.spacing
property var gradientColer: Universal.background
Label {
id: sourceLabel
topPadding: model.c_STITLE !== undefined ? 8.0 : 0.0
width: contactBox.width - mainView.innerSpacing * 2 - collectionPage.iconSize - contactRow.spacing
text: model.c_STITLE !== undefined ? model.c_STITLE : ""
font.pointSize: mainView.smallFontSize
color: backgroundItem.isMenuStatus ? "white" : mainView.fontColor
lineHeight: 1.1
wrapMode: Text.Wrap
opacity: 0.8
visible: model.c_STITLE !== undefined
}
Label {
id: titleLabel
topPadding: model.c_TITLE !== undefined ? 8.0 : 0.0
width: contactColumn.columnWidth
text: model.c_TITLE !== undefined ? model.c_TITLE : ""
font.pointSize: mainView.largeFontSize
font.weight: Font.Black
color: backgroundItem.isMenuStatus ? "white" : mainView.fontColor
clip: mainView.backgroundOpacity === 1.0 ? true : false
elide: mainView.backgroundOpacity === 1.0 ? Text.ElideNone : Text.ElideRight
visible: model.c_TITLE !== undefined
LinearGradient {
id: titleLabelTruncator
height: titleLabel.height
width: titleLabel.width
start: Qt.point(titleLabel.width - mainView.innerSpacing,0)
end: Qt.point(titleLabel.width,0)
gradient: Gradient {
GradientStop {
position: 0.0
color: "#00000000"
}
GradientStop {
position: 1.0
color: backgroundItem.isMenuStatus ? Universal.accent : contactColumn.gradientColer
}
}
visible: mainView.backgroundOpacity === 1.0
}
}
Label {
id: textLabel
width: contactColumn.columnWidth
text: model.c_TEXT !== undefined ? model.c_TEXT : ""
font.pointSize: mainView.largeFontSize
color: backgroundItem.isMenuStatus ? "white" : mainView.fontColor
lineHeight: 1.1
opacity: 0.9
wrapMode: Text.WordWrap
elide: Text.ElideRight
visible: model.c_TEXT !== undefined
}
Row {
id: statusRow
spacing: 8.0
Rectangle {
id: statusBadge
visible: model.c_SBADGE !== undefined ? model.c_SBADGE : false
width: mainView.smallFontSize * 0.6
height: mainView.smallFontSize * 0.6
y: mainView.smallFontSize * 0.3
radius: height * 0.5
color: backgroundItem.isMenuStatus ? "transparent" : Universal.accent
}
Label {
id: statusLabel
bottomPadding: model.c_IMAGE !== undefined ? mainView.innerSpacing : 0.0
width: statusBadge.visible ?
contactColumn.columnWidth - statusBadge.width - statusRow.spacing
: contactColumn.columnWidth
text: model.c_STEXT !== undefined ? model.c_STEXT : ""
font.pointSize: mainView.smallFontSize
color: backgroundItem.isMenuStatus ? "white" : mainView.fontColor
clip: mainView.backgroundOpacity === 1.0 ? true : false
elide: mainView.backgroundOpacity === 1.0 ? Text.ElideRight : Text.ElideNone
opacity: 0.8
visible: model.c_STEXT !== undefined
LinearGradient {
id: statusLabelTruncator
height: statusLabel.height
width: statusLabel.width
start: Qt.point(statusLabel.width - mainView.innerSpacing,0)
end: Qt.point(statusLabel.width,0)
gradient: Gradient {
GradientStop {
position: 0.0
color: "#00000000"
}
GradientStop {
position: 1.0
color: backgroundItem.isMenuStatus ? Universal.accent : contactColumn.gradientColer
}
}
visible: mainView.backgroundOpacity === 1.0
}
}
}
Image {
id: newsImage
sourceSize.width: contactColumn.columnWidth
source: model.c_IMAGE !== undefined ? model.c_IMAGE : ""
fillMode: Image.PreserveAspectFit
asynchronous: true
Desaturate {
anchors.fill: newsImage
source: newsImage
desaturation: 1.0
}
}
}
}
Rectangle {
id: newsIconBox
anchors.top: contactBox.top
anchors.topMargin: mainView.innerSpacing * 0.5
anchors.left: contactBox.left
anchors.leftMargin: mainView.innerSpacing
width: collectionPage.iconSize
height: collectionPage.iconSize
color: "transparent"
border.color: Universal.foreground
opacity: 0.7
radius: height * 0.5
visible: collectionPage.currentCollectionMode === mainView.collectionMode.News
}
Rectangle {
id: notificationBadge
anchors.top: contactBox.top
anchors.topMargin: mainView.innerSpacing * 0.5
anchors.left: contactBox.left
anchors.leftMargin: mainView.innerSpacing
visible: model.c_BADGE !== undefined ? model.c_BADGE : false
width: collectionPage.iconSize * 0.25
height: collectionPage.iconSize * 0.25
radius: height * 0.5
color: Universal.accent
}
Column {
id: contactMenu
anchors.top: contactRow.bottom
topPadding: 22.0
bottomPadding: 8.0
leftPadding: mainView.innerSpacing
spacing: 14.0
visible: false
Label {
id: callLabel
height: mainView.mediumFontSize * 1.2
text: qsTr("Call")
font.pointSize: mainView.mediumFontSize
color: "white"
visible: model.c_PHONE !== undefined
}
Label {
id: messageLabel
height: mainView.mediumFontSize * 1.2
text: qsTr("Send Message")
font.pointSize: mainView.mediumFontSize
color: "white"
visible: model.c_MOBILE !== undefined
}
Label {
id: emailLabel
height: mainView.mediumFontSize * 1.2
text: qsTr("Send Email")
font.pointSize: mainView.mediumFontSize
color: "white"
visible: model.c_EMAIL !== undefined
}
Label {
id: contactLabel
height: mainView.mediumFontSize * 1.2
text: qsTr("Open Contact")
font.pointSize: mainView.mediumFontSize
color: "white"
}
Label {
id: openSignalContactLabel
height: mainView.mediumFontSize * 1.2
text: qsTr("Open in Signal")
font.pointSize: mainView.mediumFontSize
color: "white"
visible: model.c_SIGNAL !== undefined
}
}
Behavior on implicitHeight {
NumberAnimation {
duration: 250.0
property bool wasRunning: false
onRunningChanged: {
console.log("Collections | Running changed to " + running)
listView.positionViewAtIndex(backgroundItem.indexOfThisDelegate, ListView.Contain)
wasRunning = running
}
}
}
}
onClicked: {
console.log("Collections | List entry '" + model.c_ID + "' clicked.")
var imPoint = mapFromItem(iconMask, 0, 0)
if (currentCollectionMode === mainView.collectionMode.News
&& mouseY > imPoint.y && mouseY < imPoint.y + iconMask.height
&& mouseX > imPoint.x && mouseX < imPoint.x + iconMask.width) {
currentCollectionModel.executeSelection(model, mainView.actionType.ShowGroup)
} else {
// todo: should be replaced by model id
currentCollectionModel.executeSelection(model, mainView.actionType.ShowDetails)
}
}
onPressAndHold: {
if (currentCollectionMode === mainView.collectionMode.People) {
contactMenu.visible = true
contactBox.color = Universal.accent
preventStealing = true
isMenuStatus = true
}
}
onExited: {
if (currentCollectionMode === mainView.collectionMode.People) {
contactMenu.visible = false
contactBox.color = "transparent"
preventStealing = false
isMenuStatus = false
backgroundItem.executeSelection()
}
}
onMouseYChanged: {
var plPoint = mapFromItem(callLabel, 0, 0)
var mlPoint = mapFromItem(messageLabel, 0, 0)
var elPoint = mapFromItem(emailLabel, 0, 0)
var clPoint = mapFromItem(contactLabel, 0, 0)
var sgPoint = mapFromItem(openSignalContactLabel, 0, 0)
var selectedItem
if (mouseY > plPoint.y && mouseY < plPoint.y + callLabel.height) {
selectedItem = callLabel
} else if (mouseY > mlPoint.y && mouseY < mlPoint.y + messageLabel.height) {
selectedItem = messageLabel
} else if (mouseY > elPoint.y && mouseY < elPoint.y + emailLabel.height) {
selectedItem = emailLabel
} else if (mouseY > clPoint.y && mouseY < clPoint.y + contactLabel.height) {
selectedItem = contactLabel
} else if (mouseY > sgPoint.y && mouseY < sgPoint.y + openSignalContactLabel.height) {
selectedItem = openSignalContactLabel
} else {
selectedItem = contactBox
}
if (selectedMenuItem !== selectedItem) {
selectedMenuItem = selectedItem
}
}
onSelectedMenuItemChanged: {
callLabel.font.bold = selectedMenuItem === callLabel
callLabel.font.pointSize = selectedMenuItem === callLabel ? mainView.mediumFontSize * 1.2 : mainView.mediumFontSize
messageLabel.font.bold = selectedMenuItem === messageLabel
messageLabel.font.pointSize = selectedMenuItem === messageLabel ? mainView.mediumFontSize * 1.2 : mainView.mediumFontSize
emailLabel.font.bold = selectedMenuItem === emailLabel
emailLabel.font.pointSize = selectedMenuItem === emailLabel ? mainView.mediumFontSize * 1.2 : mainView.mediumFontSize
contactLabel.font.bold = selectedMenuItem === contactLabel
contactLabel.font.pointSize = selectedMenuItem === contactLabel ? mainView.mediumFontSize * 1.2 : mainView.mediumFontSize
openSignalContactLabel.font.bold = selectedMenuItem === openSignalContactLabel
openSignalContactLabel.font.pointSize = selectedMenuItem === openSignalContactLabel ? mainView.mediumFontSize * 1.2 : mainView.mediumFontSize
if (selectedMenuItem !== contactBox && mainView.useVibration) {
AN.SystemDispatcher.dispatch("volla.launcher.vibrationAction", {"duration": mainView.vibrationDuration})
}
}
function executeSelection() {
if (selectedMenuItem === callLabel) {
console.log("Collections | Call " + model.c_TITLE)
currentCollectionModel.executeSelection(model, mainView.actionType.MakeCall)
} else if (selectedMenuItem === messageLabel) {
console.log("Collections | Send message to " + model.c_TITLE)
currentCollectionModel.executeSelection(model, mainView.actionType.SendSMS)
} else if (selectedMenuItem === emailLabel) {
console.log("Collections | Send email to " + model.c_TITLE)
currentCollectionModel.executeSelection(model, mainView.actionType.SendEmail)
} else if (selectedMenuItem === contactLabel) {
console.log("Collections | Open contact of " + model.c_TITLE)
currentCollectionModel.executeSelection(model, mainView.actionType.OpenContact)
} else if (selectedMenuItem === openSignalContactLabel) {
console.log("Collections | Open contact in Signal" + model.c_TITLE)
currentCollectionModel.executeSelection(model, mainView.actionType.OpenSignalContact)
} else {
console.log("Collections | Nothing selected")
}
}
}
}
ListModel {
id: peopleModel
property var modelArr: []
property var contactThreads: new Object
property var contactCalls: new Object
function loadData() {
console.log("Collections | Load data for contact collection")
var now = new Date()
collectionPage.threads.forEach(function (thread, index) {
console.log("Collections | Thread: " + thread["address"])
if ((!thread["read"] || now.getTime() - thread["date"] < collectionPage.messageAge) && thread["address"] !== undefined) {
console.log("Collections | Thread matched: " + thread["address"])
if (thread["isSignal"]) contactThreads[thread["person"]] = thread
else contactThreads[thread["address"]] = thread
}
})
collectionPage.calls.forEach(function (call, index) {
if ((call["new"] || now.getTime() - call["date"] < collectionPage.messageAge) && call["number"] !== undefined) {
console.log("Collections | Call matched: " + call["number"])
if (contactCalls[call["number"]] === undefined) {
call["count"] = call["new"] ? 1 : 0
contactCalls[call["number"]] = call
} else if (call["new"] === true) {
contactCalls[call["number"]]["count"] += 1
}
}
})
var contacts = mainView.getContacts().filter(checkStarredOrRecent)
contacts.forEach(function (contact, index) {
console.log("Collections | Matched contact: " + contact["name"])
var cContact = {c_ID: contact["id"]}
if (contact["name"] !== undefined) {
cContact.c_TITLE = contact["name"]
} else if (contact["organization"] !== undefined) {
cContact.c_TITLE = contact["organization"]
}
if (contact["organization"] !== undefined
&& contact["organization"].length > 0
&& contact["name"] !== undefined) {
cContact.c_STEXT = contact["organization"]
} else {
cContact.c_STEXT = qsTr("Private")
}
if (contact["icon"] !== undefined) {
cContact.c_ICON = "data:image/png;base64," + contact["icon"]
} else {
cContact.c_ICON = ""
AN.SystemDispatcher.dispatch("volla.launcher.contactImageAction", {"contactId": contact["id"]})
}
if (contact["phone.mobile"] !== undefined) {
cContact.c_PHONE = contact["phone.mobile"]
cContact.c_MOBILE = contact["phone.mobile"]
} else if (contact["phone.work"] !== undefined) {
cContact.c_PHONE = contact["phone.work"]
} else if (contact["phone.home"] !== undefined) {
cContact.c_PHONE = contact["phone.home"]
} else if (contact["phone.other"] !== undefined) {
cContact.c_PHONE = contact["phone.other"]
}
if (contact["phone.signal"] !== undefined) {
cContact.c_SIGNAL = contact["phone.signal"]
}
if (contact["email.work"] !== undefined) {
cContact.c_EMAIL = contact["email.work"]
} else if (contact["email.home"] !== undefined) {
cContact.c_EMAIL = contact["email.home"]
} else if (contact["email.other"] !== undefined) {
cContact.c_EMAIL = contact["email.other"]
}
var thread = contactThreads[contact["phone.mobile"]]
if (thread === undefined) {
thread = contactThreads[contact["phone.other"]]
}
if (thread === undefined) {
thread = contactThreads[contact["phone.work"]]
}
var call = contactCalls[contact["phone.mobile"]]
if (call === undefined) {
call = contactCalls[contact["phone.other"]]
}
if (call === undefined) {
call = contactCalls[contact["phone.work"]]
}
if ((thread !== undefined && call !== undefined && thread["date"] > call["date"])
|| (thread !== undefined && call === undefined)) {
cContact.c_SBADGE = !thread["read"]
if (!thread["read"]) {
cContact.c_ITEM_ID = thread["thread_id"]
cContact.c_STEXT = "1 " + qsTr("New message") + " " + mainView.parseTime(Number(thread["date"]))
}
} else if ((thread !== undefined && call !== undefined && thread["date"] < call["date"])
|| (thread === undefined && call !== undefined)) {
cContact.c_SBADGE = call["new"]
// use the recent phone number
cContact.c_PHONE = call["number"]
if (call["new"] === true) {
var messageText = (call["count"] > 1) ? qsTr("New calls") : qsTr("New call")
cContact.c_STEXT = call["count"] + " " + messageText + " " + mainView.parseTime(Number(call["date"]))
}
}
modelArr.push(cContact)
})
}
function checkStarredOrRecent(contact) {
return (contact["starred"] === true
|| (contact["phone.mobile"] in contactThreads)
|| (contact["phone.signal"] in contactThreads)
|| (contact["phone.other"] in contactThreads)
|| (contact["phone.work"] in contactThreads)
|| (contact["phone.home"] in contactThreads)
|| (contact["name"] in contactThreads)
|| (contact["phone.mobile"] in contactCalls)
|| (contact["phone.signal"] in contactCalls)
|| (contact["phone.other"] in contactCalls)
|| (contact["phone.work"] in contactCalls)
|| (contact["phone.home"] in contactCalls))
}
function updateImage(contactId, contactImage) {
console.log("Collections | Umdate image of contact " + contactId)
for (var i = 0; i < modelArr.length; i++) {
var aContact = modelArr[i]
if (aContact.c_ID === contactId) {
console.log("Collections | Contact in list model matched")
aContact.c_ICON = contactImage
modelArr[i] = aContact
break
}
}
for (i = 0; i < count; i++) {
var elem = get(i)
if (elem.c_ID === contactId) {
console.log("Collections | Contact in list view matched")
elem.c_ICON = "data:image/png;base64," + contactImage
set(i, elem)
break
}
}
for (i = 0; i < mainView.getContacts().length; i++) {
aContact = mainView.getContacts()[i]
if (aContact["id"] === contactId) {
console.log("Collections | Contact in contacts matched")
aContact["icon"] = contactImage
mainView.getContacts()[i] = aContact
break
}
}
}
function update(text) {
console.log("Collections | Update people model with text input: " + text)
if (modelArr.length === 0) {
loadData()
}
var filteredModelDict = new Object
var filteredModelItem
var modelItem
var found
var i
console.log("Collections | People model has " + modelArr.length + " elements")
for (i = 0; i < modelArr.length; i++) {
filteredModelItem = modelArr[i]
var modelItemName = modelArr[i].c_TITLE
if (text.length === 0 || modelItemName.toLowerCase().includes(text.toLowerCase())) {
// console.log("Collections | Add " + modelItemName + " to filtered items")
filteredModelDict[modelItemName] = filteredModelItem
}
}
var existingGridDict = new Object
for (i = 0; i < count; ++i) {
modelItemName = get(i).c_TITLE
existingGridDict[modelItemName] = true
}
// remove items no longer in filtered set
i = 0
while (i < count) {
modelItemName = get(i).c_TITLE
found = filteredModelDict.hasOwnProperty(modelItemName)
if (!found) {
console.log("Collections | Remove " + modelItemName)
remove(i)
} else {
i++
}
}
// add new items
for (modelItemName in filteredModelDict) {
found = existingGridDict.hasOwnProperty(modelItemName)
if (!found) {
// for simplicity, just adding to end instead of corresponding position in original list
filteredModelItem = filteredModelDict[modelItemName]
console.log("Collections | Will append " + filteredModelItem.c_TITLE)
append(filteredModelDict[modelItemName])
}
}
}
function executeSelection(item, type) {
switch (type) {
case mainView.actionType.MakeCall:
util.makeCall({"number": item.c_PHONE, "intent": "call"})
break
case mainView.actionType.SendSMS:
Qt.openUrlExternally("sms:" + item.c_MOBILE)
break
case mainView.actionType.SendEmail:
Qt.openUrlExternally("mailto:" + item.c_EMAIL)
break
case mainView.actionType.OpenContact:
AN.SystemDispatcher.dispatch("volla.launcher.showContactAction", {"contact_id": item.c_ID})
break
case mainView.actionType.OpenSignalContact:
Qt.openUrlExternally("sgnl://signal.me/#p/" + item.c_SIGNAL)
break
default:
mainView.updateConversationPage(mainView.conversationMode.Person, item.c_ID, item.c_TITLE)
}
}
}
ListModel {
id: threadModel
property var modelArr: []
function loadData() {
console.log("Collections | Load data for thread collection")
collectionPage.threads.forEach(function (thread, index) {
var cThread = {c_ID: thread["thread_id"], c_ICON: ""}
function checkMatchigThread(contact) {
var matched = false
try {
matched = (contact["id"] !== undefined && thread["person"] !== undefined && contact["id"] === thread["person"])
|| (contact["phone.mobile"] !== undefined && thread["address"] !== undefined
&& contact["phone.mobile"].toString().endsWith(thread["address"].slice(3))
&& Math.abs(contact["phone.mobile"].toString().length - thread["address"].length) < 3)
|| (contact["phone.other"] !== undefined && thread["address"] !== undefined
&& contact["phone.other"].toString().endsWith(thread["address"].slice(3))
&& Math.abs(contact["phone.other"].toString().length - thread["address"].length) < 3)
|| (contact["phone.work"] !== undefined && thread["address"] !== undefined
&& contact["phone.work"].toString().endsWith(thread["address"].slice(3))
&& Math.abs(contact["phone.work"].toString().length - thread["address"].length) < 3)
|| (contact["phone.home"] !== undefined && thread["address"] !== undefined
&& contact["phone.home"].toString().endsWith(thread["address"].slice(3))
&& Math.abs(contact["phone.home"].toString().length - thread["address"].length) < 3)
|| (contact["name"] !== undefined && thread["person"] !== undefined
&& contact["name"].toString() === thread["person"].toString())
} catch (err) {
console.log("Collections | Error for checking contact " + contact["name"] + ": " + err.message)
}
return matched
}
var contact = mainView.getContacts().find(checkMatchigThread)
if (contact !== undefined) {
cThread.c_TITLE = contact["name"]
} else if (thread["person"] !== undefined) {
cThread.c_TITLE = thread["person"]
} else if (thread["address"] !== undefined) {
cThread.c_TITLE = thread["address"]
} else {
cThread.c_TITLE = qsTr("You")
}
if (thread["body"] !== undefined) {
if (thread["isSent"]) {
cThread.c_TEXT = qsTr("You") + ": " + thread["body"]
} else {
cThread.c_TEXT = thread["body"]
}
}
var kind = "SMS"
if (thread["isMMS"]) {
kind = "MMS"
cThread.c_IMAGE = "data:image/png;base64," + thread["image"]
} else if (thread["isSignal"]) {
kind = "Signal"
}
cThread.c_STEXT = mainView.parseTime(Number(thread["date"])) + " • " + qsTr(kind)
cThread.c_TSTAMP = Number(thread["date"])
modelArr.push(cThread)
})
}
function update (text) {
console.log("Collections | Update model with text input: " + text)
if (modelArr.length === 0) {
loadData()
}
var filteredModelDict = new Object
var filteredModelItem
var modelItem
var found
var i
console.log("Collections | Model has " + modelArr.length + " elements")
for (i = 0; i < modelArr.length; i++) {
filteredModelItem = modelArr[i]
var modelItemName = modelArr[i].c_TEXT
if (text.length === 0 || modelItemName.toLowerCase().includes(text.toLowerCase())) {
//console.log("Collections | Add " + modelItemName + " to filtered items")
filteredModelDict[modelItemName] = filteredModelItem
}
}
var existingGridDict = new Object
for (i = 0; i < count; ++i) {
modelItemName = get(i).c_TEXT
existingGridDict[modelItemName] = true
}
// Remove items no longer in filtered set
i = 0
while (i < count) {
modelItemName = get(i).c_TEXT
found = filteredModelDict.hasOwnProperty(modelItemName)
if (!found) {
console.log("Collections | Remove " + modelItemName)
remove(i)
} else {
i++
}
}
// Add new items
for (modelItemName in filteredModelDict) {
found = existingGridDict.hasOwnProperty(modelItemName)
if (!found) {
// for simplicity, just adding to end instead of corresponding position in original list
filteredModelItem = filteredModelDict[modelItemName]
console.log("Collections | Will append " + filteredModelItem.c_TEXT)
append(filteredModelDict[modelItemName])
}
}
collectionPage.sortListModel()
}
function executeSelection(item, type) {
mainView.updateConversationPage(mainView.conversationMode.Thread, item.c_ID, item.c_TITLE)
}
}
ListModel {
id: newsModel
property var rssFeeds: new Array
property var modelArr: new Array
function loadData() {
// Iterate over rss feeds to the the first item
rssFeeds = mainView.getFeeds()
if (rssFeeds.length > 0) {
rssFeeds.forEach(function (rssFeed, index) {
if (rssFeed.activated === true) {