From a5c9f877f7e129ca97101cd9604de739d5dbfcd5 Mon Sep 17 00:00:00 2001 From: valfieri Date: Sun, 25 Aug 2019 00:52:05 +0200 Subject: [PATCH] Improved Downloader and Option Menu handlers. --- .../src/net/wagic/utils/ImgDownloader.java | 4 +- .../src/org/libsdl/app/SDLActivity.java | 111 +++++++++++------- 2 files changed, 74 insertions(+), 41 deletions(-) diff --git a/projects/mtg/Android/src/net/wagic/utils/ImgDownloader.java b/projects/mtg/Android/src/net/wagic/utils/ImgDownloader.java index 1ef21e282..2258a2551 100644 --- a/projects/mtg/Android/src/net/wagic/utils/ImgDownloader.java +++ b/projects/mtg/Android/src/net/wagic/utils/ImgDownloader.java @@ -228,6 +228,8 @@ public class ImgDownloader { tokenurl = "https://img.scryfall.com/cards/large/back/8/c/8ce60642-e207-46e6-b198-d803ff3b47f4.jpg?1562921132"; else if(id.equals("265141t")) tokenurl = "https://media.mtgsalvation.com/attachments/102/31/635032498723573408.jpg"; + else if(id.equals("24624t")) + tokenurl = "https://www.mtg.onl/static/6d717cba653ea9e3f6bd1419741671cb/4d406/PROXY_Minion_B_1_1.jpg"; return tokenurl; } @@ -236,7 +238,7 @@ public class ImgDownloader { id.equals("417759") || id.equals("386476") || id.equals("456371") || id.equals("456360") || id.equals("391958") || id.equals("466959") || id.equals("466813") || id.equals("201176") || id.equals("202483") || id.equals("3546") || id.equals("425949") || id.equals("426027") || id.equals("425853") || id.equals("425846") || id.equals("426036") || id.equals("370387") || id.equals("29955") || id.equals("29989") || - id.equals("19741") || id.equals("19722") || id.equals("19706") || id.equals("24597") || id.equals("24617")) + id.equals("19741") || id.equals("19722") || id.equals("19706") || id.equals("24597") || id.equals("24617") || id.equals("24563")) return false; return true; } diff --git a/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java b/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java index 991757db9..d203341b5 100644 --- a/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java +++ b/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java @@ -358,6 +358,21 @@ public class SDLActivity extends Activity implements OnKeyListener { } } + private void downloadCardInfo() { + AlertDialog.Builder cardDownloader = new AlertDialog.Builder(this); + cardDownloader.setTitle("Image Downloader"); + + cardDownloader.setMessage("IMPORTANT: After you press OK you may have to wait a bit while Downloader will evaluate all the sets available in this game version."); + + cardDownloader.setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + downloadCardImages(); + } + }); + + cardDownloader.create().show(); + } + String set = ""; String[] availableSets; Integer totalset = 0; @@ -365,48 +380,63 @@ public class SDLActivity extends Activity implements OnKeyListener { private void downloadCardImages() { AlertDialog.Builder cardDownloader = new AlertDialog.Builder(this); cardDownloader.setTitle("Which Set would you like to download?"); - - File baseFolder = new File(getSystemStorageLocation()); - File[] listOfFiles = baseFolder.listFiles(); ArrayList sets = new ArrayList(); - ZipFile zipFile = null; - try { - zipFile = new ZipFile(baseFolder + "/" + listOfFiles[0].getName()); - Enumeration e = zipFile.entries(); - while (e.hasMoreElements()) { - ZipEntry entry = e.nextElement(); - String entryName = entry.getName(); - if (entryName.contains("sets/")) { - if (!entryName.equalsIgnoreCase("sets/") && !entryName.contains("primitives") && !entryName.contains(".")) { - String[] names = entryName.split("/"); - sets.add(names[1]); + if (availableSets == null) { + File baseFolder = new File(getSystemStorageLocation()); + File[] listOfFiles = baseFolder.listFiles(); + ZipFile zipFile = null; + try { + zipFile = new ZipFile(baseFolder + "/" + listOfFiles[0].getName()); + Enumeration e = zipFile.entries(); + while (e.hasMoreElements()) { + ZipEntry entry = e.nextElement(); + String entryName = entry.getName(); + if (entryName != null && entryName.contains("sets/")) { + if (!entryName.equalsIgnoreCase("sets/") && !entryName.contains("primitives") && !entryName.contains(".")) { + String[] names = entryName.split("/"); + sets.add(names[1]); + } } } - } - } catch (IOException ioe) { - System.out.println("Error opening zip file" + ioe); - } finally { - try { - if (zipFile != null) { - zipFile.close(); - } } catch (IOException ioe) { - System.out.println("Error while closing zip file" + ioe); + System.out.println("Error opening zip file" + ioe); + } finally { + try { + if (zipFile != null) { + zipFile.close(); + } + } catch (IOException ioe) { + System.out.println("Error while closing zip file" + ioe); + } } - } - availableSets = new String[sets.size() + 1]; - availableSets[0] = "*.* - All Wagic sets (thousands of cards)"; - for (int i = 1; i < availableSets.length; i++) { - availableSets[i] = sets.get(i - 1) + " - " + ImgDownloader.getSetInfo(sets.get(i - 1), true, getSystemStorageLocation()); + availableSets = new String[sets.size() + 1]; + availableSets[0] = "*.* - All Wagic sets (thousands of cards)"; + for (int i = 1; i < availableSets.length; i++) { + availableSets[i] = sets.get(i - 1) + " - " + ImgDownloader.getSetInfo(sets.get(i - 1), true, getSystemStorageLocation()); + } } cardDownloader.setSingleChoiceItems(availableSets, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { set = availableSets[item].split(" - ")[0]; - downloadCardStarting(set); } }); + cardDownloader.setPositiveButton("Confirm Selection", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + downloadCardImagesStart(); + } + }); + + cardDownloader.create().show(); + } + + private void downloadCardImagesStart() { + AlertDialog.Builder cardDownloader = new AlertDialog.Builder(this); + cardDownloader.setTitle("Download of: " + set); + + cardDownloader.setMessage("IMPORTANT: After you press OK don't turn off phone or wi-fi/data connection and don't close Wagic.\nThe download process can take several minutes according to the number of images contained in the selected set.\nNOTE: if you choose *.* you may have to wait several hours!!!"); + cardDownloader.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean error = false; @@ -421,27 +451,25 @@ public class SDLActivity extends Activity implements OnKeyListener { } }); + cardDownloader.setNegativeButton("Back", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + downloadCardImages(); + } + }); + cardDownloader.create().show(); } - private void downloadCardStarting(String set) { - AlertDialog.Builder infoDialog = new AlertDialog.Builder(this); - infoDialog.setTitle("You choose to Download: " + set); - infoDialog.setMessage("After you press OK don't turn off phone or wi-fi/data connection and don't close Wagic.\nThe download process can take several minutes according to the number of images contained in the selected set (NOTE: if you choose *.* you will have to wait several hours!!!)"); - infoDialog.create().show(); - } - - private void downloadCardCompleted(boolean error, String res, String set) { AlertDialog.Builder infoDialog = new AlertDialog.Builder(this); if (!error) { infoDialog.setTitle("Download Completed: " + set); if (!res.isEmpty()) - infoDialog.setMessage("Following cards could not be downloaded:\n" + res); + infoDialog.setMessage("Warning: Following cards could not be downloaded:\n" + res); else infoDialog.setMessage("All the cards have been successfully downloaded"); } else { - infoDialog.setTitle("Error downloading: " + set); + infoDialog.setTitle("Error downloading: " + set + ", please try again..."); infoDialog.setMessage(res); } infoDialog.create().show(); @@ -467,7 +495,10 @@ public class SDLActivity extends Activity implements OnKeyListener { } else if (itemId == 2) { importDeckOptions(); } else if (itemId == 3) { - downloadCardImages(); + if (availableSets == null) + downloadCardInfo(); + else + downloadCardImages(); } else if (itemId == 4) { // display some info about the app AlertDialog.Builder infoDialog = new AlertDialog.Builder(this);