Files
Next-Location/app/src/main/java/com/a1/nextlocation/recyclerview/LocationLoader.java
Sem van der Hoeven c68bbd4062 ctrl alt L
2021-01-06 21:19:06 +01:00

41 lines
1.2 KiB
Java

package com.a1.nextlocation.recyclerview;
import android.content.Context;
import com.a1.nextlocation.data.FileIO;
import com.a1.nextlocation.data.Location;
import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
import java.util.List;
public class LocationLoader implements Loader<List<Location>> {
private final Context context;
public LocationLoader(Context context) {
this.context = context;
}
/**
* loads the array list from a JSON file
*
* @return array list with locations
*/
@Override
public ArrayList<Location> load() {
FileIO<ArrayList<Location>> fileIO = new FileIO<>();
String selectedLanguage = context.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", "nl");
String fileName = "locations";
// choose the locations.json based of the selected language
if (!selectedLanguage.equals("en")) {
fileName += "-" + selectedLanguage;
}
ArrayList<Location> res = fileIO.readFileData(context, fileName + ".json", new TypeToken<ArrayList<Location>>() {
}.getType());
return res == null ? new ArrayList<>() : res;
}
}