Fix on UST set for Android Downloader and fix on StopDownload action.

This commit is contained in:
valfieri
2019-08-26 19:30:58 +02:00
parent 683b2fbed8
commit ef4b18b394
2 changed files with 230 additions and 208 deletions

View File

@@ -28,6 +28,7 @@ import java.util.stream.Stream;
import android.graphics.*; import android.graphics.*;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import org.libsdl.app.SDLActivity;
public class ImgDownloader { public class ImgDownloader {
@@ -643,7 +644,7 @@ public class ImgDownloader {
throw new Exception(); throw new Exception();
} }
public static String DownloadCardImages(String set, String[] availableSets, String targetres, String basePath, String destinationPath, ProgressDialog progressBarDialog) throws IOException { public static String DownloadCardImages(String set, String[] availableSets, String targetres, String basePath, String destinationPath, ProgressDialog progressBarDialog, SDLActivity parent) throws IOException {
String res = ""; String res = "";
String baseurl = "https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid="; String baseurl = "https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=";
@@ -837,7 +838,7 @@ public class ImgDownloader {
else if (scryset.equalsIgnoreCase("ZVE")) else if (scryset.equalsIgnoreCase("ZVE"))
scryset = "DDP"; scryset = "DDP";
for (int y = 0; y < mappa.size(); y++) { for (int y = 0; y < mappa.size() && parent.downloadInProgress; y++) {
String id = mappa.keySet().toArray()[y].toString(); String id = mappa.keySet().toArray()[y].toString();
progressBarDialog.incrementProgressBy((int) (1)); progressBarDialog.incrementProgressBy((int) (1));
String specialcardurl = getSpecialCardUrl(id); String specialcardurl = getSpecialCardUrl(id);
@@ -940,7 +941,14 @@ public class ImgDownloader {
} }
String cardname = divs.get(k + 1).childNode(0).attributes().get("#text").replace("\r\n", "").trim(); String cardname = divs.get(k + 1).childNode(0).attributes().get("#text").replace("\r\n", "").trim();
if(scryset.equals("S00") || scryset.equals("UST")){ if (scryset.equals("UST") || scryset.equals("S00")) {
cardname = cardname.replace(" (a)", "");
cardname = cardname.replace(" (b)", "");
cardname = cardname.replace(" (c)", "");
cardname = cardname.replace(" (d)", "");
cardname = cardname.replace(" (e)", "");
cardname = cardname.replace(" (f)", "");
cardname = cardname.replace("...", "");
String deckutrl = "https://deckmaster.info/card.php?multiverseid="; String deckutrl = "https://deckmaster.info/card.php?multiverseid=";
try { try {
doc = Jsoup.connect(deckutrl + id).get(); doc = Jsoup.connect(deckutrl + id).get();

View File

@@ -476,7 +476,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
cardDownloader.create().show(); cardDownloader.create().show();
} }
String targetRes = ""; String targetRes = "High";
private void chooseResolution() { private void chooseResolution() {
AlertDialog.Builder resChooser = new AlertDialog.Builder(this); AlertDialog.Builder resChooser = new AlertDialog.Builder(this);
@@ -492,10 +492,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
resChooser.setPositiveButton("Download Selected", new DialogInterface.OnClickListener() { resChooser.setPositiveButton("Download Selected", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (!targetRes.isEmpty())
downloadCardImagesStart(); downloadCardImagesStart();
else
chooseResolution();
} }
}); });
@@ -504,10 +501,11 @@ public class SDLActivity extends Activity implements OnKeyListener {
boolean error = false; boolean error = false;
String res = ""; String res = "";
boolean dowloadInProgress = false; public volatile boolean downloadInProgress = false;
ProgressDialog cardDownloader; ProgressDialog cardDownloader;
private void downloadCardImagesStart() { private void downloadCardImagesStart() {
final SDLActivity parent = this;
final Handler mHandler = new Handler(); final Handler mHandler = new Handler();
cardDownloader = new ProgressDialog(this); cardDownloader = new ProgressDialog(this);
cardDownloader.setTitle("Downloading now set: " + set); cardDownloader.setTitle("Downloading now set: " + set);
@@ -520,7 +518,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
dowloadInProgress = true; downloadInProgress = true;
if (selectedSets != null) { if (selectedSets != null) {
for (int i = 0; i < selectedSets.size(); i++) { for (int i = 0; i < selectedSets.size(); i++) {
try { try {
@@ -530,7 +528,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
cardDownloader.setTitle("Downloading set: " + set); cardDownloader.setTitle("Downloading set: " + set);
} }
}); });
String details = ImgDownloader.DownloadCardImages(set, availableSets, targetRes, getSystemStorageLocation(), getUserStorageLocation() + "sets/", cardDownloader); String details = ImgDownloader.DownloadCardImages(set, availableSets, targetRes, getSystemStorageLocation(), getUserStorageLocation() + "sets/", cardDownloader, parent);
if (!details.isEmpty()) { if (!details.isEmpty()) {
if (!res.isEmpty()) if (!res.isEmpty())
res = res + "\nSET " + set + ":\n" + details; res = res + "\nSET " + set + ":\n" + details;
@@ -544,8 +542,10 @@ public class SDLActivity extends Activity implements OnKeyListener {
} }
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
public void run() { public void run() {
if (downloadInProgress) {
downloadSelectedSetsCompleted(error, res); downloadSelectedSetsCompleted(error, res);
dowloadInProgress = false; downloadInProgress = false;
}
cardDownloader.dismiss(); cardDownloader.dismiss();
} }
}); });
@@ -564,7 +564,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
public void run() { public void run() {
downloadCardInterruped(set, cardDownloader.getProgress(), cardDownloader.getMax()); downloadCardInterruped(set, cardDownloader.getProgress(), cardDownloader.getMax());
dowloadInProgress = false; downloadInProgress = false;
cardDownloader.dismiss(); cardDownloader.dismiss();
} }
}); });
@@ -585,6 +585,15 @@ public class SDLActivity extends Activity implements OnKeyListener {
} }
}); });
res = "";
set = "";
targetRes = "High";
selectedSets = new ArrayList<String>();
for (int i = 0; i < checkedSet.length; i++) {
checkedSet[i] = false;
}
error = false;
infoDialog.create().show(); infoDialog.create().show();
} }
@@ -598,12 +607,17 @@ public class SDLActivity extends Activity implements OnKeyListener {
infoDialog.setTitle("Some errors occurred during the process!"); infoDialog.setTitle("Some errors occurred during the process!");
infoDialog.setMessage(res); infoDialog.setMessage(res);
} }
infoDialog.create().show();
res = ""; res = "";
set = ""; set = "";
targetRes = ""; targetRes = "High";
selectedSets = new ArrayList<String>(); selectedSets = new ArrayList<String>();
for (int i = 0; i < checkedSet.length; i++) {
checkedSet[i] = false;
}
error = false; error = false;
infoDialog.create().show();
} }
@Override @Override
@@ -632,7 +646,7 @@ public class SDLActivity extends Activity implements OnKeyListener {
if (loadResInProgress) { if (loadResInProgress) {
progressBarDialogRes.show(); progressBarDialogRes.show();
progressBarDialogRes.show(); progressBarDialogRes.show();
} else if (dowloadInProgress) { } else if (downloadInProgress) {
cardDownloader.show(); cardDownloader.show();
cardDownloader.show(); cardDownloader.show();
} else } else