finished loading
This commit is contained in:
3
app/src/main/assets/coupons.json
Normal file
3
app/src/main/assets/coupons.json
Normal file
@@ -0,0 +1,3 @@
|
||||
[
|
||||
|
||||
]
|
||||
8
app/src/main/assets/locations.json
Normal file
8
app/src/main/assets/locations.json
Normal file
@@ -0,0 +1,8 @@
|
||||
[
|
||||
{
|
||||
"name": "kees kroket",
|
||||
"coordinates": "2.4654645,6.2342323",
|
||||
"description": "lekkere patatjes",
|
||||
"imageUrl": "R.id.yeet"
|
||||
}
|
||||
]
|
||||
3
app/src/main/assets/routes.json
Normal file
3
app/src/main/assets/routes.json
Normal file
@@ -0,0 +1,3 @@
|
||||
[
|
||||
|
||||
]
|
||||
@@ -2,6 +2,7 @@ package com.a1.nextlocation.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@@ -14,18 +15,21 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileIO<T> {
|
||||
private final String TAG = FileIO.class.getCanonicalName();
|
||||
|
||||
|
||||
public Class<T> readFileData(Context context, String fileName) {
|
||||
public T readFileData(Context context, String fileName) {
|
||||
Gson gson = new Gson();
|
||||
AssetManager am = context.getAssets();
|
||||
Class<T> res = null;
|
||||
T res = null;
|
||||
try {
|
||||
InputStream is = am.open(fileName);
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
||||
res = gson.fromJson(inputStreamReader,new TypeToken<T>(){}.getType());
|
||||
Log.d(TAG, "readFileData: got object: " + res);
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "readFileData: exception! " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
|
||||
@@ -20,6 +20,8 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.a1.nextlocation.R;
|
||||
import com.a1.nextlocation.recyclerview.CouponListManager;
|
||||
import com.a1.nextlocation.recyclerview.LocationListManager;
|
||||
|
||||
import org.osmdroid.api.IMapController;
|
||||
import org.osmdroid.config.Configuration;
|
||||
@@ -112,6 +114,9 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
LocationListManager locationListManager = new LocationListManager(requireContext());
|
||||
locationListManager.load();
|
||||
|
||||
}
|
||||
private void requestPermissionsIfNecessary(String... permissions) {
|
||||
ArrayList<String> permissionsToRequest = new ArrayList<>();
|
||||
|
||||
@@ -6,21 +6,20 @@ import com.a1.nextlocation.data.Coupon;
|
||||
import com.a1.nextlocation.data.FileIO;
|
||||
import com.a1.nextlocation.data.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();
|
||||
ArrayList<Coupon> res = fileIO.readFileData(context, "coupons.json");
|
||||
return res == null ? new ArrayList<>() : res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import android.content.Context;
|
||||
import com.a1.nextlocation.data.FileIO;
|
||||
import com.a1.nextlocation.data.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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) {
|
||||
@@ -16,12 +17,10 @@ public class LocationLoader implements Loader<List<Location>>{
|
||||
|
||||
@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;
|
||||
FileIO<ArrayList<Location>> fileIO = new FileIO<>();
|
||||
|
||||
ArrayList<Location> res = fileIO.readFileData(context, "locations.json");
|
||||
return res == null ? new ArrayList<>() : res;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import com.a1.nextlocation.data.FileIO;
|
||||
import com.a1.nextlocation.data.Location;
|
||||
import com.a1.nextlocation.data.Route;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RouteLoader implements Loader<List<Route>> {
|
||||
private final Context context;
|
||||
|
||||
public RouteLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
@@ -17,12 +19,10 @@ public class RouteLoader implements Loader<List<Route>> {
|
||||
@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;
|
||||
FileIO<ArrayList<Route>> fileIO = new FileIO<>();
|
||||
|
||||
ArrayList<Route> res = fileIO.readFileData(context, "routes.json");
|
||||
return res == null ? new ArrayList<>() : res;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user