44import android .content .res .Configuration ;
55import android .graphics .Color ;
66import android .os .*;
7- import android .os .Trace ;
87
98import androidx .activity .EdgeToEdge ;
109import androidx .activity .SystemBarStyle ;
2120import com .xapps .media .xmusic .callback .CallbackInterface ;
2221import com .xapps .media .xmusic .common .SongLoadListener ;
2322import com .xapps .media .xmusic .data .DataManager ;
23+ import com .xapps .media .xmusic .data .RuntimeData ;
2424import com .xapps .media .xmusic .databinding .ActivityRootBinding ;
2525import com .xapps .media .xmusic .helper .SongMetadataHelper ;
2626import com .xapps .media .xmusic .models .Song ;
@@ -36,25 +36,30 @@ public class RootActivity extends BaseActivity implements ActivityCallback {
3636 private LogicManager logicManager ;
3737 private MediaController mediaController ;
3838
39+ private boolean isReady = true ;
40+
3941 @ Override
4042 protected void onCreate (Bundle savedInstanceState ) {
41- Trace .beginSection ("RA:onCreate" );
42- try {
43- EdgeToEdge .enable (this ,
44- SystemBarStyle .auto (Color .TRANSPARENT , Color .TRANSPARENT ),
45- SystemBarStyle .auto (Color .TRANSPARENT , Color .TRANSPARENT )
46- );
47- XUtils .applyDynamicColors (this , DataManager .isOledThemeEnabled ());
48- if (XUtils .isDarkMode (this ) && DataManager .isOledThemeEnabled ())getTheme ().applyStyle (R .style .ThemeOverlay_XMusic_OLED , true );
49- MaterialColorUtils .initColors (this );
50- super .onCreate (savedInstanceState );
51- binding = ActivityRootBinding .inflate (getLayoutInflater ());
52- passData ();
53- setContentView (binding .getRoot ());
54- init ();
55- } finally {
56- Trace .endSection ();
57- }
43+ SplashScreen .installSplashScreen (this ).setKeepOnScreenCondition (() -> isReady );
44+ new Handler (Looper .getMainLooper ()).postDelayed (() -> {
45+ if (!XUtils .areAllPermsGranted (this )) {
46+ startActivity (new Intent (this , WelcomeActivity .class ));
47+ finish ();
48+ }
49+ isReady = false ;
50+ }, savedInstanceState == null ? 800 : 1 );
51+ EdgeToEdge .enable (this ,
52+ SystemBarStyle .auto (Color .TRANSPARENT , Color .TRANSPARENT ),
53+ SystemBarStyle .auto (Color .TRANSPARENT , Color .TRANSPARENT )
54+ );
55+ XUtils .applyDynamicColors (this , DataManager .isOledThemeEnabled ());
56+ if (XUtils .isDarkMode (this ) && DataManager .isOledThemeEnabled ())getTheme ().applyStyle (R .style .ThemeOverlay_XMusic_OLED , true );
57+ MaterialColorUtils .initColors (this );
58+ super .onCreate (savedInstanceState );
59+ binding = ActivityRootBinding .inflate (getLayoutInflater ());
60+ passData ();
61+ setContentView (binding .getRoot ());
62+ init ();
5863 }
5964
6065 @ Override
@@ -73,13 +78,8 @@ public void onStart() {
7378
7479 @ Override
7580 public void onResume () {
76- Trace .beginSection ("RA:onResume" );
77- try {
78- super .onResume ();
79- uiManager .updateContent (-1 , true );
80- } finally {
81- Trace .endSection ();
82- }
81+ super .onResume ();
82+ if (!RuntimeData .songs .isEmpty ()) uiManager .updateContent (-1 , true );
8383 }
8484
8585 @ Override
@@ -98,7 +98,7 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
9898 public void onDestroy () {
9999 super .onDestroy ();
100100 CallbackInterface .clearActivityCallback (this );
101- mediaController .release ();
101+ if ( mediaController != null ) mediaController .release ();
102102 mediaController = null ;
103103 }
104104
@@ -142,12 +142,7 @@ public void updateSongsQueue(ArrayList<Song> songs) {
142142 }
143143
144144 public void restoreStateIfPossible () {
145- Trace .beginSection ("RA:restoreStateIfPossible" );
146- try {
147- uiManager .maybeRestoreUIState ();
148- } finally {
149- Trace .endSection ();
150- }
145+ uiManager .maybeRestoreUIState ();
151146 }
152147
153148 public void loadSettings () {
@@ -161,12 +156,11 @@ public void onColorsChanged() {
161156
162157 @ Override
163158 public void onSongChanged (int position ) {
164- runOnUiThread (
165- () -> {
166- uiManager .updateContent (position , false );
167- });
168- if (CallbackInterface .mlFrag () != null ) CallbackInterface .mlFrag ().updateActiveItem (position );
169- if (CallbackInterface .srFrag () != null ) CallbackInterface .srFrag ().updateActiveItem (position );
159+ runOnUiThread (() -> {
160+ uiManager .updateContent (position , false );
161+ });
162+ if (CallbackInterface .mlFrag () != null ) CallbackInterface .mlFrag ().updateActiveItem (position );
163+ if (CallbackInterface .srFrag () != null ) CallbackInterface .srFrag ().updateActiveItem (position );
170164 }
171165
172166 @ Override
@@ -176,11 +170,17 @@ public void onProgressChanged(long progress) {
176170
177171 @ Override
178172 public void updateState () {
179- uiManager .saveState ();
173+ runOnUiThread (() -> {
174+ uiManager .saveState ();
175+ });
180176 }
181177
182178 @ Override
183179 public void passData () {
184180 if (CallbackInterface .subFrag () != null ) CallbackInterface .subFrag ().onBindingReady (binding );
185181 }
182+
183+ public void updateLyrics () {
184+ uiManager .updateLyrics ();
185+ }
186186}
0 commit comments