Merge develop into master #1
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -14,21 +15,20 @@ import java.nio.file.Paths;
|
|||||||
|
|
||||||
public class FileIO<T> {
|
public class FileIO<T> {
|
||||||
|
|
||||||
private Class<T> tClass;
|
|
||||||
|
|
||||||
|
|
||||||
public Class<T> readFileData(Context context, String fileName) {
|
public Class<T> readFileData(Context context, String fileName) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
AssetManager am = context.getAssets();
|
AssetManager am = context.getAssets();
|
||||||
|
Class<T> res = null;
|
||||||
try {
|
try {
|
||||||
InputStream is = am.open(fileName);
|
InputStream is = am.open(fileName);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
||||||
T res = gson.fromJson(inputStreamReader,);
|
res = gson.fromJson(inputStreamReader,new TypeToken<T>(){}.getType());
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
//TODO make
|
return res;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeFileData(T objectToWrite) {
|
public void writeFileData(T objectToWrite) {
|
||||||
|
|||||||
@@ -1,8 +1,26 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class CouponLoader implements Loader{
|
import android.content.Context;
|
||||||
@Override
|
|
||||||
public void load() {
|
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Coupon;
|
||||||
|
import com.a1.nextlocation.data.FileIO;
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CouponLoader implements Loader<List<Coupon>> {
|
||||||
|
private final Context context;
|
||||||
|
public CouponLoader(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public List<Coupon> load() {
|
||||||
|
FileIO<List<Coupon>> fileIO = new FileIO<>();
|
||||||
|
try {
|
||||||
|
return fileIO.readFileData(context,"coupons.json").newInstance();
|
||||||
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,27 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.FileIO;
|
||||||
import com.a1.nextlocation.data.Location;
|
import com.a1.nextlocation.data.Location;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LocationLoader implements Loader<List<Location>>{
|
public class LocationLoader implements Loader<List<Location>>{
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
public LocationLoader(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Location> load() {
|
public List<Location> load() {
|
||||||
|
FileIO<List<Location>> fileIO = new FileIO<>();
|
||||||
|
try {
|
||||||
|
return fileIO.readFileData(context,"locations.json").newInstance();
|
||||||
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,28 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class RouteLoader implements Loader {
|
import android.content.Context;
|
||||||
@Override
|
|
||||||
public void load() {
|
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.FileIO;
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
import com.a1.nextlocation.data.Route;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RouteLoader implements Loader<List<Route>> {
|
||||||
|
private final Context context;
|
||||||
|
public RouteLoader(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Route> load() {
|
||||||
|
|
||||||
|
FileIO<List<Route>> fileIO = new FileIO<>();
|
||||||
|
try {
|
||||||
|
return fileIO.readFileData(context,"routes.json").newInstance();
|
||||||
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user