-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_screen.py
730 lines (581 loc) · 37.1 KB
/
search_screen.py
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
#import kivy
from kivy.app import App
from functools import partial
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.button import ButtonBehavior
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.image import AsyncImage
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.base import runTouchApp
from kivy.properties import StringProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import time
from kivy.clock import Clock
from kivy.uix.screenmanager import FallOutTransition
from kivy.uix.screenmanager import SlideTransition
import kivy.utils
import home_screen, access_my_info
from datetime import datetime
#import pyperclip
import functions
if not __name__ == "home_screen":
import home_screen
class SearchScreen (Screen):
def __init__(self, conn, **kwargs):
super(SearchScreen, self).__init__(**kwargs)
print(2)
self.connection = conn
self.page_variable = 0
self.main_all_box = BoxLayout(orientation = "vertical")
self.add_widget(self.main_all_box)
self.banner = Button (border = (0, 0, 0, 0), size_hint = (1, None), height = Window.size[0] / 5.08, background_normal = 'images/banner.png', background_down = 'images/banner.png', on_release = self.refresh_search_screen)
self.main_all_box.add_widget(self.banner)
self.content_box = BoxLayout (orientation = "vertical")
self.main_all_box.add_widget(self.content_box)
self.content_box_scroll = ScrollView ()
self.content_box.add_widget (self.content_box_scroll)
self.content_grid = GridLayout(cols = 1, size_hint_y = None)
self.content_box_scroll.add_widget (self.content_grid)
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
#self.content_grid.add_widget(Button(text = "a", size_hint_y = None, height = 100))
self.display_header_box = BoxLayout(size_hint_y = None, height = Window.size[1] / 8)
self.content_grid.add_widget(self.display_header_box)
self.content_in_scroll_box = BoxLayout(orientation = 'vertical', size_hint_y = None)
self.content_grid.add_widget(self.content_in_scroll_box)
#self.all_flags = ['images/check_verd.png', 'images/red_cross.png', 'images/pink.jpeg']
#self.sort_list = [0, 0]
#firstposts
#current: 1 = new, 2 = search
self.current_posts = 0
self.time_variable = 0
self.all_displayed_new_posts_list = []
self.all_displayed_recommended_posts_list = []
self.new_posts_box = BoxLayout()
self.recommended_posts_box = BoxLayout()
#self.new_posts_header_press(0)
self.search_header_display_btn = Button (text = "Search", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.search_header_display_btn)
self.search_header_display_btn.bind(on_release = self.search_header_press)
self.new_posts_header_display_btn = Button(text = "New", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.new_posts_header_display_btn)
self.recommended_header_display_btn = Button (text = "For You", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.recommended_header_display_btn)
self.recommended_header_display_btn.bind(on_release = self.recommended_header_press)
self.search_header_press(0)
self.ground_box = BoxLayout (size_hint_y = None, height = Window.size[0] / 5)
self.main_all_box.add_widget(self.ground_box)
self.chat_btn = Button (border = (0, 0, 0, 0), background_normal = './images/mentions.png', background_down = './images/mentions.png')
self.ground_box.add_widget(self.chat_btn)
self.chat_btn.bind(on_release = self.press_chat_btn)
self.search_bn = Button (border = (0, 0, 0, 0), background_normal = './images/search_white.png', background_down = './images/search_white.png', on_release = self.refresh_search_screen)
self.ground_box.add_widget(self.search_bn)
self.home_btn = Button (border = (0, 0, 0, 0), background_normal = './images/home.png', background_down = './images/home.png')
self.ground_box.add_widget(self.home_btn)
self.home_btn.bind(on_release = self.press_home_btn)
self.make_posts_btn = Button (border = (0, 0, 0, 0), background_normal = './images/post.png', background_down = './images/post.png')
self.ground_box.add_widget(self.make_posts_btn)
self.make_posts_btn.bind(on_release = self.press_make_posts_btn)
self.user_profile_btn = Button (border = (0, 0, 0, 0), background_normal = './images/profile.png', background_down = './images/profile.png')
self.ground_box.add_widget(self.user_profile_btn)
self.user_profile_btn.bind(on_release = self.press_user_profile_btn)
print(20)
def search_header_press(self, instance):
if self.current_posts == 1:
self.content_in_scroll_box.clear_widgets()
if self.current_posts == 3:
self.content_in_scroll_box.clear_widgets()
if self.current_posts != 2:
self.display_header_box.clear_widgets()
#self.sort_list = [0, 0]
self.search_header_display_label = Button (text = "Search", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick_dark.png", background_down = "./images/brick_dark.png")
self.display_header_box.add_widget(self.search_header_display_label)
self.new_posts_header_display_btn = Button(text = "New", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.new_posts_header_display_btn)
self.new_posts_header_display_btn.bind(on_release = self.new_posts_header_press)
self.recommended_header_display_btn = Button (text = "For You", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.recommended_header_display_btn)
self.recommended_header_display_btn.bind(on_release = self.recommended_header_press)
self.search_header_btn = Button(size_hint_y = None, height = Window.size[1] / 15 / 2, text = "Search @user or #hashtag: ", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.content_in_scroll_box.add_widget(self.search_header_btn)
self.search_input_box = BoxLayout(orientation = "horizontal", size_hint_y = None, height = Window.size[1] / 15)
self.content_in_scroll_box.add_widget(self.search_input_box)
self.search_input = TextInput(multiline = False, background_normal = './images/paper_base.png', background_active = './images/paper_base.png')
self.search_input_box.add_widget(self.search_input)
#self.search_user_input.bind(on_text_validate = self.search_user_def)
"""
self.search_hastags_header_btn = Button(text = "Search hashtag:", size_hint_y = None, height = Window.size[1] / 15 / 2)
self.content_in_scroll_box.add_widget(self.search_hastags_header_btn)
self.search_post_hastags_input = TextInput(multiline = False, size_hint_y = None, height = Window.size[1] / 15)
self.content_in_scroll_box.add_widget(self.search_post_hastags_input)
#self.search_post_hastags.bind(on_text_validate = self.search_hastags_def)
"""
self.search_btn_box = BoxLayout(size_hint_x = None, width = Window.size[1] / 15)
self.search_input_box.add_widget(self.search_btn_box)
self.search_btn = Button(on_release = self.search_def, border = (0, 0, 0, 0), background_normal = "./images/brick_search.png", background_down = "./images/brick_search.png")
self.search_btn_box.add_widget(self.search_btn)
self.clear_search_btn = Button(size_hint_x = None, width = Window.size[1] / 15, on_release = self.clear_search_def, border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick_cross.png", background_down = "./images/brick_cross.png")
self.search_input_box.add_widget(self.clear_search_btn)
self.searched_box = BoxLayout(size_hint_y = None, height = 0, orientation = "vertical")
self.content_in_scroll_box.add_widget(self.searched_box)
self.content_in_scroll_box.height = Window.size[1] * 3 / 30
# +(Window.size[1] - Window.size[0] / 5) * 0.9 / 12
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
self.current_posts = 2
def new_posts_header_press(self, instance):
if self.current_posts == 2:
self.content_in_scroll_box.clear_widgets()
if self.current_posts == 3:
self.content_in_scroll_box.clear_widgets()
if self.current_posts != 1:
self.display_header_box.clear_widgets()
self.search_header_display_btn = Button (text = "Search", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.search_header_display_btn)
self.search_header_display_btn.bind(on_release = self.search_header_press)
self.new_posts_header_display_label = Button(text = "New", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick_dark.png", background_down = "./images/brick_dark.png")
self.display_header_box.add_widget(self.new_posts_header_display_label)
self.recommended_header_display_btn = Button (text = "For You", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.recommended_header_display_btn)
self.recommended_header_display_btn.bind(on_release = self.recommended_header_press)
self.content_in_scroll_box.height = len(self.all_displayed_new_posts_list) * (Window.size[1] - Window.size[0] * ( 1 / 5 + 1 / 5.08)) + Window.size[1] / 10
#new posts
self.content_in_scroll_box.add_widget(self.new_posts_box)
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
self.current_posts = 1
def new_posts_refresh(self, instance):
connection = self.connection
self.all_newest_posts_info = connection.get_posts(sort_by = "time_posted", sort_order = "desc", num = 5)
#include_background_color = str(1)
#self.all_newest_posts_info = functions.order_posts_by_timestamp(self.all_new_posts_info)
#print(self.all_newest_posts_info)
#create a list with users searched. in next def we get info from list
self.new_posts_box = BoxLayout(orientation = 'vertical')
#self.content_in_scroll_box.add_widget(self.new_posts_box)
self.all_displayed_new_posts_list = []
my_liked_posts_id = access_my_info.get_liked_id()
my_disliked_posts_id = access_my_info.get_disliked_id()
for t in range(len(self.all_newest_posts_info)):
actual_maybe_like = 0
try:
for liked in my_liked_posts_id:
if liked == self.all_newest_posts_info[t]["id"]:
actual_maybe_like = 1
except KeyError:
pass
try:
for disliked in my_disliked_posts_id:
if disliked == self.all_newest_posts_info[t]["id"]:
actual_maybe_like = -1
except KeyError:
pass
print(self.all_newest_posts_info[t]["background_color"])
self.post_btn = functions.make_post_btn(self, self.all_newest_posts_info[t]["user_id"], self.all_newest_posts_info[t]["content"], self.all_newest_posts_info[t]["time_posted"], actual_maybe_like, t, self.all_newest_posts_info[t]["background_color"])
self.new_posts_box.add_widget(self.post_btn)
self.all_displayed_new_posts_list.append([self.all_newest_posts_info[t]["id"], self.post_btn, actual_maybe_like, self.all_newest_posts_info[t]["user_id"]])
self.next_post_btn = Button(size_hint_y = None, height = Window.size[1]/10, border = (0, 0, 0, 0), background_normal = "images/brick.png", background_down = "images/brick.png", on_release = self.next_post, text = "Next")
self.new_posts_box.add_widget(self.next_post_btn)
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
self.new_posts_header_press(0)
self.search_header_press(0)
#def display_newest_posts(self):
# self.content_in_scroll_box.add_widget(self.new_posts_box)
def recommended_header_press(self, instance):
if self.current_posts == 2:
self.content_in_scroll_box.clear_widgets()
if self.current_posts == 1:
self.content_in_scroll_box.clear_widgets()
if self.current_posts != 3:
self.display_header_box.clear_widgets()
self.search_header_display_btn = Button (text = "Search", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.search_header_display_btn)
self.search_header_display_btn.bind(on_release = self.search_header_press)
self.new_posts_header_display_btn = Button(text = "New", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.display_header_box.add_widget(self.new_posts_header_display_btn)
self.new_posts_header_display_btn.bind(on_release = self.new_posts_header_press)
self.recommended_header_display_label = Button (text = "For You", border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick_dark.png", background_down = "./images/brick_dark.png")
self.display_header_box.add_widget(self.recommended_header_display_label)
self.content_in_scroll_box.height = len(self.all_displayed_recommended_posts_list) * (Window.size[1] - Window.size[0] * ( 1 / 5 + 1 / 5.08)) + Window.size[1] / 10
#new posts
self.content_in_scroll_box.add_widget(self.recommended_posts_box)
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
self.current_posts = 3
def recommended_posts_refresh(self, instance):
connection = self.connection
self.all_recommended_posts_info = connection.get_posts(grup = access_my_info.get_group(connection, access_my_info.get_user_name()), num = 5)
#include_background_color = str(1)
#self.all_newest_posts_info = functions.order_posts_by_timestamp(self.all_new_posts_info)
#print(self.all_newest_posts_info)
#create a list with users searched. in next def we get info from list
self.recommended_posts_box = BoxLayout(orientation = 'vertical')
#self.content_in_scroll_box.add_widget(self.new_posts_box)
self.all_displayed_recommended_posts_list = []
my_liked_posts_id = access_my_info.get_liked_id()
my_disliked_posts_id = access_my_info.get_disliked_id()
for t in range(len(self.all_recommended_posts_info)):
actual_maybe_like = 0
try:
for liked in my_liked_posts_id:
if liked == self.all_recommended_posts_info[t]["id"]:
actual_maybe_like = 1
except KeyError:
pass
try:
for disliked in my_disliked_posts_id:
if disliked == self.all_recommended_posts_info[t]["id"]:
actual_maybe_like = -1
except KeyError:
pass
self.post_btn = functions.make_post_btn(self, self.all_recommended_posts_info[t]["user_id"], self.all_recommended_posts_info[t]["content"], self.all_recommended_posts_info[t]["time_posted"], actual_maybe_like, t, self.all_recommended_posts_info[t]["background_color"])
self.recommended_posts_box.add_widget(self.post_btn)
self.all_displayed_recommended_posts_list.append([self.all_recommended_posts_info[t]["id"], self.post_btn, actual_maybe_like, self.all_recommended_posts_info[t]["user_id"]])
self.next_post_btn = Button(size_hint_y = None, height = Window.size[1]/10, border = (0, 0, 0, 0), background_normal = "images/brick.png", background_down = "images/brick.png", on_release = self.next_post, text = "Next")
self.recommended_posts_box.add_widget(self.next_post_btn)
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
def next_post(self, instance):
if self.current_posts == 1:
self.thinking = 1
self.think()
Clock.schedule_once(self.next_post_new)
if self.current_posts == 2:
self.thinking = 1
self.think()
Clock.schedule_once(self.next_post_search)
if self.current_posts == 3:
self.thinking = 1
self.think()
Clock.schedule_once(self.next_post_recommended)
def next_post_new(self, dt):
connection = self.connection
self.all_newest_posts_info = connection.get_posts(sort_by = "time_posted", sort_order = "desc", num = 1, offset = len(self.all_displayed_new_posts_list))
print(self.all_newest_posts_info)
if self.all_newest_posts_info != [{}]:
self.all_newest_posts_info = self.all_newest_posts_info[0]
self.new_posts_box.remove_widget(self.next_post_btn)
my_liked_posts_id = access_my_info.get_liked_id()
my_disliked_posts_id = access_my_info.get_disliked_id()
actual_maybe_like = 0
try:
for liked in my_liked_posts_id:
if liked == self.all_newest_posts_info["id"]:
actual_maybe_like = 1
except KeyError:
pass
try:
for disliked in my_disliked_posts_id:
if disliked == self.all_newest_posts_info["id"]:
actual_maybe_like = -1
except KeyError:
pass
self.post_btn = functions.make_post_btn(self, self.all_newest_posts_info["user_id"], self.all_newest_posts_info["content"], self.all_newest_posts_info["time_posted"], actual_maybe_like, len(self.all_displayed_new_posts_list), self.all_newest_posts_info["background_color"])
self.new_posts_box.add_widget(self.post_btn)
self.all_displayed_new_posts_list.append([self.all_newest_posts_info["id"], self.post_btn, actual_maybe_like, self.all_newest_posts_info["user_id"]])
self.next_post_btn = Button(size_hint_y = None, height = Window.size[1]/10, border = (0, 0, 0, 0), background_normal = "images/brick.png", background_down = "images/brick.png", on_release = self.next_post, text = "Next")
self.new_posts_box.add_widget(self.next_post_btn)
self.new_posts_box.height = self.new_posts_box.height + (Window.size[1] - Window.size[0] * (1 / 5 + 1 / 5.08))
self.content_in_scroll_box.height = self.content_in_scroll_box.height + (Window.size[1] - Window.size[0] * (1 / 5 + 1 / 5.08))
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
self.thinking = 0
self.think()
def next_post_recommended(self, dt):
connection = self.connection
self.all_new_recommended_posts_info = connection.get_posts(grup = access_my_info.get_group(connection, access_my_info.get_user_name()), num = 1, offset = len(self.all_displayed_new_posts_list))
print(self.all_new_recommended_posts_info)
if self.all_new_recommended_posts_info != [{}]:
self.all_new_recommended_posts_info = self.all_new_recommended_posts_info[0]
self.recommended_posts_box.remove_widget(self.next_post_btn)
my_liked_posts_id = access_my_info.get_liked_id()
my_disliked_posts_id = access_my_info.get_disliked_id()
actual_maybe_like = 0
try:
for liked in my_liked_posts_id:
if liked == self.all_new_recommended_posts_info["id"]:
actual_maybe_like = 1
except KeyError:
pass
try:
for disliked in my_disliked_posts_id:
if disliked == self.all_new_recommended_posts_info["id"]:
actual_maybe_like = -1
except KeyError:
pass
self.post_btn = functions.make_post_btn(self, self.all_new_recommended_posts_info["user_id"], self.all_new_recommended_posts_info["content"], self.all_new_recommended_posts_info["time_posted"], actual_maybe_like, len(self.all_new_recommended_posts_info), self.all_new_recommended_posts_info["background_color"])
self.recommended_posts_box.add_widget(self.post_btn)
self.all_displayed_recommended_posts_list.append([self.all_new_recommended_posts_info["id"], self.post_btn, actual_maybe_like, self.all_new_recommended_posts_info["user_id"]])
self.next_post_btn = Button(size_hint_y = None, height = Window.size[1]/10, border = (0, 0, 0, 0), background_normal = "images/brick.png", background_down = "images/brick.png", on_release = self.next_post, text = "Next")
self.recommended_posts_box.add_widget(self.next_post_btn)
self.recommended_posts_box.height = self.recommended_posts_box.height + (Window.size[1] - Window.size[0] * (1 / 5 + 1 / 5.08))
self.content_in_scroll_box.height = self.content_in_scroll_box.height + (Window.size[1] - Window.size[0] * (1 / 5 + 1 / 5.08))
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
self.thinking = 0
self.think()
def next_post_search(self, dt):
conn = self.connection
searched_posts = conn.get_posts(hashtag = self.search_content, sort_by = "time_posted", sort_order = "desc", num = 1, offset = len(self.all_displayed_searched_posts_list))
#exclude_flags = self.get_filter_flags()
print(0, searched_posts)
if searched_posts != [{}]:
searched_posts = searched_posts[0]
my_liked_posts_id = access_my_info.get_liked_id()
my_disliked_posts_id = access_my_info.get_disliked_id()
self.searched_box.remove_widget(self.next_post_btn)
actual_maybe_like = 0
try:
for liked in my_liked_posts_id:
if liked == searched_posts["id"]:
actual_maybe_like = 1
except KeyError:
pass
try:
for disliked in my_disliked_posts_id:
if disliked == searched_posts["id"]:
actual_maybe_like = -1
except KeyError:
pass
self.post_btn = functions.make_post_btn(self, searched_posts["user_id"], searched_posts["content"], searched_posts["time_posted"], actual_maybe_like, len(self.all_displayed_searched_posts_list), searched_posts["background_color"])
self.searched_box.add_widget(self.post_btn)
self.all_displayed_searched_posts_list.append([searched_posts["id"], self.post_btn, actual_maybe_like, searched_posts["user_id"]])
self.next_post_btn = Button(size_hint_y = None, height = Window.size[1]/10, border = (0, 0, 0, 0), background_normal = "images/brick.png", background_down = "images/brick.png", on_release = self.next_post, text = "Next")
self.searched_box.add_widget(self.next_post_btn)
self.searched_box.height = self.searched_box.height + (Window.size[1] - Window.size[0] * (1 / 5 + 1 / 5.08))
self.content_in_scroll_box.height = self.content_in_scroll_box.height + self.searched_box.height
self.thinking = 0
self.think()
def think(self):
print(88)
if self.thinking == 1:
self.banner.background_normal = "images/banner_loading.png"
elif self.thinking == 0:
self.banner.background_normal = "images/banner.png"
def refresh_search_screen(self, instance):
self.thinking = 1
self.think()
Clock.schedule_once(self.refresh_search_screen_2)
def refresh_search_screen_2(self, dt):
if self.current_posts == 2:
self.recommended_posts_refresh(0)
self.new_posts_refresh(0)
elif self.current_posts == 1 or self.current_posts == 0:
self.search_header_press(0)
self.recommended_posts_refresh(0)
self.new_posts_refresh(0)
self.thinking = 0
self.think()
def third_post_press(self, instance):
print(self.time_variable)
self.time_variable = 3
def second_post_press(self, instance):
print(self.time_variable)
self.time_variable = 2
def first_post_press(self, instance):
#self.go_to_user_profile(order_number)
print(self.time_variable)
self.time_variable = 1
self.post_instance = instance
Clock.schedule_once(self.clock_def, 0.5)
print(self.time_variable)
print(7)
def clock_def(self, instance):
print("a")
print(self.time_variable)
if self.time_variable == 0:
pass
elif self.time_variable == 1:
self.reply_post(self.post_instance)
elif self.time_variable == 2:
self.like_press(self.post_instance)
elif self.time_variable == 3:
self.dislike_press(self.post_instance)
self.time_variable = 0
def release_post(self, instance):
print(10)
print(self.time_variable)
if self.time_variable == 1:
self.time_variable = 0
def go_to_screen(self, instance, dt):
print(11)
other_user_profile_screen = self.other_profile_screen
other_user_profile_screen.refresh_profile_screen(instance.user_name)
self.thinking = 0
self.think()
self.manager.transition = SlideTransition()
self.manager.current = "other_profile"
self.manager.transition.direction = "right"
def reply_post(self, instance):
post_screen = self.post_screen
post_screen.reply(instance.user_name)
self.manager.transition = SlideTransition()
self.manager.current = "create"
self.manager.transition.direction = "left"
def like_press(self, instance):
print(3)
order_number = instance.order_number
print(9, order_number)
background = instance.background
print(77, background)
if self.current_posts == 1:
display = self.all_displayed_new_posts_list
elif self.current_posts == 2:
display = self.all_displayed_searched_posts_list
elif self.current_posts == 3:
display = self.all_displayed_recommended_posts_list
num = display[order_number][2]
if num == 1:
num = 0
else:
num = 1
instance.background_normal = functions.get_post_image(background, num)
access_my_info.add_or_remove_liked_post(display[order_number][0], num)
display[order_number][2] = num
def dislike_press(self, instance):
order_number = instance.order_number
background = instance.background
if self.current_posts == 1:
display = self.all_displayed_new_posts_list
elif self.current_posts == 2:
display = self.all_displayed_searched_posts_list
elif self.current_posts == 3:
display = self.all_displayed_recommended_posts_list
num = display[order_number][2]
if num == -1:
num = 0
elif num > -1:
num = -1
instance.background_normal = functions.get_post_image(background, num)
access_my_info.add_or_remove_liked_post(display[order_number][0], num)
display[order_number][2] = num
def name_press_user(self, instance):
self.thinking = 1
self.think()
Clock.schedule_once(partial(self.name_press_user_2, instance))
def name_press_user_2(self, instance, dt):
other_user_profile_screen = self.other_profile_screen
other_user_profile_screen.refresh_profile_screen(instance.text)
self.thinking = 0
self.think()
self.manager.transition = SlideTransition()
self.manager.current = "other_profile"
self.manager.transition.direction = "right"
def clear_search_def(self, instance):
self.new_posts_header_press(0)
self.search_header_press(0)
"""self.search_btn_box.clear_widgets()
self.search_btn = Button(text = "Search", on_release = self.search_def, border = (0, 0, 0, 0))
self.search_btn_box.add_widget(self.search_btn)
self.search_user_input.text = ""
self.search_post_hastags_input.text = ""
#self.sort_list = [0, 0]
self.searched_box.clear_widgets()
self.content_in_scroll_box.height = Window.size[1] / 8 + Window.size[1] / 6 + Window.size[1] * 3 / 15
# + (Window.size[1] - Window.size[0] / 5) * 0.9 / 12
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))"""
def image_press(self, order_number, instance):
pass
def search_def(self, instance):
self.thinking = 1
self.think()
Clock.schedule_once(self.search_def_2)
def search_def_2(self, dt):
conn = self.connection
self.search_btn_box.clear_widgets()
self.search_label_no_press = Button(background_normal = "./images/brick_search_dark.png", background_down = "./images/brick_search_dark.png", border = (0, 0, 0, 0))
self.search_btn_box.add_widget(self.search_label_no_press)
#self.searched_box.clear_widgets()
if self.search_input.text != "":
if self.search_input.text[0] == "#":
print(1)
self.search_content = functions.filter_chars(self.search_input.text)
searched_posts = conn.get_posts(hashtag = self.search_content, sort_by = "time_posted", sort_order = "desc", num = 1)
#exclude_flags = self.get_filter_flags()
print(0, searched_posts)
if searched_posts != {} and searched_posts != () and searched_posts != [{}]:
self.all_displayed_searched_posts_list = []
my_liked_posts_id = access_my_info.get_liked_id()
my_disliked_posts_id = access_my_info.get_disliked_id()
for t in range(len(searched_posts)):
actual_maybe_like = 0
try:
for liked in my_liked_posts_id:
if liked == searched_posts[t]["id"]:
actual_maybe_like = 1
except KeyError:
pass
try:
for disliked in my_disliked_posts_id:
if disliked == searched_posts[t]["id"]:
actual_maybe_like = -1
except KeyError:
pass
self.post_btn = functions.make_post_btn(self, searched_posts[t]["user_id"], searched_posts[t]["content"], searched_posts[t]["time_posted"], actual_maybe_like, t, searched_posts[t]["background_color"])
self.searched_box.add_widget(self.post_btn)
self.all_displayed_searched_posts_list.append([searched_posts[t]["id"], self.post_btn, actual_maybe_like, searched_posts[t]["user_id"]])
self.next_post_btn = Button(size_hint_y = None, height = Window.size[1]/10, border = (0, 0, 0, 0), background_normal = "images/brick.png", background_down = "images/brick.png", on_release = self.next_post, text = "Next")
self.searched_box.add_widget(self.next_post_btn)
self.searched_box.height = (Window.size[1] - Window.size[0] * (1 / 5 + 1 / 5.08)) * len(searched_posts) + Window.size[1] / 10
self.content_in_scroll_box.height = self.content_in_scroll_box.height + self.searched_box.height
else:
print(88)
self.not_found_label = Button(text = "Hashtag not found", size_hint_y = None, height = Window.size[1]/8, border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick_dark.png", background_down = "./images/brick_dark.png")
self.searched_box.add_widget(self.not_found_label)
self.searched_box.height = Window.size[1]/8
self.content_in_scroll_box.height = self.content_in_scroll_box.height + self.searched_box.height
elif self.search_input.text[0] == "@":
print(2)
searched_user = conn.get_user(functions.filter_chars(self.search_input.text[1::]))
print(searched_user)
if searched_user != {}:
self.searched_user_box = BoxLayout(orientation = 'horizontal', size_hint_y = None, height = Window.size[1]/6)
self.searched_box.add_widget(self.searched_user_box)
self.searched_user_image_grid = functions.build_image(self, searched_user["profile_picture"], -1, Window.size[1]/6)
self.searched_user_box.add_widget(self.searched_user_image_grid)
self.searched_user_name_btn = Button(text = searched_user["user_name"], on_release = self.name_press_user, border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick.png", background_down = "./images/brick.png")
self.searched_user_box.add_widget(self.searched_user_name_btn)
self.searched_box.height = Window.size[1]/6
self.content_in_scroll_box.height = self.content_in_scroll_box.height + self.searched_box.height
else:
self.not_found_label = Button(text = "Nothing found", size_hint_y = None, height = Window.size[1]/8, border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick_dark.png", background_down = "./images/brick_dark.png")
self.searched_box.add_widget(self.not_found_label)
self.searched_box.height = Window.size[1]/8
self.content_in_scroll_box.height = self.content_in_scroll_box.height + self.searched_box.height
else:
self.not_found_label = Button(text = "Nothing found", size_hint_y = None, height = Window.size[1]/8, border = (0, 0, 0, 0), color = (0, 0, 0, 1), background_normal = "./images/brick_dark.png", background_down = "./images/brick_dark.png")
self.searched_box.add_widget(self.not_found_label)
self.searched_box.height = Window.size[1]/8
self.content_in_scroll_box.height = self.content_in_scroll_box.height + self.searched_box.height
self.content_grid.bind(minimum_height=self.content_grid.setter('height'))
self.thinking = 0
self.think()
def press_chat_btn(self, instance):
self.manager.transition = SlideTransition()
self.manager.current = "chat"
self.manager.transition.direction = "right"
#def press_search_btn(self, instance):
# pass
def press_home_btn(self, instance):
#home_screen = self.home_screen
#home_screen.get_my_posts(home_screen)
self.manager.transition = SlideTransition()
self.manager.current = "main"
self.manager.transition.direction = "left"
def press_make_posts_btn(self, instance):
self.manager.transition = SlideTransition()
self.manager.current = "create"
self.manager.transition.direction = "left"
def press_user_profile_btn(self, instance):
#profile_screen = self.profile_screen
#profile_screen.refresh_profile_screen(profile_screen)
self.manager.transition = SlideTransition()
self.manager.current = "profile"
self.manager.transition.direction = "left"
def add_screens(self, home_screen, profile_screen, other_profile_screen, chat_screen, post_screen):
self.home_screen = home_screen
self.profile_screen = profile_screen
self.other_profile_screen = other_profile_screen
self.chat_screen = chat_screen
self.post_screen = post_screen