diff --git a/src/main/java/org/ligi/passandroid/helper/PassVisualizer.java b/src/main/java/org/ligi/passandroid/helper/PassVisualizer.java index 3ebe96a8..3055d972 100644 --- a/src/main/java/org/ligi/passandroid/helper/PassVisualizer.java +++ b/src/main/java/org/ligi/passandroid/helper/PassVisualizer.java @@ -31,7 +31,8 @@ public class PassVisualizer { findById(res, R.id.navigateTo).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - NavigateToLocationsDialog.perform(activity, App.getPassStore().getPassbookForId(pass.getId()), false); + final String lang = activity.getResources().getConfiguration().locale.getLanguage(); + NavigateToLocationsDialog.perform(activity, App.getPassStore().getPassbookForId(pass.getId(), lang), false); } }); } else { diff --git a/src/main/java/org/ligi/passandroid/model/AndroidFileSystemPassStore.java b/src/main/java/org/ligi/passandroid/model/AndroidFileSystemPassStore.java index c04c5b4c..00c6033c 100644 --- a/src/main/java/org/ligi/passandroid/model/AndroidFileSystemPassStore.java +++ b/src/main/java/org/ligi/passandroid/model/AndroidFileSystemPassStore.java @@ -61,7 +61,8 @@ public class AndroidFileSystemPassStore implements PassStore { } catch (Exception e) { } - final Pass pass = AppleStylePassReader.read(getPathForID(id)); + final String language = context.getResources().getConfiguration().locale.getLanguage(); + final Pass pass = AppleStylePassReader.read(getPathForID(id), language); AXT.at(cachedFile).writeObject(pass); return pass; } @@ -87,10 +88,10 @@ public class AndroidFileSystemPassStore implements PassStore { return passList.get(pos); } - public Pass getPassbookForId(final String id) { + public Pass getPassbookForId(final String id,final String language) { final String mPath = path + "/" + id; // TODO read from cache - return AppleStylePassReader.read(mPath); + return AppleStylePassReader.read(mPath,language); } public void sort(final SortOrder order) { diff --git a/src/main/java/org/ligi/passandroid/model/AppleStylePassReader.java b/src/main/java/org/ligi/passandroid/model/AppleStylePassReader.java index 93e36c03..262e438a 100644 --- a/src/main/java/org/ligi/passandroid/model/AppleStylePassReader.java +++ b/src/main/java/org/ligi/passandroid/model/AppleStylePassReader.java @@ -26,7 +26,7 @@ import java.util.regex.Pattern; public class AppleStylePassReader { - public static Pass read(String path) { + public static Pass read(String path,String language) { final PassImpl pass = new PassImpl(); if (path.endsWith("/")) { @@ -39,9 +39,13 @@ public class AppleStylePassReader { JSONObject pass_json = null, type_json = null; - pass.setIconBitmapFile(findBitmapFile(path, "icon")); - pass.setLogoBitmapFile(findBitmapFile(path, "logo")); - pass.setThumbnailBitmapFile(findBitmapFile(path, "thumbnail")); + Optional localized_path=Optional.absent(); + + localized_path=findLocalizedPath(path,language); + + pass.setIconBitmapFile(findBitmapFile(path,localized_path, "icon")); + pass.setLogoBitmapFile(findBitmapFile(path,localized_path, "logo")); + pass.setThumbnailBitmapFile(findBitmapFile(path,localized_path, "thumbnail")); final File file = new File(path + "/pass.json"); @@ -210,8 +214,38 @@ public class AppleStylePassReader { return pass; } - private static String findBitmapFile(String path, String bitmap) { - String res=path+"/"+bitmap+"@2x.png"; + private static Optional findLocalizedPath(String path,String language) { + + final File localized=new File(path,language+".lproj"); + + if (localized.exists() && localized.isDirectory()) { + return Optional.of(localized.getPath()); + } + + final File fallback=new File(path,"en.lproj"); + + if (fallback.exists() && fallback.isDirectory()) { + return Optional.of(fallback.getPath()); + } + + return Optional.absent(); + } + + private static String findBitmapFile(String path, Optional localizedPath, String bitmap) { + String res; + if (localizedPath.isPresent()) { + res=localizedPath.get()+"/"+bitmap+"@2x.png"; + if (BitmapFactory.decodeFile(res)!=null) { + return res; + } + + res=localizedPath.get()+"/"+bitmap+".png"; + if (BitmapFactory.decodeFile(res)!=null) { + return res; + } + } + + res=path+"/"+bitmap+"@2x.png"; if (BitmapFactory.decodeFile(res)!=null) { return res; } diff --git a/src/main/java/org/ligi/passandroid/model/PassStore.java b/src/main/java/org/ligi/passandroid/model/PassStore.java index 74bf3ac8..f7ad2e45 100644 --- a/src/main/java/org/ligi/passandroid/model/PassStore.java +++ b/src/main/java/org/ligi/passandroid/model/PassStore.java @@ -47,7 +47,7 @@ public interface PassStore { public Pass getPassbookAt(int pos); - public Pass getPassbookForId(String id); + public Pass getPassbookForId(String id,String language); public void sort(SortOrder order); diff --git a/src/main/java/org/ligi/passandroid/ui/PassImportActivity.java b/src/main/java/org/ligi/passandroid/ui/PassImportActivity.java index b88cb677..07f03c84 100644 --- a/src/main/java/org/ligi/passandroid/ui/PassImportActivity.java +++ b/src/main/java/org/ligi/passandroid/ui/PassImportActivity.java @@ -69,7 +69,7 @@ public class PassImportActivity extends ActionBarActivity { final String id = AXT.at(path.split("/")).last(); final PassStore store = App.getPassStore(); - store.setCurrentPass(store.getPassbookForId(id)); + store.setCurrentPass(store.getPassbookForId(id,getResources().getConfiguration().locale.getLanguage())); AXT.at(PassImportActivity.this).startCommonIntent().activityFromClass(PassViewActivity.class); finish();