3434import com .fox2code .mmm .utils .ExternalHelper ;
3535import com .fox2code .mmm .utils .Http ;
3636import com .fox2code .mmm .utils .IntentHelper ;
37+ import com .fox2code .mmm .utils .NoodleDebug ;
3738import com .google .android .material .progressindicator .LinearProgressIndicator ;
3839
3940import eightbitlab .com .blurview .BlurView ;
@@ -44,6 +45,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
4445 OverScrollManager .OverScrollHelper {
4546 private static final String TAG = "MainActivity" ;
4647 private static final int PRECISION = 10000 ;
48+ public static boolean noodleDebugState = BuildConfig .DEBUG ;
4749 public final ModuleViewListBuilder moduleViewListBuilder ;
4850 public LinearProgressIndicator progressIndicator ;
4951 private ModuleViewAdapter moduleViewAdapter ;
@@ -59,6 +61,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
5961 private RecyclerView moduleList ;
6062 private CardView searchCard ;
6163 private SearchView searchView ;
64+ private NoodleDebug noodleDebug ;
6265 private boolean initMode ;
6366
6467 public MainActivity () {
@@ -106,6 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
106109 this .moduleList = findViewById (R .id .module_list );
107110 this .searchCard = findViewById (R .id .search_card );
108111 this .searchView = findViewById (R .id .search_bar );
112+ this .noodleDebug = new NoodleDebug (this , R .id .noodle_debug );
109113 this .moduleViewAdapter = new ModuleViewAdapter ();
110114 this .moduleList .setAdapter (this .moduleViewAdapter );
111115 this .moduleList .setLayoutManager (new LinearLayoutManager (this ));
@@ -152,6 +156,8 @@ public void onPathReceived(String path) {
152156 moduleViewListBuilder .addNotification (NotificationType .MAGISK_OUTDATED );
153157 if (!MainApplication .isShowcaseMode ())
154158 moduleViewListBuilder .addNotification (NotificationType .INSTALL_FROM_STORAGE );
159+ noodleDebug .setEnabled (noodleDebugState );
160+ noodleDebug .bind ();
155161 ModuleManager .getINSTANCE ().scan ();
156162 ModuleManager .getINSTANCE ().runAfterScan (
157163 moduleViewListBuilder ::appendInstalledModules );
@@ -161,18 +167,22 @@ public void onPathReceived(String path) {
161167 @ Override
162168 public void onFailure (int error ) {
163169 Log .i (TAG , "Failed to get magisk path!" );
170+ noodleDebug .setEnabled (noodleDebugState );
171+ noodleDebug .bind ();
164172 moduleViewListBuilder .addNotification (
165173 InstallerInitializer .getErrorNotification ());
166174 this .commonNext ();
167175 }
168176
169177 public void commonNext () {
178+ NoodleDebug noodleDebug = NoodleDebug .getNoodleDebug ();
170179 swipeRefreshBlocker = System .currentTimeMillis () + 5_000L ;
171180 updateScreenInsets (); // Fix an edge case
172181 if (MainApplication .isShowcaseMode ())
173182 moduleViewListBuilder .addNotification (NotificationType .SHOWCASE_MODE );
174183 if (!Http .hasWebView ()) // Check Http for WebView availability
175184 moduleViewListBuilder .addNotification (NotificationType .NO_WEB_VIEW );
185+ noodleDebug .push ("Apply" );
176186 moduleViewListBuilder .applyTo (moduleList , moduleViewAdapter );
177187 runOnUiThread (() -> {
178188 progressIndicator .setIndeterminate (false );
@@ -181,11 +191,14 @@ public void commonNext() {
181191 updateScreenInsets (getResources ().getConfiguration ());
182192 });
183193 Log .i (TAG , "Scanning for modules!" );
194+ noodleDebug .replace ("Initialize Update" );
184195 final int max = ModuleManager .getINSTANCE ().getUpdatableModuleCount ();
185196 if (RepoManager .getINSTANCE ().getCustomRepoManager ().needUpdate ()) {
186197 Log .w (TAG , "Need update on create?" );
187198 }
199+ noodleDebug .replace ("Check Update Compat" );
188200 AppUpdateManager .getAppUpdateManager ().checkUpdateCompat ();
201+ noodleDebug .replace ("Check Update" );
189202 RepoManager .getINSTANCE ().update (value -> runOnUiThread (max == 0 ? () ->
190203 progressIndicator .setProgressCompat (
191204 (int ) (value * PRECISION ), true ) :() ->
@@ -196,13 +209,17 @@ public void commonNext() {
196209 } else {
197210 // Compatibility data still needs to be updated
198211 AppUpdateManager appUpdateManager = AppUpdateManager .getAppUpdateManager ();
212+ noodleDebug .replace ("Check App Update" );
199213 if (BuildConfig .ENABLE_AUTO_UPDATER && appUpdateManager .checkUpdate (true ))
200214 moduleViewListBuilder .addNotification (NotificationType .UPDATE_AVAILABLE );
215+ noodleDebug .replace ("Check Json Update" );
201216 if (max != 0 ) {
202217 int current = 0 ;
218+ noodleDebug .push ("" );
203219 for (LocalModuleInfo localModuleInfo :
204220 ModuleManager .getINSTANCE ().getModules ().values ()) {
205221 if (localModuleInfo .updateJson != null ) {
222+ noodleDebug .replace (localModuleInfo .id );
206223 try {
207224 localModuleInfo .checkModuleUpdate ();
208225 } catch (Exception e ) {
@@ -216,6 +233,7 @@ public void commonNext() {
216233 + (PRECISION * 0.75F )), true ));
217234 }
218235 }
236+ noodleDebug .pop ();
219237 }
220238 }
221239 runOnUiThread (() -> {
@@ -225,10 +243,13 @@ public void commonNext() {
225243 setActionBarBackground (null );
226244 updateScreenInsets (getResources ().getConfiguration ());
227245 });
246+ noodleDebug .push ("Apply" );
228247 RepoManager .getINSTANCE ().runAfterUpdate (
229248 moduleViewListBuilder ::appendRemoteModules );
230249 moduleViewListBuilder .applyTo (moduleList , moduleViewAdapter );
250+ noodleDebug .pop ();
231251 Log .i (TAG , "Finished app opening state!" );
252+ noodleDebug .unbind ();
232253 }
233254 }, true );
234255 ExternalHelper .INSTANCE .refreshHelper (this );
@@ -321,6 +342,8 @@ public void onPathReceived(String path) {
321342 moduleViewListBuilder .addNotification (NotificationType .MAGISK_OUTDATED );
322343 if (!MainApplication .isShowcaseMode ())
323344 moduleViewListBuilder .addNotification (NotificationType .INSTALL_FROM_STORAGE );
345+ noodleDebug .setEnabled (noodleDebugState );
346+ noodleDebug .bind ();
324347 ModuleManager .getINSTANCE ().scan ();
325348 ModuleManager .getINSTANCE ().runAfterScan (
326349 moduleViewListBuilder ::appendInstalledModules );
@@ -331,23 +354,28 @@ public void onPathReceived(String path) {
331354 public void onFailure (int error ) {
332355 moduleViewListBuilder .addNotification (
333356 InstallerInitializer .getErrorNotification ());
357+ noodleDebug .setEnabled (noodleDebugState );
358+ noodleDebug .bind ();
334359 this .commonNext ();
335360 }
336361
337362 public void commonNext () {
338363 Log .i (TAG , "Common Before" );
364+ NoodleDebug noodleDebug = NoodleDebug .getNoodleDebug ();
339365 if (MainApplication .isShowcaseMode ())
340366 moduleViewListBuilder .addNotification (NotificationType .SHOWCASE_MODE );
341367 if (!NotificationType .NO_INTERNET .shouldRemove ())
342368 moduleViewListBuilder .addNotification (NotificationType .NO_INTERNET );
343369 else if (AppUpdateManager .getAppUpdateManager ().checkUpdate (false ))
344370 moduleViewListBuilder .addNotification (NotificationType .UPDATE_AVAILABLE );
345371 RepoManager .getINSTANCE ().updateEnabledStates ();
372+ noodleDebug .push ("" );
346373 if (RepoManager .getINSTANCE ().getCustomRepoManager ().needUpdate ()) {
347374 runOnUiThread (() -> {
348375 progressIndicator .setIndeterminate (false );
349376 progressIndicator .setMax (PRECISION );
350377 });
378+ noodleDebug .replace ("Check Update" );
351379 RepoManager .getINSTANCE ().update (value -> runOnUiThread (() ->
352380 progressIndicator .setProgressCompat (
353381 (int ) (value * PRECISION ), true )));
@@ -356,11 +384,14 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
356384 progressIndicator .setVisibility (View .GONE );
357385 });
358386 }
387+ noodleDebug .replace ("Apply" );
359388 RepoManager .getINSTANCE ().runAfterUpdate (
360389 moduleViewListBuilder ::appendRemoteModules );
361390 Log .i (TAG , "Common Before applyTo" );
362391 moduleViewListBuilder .applyTo (moduleList , moduleViewAdapter );
392+ noodleDebug .pop ();
363393 Log .i (TAG , "Common After" );
394+ noodleDebug .unbind ();
364395 }
365396 });
366397 this .initMode = false ;
@@ -384,14 +415,49 @@ public void onRefresh() {
384415 this .swipeRefreshBlocker = System .currentTimeMillis () + 5_000L ;
385416 // this.swipeRefreshLayout.setRefreshing(true); ??
386417 new Thread (() -> {
418+ noodleDebug .setEnabled (noodleDebugState );
419+ NoodleDebug noodleDebug = this .noodleDebug .bind ();
387420 Http .cleanDnsCache (); // Allow DNS reload from network
388- RepoManager .getINSTANCE ().update (value -> runOnUiThread (() ->
389- this .progressIndicator .setProgressCompat (
390- (int ) (value * PRECISION ), true )));
391- if (!NotificationType .NO_INTERNET .shouldRemove ())
421+ noodleDebug .push ("Check Update" );
422+ final int max = ModuleManager .getINSTANCE ().getUpdatableModuleCount ();
423+ RepoManager .getINSTANCE ().update (value -> runOnUiThread (max == 0 ? () ->
424+ progressIndicator .setProgressCompat (
425+ (int ) (value * PRECISION ), true ) :() ->
426+ progressIndicator .setProgressCompat (
427+ (int ) (value * PRECISION * 0.75F ), true )));
428+ if (!NotificationType .NO_INTERNET .shouldRemove ()) {
392429 moduleViewListBuilder .addNotification (NotificationType .NO_INTERNET );
393- else if (AppUpdateManager .getAppUpdateManager ().checkUpdate (true ))
394- moduleViewListBuilder .addNotification (NotificationType .UPDATE_AVAILABLE );
430+ } else {
431+ // Compatibility data still needs to be updated
432+ AppUpdateManager appUpdateManager = AppUpdateManager .getAppUpdateManager ();
433+ noodleDebug .replace ("Check App Update" );
434+ if (BuildConfig .ENABLE_AUTO_UPDATER && appUpdateManager .checkUpdate (true ))
435+ moduleViewListBuilder .addNotification (NotificationType .UPDATE_AVAILABLE );
436+ noodleDebug .replace ("Check Json Update" );
437+ if (max != 0 ) {
438+ int current = 0 ;
439+ noodleDebug .push ("" );
440+ for (LocalModuleInfo localModuleInfo :
441+ ModuleManager .getINSTANCE ().getModules ().values ()) {
442+ if (localModuleInfo .updateJson != null ) {
443+ noodleDebug .replace (localModuleInfo .id );
444+ try {
445+ localModuleInfo .checkModuleUpdate ();
446+ } catch (Exception e ) {
447+ Log .e ("MainActivity" , "Failed to fetch update of: "
448+ + localModuleInfo .id , e );
449+ }
450+ current ++;
451+ final int currentTmp = current ;
452+ runOnUiThread (() -> progressIndicator .setProgressCompat (
453+ (int ) ((1F * currentTmp / max ) * PRECISION * 0.25F
454+ + (PRECISION * 0.75F )), true ));
455+ }
456+ }
457+ noodleDebug .pop ();
458+ }
459+ }
460+ noodleDebug .replace ("Apply" );
395461 runOnUiThread (() -> {
396462 this .progressIndicator .setVisibility (View .GONE );
397463 this .swipeRefreshLayout .setRefreshing (false );
@@ -403,6 +469,8 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(true))
403469 RepoManager .getINSTANCE ().runAfterUpdate (
404470 moduleViewListBuilder ::appendRemoteModules );
405471 this .moduleViewListBuilder .applyTo (moduleList , moduleViewAdapter );
472+ noodleDebug .pop ();
473+ noodleDebug .unbind ();
406474 },"Repo update thread" ).start ();
407475 }
408476
0 commit comments