Improved Downloader and Option Menu handlers.
This commit is contained in:
@@ -228,6 +228,8 @@ public class ImgDownloader {
|
|||||||
tokenurl = "https://img.scryfall.com/cards/large/back/8/c/8ce60642-e207-46e6-b198-d803ff3b47f4.jpg?1562921132";
|
tokenurl = "https://img.scryfall.com/cards/large/back/8/c/8ce60642-e207-46e6-b198-d803ff3b47f4.jpg?1562921132";
|
||||||
else if(id.equals("265141t"))
|
else if(id.equals("265141t"))
|
||||||
tokenurl = "https://media.mtgsalvation.com/attachments/102/31/635032498723573408.jpg";
|
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;
|
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("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("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("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 false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 set = "";
|
||||||
String[] availableSets;
|
String[] availableSets;
|
||||||
Integer totalset = 0;
|
Integer totalset = 0;
|
||||||
@@ -365,48 +380,63 @@ public class SDLActivity extends Activity implements OnKeyListener {
|
|||||||
private void downloadCardImages() {
|
private void downloadCardImages() {
|
||||||
AlertDialog.Builder cardDownloader = new AlertDialog.Builder(this);
|
AlertDialog.Builder cardDownloader = new AlertDialog.Builder(this);
|
||||||
cardDownloader.setTitle("Which Set would you like to download?");
|
cardDownloader.setTitle("Which Set would you like to download?");
|
||||||
|
|
||||||
File baseFolder = new File(getSystemStorageLocation());
|
|
||||||
File[] listOfFiles = baseFolder.listFiles();
|
|
||||||
ArrayList<String> sets = new ArrayList<String>();
|
ArrayList<String> sets = new ArrayList<String>();
|
||||||
ZipFile zipFile = null;
|
if (availableSets == null) {
|
||||||
try {
|
File baseFolder = new File(getSystemStorageLocation());
|
||||||
zipFile = new ZipFile(baseFolder + "/" + listOfFiles[0].getName());
|
File[] listOfFiles = baseFolder.listFiles();
|
||||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
ZipFile zipFile = null;
|
||||||
while (e.hasMoreElements()) {
|
try {
|
||||||
ZipEntry entry = e.nextElement();
|
zipFile = new ZipFile(baseFolder + "/" + listOfFiles[0].getName());
|
||||||
String entryName = entry.getName();
|
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||||
if (entryName.contains("sets/")) {
|
while (e.hasMoreElements()) {
|
||||||
if (!entryName.equalsIgnoreCase("sets/") && !entryName.contains("primitives") && !entryName.contains(".")) {
|
ZipEntry entry = e.nextElement();
|
||||||
String[] names = entryName.split("/");
|
String entryName = entry.getName();
|
||||||
sets.add(names[1]);
|
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) {
|
} 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 = new String[sets.size() + 1];
|
||||||
availableSets[0] = "*.* - All Wagic sets (thousands of cards)";
|
availableSets[0] = "*.* - All Wagic sets (thousands of cards)";
|
||||||
for (int i = 1; i < availableSets.length; i++) {
|
for (int i = 1; i < availableSets.length; i++) {
|
||||||
availableSets[i] = sets.get(i - 1) + " - " + ImgDownloader.getSetInfo(sets.get(i - 1), true, getSystemStorageLocation());
|
availableSets[i] = sets.get(i - 1) + " - " + ImgDownloader.getSetInfo(sets.get(i - 1), true, getSystemStorageLocation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cardDownloader.setSingleChoiceItems(availableSets, -1, new DialogInterface.OnClickListener() {
|
cardDownloader.setSingleChoiceItems(availableSets, -1, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int item) {
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
set = availableSets[item].split(" - ")[0];
|
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() {
|
cardDownloader.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
boolean error = false;
|
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();
|
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) {
|
private void downloadCardCompleted(boolean error, String res, String set) {
|
||||||
AlertDialog.Builder infoDialog = new AlertDialog.Builder(this);
|
AlertDialog.Builder infoDialog = new AlertDialog.Builder(this);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
infoDialog.setTitle("Download Completed: " + set);
|
infoDialog.setTitle("Download Completed: " + set);
|
||||||
if (!res.isEmpty())
|
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
|
else
|
||||||
infoDialog.setMessage("All the cards have been successfully downloaded");
|
infoDialog.setMessage("All the cards have been successfully downloaded");
|
||||||
} else {
|
} else {
|
||||||
infoDialog.setTitle("Error downloading: " + set);
|
infoDialog.setTitle("Error downloading: " + set + ", please try again...");
|
||||||
infoDialog.setMessage(res);
|
infoDialog.setMessage(res);
|
||||||
}
|
}
|
||||||
infoDialog.create().show();
|
infoDialog.create().show();
|
||||||
@@ -467,7 +495,10 @@ public class SDLActivity extends Activity implements OnKeyListener {
|
|||||||
} else if (itemId == 2) {
|
} else if (itemId == 2) {
|
||||||
importDeckOptions();
|
importDeckOptions();
|
||||||
} else if (itemId == 3) {
|
} else if (itemId == 3) {
|
||||||
downloadCardImages();
|
if (availableSets == null)
|
||||||
|
downloadCardInfo();
|
||||||
|
else
|
||||||
|
downloadCardImages();
|
||||||
} else if (itemId == 4) {
|
} else if (itemId == 4) {
|
||||||
// display some info about the app
|
// display some info about the app
|
||||||
AlertDialog.Builder infoDialog = new AlertDialog.Builder(this);
|
AlertDialog.Builder infoDialog = new AlertDialog.Builder(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user