This commit is contained in:
Sem van der Hoeven
2021-01-04 15:49:42 +01:00
24 changed files with 434 additions and 623 deletions

View File

@@ -1,12 +1,15 @@
package com.a1.nextlocation.data;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.osmdroid.util.GeoPoint;
public class Location {
public class Location implements Parcelable {
@NonNull
private String name;
@@ -32,6 +35,25 @@ public class Location {
this(name,getStringFromCoordinates(latCoord,longCoord),description,imageUrl);
}
protected Location(Parcel in) {
name = in.readString();
coordinates = in.readString();
description = in.readString();
imageUrl = in.readString();
}
public static final Creator<Location> CREATOR = new Creator<Location>() {
@Override
public Location createFromParcel(Parcel in) {
return new Location(in);
}
@Override
public Location[] newArray(int size) {
return new Location[size];
}
};
@NotNull
public String getName() {
return name;
@@ -90,4 +112,16 @@ public class Location {
return new GeoPoint(this.getLat(),this.getLong());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(name);
parcel.writeString(coordinates);
parcel.writeString(description);
parcel.writeString(imageUrl);
}
}

View File

@@ -1,5 +1,8 @@
package com.a1.nextlocation.data;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import org.jetbrains.annotations.NotNull;
@@ -7,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class Route {
public class Route implements Parcelable {
@NonNull
@@ -29,6 +32,25 @@ public class Route {
}
protected Route(Parcel in) {
this.name = in.readString();
this.locations = in.createTypedArrayList(Location.CREATOR);
this.totalDistance = in.readFloat();
this.totalTime = in.readInt();
}
public static final Creator<Route> CREATOR = new Creator<Route>() {
@Override
public Route createFromParcel(Parcel in) {
return new Route(in);
}
@Override
public Route[] newArray(int size) {
return new Route[size];
}
};
public void addLocation(Location location) {
this.locations.add(location);
}
@@ -69,4 +91,16 @@ public class Route {
this.totalTime = totalTime;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(name);
parcel.writeTypedList(locations);
parcel.writeFloat(totalDistance);
parcel.writeInt(totalTime);
}
}

View File

@@ -1,26 +1,85 @@
package com.a1.nextlocation.fragments;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Coupon;
import com.a1.nextlocation.recyclerview.CouponAdapter;
import com.a1.nextlocation.recyclerview.CouponListManager;
import java.util.List;
public class CouponFragment extends Fragment {
private RecyclerView couponRecyclerView;
private RecyclerView.LayoutManager layoutManager;
private List<Coupon> couponList;
private CouponAdapter couponAdapter;
private ImageButton imageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_coupon, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_coupon, container, false);
this.couponRecyclerView = view.findViewById(R.id.couponRecyclerView);
this.couponRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
this.imageButton = view.findViewById(R.id.couponBackButton);
this.imageButton.setOnClickListener(v -> {
StatisticFragment statisticFragment = new StatisticFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, statisticFragment).addToBackStack(null).commit();
});
CouponListManager.INSTANCE.setContext(this.getContext());
CouponListManager.INSTANCE.load();
this.couponList = CouponListManager.INSTANCE.getCouponList();
this.couponAdapter = new CouponAdapter(this.getContext(), this.couponList, clickedPosition -> showPopup(this.couponList.get(clickedPosition)));
this.couponRecyclerView.setLayoutManager(this.layoutManager);
this.couponRecyclerView.setAdapter(this.couponAdapter);
return view;
}
private void showPopup(Coupon coupon) {
AlertDialog.Builder activateBuilder = new AlertDialog.Builder(getContext());
AlertDialog.Builder couponCodeBuilder = new AlertDialog.Builder(getContext());
// TODO: use string resources instead of hardcoded strings
activateBuilder.setMessage("Weet je zeker dat je deze coupon wilt activeren?");
activateBuilder.setCancelable(true);
// TODO: use string resources instead of hardcoded strings
activateBuilder.setPositiveButton("activeren", (dialog, which) -> {
// TODO: use string resources instead of hardcoded strings
dialog.cancel();
couponCodeBuilder.setMessage("Code: " + coupon.getCode());
couponCodeBuilder.setPositiveButton("Klaar", (dialog1, which1) -> {
dialog.cancel();
});
AlertDialog couponCodePopup = couponCodeBuilder.create();
couponCodePopup.show();
});
// TODO: use string resources instead of hardcoded strings
activateBuilder.setNegativeButton("annuleren", (dialog, which) -> dialog.cancel());
AlertDialog couponPopup = activateBuilder.create();
couponPopup.show();
}
}

View File

@@ -13,12 +13,14 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Route;
@@ -42,6 +44,7 @@ import java.util.ArrayList;
public class HomeFragment extends Fragment {
private final String userAgent = "com.ai.nextlocation.fragments";
private ImageButton imageButton;
private MapView mapView;
private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
private final String TAG = HomeFragment.class.getCanonicalName();
@@ -60,10 +63,16 @@ public class HomeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
View view = inflater.inflate(R.layout.fragment_home, container, false);
this.imageButton = view.findViewById(R.id.location_list_button);
this.imageButton.setOnClickListener(v -> {
LocationFragment locationFragment = new LocationFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit();
});
return view;
}
@Override

View File

@@ -3,15 +3,19 @@ package com.a1.nextlocation.fragments;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import com.a1.nextlocation.R;
public class LocationDetailFragment extends Fragment {
private ImageButton imageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -21,7 +25,15 @@ public class LocationDetailFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_location_detail, container, false);
View view = inflater.inflate(R.layout.fragment_location_detail, container, false);
//
// this.imageButton = view.findViewById(R.id.detail_location_back_button);
// this.imageButton.setOnClickListener(v -> {
// LocationFragment locationFragment = new LocationFragment();
// ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit();
// });
return view;
}
}

View File

@@ -3,25 +3,65 @@ package com.a1.nextlocation.fragments;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Location;
import com.a1.nextlocation.recyclerview.CouponAdapter;
import com.a1.nextlocation.recyclerview.LocationAdapter;
import com.a1.nextlocation.recyclerview.LocationListManager;
import java.util.ArrayList;
import java.util.List;
public class LocationFragment extends Fragment {
private RecyclerView locationRecyclerView;
private LocationAdapter locationAdapter;
private RecyclerView.LayoutManager layoutManager;
private List<Location> locationList;
private ImageButton imageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_location, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_location, container, false);
this.locationRecyclerView = view.findViewById(R.id.locationRecyclerView);
this.locationRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
this.imageButton = view.findViewById(R.id.locationBackButton);
this.imageButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
LocationListManager.INSTANCE.setContext(this.getContext());
LocationListManager.INSTANCE.load();
this.locationList = LocationListManager.INSTANCE.getLocationList();
this.locationAdapter = new LocationAdapter(this.getContext(), this.locationList, clickedPosition -> {
LocationDetailFragment locationDetailFragment = new LocationDetailFragment();
Bundle locationBundle = new Bundle();
locationBundle.putParcelable("location", this.locationList.get(clickedPosition));
locationDetailFragment.setArguments(locationBundle);
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationDetailFragment).addToBackStack(null).commit();
});
this.locationRecyclerView.setLayoutManager(this.layoutManager);
this.locationRecyclerView.setAdapter(this.locationAdapter);
return view;
}
}

View File

@@ -7,11 +7,16 @@ import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Route;
public class RouteDetailFragment extends Fragment {
private Route route;
private TextView routeDetailText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -19,9 +24,16 @@ public class RouteDetailFragment extends Fragment {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_route_detail, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_route_detail, container, false);
if(getArguments().getParcelable("route") != null) {
this.route = getArguments().getParcelable("route");
}
this.routeDetailText = view.findViewById(R.id.routeDetailText);
this.routeDetailText.setText(this.route.getName());
return view;
}
}

View File

@@ -5,6 +5,9 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
@@ -12,6 +15,12 @@ import android.view.View;
import android.view.ViewGroup;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Route;
import com.a1.nextlocation.recyclerview.RouteAdapter;
import com.a1.nextlocation.recyclerview.RouteListManager;
import java.util.ArrayList;
import java.util.List;
import com.a1.nextlocation.data.Location;
import com.a1.nextlocation.data.Route;
import com.a1.nextlocation.json.DirectionsResult;
@@ -21,6 +30,11 @@ import com.a1.nextlocation.network.DirectionsListener;
public class RouteFragment extends Fragment {
private static final String TAG = RouteFragment.class.getCanonicalName();
private RecyclerView routeRecyclerView;
private RecyclerView.LayoutManager layoutManager;
private List<Route> routeList;
private RouteAdapter routeAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -29,10 +43,28 @@ public class RouteFragment extends Fragment {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_route, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_route, container, false);
this.routeRecyclerView = view.findViewById(R.id.routeRecyclerView);
this.routeRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
RouteListManager.INSTANCE.setContext(this.getContext());
RouteListManager.INSTANCE.load();
this.routeList = RouteListManager.INSTANCE.getRouteList();
this.routeAdapter = new RouteAdapter(this.getContext(), this.routeList, clickedPosition -> {
RouteDetailFragment routeDetailFragment = new RouteDetailFragment();
Bundle routeBundle = new Bundle();
routeBundle.putParcelable("route", this.routeList.get(clickedPosition));
routeDetailFragment.setArguments(routeBundle);
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeDetailFragment).addToBackStack(null).commit();
});
this.routeRecyclerView.setLayoutManager(this.layoutManager);
this.routeRecyclerView.setAdapter(this.routeAdapter);
return view;
}
@Override
@@ -40,15 +72,15 @@ public class RouteFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
// ApiHandler.INSTANCE.getDirections(8.681436,49.41461,8.687872,49.420318);
Route r = new Route("test");
r.addLocation(new Location("test",8.681436,49.41461,"route",null));
r.addLocation(new Location("test",8.687872,49.420318,"route",null));
ApiHandler.INSTANCE.getDirections(r);
// Route r = new Route("test");
// r.addLocation(new Location("test",8.681436,49.41461,"route",null));
// r.addLocation(new Location("test",8.687872,49.420318,"route",null));
// ApiHandler.INSTANCE.getDirections(r);
}
public void onDirectionsAvailable(DirectionsResult result) {
Log.d(TAG, "onDirectionsAvailable: got result! " + result);
}
}

View File

@@ -2,26 +2,51 @@ package com.a1.nextlocation.fragments;
import android.os.Bundle;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Coupon;
import com.a1.nextlocation.recyclerview.CouponAdapter;
import com.a1.nextlocation.recyclerview.CouponListManager;
import java.util.List;
public class StatisticFragment extends Fragment {
private List<Coupon> couponList;
private ImageView imageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_statistic, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_statistic, container, false);
this.couponList = CouponListManager.INSTANCE.getCouponList();
CouponAdapter adapter = new CouponAdapter(this.getContext(), this.couponList);
TextView couponNumber = view.findViewById(R.id.couponAmount);
couponNumber.setText(String.valueOf(adapter.getItemCount()));
ConstraintLayout constraintLayout = view.findViewById(R.id.Box4);
constraintLayout.setOnClickListener(v -> {
CouponFragment couponFragment = new CouponFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, couponFragment).addToBackStack(null).commit();
});
return view;
}
}

View File

@@ -3,10 +3,13 @@ package com.a1.nextlocation.recyclerview;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Coupon;
import java.util.List;
@@ -23,31 +26,49 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
class CouponViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView couponCode;
private TextView couponReward;
public CouponViewHolder(@NonNull View itemView) {
super(itemView);
itemView.setOnClickListener(this);
}
public void setTextViewName(String text){
this.couponReward = itemView.findViewById(R.id.coupon_name);
this.couponReward.setText(text);
}
@Override
public void onClick(View view) {
public void onClick(View v) {
clickListener.onItemClick(getAdapterPosition());
}
}
public CouponAdapter(Context context, List<Coupon> coupon, OnItemClickListener listener){
appContext = context;
couponList = coupon;
clickListener = listener;
this.appContext = context;
this.couponList = coupon;
this.clickListener = listener;
}
public CouponAdapter(Context context, List<Coupon> coupon) {
this.appContext = context;
this.couponList = coupon;
}
@NonNull
@Override
public CouponViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.coupon_item, parent, false);
return new CouponViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) {
Coupon coupon = couponList.get(position);
holder.setTextViewName(coupon.getReward());
}
@Override
@@ -55,7 +76,4 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
return couponList.size();
}
}

View File

@@ -5,11 +5,9 @@ import android.util.Log;
import com.a1.nextlocation.data.Coupon;
import com.a1.nextlocation.data.FileIO;
import com.a1.nextlocation.data.Location;
import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CouponLoader implements Loader<List<Coupon>> {

View File

@@ -18,7 +18,7 @@ public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.Locati
private Context appContext;
private List<Location> locationList;
private CouponAdapter.OnItemClickListener clickListener;
private OnItemClickListener clickListener;
public interface OnItemClickListener {
void onItemClick(int clickedPosition);
@@ -31,6 +31,7 @@ public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.Locati
public LocationViewHolder(@NonNull View itemView) {
super(itemView);
this.locationName = itemView.findViewById(R.id.location_name);
itemView.setOnClickListener(this);
}
@Override
@@ -39,11 +40,12 @@ public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.Locati
}
public void setTextViewText(String text){
this.locationName = itemView.findViewById(R.id.location_name);
locationName.setText(text);
}
}
public LocationAdapter(Context context, List<Location> location, CouponAdapter.OnItemClickListener listener){
public LocationAdapter(Context context, List<Location> location, OnItemClickListener listener){
this.appContext = context;
this.locationList = location;
this.clickListener = listener;
@@ -52,9 +54,8 @@ public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.Locati
@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;
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.location_item, parent, false);
return new LocationViewHolder(itemView);
}
@Override

View File

@@ -1,12 +1,17 @@
package com.a1.nextlocation.recyclerview;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Location;
import com.a1.nextlocation.data.Route;
import java.util.List;
@@ -23,14 +28,23 @@ public class RouteAdapter extends RecyclerView.Adapter<RouteAdapter.RouteViewHol
class RouteViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView routeName;
public RouteViewHolder(@NonNull View itemView) {
super(itemView);
this.routeName = itemView.findViewById(R.id.route_name);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
clickListener.onItemClick(getAdapterPosition());
}
public void setTextViewText(String text){
this.routeName = itemView.findViewById(R.id.route_name);
this.routeName.setText(text);
}
}
public RouteAdapter(Context context, List<Route> route, CouponAdapter.OnItemClickListener listener){
@@ -42,12 +56,14 @@ public class RouteAdapter extends RecyclerView.Adapter<RouteAdapter.RouteViewHol
@NonNull
@Override
public RouteAdapter.RouteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.route_item, parent, false);
return new RouteViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull RouteAdapter.RouteViewHolder holder, int position) {
Route route = routeList.get(position);
holder.setTextViewText(route.getName());
}
@Override