diff --git a/app/src/main/java/com/cringe_studios/code_guard/MainActivity.java b/app/src/main/java/com/cringe_studios/code_guard/MainActivity.java index e6860a5..9076092 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/MainActivity.java +++ b/app/src/main/java/com/cringe_studios/code_guard/MainActivity.java @@ -60,7 +60,7 @@ public class MainActivity extends BaseActivity { private Consumer pickBackupFileLoadCallback; - private ActivityResultLauncher pickIconPackFileLoad; + private ActivityResultLauncher pickIconPackFile; private ActivityResultLauncher pickIconImage; @@ -141,12 +141,23 @@ public class MainActivity extends BaseActivity { } }); - pickIconPackFileLoad = registerForActivityResult(new ActivityResultContracts.OpenDocument(), doc -> { + pickIconPackFile = registerForActivityResult(new ActivityResultContracts.OpenDocument(), doc -> { lockOnStop = true; try { if(doc == null) return; - IconPackMetadata meta = IconUtil.importIconPack(this, doc); // TODO: check if pack contains icons + IconPackMetadata meta = IconUtil.importIconPack(this, doc); + + if(!meta.validate()) { + DialogUtil.showErrorDialog(this, getString(R.string.error_icon_pack_invalid)); + return; + } + + if(meta.getIcons().length == 0) { + DialogUtil.showErrorDialog(this, getString(R.string.error_icon_pack_empty)); + return; + } + DialogUtil.showErrorDialog(this, "Icon pack contains " + meta.getIcons().length + " icons"); } catch (IconPackException e) { DialogUtil.showErrorDialog(this, "Failed to import icon pack", e); @@ -250,7 +261,10 @@ public class MainActivity extends BaseActivity { if(!(fragment instanceof HomeFragment)) { NavigationUtil.navigate(this, HomeFragment.class, null); + return; } + + finishAffinity(); } public void openSettings(MenuItem item) { @@ -392,9 +406,9 @@ public class MainActivity extends BaseActivity { pickBackupFileLoad.launch(new String[]{"application/json", "*/*"}); } - public void promptPickIconPackLoad() { + public void promptPickIconPackFile() { this.lockOnStop = false; - pickIconPackFileLoad.launch(new String[]{"application/zip", "*/*"}); + pickIconPackFile.launch(new String[]{"application/zip", "*/*"}); } public void promptPickIconImage(Consumer callback) { diff --git a/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java b/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java index a8d3808..c6976bc 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java +++ b/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java @@ -261,7 +261,7 @@ public class SettingsFragment extends NamedFragment { }); }); - binding.settingsLoadIconPack.setOnClickListener(v -> ((MainActivity) requireActivity()).promptPickIconPackLoad()); + binding.settingsLoadIconPack.setOnClickListener(v -> ((MainActivity) requireActivity()).promptPickIconPackFile()); binding.settingsManageIconPacks.setOnClickListener(v -> { List packs = IconUtil.loadAllIconPacks(requireContext()); diff --git a/app/src/main/java/com/cringe_studios/code_guard/icon/IconMetadata.java b/app/src/main/java/com/cringe_studios/code_guard/icon/IconMetadata.java index faaaaa3..1144898 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/icon/IconMetadata.java +++ b/app/src/main/java/com/cringe_studios/code_guard/icon/IconMetadata.java @@ -30,4 +30,9 @@ public class IconMetadata { public String[] getIssuer() { return issuer; } + + public boolean validate() { + return filename != null && category != null && issuer != null; + } + } diff --git a/app/src/main/java/com/cringe_studios/code_guard/icon/IconPackMetadata.java b/app/src/main/java/com/cringe_studios/code_guard/icon/IconPackMetadata.java index 02a64fe..74cf4e8 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/icon/IconPackMetadata.java +++ b/app/src/main/java/com/cringe_studios/code_guard/icon/IconPackMetadata.java @@ -24,4 +24,15 @@ public class IconPackMetadata { public IconMetadata[] getIcons() { return icons; } + + public boolean validate() { + if(uuid == null || name == null || icons == null) return false; + + for(IconMetadata i : icons) { + if(!i.validate()) return false; + } + + return true; + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c5dfa7c..47c7227 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -121,4 +121,6 @@ https://git.cringe-studios.com/CringeStudios/Code-Guard https://git.cringe-studios.com/CringeStudios/Code-Guard https://git.cringe-studios.com/CringeStudios/Code-Guard + The icon pack doesn\'t contain any icons + Pack contains invalid metadata. Make sure you selected the correct file \ No newline at end of file