Merge branch 'develop' into RecyclerView
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -14,21 +15,20 @@ import java.nio.file.Paths;
|
||||
|
||||
public class FileIO<T> {
|
||||
|
||||
private Class<T> tClass;
|
||||
|
||||
|
||||
public Class<T> readFileData(Context context, String fileName) {
|
||||
Gson gson = new Gson();
|
||||
AssetManager am = context.getAssets();
|
||||
Class<T> res = null;
|
||||
try {
|
||||
InputStream is = am.open(fileName);
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
||||
T res = gson.fromJson(inputStreamReader,);
|
||||
res = gson.fromJson(inputStreamReader,new TypeToken<T>(){}.getType());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//TODO make
|
||||
return null;
|
||||
return res;
|
||||
}
|
||||
|
||||
public void writeFileData(T objectToWrite) {
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
package com.a1.nextlocation.recyclerview;
|
||||
|
||||
public class CouponLoader implements Loader{
|
||||
@Override
|
||||
public void load() {
|
||||
import android.content.Context;
|
||||
|
||||
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;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.a1.nextlocation.data.FileIO;
|
||||
import com.a1.nextlocation.data.Location;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LocationLoader implements Loader<List<Location>>{
|
||||
private final Context context;
|
||||
|
||||
public LocationLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
package com.a1.nextlocation.recyclerview;
|
||||
|
||||
public class RouteLoader implements Loader {
|
||||
@Override
|
||||
public void load() {
|
||||
import android.content.Context;
|
||||
|
||||
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