Compare commits
22 Commits
Fragment
...
LocationCr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5edf50c808 | ||
|
|
db7d944a41 | ||
|
|
3f132f48a7 | ||
|
|
17f624cc30 | ||
|
|
521c9fd188 | ||
|
|
1fd245f4f0 | ||
|
|
8d210a9707 | ||
|
|
ee1ae23e0f | ||
|
|
49f78efdd3 | ||
|
|
512ad3980f | ||
|
|
e2f76c94f7 | ||
|
|
2479563474 | ||
|
|
ea59b97f0f | ||
|
|
0b9bba63a3 | ||
|
|
996b061b65 | ||
|
|
ad6e171a14 | ||
|
|
16b9b15856 | ||
|
|
63c49c40d7 | ||
|
|
13b73fb0de | ||
|
|
e5fa7db27d | ||
|
|
aee2797a0f | ||
|
|
12b446b679 |
@@ -35,6 +35,8 @@ dependencies {
|
|||||||
implementation "androidx.room:room-runtime:$room_version"
|
implementation "androidx.room:room-runtime:$room_version"
|
||||||
annotationProcessor "androidx.room:room-compiler:$room_version"
|
annotationProcessor "androidx.room:room-compiler:$room_version"
|
||||||
|
|
||||||
|
//gson
|
||||||
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||||
implementation 'com.google.android.material:material:1.2.1'
|
implementation 'com.google.android.material:material:1.2.1'
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
package com.a1.nextlocation;
|
package com.a1.nextlocation;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.a1.nextlocation.R;
|
import com.a1.nextlocation.R;
|
||||||
|
import com.a1.nextlocation.fragments.HomeFragment;
|
||||||
|
import com.a1.nextlocation.fragments.RouteFragment;
|
||||||
|
import com.a1.nextlocation.fragments.SettingsFragment;
|
||||||
|
import com.a1.nextlocation.fragments.StatisticFragment;
|
||||||
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onCreate method that creates the main activity
|
* onCreate method that creates the main activity
|
||||||
* @param savedInstanceState the saved instance state of the app
|
* @param savedInstanceState the saved instance state of the app
|
||||||
@@ -16,5 +24,33 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
BottomNavigationView bottomNav = findViewById(R.id.navbar);
|
||||||
|
bottomNav.setOnNavigationItemSelectedListener(navListener);
|
||||||
|
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private BottomNavigationView.OnNavigationItemSelectedListener navListener = item -> {
|
||||||
|
Fragment selectedFragment = null;
|
||||||
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.locations:
|
||||||
|
selectedFragment = new HomeFragment();
|
||||||
|
break;
|
||||||
|
case R.id.routes:
|
||||||
|
selectedFragment = new RouteFragment();
|
||||||
|
break;
|
||||||
|
case R.id.statistics:
|
||||||
|
selectedFragment = new StatisticFragment();
|
||||||
|
break;
|
||||||
|
case R.id.settings:
|
||||||
|
selectedFragment = new SettingsFragment();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, selectedFragment).commit();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,34 @@
|
|||||||
package com.a1.nextlocation.data;
|
package com.a1.nextlocation.data;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.Ignore;
|
import androidx.room.Ignore;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
import androidx.room.TypeConverters;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.db.CouponListTypeConverter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity(tableName = "userdata")
|
||||||
public class Data {
|
public class Data {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ColumnInfo(name = "distance_traveled")
|
||||||
private float distanceTraveled;
|
private float distanceTraveled;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "locations_visited")
|
||||||
private int locationsVisited;
|
private int locationsVisited;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "total_time")
|
||||||
private int totalTime;
|
private int totalTime;
|
||||||
|
|
||||||
|
@TypeConverters(CouponListTypeConverter.class)
|
||||||
private List<Coupon> couponList;
|
private List<Coupon> couponList;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@@ -34,6 +45,7 @@ public class Data {
|
|||||||
this.distanceTraveled = 0;
|
this.distanceTraveled = 0;
|
||||||
this.locationsVisited = 0;
|
this.locationsVisited = 0;
|
||||||
this.totalTime = 0;
|
this.totalTime = 0;
|
||||||
|
couponList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.a1.nextlocation.data;
|
package com.a1.nextlocation.data;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
@@ -13,13 +15,26 @@ public class Location {
|
|||||||
@NonNull
|
@NonNull
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* coordinates will be saved as for example: 2.434343,4.65656;3.656565,6.43434
|
||||||
|
* so lat1,long1;lat2,long2
|
||||||
|
*/
|
||||||
private String coordinates;
|
private String coordinates;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
public Location(@NotNull String name, String coordinates, String description) {
|
@ColumnInfo(name = "image_url")
|
||||||
|
@Nullable
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
public Location(@NotNull String name, String coordinates, String description, @Nullable String imageUrl) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location(@NotNull String name, double latCoord, double longCoord, String description, @Nullable String imageUrl) {
|
||||||
|
this(name,getStringFromCoordinates(latCoord,longCoord),description,imageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -46,4 +61,34 @@ public class Location {
|
|||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(@Nullable String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double[] getCoordinatesAsDoubles() {
|
||||||
|
double[] res = new double[2];
|
||||||
|
res[0] = getLat();
|
||||||
|
res[1] = getLong();
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLat() {
|
||||||
|
return Double.parseDouble(this.coordinates.split(",")[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLong() {
|
||||||
|
return Double.parseDouble(this.coordinates.split(",")[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getStringFromCoordinates(double lat1, double long1) {
|
||||||
|
return lat1 + "," + long1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.room.ColumnInfo;
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
import androidx.room.TypeConverters;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.db.LocationListTypeConverter;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -17,6 +20,7 @@ public class Route {
|
|||||||
@NonNull
|
@NonNull
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@TypeConverters(LocationListTypeConverter.class)
|
||||||
private List<Location> locations;
|
private List<Location> locations;
|
||||||
|
|
||||||
@ColumnInfo(name = "total_distance")
|
@ColumnInfo(name = "total_distance")
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.a1.nextlocation.data.db;
|
||||||
|
|
||||||
|
import androidx.room.TypeConverter;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Coupon;
|
||||||
|
import com.a1.nextlocation.data.Route;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CouponListTypeConverter {
|
||||||
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
public static List<Coupon> toRoutesList(String data) {
|
||||||
|
if (data == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
Type listType = new TypeToken<List<Coupon>>() {}.getType();
|
||||||
|
|
||||||
|
return gson.fromJson(data,listType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
public static String fromRoutesList(List<Coupon> list) {
|
||||||
|
return gson.toJson(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,9 +8,11 @@ import androidx.room.RoomDatabase;
|
|||||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||||
|
|
||||||
import com.a1.nextlocation.data.Coupon;
|
import com.a1.nextlocation.data.Coupon;
|
||||||
|
import com.a1.nextlocation.data.Data;
|
||||||
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.a1.nextlocation.data.db.dao.CouponDao;
|
import com.a1.nextlocation.data.db.dao.CouponDao;
|
||||||
|
import com.a1.nextlocation.data.db.dao.DataDao;
|
||||||
import com.a1.nextlocation.data.db.dao.LocationDao;
|
import com.a1.nextlocation.data.db.dao.LocationDao;
|
||||||
import com.a1.nextlocation.data.db.dao.RouteDao;
|
import com.a1.nextlocation.data.db.dao.RouteDao;
|
||||||
|
|
||||||
@@ -20,12 +22,13 @@ import java.util.concurrent.Executors;
|
|||||||
/**
|
/**
|
||||||
* @author Sem
|
* @author Sem
|
||||||
*/
|
*/
|
||||||
@androidx.room.Database(entities = {Coupon.class,Route.class, Location.class},version = 1,exportSchema = false)
|
@androidx.room.Database(entities = {Coupon.class,Route.class, Location.class, Data.class},version = 1,exportSchema = false)
|
||||||
public abstract class Database extends RoomDatabase {
|
public abstract class Database extends RoomDatabase {
|
||||||
|
|
||||||
public abstract RouteDao routeDao();
|
public abstract RouteDao routeDao();
|
||||||
public abstract CouponDao couponDao();
|
public abstract CouponDao couponDao();
|
||||||
public abstract LocationDao locationDao();
|
public abstract LocationDao locationDao();
|
||||||
|
public abstract DataDao dataDao();
|
||||||
|
|
||||||
private static volatile Database INSTANCE;
|
private static volatile Database INSTANCE;
|
||||||
private static final int NUMBER_OF_THREADS = 4;
|
private static final int NUMBER_OF_THREADS = 4;
|
||||||
@@ -50,6 +53,7 @@ public abstract class Database extends RoomDatabase {
|
|||||||
super.onCreate(db);
|
super.onCreate(db);
|
||||||
|
|
||||||
databaseWriterExecutor.execute(() -> {
|
databaseWriterExecutor.execute(() -> {
|
||||||
|
|
||||||
// TODO populate our database here
|
// TODO populate our database here
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.a1.nextlocation.data.db;
|
||||||
|
|
||||||
|
import androidx.room.TypeConverter;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
import com.a1.nextlocation.data.Route;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LocationListTypeConverter {
|
||||||
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
public static List<Location> toLocationList(String data) {
|
||||||
|
if (data == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
Type listType = new TypeToken<List<Location>>() {}.getType();
|
||||||
|
|
||||||
|
return gson.fromJson(data,listType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
public static String fromLocationList(List<Location> list) {
|
||||||
|
return gson.toJson(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,9 @@ public interface CouponDao {
|
|||||||
@Query("SELECT * FROM coupon")
|
@Query("SELECT * FROM coupon")
|
||||||
LiveData<List<Coupon>> selectAll();
|
LiveData<List<Coupon>> selectAll();
|
||||||
|
|
||||||
|
@Update
|
||||||
|
public void update(Coupon coupon);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
to add an observer to the livedata, you can use the example from https://medium.com/mindorks/using-room-database-with-livedata-android-jetpack-cbf89b677b47
|
to add an observer to the livedata, you can use the example from https://medium.com/mindorks/using-room-database-with-livedata-android-jetpack-cbf89b677b47
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.a1.nextlocation.data.db.dao;
|
||||||
|
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Insert;
|
||||||
|
import androidx.room.OnConflictStrategy;
|
||||||
|
import androidx.room.Query;
|
||||||
|
import androidx.room.Update;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Data;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface DataDao {
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
void insertAll(Data... datas);
|
||||||
|
|
||||||
|
@Update
|
||||||
|
void update(Data data);
|
||||||
|
|
||||||
|
@Query("DELETE FROM userdata")
|
||||||
|
void delete();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM userdata LIMIT 1")
|
||||||
|
Data getData();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM userdata WHERE distance_traveled = :distance LIMIT 1")
|
||||||
|
Data getDataByDistance(float distance);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,6 +20,14 @@ public class CouponRepository {
|
|||||||
mAllCoupons = mCouponDao.selectAll();
|
mAllCoupons = mCouponDao.selectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insert(Coupon... coupons) {
|
||||||
|
mCouponDao.insertAll(coupons);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Coupon coupon) {
|
||||||
|
mCouponDao.update(coupon);
|
||||||
|
}
|
||||||
|
|
||||||
public LiveData<List<Coupon>> getAllCoupons() {
|
public LiveData<List<Coupon>> getAllCoupons() {
|
||||||
return mAllCoupons;
|
return mAllCoupons;
|
||||||
}
|
}
|
||||||
@@ -27,4 +35,8 @@ public class CouponRepository {
|
|||||||
public Coupon getCoupon(String code) {
|
public Coupon getCoupon(String code) {
|
||||||
return mCouponDao.selectCouponByCode(code);
|
return mCouponDao.selectCouponByCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
mCouponDao.deleteAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.a1.nextlocation.data.db.repositories;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Data;
|
||||||
|
import com.a1.nextlocation.data.db.Database;
|
||||||
|
import com.a1.nextlocation.data.db.dao.DataDao;
|
||||||
|
|
||||||
|
public class DataRepository {
|
||||||
|
private DataDao mDataDao;
|
||||||
|
private Data data;
|
||||||
|
|
||||||
|
public DataRepository(Context context) {
|
||||||
|
Database db = Database.getDatabase(context);
|
||||||
|
mDataDao = db.dataDao();
|
||||||
|
data = mDataDao.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Data getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Data getDataByDistance(float distance) {
|
||||||
|
return mDataDao.getDataByDistance(distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
mDataDao.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Data data) {
|
||||||
|
mDataDao.update(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertAll(Data... datas) {
|
||||||
|
mDataDao.insertAll(datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,4 +27,12 @@ public class LocationRepository {
|
|||||||
public Location getLocationByName(String name) {
|
public Location getLocationByName(String name) {
|
||||||
return mLocationDao.getLocationByName(name);
|
return mLocationDao.getLocationByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertAll(Location... locations) {
|
||||||
|
mLocationDao.insertAll(locations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
mLocationDao.deleteAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,8 @@ public class RouteRepository {
|
|||||||
public Route getRouteByName(String name) {
|
public Route getRouteByName(String name) {
|
||||||
return mRouteDao.getRouteByName(name);
|
return mRouteDao.getRouteByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
mRouteDao.deleteAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
package com.a1.nextlocation.fragments;
|
package com.a1.nextlocation.fragments;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -13,11 +19,6 @@ import androidx.core.app.ActivityCompat;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import com.a1.nextlocation.R;
|
import com.a1.nextlocation.R;
|
||||||
|
|
||||||
import org.osmdroid.api.IMapController;
|
import org.osmdroid.api.IMapController;
|
||||||
@@ -69,7 +70,7 @@ public class HomeFragment extends Fragment {
|
|||||||
Configuration.getInstance().setUserAgentValue(userAgent);
|
Configuration.getInstance().setUserAgentValue(userAgent);
|
||||||
|
|
||||||
// create the map view
|
// create the map view
|
||||||
mapView = (MapView) view.findViewById(R.id.mapView);
|
mapView = view.findViewById(R.id.mapView);
|
||||||
mapView.setDestroyMode(false);
|
mapView.setDestroyMode(false);
|
||||||
mapView.setTag("mapView");
|
mapView.setTag("mapView");
|
||||||
mapView.setMultiTouchControls(true);
|
mapView.setMultiTouchControls(true);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.a1.nextlocation.fragments;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -23,15 +25,20 @@ public class SettingsFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
return inflater.inflate(R.layout.fragment_settings, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = getView();
|
|
||||||
Spinner dropdown = view.findViewById(R.id.dropdown_menu_Settings);
|
Spinner dropdown = view.findViewById(R.id.dropdown_menu_Settings);
|
||||||
|
|
||||||
String[] items = new String[]{"Nederlands", "Engels", "Chinees"};
|
String[] items = new String[]{"Nederlands", "Engels", "Chinees"};
|
||||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, items);
|
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, items);
|
||||||
|
|
||||||
dropdown.setAdapter(arrayAdapter);
|
dropdown.setAdapter(arrayAdapter);
|
||||||
|
|
||||||
return inflater.inflate(R.layout.fragment_settings, container, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.a1.nextlocation.network;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
import com.a1.nextlocation.data.Route;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public enum ApiHandler {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
|
||||||
|
private static String TAG = ApiHandler.class.getCanonicalName();
|
||||||
|
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
|
||||||
|
private final String BASE_URL = "https://api.openrouteservice.org/v2/directions/";
|
||||||
|
private final String API_KEY = "5b3ce3597851110001cf6248d4eee2099f724255918adc71cc502b2a";
|
||||||
|
private final String DIRECTIONS_MODE = "foot_walking";
|
||||||
|
|
||||||
|
private OkHttpClient client = new OkHttpClient();
|
||||||
|
|
||||||
|
public Route getDirections(Location startLocation, Location endLocation) {
|
||||||
|
return getDirections(startLocation.getCoordinates(),endLocation.getCoordinates());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Route getDirections(double startLat, double startLong, double endLat, double endLong) {
|
||||||
|
return getDirections(startLat + "," + startLong, endLat + "," + endLong);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Route getDirections(String startLocation, String endLocation) {
|
||||||
|
String requestUrl = BASE_URL + DIRECTIONS_MODE + "?api_key=" + API_KEY + "&start=" +startLocation + "&end=" + endLocation;
|
||||||
|
AtomicReference<Route> res = null;
|
||||||
|
Thread t = new Thread(() -> {
|
||||||
|
|
||||||
|
Request request = new Request.Builder().url(requestUrl).build();
|
||||||
|
|
||||||
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
if (response.body() != null) {
|
||||||
|
String responseString = Objects.requireNonNull(response.body()).string();
|
||||||
|
Log.d(TAG, "getDirections: got response: " + responseString);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, "getDirections: caught exception: " + e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
t.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
t.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return res.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,61 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class CouponAdapter {
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
class CouponViewHolder {
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Coupon;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponViewHolder> {
|
||||||
|
|
||||||
|
private Context appContext;
|
||||||
|
private List<Coupon> couponList;
|
||||||
|
private OnItemClickListener clickListener;
|
||||||
|
|
||||||
|
public interface OnItemClickListener {
|
||||||
|
void onItemClick(int clickedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
class CouponViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
||||||
|
public CouponViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
clickListener.onItemClick(getAdapterPosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CouponAdapter(Context context, List<Coupon> coupon, OnItemClickListener listener){
|
||||||
|
appContext = context;
|
||||||
|
couponList = coupon;
|
||||||
|
clickListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public CouponViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return couponList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,23 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Coupon;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CouponListManager {
|
public class CouponListManager {
|
||||||
|
|
||||||
|
private List<Coupon> coupon;
|
||||||
|
|
||||||
|
public CouponListManager(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Coupon> getCoupon() {
|
||||||
|
return coupon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoupon(List<Coupon> location) {
|
||||||
|
this.coupon = coupon;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class CouponLoader {
|
public class CouponLoader implements Loader{
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
|
public interface Loader {
|
||||||
|
void load();
|
||||||
|
}
|
||||||
@@ -1,8 +1,70 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class LocationAdapter {
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
class LocationViewHolder {
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.R;
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.LocationViewHolder> {
|
||||||
|
|
||||||
|
private Context appContext;
|
||||||
|
private List<Location> locationList;
|
||||||
|
private CouponAdapter.OnItemClickListener clickListener;
|
||||||
|
|
||||||
|
public interface OnItemClickListener {
|
||||||
|
void onItemClick(int clickedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocationViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
||||||
|
private TextView locationName;
|
||||||
|
|
||||||
|
public LocationViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
this.locationName = itemView.findViewById(R.id.location_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
clickListener.onItemClick(getAdapterPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextViewText(String text){
|
||||||
|
locationName.setText(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocationAdapter(Context context, List<Location> location, CouponAdapter.OnItemClickListener listener){
|
||||||
|
this.appContext = context;
|
||||||
|
this.locationList = location;
|
||||||
|
this.clickListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public LocationAdapter.LocationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_location, parent, false);
|
||||||
|
LocationViewHolder viewHolder = new LocationViewHolder(itemView);
|
||||||
|
return viewHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull LocationAdapter.LocationViewHolder holder, int position) {
|
||||||
|
Location location = locationList.get(position);
|
||||||
|
holder.setTextViewText(location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return locationList.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,22 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LocationListManager {
|
public class LocationListManager {
|
||||||
|
|
||||||
|
private List<Location> location;
|
||||||
|
|
||||||
|
public LocationListManager(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Location> getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(List<Location> location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class LocationLoader {
|
public class LocationLoader implements Loader{
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,57 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class RouteAdapter {
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
class RouteViewHolder {
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Route;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RouteAdapter extends RecyclerView.Adapter<RouteAdapter.RouteViewHolder>{
|
||||||
|
|
||||||
|
private Context appContext;
|
||||||
|
private List<Route> routeList;
|
||||||
|
private CouponAdapter.OnItemClickListener clickListener;
|
||||||
|
|
||||||
|
public interface OnItemClickListener {
|
||||||
|
void onItemClick(int clickedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
class RouteViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
||||||
|
public RouteViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
clickListener.onItemClick(getAdapterPosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RouteAdapter(Context context, List<Route> route, CouponAdapter.OnItemClickListener listener){
|
||||||
|
appContext = context;
|
||||||
|
routeList = route;
|
||||||
|
clickListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RouteAdapter.RouteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull RouteAdapter.RouteViewHolder holder, int position) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return routeList.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,27 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class RouteListManager {
|
import com.a1.nextlocation.data.Route;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RouteListManager implements Loader{
|
||||||
|
|
||||||
|
List<Route> routes;
|
||||||
|
|
||||||
|
public RouteListManager(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Route> getRoutes() {
|
||||||
|
return routes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoutes(List<Route> routes) {
|
||||||
|
this.routes = routes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
public class RouteLoader {
|
public class RouteLoader implements Loader {
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
app/src/main/res/drawable/ic_home.xml
Normal file
10
app/src/main/res/drawable/ic_home.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||||
|
</vector>
|
||||||
10
app/src/main/res/drawable/ic_placeholder.xml
Normal file
10
app/src/main/res/drawable/ic_placeholder.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"
|
||||||
|
android:fillColor="@android:color/white"/>
|
||||||
|
</vector>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
tools:context=".fragments.HomeFragment">
|
tools:context=".fragments.HomeFragment">
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.gms.maps.MapView
|
<org.osmdroid.views.MapView
|
||||||
android:id="@+id/mapView"
|
android:id="@+id/mapView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|||||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Tue Dec 08 10:31:45 CET 2020
|
#Mon Dec 14 14:48:57 CET 2020
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
||||||
|
|||||||
Reference in New Issue
Block a user