55import android .util .Log ;
66
77import com .fox2code .mmm .MainApplication ;
8+ import com .fox2code .mmm .XHooks ;
89import com .fox2code .mmm .androidacy .AndroidacyRepoData ;
910import com .fox2code .mmm .manager .ModuleInfo ;
1011import com .fox2code .mmm .utils .Files ;
@@ -45,6 +46,7 @@ public static RepoManager getINSTANCE() {
4546 MainApplication mainApplication = MainApplication .getINSTANCE ();
4647 if (mainApplication != null ) {
4748 INSTANCE = new RepoManager (mainApplication );
49+ XHooks .onRepoManagerInitialized ();
4850 } else {
4951 throw new RuntimeException ("Getting RepoManager too soon!" );
5052 }
@@ -58,8 +60,10 @@ public static RepoManager getINSTANCE() {
5860 private final LinkedHashMap <String , RepoData > repoData ;
5961 private final HashMap <String , RepoModule > modules ;
6062 private final AndroidacyRepoData androidacyRepoData ;
63+ private boolean initialized ;
6164
6265 private RepoManager (MainApplication mainApplication ) {
66+ this .initialized = false ;
6367 this .mainApplication = mainApplication ;
6468 this .repoData = new LinkedHashMap <>();
6569 this .modules = new HashMap <>();
@@ -69,19 +73,24 @@ private RepoManager(MainApplication mainApplication) {
6973 this .addAndroidacyRepoData ();
7074 // Populate default cache
7175 for (RepoData repoData :this .repoData .values ()) {
72- for (RepoModule repoModule :repoData .moduleHashMap .values ()) {
73- if (!repoModule .moduleInfo .hasFlag (ModuleInfo .FLAG_METADATA_INVALID )) {
74- RepoModule registeredRepoModule = this .modules .get (repoModule .id );
75- if (registeredRepoModule == null ) {
76- this .modules .put (repoModule .id , repoModule );
77- } else if (repoModule .moduleInfo .versionCode >
78- registeredRepoModule .moduleInfo .versionCode ) {
79- this .modules .put (repoModule .id , repoModule );
80- }
81- } else {
82- Log .e (TAG , "Detected module with invalid metadata: " +
83- repoModule .repoName + "/" + repoModule .id );
76+ this .populateDefaultCache (repoData );
77+ }
78+ this .initialized = true ;
79+ }
80+
81+ private void populateDefaultCache (RepoData repoData ) {
82+ for (RepoModule repoModule :repoData .moduleHashMap .values ()) {
83+ if (!repoModule .moduleInfo .hasFlag (ModuleInfo .FLAG_METADATA_INVALID )) {
84+ RepoModule registeredRepoModule = this .modules .get (repoModule .id );
85+ if (registeredRepoModule == null ) {
86+ this .modules .put (repoModule .id , repoModule );
87+ } else if (repoModule .moduleInfo .versionCode >
88+ registeredRepoModule .moduleInfo .versionCode ) {
89+ this .modules .put (repoModule .id , repoModule );
8490 }
91+ } else {
92+ Log .e (TAG , "Detected module with invalid metadata: " +
93+ repoModule .repoName + "/" + repoModule .id );
8594 }
8695 }
8796 }
@@ -121,18 +130,18 @@ public boolean isRepoUpdating() {
121130 return this .repoUpdating ;
122131 }
123132
124- public final void afterUpdate () {
133+ public void afterUpdate () {
125134 if (this .repoUpdating ) synchronized (this .repoUpdateLock ) {}
126135 }
127136
128- public final void runAfterUpdate (Runnable runnable ) {
137+ public void runAfterUpdate (Runnable runnable ) {
129138 synchronized (this .repoUpdateLock ) {
130139 runnable .run ();
131140 }
132141 }
133142
134143 // MultiThread friendly method
135- public final void update (UpdateListener updateListener ) {
144+ public void update (UpdateListener updateListener ) {
136145 if (!this .repoUpdating ) {
137146 // Do scan
138147 synchronized (this .repoUpdateLock ) {
@@ -255,6 +264,9 @@ private RepoData addRepoData(String url) {
255264 .getSharedPreferences ("mmm_" + id , Context .MODE_PRIVATE );
256265 RepoData repoData = new RepoData (url , cacheRoot , sharedPreferences );
257266 this .repoData .put (url , repoData );
267+ if (this .initialized ) {
268+ this .populateDefaultCache (repoData );
269+ }
258270 return repoData ;
259271 }
260272
0 commit comments