Added support for different language routes and coupons

This commit is contained in:
Bart
2021-01-06 17:41:57 +01:00
parent 5844445555
commit 7089524be6
6 changed files with 74 additions and 4 deletions

View File

@@ -34,8 +34,13 @@ public class FileIO<T> {
AssetManager am = context.getAssets();
T res = null;
StringBuilder sb = new StringBuilder();
InputStream is = null;
try {
InputStream is = am.open(fileName);
if (new File(fileName).exists()) {
is = am.open(fileName);
} else {
is = am.open(fileName.substring(0, fileName.length() - 8) + ".json");
}
InputStreamReader inputStreamReader = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(inputStreamReader);
String line;

View File

@@ -21,7 +21,14 @@ public class CouponLoader implements Loader<List<Coupon>> {
@Override
public ArrayList<Coupon> load() {
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();
ArrayList<Coupon> res = fileIO.readFileData(context, "coupons.json",new TypeToken<ArrayList<Coupon>>(){}.getType());
String selectedLanguage = context.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", "nl");
String fileName = "locations";
// choose the coupon.json based of the selected language
if (!selectedLanguage.equals("en")) {
fileName += "-" + selectedLanguage;
}
ArrayList<Coupon> res = fileIO.readFileData(context, fileName + ".json", new TypeToken<ArrayList<Coupon>>(){}.getType());
Log.d(TAG, "load: " + res);
return res == null ? new ArrayList<>() : res;

View File

@@ -23,7 +23,7 @@ public class LocationLoader implements Loader<List<Location>> {
String selectedLanguage = context.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", "nl");
String fileName = "locations";
// choose the locations.json based of the selectedLanguage
// choose the locations.json based of the selected language
if (!selectedLanguage.equals("en")) {
fileName += "-" + selectedLanguage;
}

View File

@@ -22,7 +22,15 @@ public class RouteLoader implements Loader<List<Route>> {
public ArrayList<Route> load() {
FileIO<ArrayList<Route>> fileIO = new FileIO<>();
ArrayList<Route> res = fileIO.readFileData(context, "routes.json",new TypeToken<ArrayList<Route>>(){}.getType());
String selectedLanguage = context.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", "nl");
String fileName = "routes";
// choose the routes.json based of the selected language
if (!selectedLanguage.equals("en")) {
fileName += "-" + selectedLanguage;
}
ArrayList<Route> res = fileIO.readFileData(context, fileName + ".json",new TypeToken<ArrayList<Route>>(){}.getType());
return res == null ? new ArrayList<>() : res;
}