3030import java .util .List ;
3131
3232public class RepoData extends XRepo {
33- private final Object populateLock = new Object ();
3433 public final String url ;
3534 public final String id ;
3635 public final File cacheRoot ;
3736 public final SharedPreferences cachedPreferences ;
3837 public final File metaDataCache ;
3938 public final HashMap <String , RepoModule > moduleHashMap ;
39+ private final Object populateLock = new Object ();
4040 public long lastUpdate ;
41- protected String defaultName , defaultWebsite ,
42- defaultSupport , defaultDonate , defaultSubmitModule ;
4341 public String name , website , support , donate , submitModule ;
42+ protected String defaultName , defaultWebsite , defaultSupport , defaultDonate , defaultSubmitModule ;
4443 private boolean forceHide , enabled ; // Cache for speed
4544
4645 public RepoData (String url , File cacheRoot , SharedPreferences cachedPreferences ) {
@@ -52,8 +51,7 @@ public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences)
5251 this .moduleHashMap = new HashMap <>();
5352 this .defaultName = url ; // Set url as default name
5453 this .forceHide = AppUpdateManager .shouldForceHide (this .id );
55- this .enabled = (!this .forceHide ) && MainApplication .getSharedPreferences ()
56- .getBoolean ("pref_" + this .getPreferenceId () + "_enabled" , true );
54+ this .enabled = (!this .forceHide ) && MainApplication .getSharedPreferences ().getBoolean ("pref_" + this .getPreferenceId () + "_enabled" , true );
5755 this .defaultWebsite = "https://" + Uri .parse (url ).getHost () + "/" ;
5856 if (!this .cacheRoot .isDirectory ()) {
5957 boolean mkdirs = this .cacheRoot .mkdirs ();
@@ -67,14 +65,14 @@ public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences)
6765 this .lastUpdate = 0 ; // Don't allow time travel
6866 }
6967 try {
70- List <RepoModule > modules = this .populate (new JSONObject (
71- new String (Files .read (this .metaDataCache ), StandardCharsets .UTF_8 )));
68+ List <RepoModule > modules = this .populate (new JSONObject (new String (Files .read (this .metaDataCache ), StandardCharsets .UTF_8 )));
7269 for (RepoModule repoModule : modules ) {
7370 if (!this .tryLoadMetadata (repoModule )) {
7471 repoModule .moduleInfo .flags &= ~ModuleInfo .FLAG_METADATA_INVALID ;
7572 }
7673 }
77- } catch (Exception e ) {
74+ } catch (
75+ Exception e ) {
7876 boolean delete = this .metaDataCache .delete ();
7977 if (!delete ) {
8078 throw new RuntimeException ("Failed to delete invalid cache file" );
@@ -84,6 +82,10 @@ public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences)
8482 }
8583 }
8684
85+ private static boolean isNonNull (String str ) {
86+ return str != null && !str .isEmpty () && !"null" .equals (str );
87+ }
88+
8789 protected boolean prepare () throws NoSuchAlgorithmException {
8890 return true ;
8991 }
@@ -92,8 +94,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
9294 List <RepoModule > newModules = new ArrayList <>();
9395 synchronized (this .populateLock ) {
9496 String name = jsonObject .getString ("name" ).trim ();
95- String nameForModules = name .endsWith (" (Official)" ) ?
96- name .substring (0 , name .length () - 11 ) : name ;
97+ String nameForModules = name .endsWith (" (Official)" ) ? name .substring (0 , name .length () - 11 ) : name ;
9798 long lastUpdate = jsonObject .getLong ("last_update" );
9899 for (RepoModule repoModule : this .moduleHashMap .values ()) {
99100 repoModule .processed = false ;
@@ -104,8 +105,8 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
104105 JSONObject module = array .getJSONObject (i );
105106 String moduleId = module .getString ("id" );
106107 // Deny remote modules ids shorter than 3 chars or containing null char or space
107- if (moduleId .length () < 3 || moduleId .indexOf ('\0' ) != -1 ||
108- moduleId . indexOf ( ' ' ) != - 1 || "ak3-helper" . equals ( moduleId )) continue ;
108+ if (moduleId .length () < 3 || moduleId .indexOf ('\0' ) != -1 || moduleId . indexOf ( ' ' ) != - 1 || "ak3-helper" . equals ( moduleId ))
109+ continue ;
109110 long moduleLastUpdate = module .getLong ("last_update" );
110111 String moduleNotesUrl = module .getString ("notes_url" );
111112 String modulePropsUrl = module .getString ("prop_url" );
@@ -119,8 +120,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
119120 this .moduleHashMap .put (moduleId , repoModule );
120121 newModules .add (repoModule );
121122 } else {
122- if (repoModule .lastUpdated < moduleLastUpdate ||
123- repoModule .moduleInfo .hasFlag (ModuleInfo .FLAG_METADATA_INVALID )) {
123+ if (repoModule .lastUpdated < moduleLastUpdate || repoModule .moduleInfo .hasFlag (ModuleInfo .FLAG_METADATA_INVALID )) {
124124 newModules .add (repoModule );
125125 }
126126 }
@@ -135,12 +135,16 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
135135 try {
136136 repoModule .qualityValue = Integer .parseInt (moduleStars );
137137 repoModule .qualityText = R .string .module_stars ;
138- } catch (NumberFormatException ignored ) {}
138+ } catch (
139+ NumberFormatException ignored ) {
140+ }
139141 } else if (!moduleDownloads .isEmpty ()) {
140142 try {
141143 repoModule .qualityValue = Integer .parseInt (moduleDownloads );
142144 repoModule .qualityText = R .string .module_downloads ;
143- } catch (NumberFormatException ignored ) {}
145+ } catch (
146+ NumberFormatException ignored ) {
147+ }
144148 }
145149 }
146150 // Remove no longer existing modules
@@ -173,7 +177,7 @@ public boolean isEnabledByDefault() {
173177 return BuildConfig .ENABLED_REPOS .contains (this .id );
174178 }
175179
176- public void storeMetadata (RepoModule repoModule ,byte [] data ) throws IOException {
180+ public void storeMetadata (RepoModule repoModule , byte [] data ) throws IOException {
177181 Files .write (new File (this .cacheRoot , repoModule .id + ".prop" ), data );
178182 }
179183
@@ -182,14 +186,14 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
182186 if (file .exists ()) {
183187 try {
184188 ModuleInfo moduleInfo = repoModule .moduleInfo ;
185- PropUtils .readProperties (moduleInfo , file .getAbsolutePath (),
186- repoModule .repoName + "/" + moduleInfo .name , false );
189+ PropUtils .readProperties (moduleInfo , file .getAbsolutePath (), repoModule .repoName + "/" + moduleInfo .name , false );
187190 moduleInfo .flags &= ~ModuleInfo .FLAG_METADATA_INVALID ;
188191 if (moduleInfo .version == null ) {
189192 moduleInfo .version = "v" + moduleInfo .versionCode ;
190193 }
191194 return true ;
192- } catch (Exception ignored ) {
195+ } catch (
196+ Exception ignored ) {
193197 boolean delete = file .delete ();
194198 if (!delete ) {
195199 throw new RuntimeException ("Failed to delete invalid metadata file" );
@@ -202,18 +206,24 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
202206
203207 @ Override
204208 public boolean isEnabled () {
209+ SharedPreferences preferenceManager = MainApplication .getSharedPreferences ();
210+ boolean enabled = preferenceManager .getBoolean ("pref_" + this .id + "_enabled" , this .isEnabledByDefault ());
211+ if (this .enabled != enabled ) {
212+ if (BuildConfig .DEBUG ) {
213+ Log .d ("NoodleDebug" , "Repo " + this .id + " enable mismatch: " + this .enabled + " vs " + enabled );
214+ }
215+ this .enabled = enabled ;
216+ }
205217 return this .enabled ;
206218 }
207219
208220 @ Override
209221 public void setEnabled (boolean enabled ) {
210222 this .enabled = enabled && !this .forceHide ;
211223 if (BuildConfig .DEBUG ) {
212- Log .i ("RepoData" ,
213- "Repo " + this .id + " enabled: " + this .enabled + " (forced: " + this .forceHide + ") with preferenceID: " + this .getPreferenceId ());
224+ Log .i ("RepoData" , "Repo " + this .id + " enabled: " + this .enabled + " (forced: " + this .forceHide + ") with preferenceID: " + this .getPreferenceId ());
214225 }
215- MainApplication .getSharedPreferences ().edit ()
216- .putBoolean ("pref_" + this .getPreferenceId () + "_enabled" , enabled ).apply ();
226+ MainApplication .getSharedPreferences ().edit ().putBoolean ("pref_" + this .getPreferenceId () + "_enabled" , enabled ).apply ();
217227 }
218228
219229 public void updateEnabledState () {
@@ -223,11 +233,9 @@ public void updateEnabledState() {
223233 }
224234 this .forceHide = AppUpdateManager .shouldForceHide (this .id );
225235 if (BuildConfig .DEBUG ) {
226- Log .i ("RepoData" ,
227- "Repo " + this .id + " update enabled: " + this .enabled + " (forced: " + this .forceHide + ") with preferenceID: " + this .getPreferenceId ());
236+ Log .i ("RepoData" , "Repo " + this .id + " update enabled: " + this .enabled + " (forced: " + this .forceHide + ") with preferenceID: " + this .getPreferenceId ());
228237 }
229- this .enabled = (!this .forceHide ) && MainApplication .getSharedPreferences ()
230- .getBoolean ("pref_" + this .getPreferenceId () + "_enabled" , true );
238+ this .enabled = (!this .forceHide ) && MainApplication .getSharedPreferences ().getBoolean ("pref_" + this .getPreferenceId () + "_enabled" , true );
231239 }
232240
233241 public String getUrl () throws NoSuchAlgorithmException {
@@ -238,10 +246,6 @@ public String getPreferenceId() {
238246 return this .id ;
239247 }
240248
241- private static boolean isNonNull (String str ) {
242- return str != null && !str .isEmpty () && !"null" .equals (str );
243- }
244-
245249 // Repo data info getters
246250 @ NonNull
247251 @ Override
0 commit comments