def __init__(self, *args, **kwargs): super().__init__() with self.canvas.before: Color(rgb=(kivy.utils.get_color_from_hex("#67697C"))) self.rect = Rectangle(size=self.size, pos=self.pos) self.bind(pos=self.update_rect, size=self.update_rect) fave = requests.get("https://nappyhour-6eb5d.firebaseio.com/" + str(kwargs['favorite_shop']) + ".json") faveid = json.loads(fave.content.decode()) print(kwargs['favorite_shop']) image = ImageButton(source="images/barber.png", size_hint=(.3, 1), pos_hint={ "top": 1, "right": .3 }) label = LabelButton(text=faveid['shopname'], size_hint=(.7, 1), pos_hint={ "top": 1, "right": 1 }, on_release=partial( App.get_running_app().load_shop_page, str(kwargs['favorite_shop']))) self.add_widget(image) self.add_widget(label)
def __init__(self, **kwargs): super(FriendBanner, self).__init__(**kwargs) with self.canvas.before: Color(rgba=(kivy.utils.get_color_from_hex("#6C5B7B"))[:3] + [.5]) self.rect = Rectangle(size=self.size, pos=self.pos) self.bind(pos=self.update_rect, size=self.update_rect) # Make friend id an attribute of this widget so it can be removed later by the app.remove_friend function self.friend_id = kwargs['friend_id'] # Add the friend's avatar # Query firebase and order by my_friend_id equalTo friend_id for this person to get their identifer check_req = requests.get( 'https://friendly-fitness.firebaseio.com/.json?orderBy="my_friend_id"&equalTo=' + kwargs['friend_id']) data = check_req.json() unique_identifer = data.keys()[0] their_avatar = data[unique_identifer]['avatar'] print(their_avatar) self.remove_label = LabelButton( size_hint=(.10, 1), pos_hint={ "top": 1, "right": .1 }, on_release=partial(App.get_running_app().remove_friend, kwargs['friend_id'])) with self.remove_label.canvas.before: Color(rgba=(1, 0, 0, .5)) self.rect2 = Rectangle(size=self.remove_label.size, pos=self.remove_label.pos) self.remove_label.bind(pos=self.update_remove_label_rect, size=self.update_remove_label_rect) image_button = ImageButton( source="icons/avatars/" + their_avatar, size_hint=(.3, .8), pos_hint={ "top": .9, "right": 0.5 }, on_release=partial( App.get_running_app().load_friend_booking_screen, kwargs['friend_id'])) # Add the friend's ID self.friend_label = LabelButton( text=kwargs['friend_id_text'], markup=True, size_hint=(.5, 1), pos_hint={ "top": 1, "right": 1 }, on_release=partial( App.get_running_app().load_friend_booking_screen, kwargs['friend_id'])) self.add_widget(self.remove_label) self.add_widget(image_button) self.add_widget(self.friend_label)
def on_start(self): # Display the ads if platform == 'ios': from pyobjus import autoclass self.banner_ad = autoclass('adSwitch').alloc().init() # Choose the correct time icon to show based on the current hour of day now = datetime.now() hour = now.hour if hour <= 6: self.root.ids['time_indicator1'].opacity = 1 elif hour <= 12: self.root.ids['time_indicator2'].opacity = 1 elif hour <= 18: self.root.ids['time_indicator3'].opacity = 1 else: self.root.ids['time_indicator4'].opacity = 1 # Set the current day, month, and year in the add workout section day, month, year = now.day, now.month, now.year self.root.ids.add_workout_screen.ids.month_input.text = str(month) self.root.ids.add_workout_screen.ids.day_input.text = str(day) self.root.ids.add_workout_screen.ids.year_input.text = str(year) # Populate avatar grid avatar_grid = self.root.ids['change_avatar_screen'].ids['avatar_grid'] for root_dir, folders, files in walk("icons/avatars"): for f in files: img = ImageButtonSelectable(source="icons/avatars/" + f, on_release=partial( self.change_avatar, f)) avatar_grid.add_widget(img) # Populate workout image grid workout_image_grid = self.root.ids['add_workout_screen'].ids[ 'workout_image_grid'] for root_dir, folders, files in walk("icons/workouts"): for f in files: if '.png' in f: img = ImageButton(source="icons/workouts/" + f, on_release=partial( self.update_workout_image, f)) workout_image_grid.add_widget(img) try: # Try to read the persistent signin credentials (refresh token) with open(self.refresh_token_file, 'r') as f: refresh_token = f.read() # Use refresh token to get a new idToken id_token, local_id = self.my_firebase.exchange_refresh_token( refresh_token) self.local_id = local_id self.id_token = id_token # Get database data print("LOCAL ID IS", local_id) print("https://friendly-fitness.firebaseio.com/" + local_id + ".json?auth=" + id_token) result = requests.get("https://friendly-fitness.firebaseio.com/" + local_id + ".json?auth=" + id_token) data = json.loads(result.content.decode()) print("id token is", id_token) print(result.ok) print("DATA IS", data) self.my_friend_id = data['my_friend_id'] friend_id_label = self.root.ids['settings_screen'].ids[ 'friend_id_label'] friend_id_label.text = "Friend ID: " + str(self.my_friend_id) # Get and update avatar image avatar_image = self.root.ids['avatar_image'] avatar_image.source = "icons/avatars/" + data['avatar'] # Get friends list self.friends_list = data['friends'] # Get nicknames try: print(data['nicknames']) for i, friend_id in enumerate(self.friends_list.split(",")): if friend_id: print(i, friend_id) self.nicknames[friend_id] = data['nicknames'][i] except: self.nicknames = data.get('nicknames', {}) # Populate friends list grid friends_list_array = self.friends_list.split(",") for friend_id in friends_list_array: friend_id = friend_id.replace(" ", "") if friend_id == "": continue try: nicknames = list(self.friends_list.keys()) except: nicknames = self.nicknames if friend_id in nicknames: friend_id_text = "[u]" + self.nicknames[friend_id] + "[/u]" else: friend_id_text = "[u]Friend ID: " + friend_id + "[/u]" friend_banner = FriendBanner(friend_id=friend_id, friend_id_text=friend_id_text) self.root.ids['friends_list_screen'].ids[ 'friends_list_grid'].add_widget(friend_banner) # Get and update streak label streak_label = self.root.ids['home_screen'].ids['streak_label'] #streak_label.text = str(data['streak']) + " Day Streak" # Thisis updated if there are workouts # Set the images in the add_workout_screen banner_grid = self.root.ids['home_screen'].ids['banner_grid'] workouts = data['workouts'] if workouts != "": workout_keys = list(workouts.keys()) streak = helperfunctions.count_workout_streak(workouts) if str(streak) == 0: streak_label.text = "0 Day Streak. Go workout!" else: streak_label.text = str(streak) + " Day Streak!" # Sort workouts by date then reverse (we want youngest dates at the start) workout_keys.sort(key=lambda value: datetime.strptime( workouts[value]['date'], "%m/%d/%Y")) workout_keys = workout_keys[::-1] for workout_key in workout_keys: workout = workouts[workout_key] # Populate workout grid in home screen W = WorkoutBanner(workout_image=workout['workout_image'], description=workout['description'], type_image=workout['type_image'], number=workout['number'], units=workout['units'], likes=workout['likes'], date=workout['date']) banner_grid.add_widget(W) self.change_screen("home_screen", "None") except Exception as e: traceback.print_exc() pass
def on_start(self): # Choose the correct time icon to show based on the current hour of day now = datetime.now() hour = now.hour if hour <= 6: self.root.ids['time_indicator1'].opacity = 1 elif hour <= 12: self.root.ids['time_indicator2'].opacity = 1 elif hour <= 18: self.root.ids['time_indicator3'].opacity = 1 else: self.root.ids['time_indicator4'].opacity = 1 # Set the current day, month, and year in the add workout section day, month, year = now.day, now.month, now.year self.root.ids.add_workout_screen.ids.month_input.text = str(month) self.root.ids.add_workout_screen.ids.day_input.text = str(day) self.root.ids.add_workout_screen.ids.year_input.text = str(year) # Populate avatar grid avatar_grid = self.root.ids['change_avatar_screen'].ids['avatar_grid'] for root_dir, folders, files in walk("icons/avatars"): for f in files: img = ImageButton(source="icons/avatars/" + f, on_release=partial(self.change_avatar, f)) avatar_grid.add_widget(img) # Populate workout image grid workout_image_grid = self.root.ids['add_workout_screen'].ids[ 'workout_image_grid'] for root_dir, folders, files in walk("icons/workouts"): for f in files: img = ImageButton(source="icons/workouts/" + f, on_release=partial(self.update_workout_image, f)) workout_image_grid.add_widget(img) try: # Try to read the persisten signin credentials (refresh token) with open("refresh_token.txt", "r") as f: refresh_token = f.read() # use refresh_token to get a new idToken self.id_token, self.local_id = self.my_firebase.exchange_refresh_token( refresh_token) # Get database data result = requests.get("https://fitnessapp-kivy.firebaseio.com/" + self.local_id + ".json?auth=" + self.id_token) data = json.loads(result.content.decode()) # Update avatar image avatar_image = self.root.ids['avatar_image'] avatar_image.source = "icons/avatars/" + data['avatar'] # Update streak label label_streak = self.root.ids['home_screen'].ids['streak_label'] # Friend List self.friends_list = data['friends'] # Get nicknames try: print(data['nicknames']) for i, friend_id in enumerate(self.friends_list.split(",")): if friend_id: print(i, friend_id) self.nicknames[friend_id] = data['nicknames'][i] except: self.nicknames = data.get('nicknames', {}) # Populate friends list grid friends_list_array = self.friends_list.split(",") for friend_id in friends_list_array: friend_id = friend_id.replace(" ", "") if friend_id == "": continue try: nicknames = list(self.friends_list.keys()) except: nicknames = self.nicknames if friend_id in nicknames: friend_id_text = "[u]" + self.nicknames[friend_id] + "[/u]" else: friend_id_text = "[u]Friend ID: " + friend_id + "[/u]" friend_banner = FriendBanner(friend_id=friend_id, friend_id_text=friend_id_text) self.root.ids['friends_list_screen'].ids[ 'friends_list_grid'].add_widget(friend_banner) # Update id label self.my_friend_id = data['my_friend_id'] friend_id_label = self.root.ids['settings_screen'].ids[ 'friend_id_label'] friend_id_label.text = "ID: " + str(data['my_friend_id']) # Get data workouts banner_grid = self.root.ids['home_screen'].ids['banner_grid'] workouts = data['workouts'] if workouts != "": workout_keys = list(workouts.keys()) streak = helperfunctions.count_workout_streak(workouts) if str(streak) == "0": label_streak.text = "[b]0 Hari berturut-turut, latihan sekarang![/b]" else: label_streak.text = "[b]" + str( streak) + " Hari berturut-turut[/b]" # Sort workouts by date then reverse (we want youngest dates at the start) workout_keys.sort(key=lambda value: datetime.strptime( workouts[value]['date'], "%m/%d/%Y")) workout_keys = workout_keys[::-1] for workout_key in workout_keys: workout = workouts[workout_key] # Populate workout grid in home screen W = WorkoutsBanner(workout_image=workout['workout_image'], description=workout['description'], type_image=workout['type_image'], number=float(workout['number']), units=workout['units'], likes=workout['likes'], date=workout['date']) banner_grid.add_widget(W) self.change_screen("home_screen", "none") except Exception as e: print(e) pass