[Mobile] Fix card image not loading

This commit is contained in:
Anthony Calosa
2021-09-13 23:01:13 +08:00
parent 176f86aa62
commit ac350a0bfb
2 changed files with 8 additions and 9 deletions

View File

@@ -66,6 +66,9 @@ public final class ImageKeys {
} }
private static final Map<String, File> cachedCards = new HashMap<>(50000); private static final Map<String, File> cachedCards = new HashMap<>(50000);
public static File getCachedCardsFile(String key) {
return cachedCards.get(key);
}
public static File getImageFile(String key) { public static File getImageFile(String key) {
if (StringUtils.isEmpty(key)) if (StringUtils.isEmpty(key))
return null; return null;

View File

@@ -50,7 +50,6 @@ import forge.localinstance.properties.ForgeConstants;
import forge.localinstance.properties.ForgePreferences; import forge.localinstance.properties.ForgePreferences;
import forge.model.FModel; import forge.model.FModel;
import forge.util.ImageUtil; import forge.util.ImageUtil;
import forge.util.TextUtil;
/** /**
* This class stores ALL card images in a cache with soft values. this means * This class stores ALL card images in a cache with soft values. this means
@@ -171,10 +170,7 @@ public class ImageCache {
} else { } else {
final boolean backFace = imageKey.endsWith(ImageKeys.BACKFACE_POSTFIX); final boolean backFace = imageKey.endsWith(ImageKeys.BACKFACE_POSTFIX);
final String cardfilename = backFace ? paperCard.getCardAltImageKey() : paperCard.getCardImageKey(); final String cardfilename = backFace ? paperCard.getCardAltImageKey() : paperCard.getCardImageKey();
if (!new File(ForgeConstants.CACHE_CARD_PICS_DIR + "/" + cardfilename + ".jpg").exists()) return ImageKeys.getCachedCardsFile(cardfilename) != null;
if (!new File(ForgeConstants.CACHE_CARD_PICS_DIR + "/" + cardfilename + ".png").exists())
if (!new File(ForgeConstants.CACHE_CARD_PICS_DIR + "/" + TextUtil.fastReplace(cardfilename,".full", ".fullborder") + ".jpg").exists())
return false;
} }
} else if (prefix.equals(ImageKeys.TOKEN_PREFIX)) { } else if (prefix.equals(ImageKeys.TOKEN_PREFIX)) {
final String tokenfilename = imageKey.substring(2) + ".jpg"; final String tokenfilename = imageKey.substring(2) + ".jpg";
@@ -242,10 +238,10 @@ public class ImageCache {
// a default "not available" image and add to cache for given key. // a default "not available" image and add to cache for given key.
if (image == null) { if (image == null) {
if (useDefaultIfNotFound) { if (useDefaultIfNotFound) {
image = useOtherCache ? defaultImage : null; image = defaultImage;
if (useOtherCache) /*fix not loading image file since we intentionally not to update the cache in order for the
otherCache.put(imageKey, defaultImage); image fetcher to update automatically after the card image/s are downloaded*/
imageLoaded = false;
if (image != null && imageBorder.get(image.toString()) == null) if (image != null && imageBorder.get(image.toString()) == null)
imageBorder.put(image.toString(), Pair.of(Color.valueOf("#171717").toString(), false)); //black border imageBorder.put(image.toString(), Pair.of(Color.valueOf("#171717").toString(), false)); //black border
} }