@@ -24,6 +24,7 @@ class AppStore(Activity):
2424install_label = None
2525please_wait_label = None
2626progress_bar = None
27+ _icon_widgets = {}
2728
2829def onCreate (self ):
2930self .main_screen = lv .obj ()
@@ -56,7 +57,6 @@ def download_app_index(self, json_url):
5657if response and response .status_code == 200 :
5758#print(f"Got response text: {response.text}")
5859try :
59- applist = json .loads (response .text )
6060for app in json .loads (response .text ):
6161try :
6262self .apps .append (App (app ["name" ],app ["publisher" ],app ["short_description" ],app ["long_description" ],app ["icon_url" ],app ["download_url" ],app ["fullname" ],app ["version" ],app ["category" ],app ["activities" ]))
@@ -70,6 +70,7 @@ def download_app_index(self, json_url):
7070time .sleep_ms (200 )
7171self .update_ui_threadsafe_if_foreground (self .please_wait_label .add_flag ,lv .obj .FLAG .HIDDEN )
7272self .update_ui_threadsafe_if_foreground (self .create_apps_list )
73+ time .sleep (0.1 )# give the UI time to display the app list before starting to download
7374self .download_icons ()
7475except Exception as e :
7576print (f"ERROR: could not parse reponse.text JSON:{ e } " )
@@ -78,12 +79,13 @@ def download_app_index(self, json_url):
7879
7980def create_apps_list (self ):
8081print ("create_apps_list" )
81- default_icon_dsc = self .load_icon ("builtin/res/mipmap-mdpi/default_icon_64x64.png" )
8282apps_list = lv .list (self .main_screen )
8383apps_list .set_style_border_width (0 ,0 )
8484apps_list .set_style_radius (0 ,0 )
8585apps_list .set_style_pad_all (0 ,0 )
8686apps_list .set_size (lv .pct (100 ),lv .pct (100 ))
87+ # Clear old icons
88+ self ._icon_widgets = {}
8789print ("create_apps_list iterating" )
8890for app in self .apps :
8991print (app )
@@ -103,7 +105,8 @@ def create_apps_list(self):
103105cont .add_event_cb (lambda e ,a = app :self .show_app_detail (a ),lv .EVENT .CLICKED ,None )
104106icon_spacer = lv .image (cont )
105107icon_spacer .set_size (64 ,64 )
106- app .image = icon_spacer
108+ icon_spacer .set_src (lv .SYMBOL .REFRESH )
109+ self ._icon_widgets [app .fullname ]= icon_spacer
107110icon_spacer .add_event_cb (lambda e ,a = app :self .show_app_detail (a ),lv .EVENT .CLICKED ,None )
108111label_cont = lv .obj (cont )
109112label_cont .set_style_border_width (0 ,0 )
@@ -123,18 +126,21 @@ def create_apps_list(self):
123126
124127def download_icons (self ):
125128for app in self .apps :
126- if app .image_dsc :
127- print (f"Skipping icon download for{ app .name } because already downloaded." )
128- continue
129129if not self .has_foreground ():
130130print (f"App is stopping, aborting icon downloads." )
131131break
132- #if app.icon_path:
133- print (f"Downloading icon for{ app .name } " )
134- image_dsc = self .download_icon (app .icon_url )
135- app .image_dsc = image_dsc # save it for the app detail page
136- self .update_ui_threadsafe_if_foreground (app .image .set_src ,image_dsc )
137- time .sleep_ms (200 )# not waiting here will result in some async_calls() not being executed
132+ if not app .icon_data :
133+ print (f"No icon_data found for{ app } , downloading..." )
134+ app .icon_data = self .download_icon_data (app .icon_url )
135+ if app .icon_data :
136+ print ("download_icons has icon_data, showing it..." )
137+ icon_widget = self ._icon_widgets .get (app .fullname )
138+ if icon_widget :
139+ image_dsc = lv .image_dsc_t ({
140+ 'data_size' :len (app .icon_data ),
141+ 'data' :app .icon_data
142+ })
143+ self .update_ui_threadsafe_if_foreground (icon_widget .set_src ,image_dsc )# error: 'App' object has no attribute 'image'
138144print ("Finished downloading icons." )
139145
140146def show_app_detail (self ,app ):
@@ -143,34 +149,20 @@ def show_app_detail(self, app):
143149self .startActivity (intent )
144150
145151@staticmethod
146- def download_icon (url ):
152+ def download_icon_data (url ):
147153print (f"Downloading icon from{ url } " )
148154try :
149155response = requests .get (url ,timeout = 5 )
150156if response .status_code == 200 :
151157image_data = response .content
152158print ("Downloaded image, size:" ,len (image_data ),"bytes" )
153- image_dsc = lv .image_dsc_t ({
154- 'data_size' :len (image_data ),
155- 'data' :image_data
156- })
157- return image_dsc
159+ return image_data
158160else :
159161print ("Failed to download image: Status code" ,response .status_code )
160162except Exception as e :
161163print (f"Exception during download of icon:{ e } " )
162164return None
163165
164- @staticmethod
165- def load_icon (icon_path ):
166- with open (icon_path ,'rb' )as f :
167- image_data = f .read ()
168- image_dsc = lv .image_dsc_t ({
169- 'data_size' :len (image_data ),
170- 'data' :image_data
171- })
172- return image_dsc
173-
174166class AppDetail (Activity ):
175167
176168action_label_install = "Install"
@@ -192,18 +184,23 @@ def onCreate(self):
192184app_detail_screen .set_size (lv .pct (100 ),lv .pct (100 ))
193185app_detail_screen .set_pos (0 ,40 )
194186app_detail_screen .set_flex_flow (lv .FLEX_FLOW .COLUMN )
195- #
187+
196188headercont = lv .obj (app_detail_screen )
197189headercont .set_style_border_width (0 ,0 )
198190headercont .set_style_pad_all (0 ,0 )
199191headercont .set_flex_flow (lv .FLEX_FLOW .ROW )
200192headercont .set_size (lv .pct (100 ),lv .SIZE_CONTENT )
201193headercont .set_scrollbar_mode (lv .SCROLLBAR_MODE .OFF )
202194icon_spacer = lv .image (headercont )
203- if app .image_dsc :
204- icon_spacer .set_src (app .image_dsc )
205195icon_spacer .set_size (64 ,64 )
206- #
196+ if app .icon_data :
197+ image_dsc = lv .image_dsc_t ({
198+ 'data_size' :len (app .icon_data ),
199+ 'data' :app .icon_data
200+ })
201+ icon_spacer .set_src (image_dsc )
202+ else :
203+ icon_spacer .set_src (lv .SYMBOL .REFRESH )
207204detail_cont = lv .obj (headercont )
208205detail_cont .set_style_border_width (0 ,0 )
209206detail_cont .set_style_radius (0 ,0 )
@@ -216,7 +213,7 @@ def onCreate(self):
216213publisher_label = lv .label (detail_cont )
217214publisher_label .set_text (app .publisher )
218215publisher_label .set_style_text_font (lv .font_montserrat_16 ,0 )
219- #
216+
220217self .progress_bar = lv .bar (app_detail_screen )
221218self .progress_bar .set_width (lv .pct (100 ))
222219self .progress_bar .set_range (0 ,100 )