GUI: fixed wrong options in download images dialog for some sources

This commit is contained in:
Oleg Agafonov 2020-08-29 18:07:14 +04:00
parent f819340297
commit c67e937dfb
11 changed files with 85 additions and 39 deletions

View file

@ -151,7 +151,18 @@ public enum AltMtgOnlTokensImageSource implements CardImageSource {
return true; return true;
} }
@Override
public boolean isCardSource() {
return false;
}
@Override @Override
public void doPause(String httpImageUrl) { public void doPause(String httpImageUrl) {
} }
@Override
public boolean isCardImageProvided(String setCode, String cardName) {
// no cards support, only tokens
return false;
}
} }

View file

@ -32,9 +32,9 @@ public interface CardImageSource {
return 0; return 0;
} }
default boolean isTokenSource() { boolean isCardSource();
return false;
} boolean isTokenSource();
default boolean isLanguagesSupport() { default boolean isLanguagesSupport() {
return false; return false;
@ -53,13 +53,8 @@ public interface CardImageSource {
return new ArrayList<>(); return new ArrayList<>();
} }
default boolean isSetSupportedComplete(String setCode) {
return true;
}
default boolean isCardImageProvided(String setCode, String cardName) { boolean isCardImageProvided(String setCode, String cardName);
return false;
}
default boolean isTokenImageProvided(String setCode, String cardName, Integer tokenNumber) { default boolean isTokenImageProvided(String setCode, String cardName, Integer tokenNumber) {
return false; return false;

View file

@ -21,8 +21,8 @@ public enum CopyPasteImageSource implements CardImageSource {
instance; instance;
private Set<String> supportedSets = new LinkedHashSet<String>(); private final Set<String> supportedSets = new LinkedHashSet<String>();
private Set<String> missingCards = new LinkedHashSet<String>(); private final Set<String> missingCards = new LinkedHashSet<String>();
Map<String, String> singleLinks = null; Map<String, String> singleLinks = null;
boolean loadedFromDialog = false; boolean loadedFromDialog = false;
boolean viewMissingCards = true; boolean viewMissingCards = true;
@ -221,7 +221,12 @@ public enum CopyPasteImageSource implements CardImageSource {
@Override @Override
public boolean isTokenSource() { public boolean isTokenSource() {
return false; return true;
}
@Override
public boolean isCardSource() {
return true;
} }
@Override @Override
@ -254,9 +259,4 @@ public enum CopyPasteImageSource implements CardImageSource {
public boolean isTokenImageProvided(String setCode, String cardName, Integer tokenNumber) { public boolean isTokenImageProvided(String setCode, String cardName, Integer tokenNumber) {
return false; return false;
} }
@Override
public boolean isSetSupportedComplete(String setCode) {
return false;
}
} }

View file

@ -463,6 +463,11 @@ public enum GrabbagImageSource implements CardImageSource {
return true; return true;
} }
@Override
public boolean isCardSource() {
return true;
}
private String getSourceName(CardDownloadData card, String httpImageUrl) { private String getSourceName(CardDownloadData card, String httpImageUrl) {
if (card.getSet().equals("MTG")) { if (card.getSet().equals("MTG")) {
return "http://static.starcitygames.com/sales/cardscans/"; return "http://static.starcitygames.com/sales/cardscans/";
@ -495,10 +500,4 @@ public enum GrabbagImageSource implements CardImageSource {
} }
return singleLinks.containsKey(setCode + "/" + cardName) || singleLinks.containsKey(setCode + "/" + cardName + "-a"); return singleLinks.containsKey(setCode + "/" + cardName) || singleLinks.containsKey(setCode + "/" + cardName + "-a");
} }
@Override
public boolean isSetSupportedComplete(String setCode) {
return false;
}
} }

View file

@ -284,6 +284,11 @@ public enum MagidexImageSource implements CardImageSource {
return false; return false;
} }
@Override
public boolean isCardSource() {
return true;
}
@Override @Override
public void doPause(String httpImageUrl) { public void doPause(String httpImageUrl) {
} }
@ -292,4 +297,9 @@ public enum MagidexImageSource implements CardImageSource {
public List<String> getSupportedSets() { public List<String> getSupportedSets() {
return new ArrayList<>(supportedSets); return new ArrayList<>(supportedSets);
} }
@Override
public boolean isCardImageProvided(String setCode, String cardName) {
return supportedSets.contains(setCode);
}
} }

View file

@ -354,6 +354,11 @@ public enum MtgOnlTokensImageSource implements CardImageSource {
return true; return true;
} }
@Override
public boolean isCardSource() {
return false;
}
@Override @Override
public void doPause(String httpImageUrl) { public void doPause(String httpImageUrl) {
} }

View file

@ -445,6 +445,11 @@ public enum MythicspoilerComSource implements CardImageSource {
return false; return false;
} }
@Override
public boolean isCardSource() {
return true;
}
@Override @Override
public void doPause(String httpImageUrl) { public void doPause(String httpImageUrl) {
} }
@ -454,4 +459,8 @@ public enum MythicspoilerComSource implements CardImageSource {
return new ArrayList<>(supportedSets); return new ArrayList<>(supportedSets);
} }
@Override
public boolean isCardImageProvided(String setCode, String cardName) {
return supportedSets.contains(setCode);
}
} }

View file

@ -219,6 +219,11 @@ public enum ScryfallImageSource implements CardImageSource {
return true; return true;
} }
@Override
public boolean isCardSource() {
return true;
}
@Override @Override
public boolean isLanguagesSupport() { public boolean isLanguagesSupport() {
return true; return true;

View file

@ -146,6 +146,11 @@ public enum TokensMtgImageSource implements CardImageSource {
return true; return true;
} }
@Override
public boolean isCardSource() {
return false;
}
@Override @Override
public void doPause(String httpImageUrl) { public void doPause(String httpImageUrl) {
} }
@ -157,6 +162,7 @@ public enum TokensMtgImageSource implements CardImageSource {
@Override @Override
public boolean isCardImageProvided(String setCode, String cardName) { public boolean isCardImageProvided(String setCode, String cardName) {
// no cards support, only tokens
return false; return false;
} }
@ -175,11 +181,6 @@ public enum TokensMtgImageSource implements CardImageSource {
return (tokensData.containsKey(key)); return (tokensData.containsKey(key));
} }
@Override
public boolean isSetSupportedComplete(String setCode) {
return false;
}
private HashMap<String, List<TokenData>> getTokensData() throws IOException { private HashMap<String, List<TokenData>> getTokensData() throws IOException {
synchronized (tokensDataSync) { synchronized (tokensDataSync) {
if (tokensData == null) { if (tokensData == null) {

View file

@ -690,6 +690,11 @@ public enum WizardCardsImageSource implements CardImageSource {
return false; return false;
} }
@Override
public boolean isCardSource() {
return true;
}
@Override @Override
public boolean isLanguagesSupport() { public boolean isLanguagesSupport() {
return true; return true;
@ -714,4 +719,9 @@ public enum WizardCardsImageSource implements CardImageSource {
return new ArrayList<>(supportedSets); return new ArrayList<>(supportedSets);
} }
@Override
public boolean isCardImageProvided(String setCode, String cardName) {
return supportedSets.contains(setCode);
}
} }

View file

@ -272,9 +272,11 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
List<String> setNames = new ArrayList<>(); List<String> setNames = new ArrayList<>();
// multiple sets selection // multiple sets selection
if (selectedSource.isCardSource()) {
setNames.add(ALL_IMAGES); setNames.add(ALL_IMAGES);
setNames.add(ALL_MODERN_IMAGES); setNames.add(ALL_MODERN_IMAGES);
setNames.add(ALL_STANDARD_IMAGES); setNames.add(ALL_STANDARD_IMAGES);
}
if (selectedSource.isTokenSource()) { if (selectedSource.isTokenSource()) {
setNames.add(ALL_TOKENS); setNames.add(ALL_TOKENS);
} }
@ -338,21 +340,20 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
int numberCardImagesAvailable = 0; int numberCardImagesAvailable = 0;
for (CardDownloadData data : cardsMissing) { for (CardDownloadData data : cardsMissing) {
if (data.isToken()) { if (data.isToken()) {
if (selectedSource.isTokenSource() && selectedSource.isTokenImageProvided(data.getSet(), data.getName(), data.getType())) { if (selectedSource.isTokenSource()
&& selectedSource.isTokenImageProvided(data.getSet(), data.getName(), data.getType())) {
numberTokenImagesAvailable++; numberTokenImagesAvailable++;
cardsDownloadQueue.add(data); cardsDownloadQueue.add(data);
} else {
//logger.warn("Source do not support token (set " + data.getSet() + ", token " + data.getName() + ")");
} }
} else { } else {
if (selectedSets != null && selectedSets.contains(data.getSet())) { if (selectedSource.isCardSource()
if (selectedSource.isSetSupportedComplete(data.getSet()) || selectedSource.isCardImageProvided(data.getSet(), data.getName())) { && selectedSource.isCardImageProvided(data.getSet(), data.getName())
&& selectedSets.contains(data.getSet())) {
numberCardImagesAvailable++; numberCardImagesAvailable++;
cardsDownloadQueue.add(data); cardsDownloadQueue.add(data);
} }
} }
} }
}
updateProgressText(numberCardImagesAvailable, numberTokenImagesAvailable); updateProgressText(numberCardImagesAvailable, numberTokenImagesAvailable);
} }