5151 create_preview_container ,
5252 create_preview_image ,
5353 create_top_mask ,
54+ refresh_preview_device_labels ,
5455)
5556from .widgets .style import StyleWrapper
5657
@@ -400,9 +401,9 @@ def apply_lock_wallpaper(new_wallpaper: str | None) -> None:
400401
401402def replace_wallpaper_if_in_use (
402403 deleted_path : str | None , replacement_path : str | None = None
403- ) -> None :
404+ ) -> bool :
404405 if not deleted_path :
405- return
406+ return False
406407
407408 replacement = replacement_path or utils .get_default_wallpaper ()
408409 base_name = deleted_path .split ("/" )[- 1 ]
@@ -415,6 +416,7 @@ def replace_wallpaper_if_in_use(
415416
416417 current_home = storage_device .get_appdrawer_background ()
417418 current_lock = storage_device .get_homescreen ()
419+ replaced = False
418420
419421 def _matches (candidate : str | None ) -> bool :
420422 if not candidate :
@@ -427,8 +429,11 @@ def _matches(candidate: str | None) -> bool:
427429
428430 if _matches (current_home ):
429431 apply_home_wallpaper (replacement )
432+ replaced = True
430433 if _matches (current_lock ):
431434 apply_lock_wallpaper (replacement )
435+ replaced = True
436+ return replaced
432437
433438
434439def brightness2_percent_str (brightness : int ) -> str :
@@ -882,7 +887,6 @@ def hidden(self):
882887 self .add_flag (lv .obj .FLAG .HIDDEN )
883888
884889 class AppDrawer (lv .obj ):
885- PAGE_SIZE = 2
886890 PAGE_SLIDE_TIME = 300 # Animation time with ease_out for smooth feel
887891
888892 def __init__ (self , parent ):
@@ -897,6 +901,10 @@ def __init__(self, parent):
897901
898902 # Remove style and lazy loading related code to fix system freeze
899903
904+ # Calculate PAGE_SIZE dynamically
905+ item_count = 7 if utils .BITCOIN_ONLY else 8
906+ self .PAGE_SIZE = (item_count + 3 ) // 4
907+
900908 self .init_ui ()
901909 self .init_items () # Restore original immediate creation of all items
902910 self ._configure_image_cache ()
@@ -1295,6 +1303,58 @@ def hide_to_mainscreen_fallback(self):
12951303 if hasattr (self .parent , "restore_main_content" ):
12961304 self .parent .restore_main_content ()
12971305
1306+ def bounce_page (self , direction ):
1307+ if self .page_animating :
1308+ return
1309+
1310+ self .page_animating = True
1311+ current_wrap = self .page_wraps [self .current_page ]
1312+
1313+ # If swiping LEFT (trying to go next), we move left (negative x) then back
1314+ # If swiping RIGHT (trying to go prev), we move right (positive x) then back
1315+ bounce_dist = 40
1316+ offset = - bounce_dist if direction == lv .DIR .LEFT else bounce_dist
1317+
1318+ original_x = self ._page_wrap_origin_x
1319+ target_x = original_x + offset
1320+
1321+ anim_time = 150
1322+
1323+ def animate_x (target_obj , start_x , end_x , ready_cb = None ):
1324+ anim = lv .anim_t ()
1325+ anim .init ()
1326+ anim .set_var (target_obj )
1327+ anim .set_values (start_x , end_x )
1328+ anim .set_time (anim_time )
1329+ anim .set_path_cb (lv .anim_t .path_ease_out )
1330+
1331+ def exec_cb (_anim , val , * , target = target_obj ):
1332+ target .set_x (int (val ))
1333+
1334+ anim .set_custom_exec_cb (exec_cb )
1335+ if ready_cb :
1336+ anim .set_ready_cb (ready_cb )
1337+ anim .set_repeat_count (1 )
1338+ return anim
1339+
1340+ def on_bounce_back_ready (_anim ):
1341+ self .page_animating = False
1342+ self ._page_anim_refs = []
1343+ self ._page_anim_handles = []
1344+
1345+ def on_bounce_out_ready (_anim ):
1346+ anim_back = animate_x (
1347+ current_wrap , target_x , original_x , on_bounce_back_ready
1348+ )
1349+ self ._page_anim_refs = [anim_back ]
1350+ self ._page_anim_handles = [lv .anim_t .start (anim_back )]
1351+
1352+ anim_out = animate_x (
1353+ current_wrap , original_x , target_x , on_bounce_out_ready
1354+ )
1355+ self ._page_anim_refs = [anim_out ]
1356+ self ._page_anim_handles = [lv .anim_t .start (anim_out )]
1357+
12981358 def handle_page_gesture (self , _dir ):
12991359 if _dir not in [lv .DIR .RIGHT , lv .DIR .LEFT ]:
13001360 return
@@ -1309,9 +1369,13 @@ def handle_page_gesture(self, _dir):
13091369 return
13101370
13111371 if _dir == lv .DIR .LEFT :
1312- target_page = ( self .current_page + 1 ) % self . PAGE_SIZE
1372+ target_page = self .current_page + 1
13131373 else :
1314- target_page = (self .current_page - 1 + self .PAGE_SIZE ) % self .PAGE_SIZE
1374+ target_page = self .current_page - 1
1375+
1376+ if target_page < 0 or target_page >= self .PAGE_SIZE :
1377+ self .bounce_page (_dir )
1378+ return
13151379
13161380 if target_page == self .current_page :
13171381 return
@@ -1369,7 +1433,7 @@ def animate_page_transition(self, target_index: int, direction: int):
13691433 return
13701434
13711435 # Clean up memory before starting animation to prevent GC during animation
1372- gc .collect ()
1436+ # gc.collect() # Removed to improve start smoothness
13731437
13741438 self .page_animating = True
13751439 self ._page_anim_target = target_index
@@ -1485,8 +1549,10 @@ def _on_page_anim_ready(
14851549 self ._page_anim_handles = []
14861550
14871551 # Clean up immediately if forced, otherwise let normal GC handle it
1488- if force :
1489- gc .collect ()
1552+ # if force:
1553+ # gc.collect()
1554+ # Always collect at the end of animation to keep memory clean for next time
1555+ gc .collect ()
14901556
14911557 def force_cleanup (self ):
14921558 self .finish_page_animation (force = True )
@@ -3860,11 +3926,7 @@ def __init__(
38603926 self .current_wallpaper_path = "A:/res/wallpaper-7.jpg"
38613927 self .lockscreen_preview .set_src ("A:/res/wallpaper-7.jpg" )
38623928
3863- device_name = storage_device .get_label () or "OneKey Pro"
3864- ble_name = storage_device .get_ble_name () or uart .get_ble_name ()
3865-
38663929 self .device_name_label = lv .label (self .preview_container )
3867- self .device_name_label .set_text (device_name )
38683930
38693931 self .device_name_label .add_style (
38703932 StyleWrapper ()
@@ -3873,14 +3935,11 @@ def __init__(
38733935 .text_align (lv .TEXT_ALIGN .CENTER ),
38743936 0 ,
38753937 )
3876-
3938+ # Stretch to container width so center alignment is accurate
3939+ self .device_name_label .set_width (self .preview_container .get_width ())
38773940 self .device_name_label .align_to (self .preview_container , lv .ALIGN .TOP_MID , 0 , 49 )
38783941
38793942 self .bluetooth_label = lv .label (self .preview_container )
3880- if ble_name and len (ble_name ) >= 4 :
3881- self .bluetooth_label .set_text ("Pro " + ble_name [- 4 :])
3882- else :
3883- self .bluetooth_label .set_text ("Pro" )
38843943
38853944 self .bluetooth_label .add_style (
38863945 StyleWrapper ()
@@ -3889,10 +3948,12 @@ def __init__(
38893948 .text_align (lv .TEXT_ALIGN .CENTER ),
38903949 0 ,
38913950 )
3892-
3951+ self . bluetooth_label . set_width ( self . preview_container . get_width ())
38933952 self .bluetooth_label .align_to (
38943953 self .device_name_label , lv .ALIGN .OUT_BOTTOM_MID , 0 , 8
38953954 )
3955+ # Sync visibility/text with the Display setting (model name & Bluetooth ID)
3956+ refresh_preview_device_labels (self .device_name_label , self .bluetooth_label )
38963957
38973958 self .change_button_container = lv .obj (self .container )
38983959 self .change_button_container .set_size (120 , 100 )
@@ -4002,6 +4063,7 @@ def refresh_text(self):
40024063 self .container .invalidate ()
40034064
40044065 self .invalidate ()
4066+ refresh_preview_device_labels (self .device_name_label , self .bluetooth_label )
40054067
40064068 async def _first_frame_fix (self ):
40074069 utime .sleep_ms (100 )
@@ -4850,7 +4912,37 @@ def delete_marked_files(self):
48504912 self .__init__ (self .prev_scr )
48514913
48524914 def replace_if_in_use (self , deleted_path ):
4853- replace_wallpaper_if_in_use (deleted_path , "A:/res/wallpaper-7.jpg" )
4915+ replacement = "A:/res/wallpaper-7.jpg"
4916+ was_replaced = replace_wallpaper_if_in_use (deleted_path , replacement )
4917+
4918+ if not was_replaced :
4919+ return
4920+
4921+ prev = getattr (self , "prev_scr" , None )
4922+ if not prev :
4923+ return
4924+
4925+ if prev .__class__ .__name__ == "HomeScreenSetting" :
4926+ prev .is_blur_active = False
4927+ prev .original_wallpaper_path = replacement
4928+ prev .current_wallpaper_path = replacement
4929+ if hasattr (prev , "_blur_cache" ):
4930+ prev ._blur_cache .clear ()
4931+ if hasattr (prev , "homescreen_preview" ):
4932+ prev .homescreen_preview .set_src (replacement )
4933+ if hasattr (prev , "_update_blur_button_state" ):
4934+ prev ._update_blur_button_state ()
4935+
4936+ if prev .__class__ .__name__ == "AppdrawerBackgroundSetting" :
4937+ prev .selected_wallpaper = replacement
4938+ prev .current_wallpaper_path = replacement
4939+ if hasattr (prev , "lockscreen_preview" ):
4940+ prev .lockscreen_preview .set_src (replacement )
4941+ if hasattr (prev , "refresh_text" ):
4942+ prev .refresh_text ()
4943+
4944+ if hasattr (prev , "invalidate" ):
4945+ prev .invalidate ()
48544946
48554947 def eventhandler (self , event_obj ):
48564948 event = event_obj .code
0 commit comments