Merge branch 'develop' into RecyclerView
This commit is contained in:
6
app/src/main/assets/coupons.json
Normal file
6
app/src/main/assets/coupons.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"code": "2345",
|
||||||
|
"reward": "fdasfasdf"
|
||||||
|
}
|
||||||
|
]
|
||||||
12
app/src/main/assets/locations.json
Normal file
12
app/src/main/assets/locations.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "kees kroket",
|
||||||
|
"coordinates": "2.4654645,6.2342323",
|
||||||
|
"description": "lekkere patatjes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "locatie2",
|
||||||
|
"coordinates": "3.65656,9.564564",
|
||||||
|
"description": "locatie 2"
|
||||||
|
}
|
||||||
|
]
|
||||||
14
app/src/main/assets/routes.json
Normal file
14
app/src/main/assets/routes.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "rondje stad",
|
||||||
|
"locations": [
|
||||||
|
{
|
||||||
|
"name": "kees kroket",
|
||||||
|
"coordinates": "2.4654645,6.2342323",
|
||||||
|
"description": "lekkere patatjes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"totalDistance": 2.3434,
|
||||||
|
"totalTime": 342342
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -13,6 +13,9 @@ import com.a1.nextlocation.fragments.HomeFragment;
|
|||||||
import com.a1.nextlocation.fragments.RouteFragment;
|
import com.a1.nextlocation.fragments.RouteFragment;
|
||||||
import com.a1.nextlocation.fragments.SettingsFragment;
|
import com.a1.nextlocation.fragments.SettingsFragment;
|
||||||
import com.a1.nextlocation.fragments.StatisticFragment;
|
import com.a1.nextlocation.fragments.StatisticFragment;
|
||||||
|
import com.a1.nextlocation.recyclerview.CouponListManager;
|
||||||
|
import com.a1.nextlocation.recyclerview.LocationListManager;
|
||||||
|
import com.a1.nextlocation.recyclerview.RouteListManager;
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
@@ -28,6 +31,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
BottomNavigationView bottomNav = findViewById(R.id.navbar);
|
BottomNavigationView bottomNav = findViewById(R.id.navbar);
|
||||||
bottomNav.setOnNavigationItemSelectedListener(navListener);
|
bottomNav.setOnNavigationItemSelectedListener(navListener);
|
||||||
|
|
||||||
|
LocationListManager.INSTANCE.setContext(this);
|
||||||
|
LocationListManager.INSTANCE.load();
|
||||||
|
CouponListManager.INSTANCE.setContext(this);
|
||||||
|
CouponListManager.INSTANCE.load();
|
||||||
|
RouteListManager.INSTANCE.setContext(this);
|
||||||
|
RouteListManager.INSTANCE.load();
|
||||||
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,30 +2,49 @@ package com.a1.nextlocation.data;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
|
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;
|
||||||
|
|
||||||
public class FileIO<T> {
|
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, Type typeOf) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
AssetManager am = context.getAssets();
|
AssetManager am = context.getAssets();
|
||||||
Class<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);
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
inputStreamReader.close();
|
||||||
|
is.close();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, "readFileData: exception! " + e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -20,6 +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.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;
|
||||||
@@ -96,6 +100,7 @@ public class HomeFragment extends Fragment {
|
|||||||
// add location manager and set the start point
|
// add location manager and set the start point
|
||||||
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||||
GeoPoint startPoint = new GeoPoint(location.getLatitude(), location.getLongitude());
|
GeoPoint startPoint = new GeoPoint(location.getLatitude(), location.getLongitude());
|
||||||
|
|||||||
@@ -4,15 +4,18 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.a1.nextlocation.data.Coupon;
|
import com.a1.nextlocation.data.Coupon;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CouponListManager {
|
public enum CouponListManager {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
private List<Coupon> couponList;
|
private List<Coupon> couponList;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public CouponListManager(Context context){
|
public void setContext(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.couponList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Coupon> getCouponList() {
|
public List<Coupon> getCouponList() {
|
||||||
|
|||||||
@@ -1,26 +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.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<List<Coupon>> fileIO = new FileIO<>();
|
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();
|
||||||
try {
|
ArrayList<Coupon> res = fileIO.readFileData(context, "coupons.json",new TypeToken<ArrayList<Coupon>>(){}.getType());
|
||||||
return fileIO.readFileData(context,"coupons.json").newInstance();
|
Log.d(TAG, "load: " + res);
|
||||||
} catch (IllegalAccessException | InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
return res == null ? new ArrayList<>() : res;
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,18 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.a1.nextlocation.data.Location;
|
import com.a1.nextlocation.data.Location;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LocationListManager {
|
public enum LocationListManager {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
private List<Location> locationList;
|
private List<Location> locationList;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public LocationListManager(Context context){
|
public void setContext(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.locationList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Location> getLocationList() {
|
public List<Location> getLocationList() {
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ 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.Arrays;
|
||||||
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;
|
private final Context context;
|
||||||
|
|
||||||
public LocationLoader(Context context) {
|
public LocationLoader(Context context) {
|
||||||
@@ -15,13 +18,11 @@ public class LocationLoader implements Loader<List<Location>>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Location> load() {
|
public ArrayList<Location> load() {
|
||||||
FileIO<List<Location>> fileIO = new FileIO<>();
|
FileIO<ArrayList<Location>> fileIO = new FileIO<>();
|
||||||
try {
|
|
||||||
return fileIO.readFileData(context,"locations.json").newInstance();
|
ArrayList<Location> res = fileIO.readFileData(context,"locations.json",new TypeToken<ArrayList<Location>>(){}.getType());
|
||||||
} catch (IllegalAccessException | InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
return res == null ? new ArrayList<>() : res;
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,21 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.a1.nextlocation.data.Route;
|
import com.a1.nextlocation.data.Route;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RouteListManager{
|
public enum RouteListManager{
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
private List<Route> routeList;
|
private List<Route> routeList;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public RouteListManager(Context context){
|
public void setContext(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.routeList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Route> getRouteList() {
|
public List<Route> getRouteList() {
|
||||||
return routeList;
|
return routeList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,24 +5,25 @@ 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.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RouteLoader implements Loader<List<Route>> {
|
public class RouteLoader implements Loader<List<Route>> {
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
public RouteLoader(Context context) {
|
public RouteLoader(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Route> load() {
|
public ArrayList<Route> load() {
|
||||||
|
|
||||||
|
FileIO<ArrayList<Route>> fileIO = new FileIO<>();
|
||||||
|
ArrayList<Route> res = fileIO.readFileData(context, "routes.json",new TypeToken<ArrayList<Route>>(){}.getType());
|
||||||
|
return res == null ? new ArrayList<>() : res;
|
||||||
|
|
||||||
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