Improved Android Downloader and added the multiple set selection in the download option menu.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@ import net.wagic.utils.DeckImporter;
|
|||||||
import net.wagic.utils.ImgDownloader;
|
import net.wagic.utils.ImgDownloader;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -360,6 +361,8 @@ public class SDLActivity extends Activity implements OnKeyListener {
|
|||||||
|
|
||||||
String set = "";
|
String set = "";
|
||||||
String[] availableSets;
|
String[] availableSets;
|
||||||
|
ArrayList<String> selectedSets;
|
||||||
|
boolean[] checkedSet;
|
||||||
Integer totalset = 0;
|
Integer totalset = 0;
|
||||||
boolean finished = false;
|
boolean finished = false;
|
||||||
boolean loadResInProgress = false;
|
boolean loadResInProgress = false;
|
||||||
@@ -404,11 +407,12 @@ public class SDLActivity extends Activity implements OnKeyListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
availableSets = new String[sets.size() + 1];
|
availableSets = new String[sets.size()];
|
||||||
availableSets[0] = "*.* - All Wagic sets (thousands of cards)";
|
checkedSet = new boolean[sets.size()];
|
||||||
progressBarDialogRes.setMax(sets.size());
|
progressBarDialogRes.setMax(sets.size());
|
||||||
for (int i = 1; i < availableSets.length; i++) {
|
for (int i = 0; i < availableSets.length; i++) {
|
||||||
availableSets[i] = sets.get(i - 1) + " - " + ImgDownloader.getSetInfo(sets.get(i - 1), true, getSystemStorageLocation());
|
availableSets[i] = sets.get(i) + " - " + ImgDownloader.getSetInfo(sets.get(i), true, getSystemStorageLocation());
|
||||||
|
checkedSet[i] = false;
|
||||||
progressBarDialogRes.incrementProgressBy((int) (1));
|
progressBarDialogRes.incrementProgressBy((int) (1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,20 +441,38 @@ 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 Sets would you like to download?");
|
||||||
|
selectedSets = new ArrayList<String>();
|
||||||
|
|
||||||
cardDownloader.setSingleChoiceItems(availableSets, -1, new DialogInterface.OnClickListener() {
|
cardDownloader.setMultiChoiceItems(availableSets, checkedSet, new DialogInterface.OnMultiChoiceClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int item) {
|
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||||
set = availableSets[item].split(" - ")[0];
|
checkedSet[which] = isChecked;
|
||||||
|
if (checkedSet[which])
|
||||||
|
selectedSets.add(availableSets[which].split(" - ")[0]);
|
||||||
|
else
|
||||||
|
selectedSets.remove(availableSets[which].split(" - ")[0]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cardDownloader.setPositiveButton("Confirm Selection", new DialogInterface.OnClickListener() {
|
cardDownloader.setNeutralButton("Download All", new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
selectedSets.clear();
|
||||||
|
for (int i = 0; i < availableSets.length; i++) {
|
||||||
|
selectedSets.add(availableSets[i].split(" - ")[0]);
|
||||||
|
}
|
||||||
downloadCardImagesStart();
|
downloadCardImagesStart();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cardDownloader.setPositiveButton("Download Selected", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if (selectedSets.size() > 0)
|
||||||
|
downloadCardImagesStart();
|
||||||
|
else
|
||||||
|
downloadCardImages();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
cardDownloader.create().show();
|
cardDownloader.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,27 +484,46 @@ public class SDLActivity extends Activity implements OnKeyListener {
|
|||||||
private void downloadCardImagesStart() {
|
private void downloadCardImagesStart() {
|
||||||
final Handler mHandler = new Handler();
|
final Handler mHandler = new Handler();
|
||||||
cardDownloader = new ProgressDialog(this);
|
cardDownloader = new ProgressDialog(this);
|
||||||
cardDownloader.setTitle("Downloading set: " + set);
|
cardDownloader.setTitle("Downloading now set: " + set);
|
||||||
cardDownloader.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
cardDownloader.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
cardDownloader.setProgress(0);
|
cardDownloader.setProgress(0);
|
||||||
cardDownloader.setMessage("Don't turn off phone or wi-fi/data connection and don't quit Wagic. The download could take several minutes, but you can hide this window and continue to play, a pop-up will notify the completion of process.");
|
if (selectedSets.size() == 1)
|
||||||
|
cardDownloader.setMessage("You choose to download just 1 set: Please don't quit Wagic or turn off Internet connection, you can hide this window and continue to play, a pop-up will notify the completion of download process.");
|
||||||
|
else
|
||||||
|
cardDownloader.setMessage("You choose to download " + selectedSets.size() + " sets: Please don't quit Wagic or turn off Internet connection, you can hide this window and continue to play, a pop-up will notify the completion of download process.");
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
dowloadInProgress = true;
|
||||||
dowloadInProgress = true;
|
if (selectedSets != null) {
|
||||||
res = ImgDownloader.DownloadCardImages(set, availableSets, "HI", getSystemStorageLocation(), getUserStorageLocation() + "sets/", cardDownloader);
|
for (int i = 0; i < selectedSets.size(); i++) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
res = e.getMessage();
|
set = selectedSets.get(i);
|
||||||
error = true;
|
mHandler.post(new Runnable() {
|
||||||
}
|
public void run() {
|
||||||
mHandler.post(new Runnable() {
|
cardDownloader.setTitle("Downloading set: " + set);
|
||||||
public void run() {
|
}
|
||||||
downloadCardCompleted(error, res, set);
|
});
|
||||||
dowloadInProgress = false;
|
String details = ImgDownloader.DownloadCardImages(set, availableSets, "High", getSystemStorageLocation(), getUserStorageLocation() + "sets/", cardDownloader);
|
||||||
cardDownloader.dismiss();
|
if (!details.isEmpty()) {
|
||||||
|
if (!res.isEmpty())
|
||||||
|
res = res + "\nSET " + set + ":\n" + details;
|
||||||
|
else
|
||||||
|
res = "SET " + set + ":\n" + details;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
res = res + "\n" + e.getMessage();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
mHandler.post(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
downloadSelectedSetsCompleted(error, res);
|
||||||
|
dowloadInProgress = false;
|
||||||
|
cardDownloader.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@@ -521,19 +562,21 @@ public class SDLActivity extends Activity implements OnKeyListener {
|
|||||||
infoDialog.create().show();
|
infoDialog.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadCardCompleted(boolean error, String res, String set) {
|
private void downloadSelectedSetsCompleted(boolean error, String res) {
|
||||||
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("The download process has completed without any error");
|
||||||
if (!res.isEmpty())
|
if (!res.isEmpty())
|
||||||
infoDialog.setMessage("Warning: Following cards could not be downloaded:\n" + res);
|
infoDialog.setMessage("Following cards could not be downloaded:\n" + res);
|
||||||
else
|
|
||||||
infoDialog.setMessage("All the cards have been successfully downloaded");
|
|
||||||
} else {
|
} else {
|
||||||
infoDialog.setTitle("Error downloading: " + set + ", please try again...");
|
infoDialog.setTitle("Some errors occurred during the process!");
|
||||||
infoDialog.setMessage(res);
|
infoDialog.setMessage(res);
|
||||||
}
|
}
|
||||||
infoDialog.create().show();
|
infoDialog.create().show();
|
||||||
|
res = "";
|
||||||
|
set = "";
|
||||||
|
selectedSets = new ArrayList<String>();
|
||||||
|
error = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user