fixed loading
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"code": "2345",
|
||||||
|
"reward": "fdasfasdf"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kees kroket",
|
"name": "kees kroket",
|
||||||
"coordinates": "2.4654645,6.2342323",
|
"coordinates": "2.4654645,6.2342323",
|
||||||
"description": "lekkere patatjes",
|
"description": "lekkere patatjes"
|
||||||
"imageUrl": "R.id.yeet"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"name": "rondje stad",
|
||||||
|
"locations": [
|
||||||
|
{
|
||||||
|
"name": "kees kroket",
|
||||||
|
"coordinates": "2.4654645,6.2342323",
|
||||||
|
"description": "lekkere patatjes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"totalDistance": 2.3434,
|
||||||
|
"totalTime": 342342
|
||||||
|
}
|
||||||
]
|
]
|
||||||
@@ -7,10 +7,12 @@ import android.util.Log;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@@ -18,16 +20,29 @@ public class FileIO<T> {
|
|||||||
private final String TAG = FileIO.class.getCanonicalName();
|
private final String TAG = FileIO.class.getCanonicalName();
|
||||||
|
|
||||||
|
|
||||||
public T readFileData(Context context, String fileName) {
|
public T readFileData(Context context, String fileName, Type typeOf) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
AssetManager am = context.getAssets();
|
AssetManager am = context.getAssets();
|
||||||
T res = null;
|
T res = null;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
InputStream is = am.open(fileName);
|
InputStream is = am.open(fileName);
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
||||||
res = gson.fromJson(inputStreamReader,new TypeToken<T>(){}.getType());
|
BufferedReader reader = new BufferedReader(inputStreamReader);
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine())!= null) {
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log.d(TAG, "readFileData: got string: " + sb.toString());
|
||||||
|
res = gson.fromJson(sb.toString(),typeOf);
|
||||||
Log.d(TAG, "readFileData: got object: " + res);
|
Log.d(TAG, "readFileData: got object: " + res);
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
inputStreamReader.close();
|
||||||
|
is.close();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, "readFileData: exception! " + e.getLocalizedMessage());
|
Log.d(TAG, "readFileData: exception! " + e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ import androidx.core.content.ContextCompat;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.a1.nextlocation.R;
|
import com.a1.nextlocation.R;
|
||||||
|
import com.a1.nextlocation.data.Route;
|
||||||
import com.a1.nextlocation.recyclerview.CouponListManager;
|
import com.a1.nextlocation.recyclerview.CouponListManager;
|
||||||
import com.a1.nextlocation.recyclerview.LocationListManager;
|
import com.a1.nextlocation.recyclerview.LocationListManager;
|
||||||
|
import com.a1.nextlocation.recyclerview.RouteListManager;
|
||||||
|
|
||||||
import org.osmdroid.api.IMapController;
|
import org.osmdroid.api.IMapController;
|
||||||
import org.osmdroid.config.Configuration;
|
import org.osmdroid.config.Configuration;
|
||||||
@@ -114,8 +116,9 @@ public class HomeFragment extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationListManager locationListManager = new LocationListManager(requireContext());
|
CouponListManager couponListManager = new CouponListManager(requireContext());
|
||||||
locationListManager.load();
|
couponListManager.load();
|
||||||
|
Log.d(TAG, "initMap: " + couponListManager.getCoupon(0).getCode());
|
||||||
|
|
||||||
}
|
}
|
||||||
private void requestPermissionsIfNecessary(String... permissions) {
|
private void requestPermissionsIfNecessary(String... permissions) {
|
||||||
|
|||||||
@@ -1,25 +1,32 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.a1.nextlocation.data.Coupon;
|
import com.a1.nextlocation.data.Coupon;
|
||||||
import com.a1.nextlocation.data.FileIO;
|
import com.a1.nextlocation.data.FileIO;
|
||||||
import com.a1.nextlocation.data.Location;
|
import com.a1.nextlocation.data.Location;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CouponLoader implements Loader<List<Coupon>> {
|
public class CouponLoader implements Loader<List<Coupon>> {
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
private final String TAG = CouponLoader.class.getCanonicalName();
|
||||||
|
|
||||||
public CouponLoader(Context context) {
|
public CouponLoader(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Coupon> load() {
|
public ArrayList<Coupon> load() {
|
||||||
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();
|
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();
|
||||||
ArrayList<Coupon> res = fileIO.readFileData(context, "coupons.json");
|
ArrayList<Coupon> res = fileIO.readFileData(context, "coupons.json",new TypeToken<ArrayList<Coupon>>(){}.getType());
|
||||||
|
Log.d(TAG, "load: " + res);
|
||||||
|
|
||||||
return res == null ? new ArrayList<>() : res;
|
return res == null ? new ArrayList<>() : res;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.a1.nextlocation.data.FileIO;
|
import com.a1.nextlocation.data.FileIO;
|
||||||
import com.a1.nextlocation.data.Location;
|
import com.a1.nextlocation.data.Location;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LocationLoader implements Loader<List<Location>> {
|
public class LocationLoader implements Loader<List<Location>> {
|
||||||
@@ -16,11 +18,11 @@ public class LocationLoader implements Loader<List<Location>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Location> load() {
|
public ArrayList<Location> load() {
|
||||||
FileIO<ArrayList<Location>> fileIO = new FileIO<>();
|
FileIO<ArrayList<Location>> fileIO = new FileIO<>();
|
||||||
|
|
||||||
ArrayList<Location> res = fileIO.readFileData(context, "locations.json");
|
ArrayList<Location> res = fileIO.readFileData(context,"locations.json",new TypeToken<ArrayList<Location>>(){}.getType());
|
||||||
return res == null ? new ArrayList<>() : res;
|
|
||||||
|
|
||||||
|
return res == null ? new ArrayList<>() : res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import android.content.Context;
|
|||||||
import com.a1.nextlocation.data.FileIO;
|
import com.a1.nextlocation.data.FileIO;
|
||||||
import com.a1.nextlocation.data.Location;
|
import com.a1.nextlocation.data.Location;
|
||||||
import com.a1.nextlocation.data.Route;
|
import com.a1.nextlocation.data.Route;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RouteLoader implements Loader<List<Route>> {
|
public class RouteLoader implements Loader<List<Route>> {
|
||||||
@@ -17,11 +19,10 @@ public class RouteLoader implements Loader<List<Route>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Route> load() {
|
public ArrayList<Route> load() {
|
||||||
|
|
||||||
FileIO<ArrayList<Route>> fileIO = new FileIO<>();
|
FileIO<ArrayList<Route>> fileIO = new FileIO<>();
|
||||||
|
ArrayList<Route> res = fileIO.readFileData(context, "routes.json",new TypeToken<ArrayList<Route>>(){}.getType());
|
||||||
ArrayList<Route> res = fileIO.readFileData(context, "routes.json");
|
|
||||||
return res == null ? new ArrayList<>() : res;
|
return res == null ? new ArrayList<>() : res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user