Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Robin Koedood
2021-01-06 19:19:58 +01:00
6 changed files with 49 additions and 55 deletions

View File

@@ -26,7 +26,7 @@ public class CouponFragment extends Fragment {
private RecyclerView.LayoutManager layoutManager;
private List<Coupon> couponList;
private CouponAdapter couponAdapter;
private ImageButton imageButton;
private ImageButton backButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -37,18 +37,22 @@ public class CouponFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_coupon, container, false);
//Makes the recyclerview
this.couponRecyclerView = view.findViewById(R.id.coupon_recyclerview);
this.couponRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
//Loads the couponList
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.imageButton = view.findViewById(R.id.coupon_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialises the back button
this.backButton = view.findViewById(R.id.coupon_back_button);
this.backButton.setOnClickListener(v -> {
StatisticFragment statisticFragment = new StatisticFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, statisticFragment).addToBackStack(null).commit();
});
@@ -58,6 +62,10 @@ public class CouponFragment extends Fragment {
return view;
}
/**
* shows the popup of a coupon
* @param coupon the coupon that will be displayed
*/
private void showPopup(Coupon coupon) {
AlertDialog.Builder activateBuilder = new AlertDialog.Builder(getContext());
AlertDialog.Builder couponCodeBuilder = new AlertDialog.Builder(getContext());

View File

@@ -1,7 +1,6 @@
package com.a1.nextlocation.fragments;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -21,14 +20,13 @@ import com.a1.nextlocation.data.Location;
public class LocationDetailFragment extends Fragment {
private static final String TAG = LocationDetailFragment.class.getCanonicalName();
private ImageButton imageButton;
private ImageButton backButton;
private Location location;
private TextView titelText;
private TextView detailText;
private ImageView locationImage;
public LocationDetailFragment() {
}
public LocationDetailFragment(Location location) {
@@ -51,12 +49,14 @@ public class LocationDetailFragment extends Fragment {
this.detailText = view.findViewById(R.id.detail_location_text);
this.detailText.setText(location.getDescription());
this.imageButton = view.findViewById(R.id.detail_location_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialises the back button
this.backButton = view.findViewById(R.id.detail_location_back_button);
this.backButton.setOnClickListener(v -> {
LocationFragment locationFragment = new LocationFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit();
});
//Logs the location
if (location != null) {
Log.d(TAG, "onCreateView: the location has a name of: " + location.getName());
}
@@ -68,8 +68,4 @@ public class LocationDetailFragment extends Fragment {
return view;
}
public void setLocation(Location location) {
this.location = location;
}
}

View File

@@ -1,6 +1,5 @@
package com.a1.nextlocation.fragments;
import android.media.Image;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -25,7 +24,7 @@ public class LocationFragment extends Fragment {
private LocationAdapter locationAdapter;
private RecyclerView.LayoutManager layoutManager;
private List<Location> locationList;
private ImageButton imageButton;
private ImageButton backButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -41,22 +40,24 @@ public class LocationFragment extends Fragment {
this.locationRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
this.imageButton = view.findViewById(R.id.location_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialised the back button
this.backButton = view.findViewById(R.id.location_back_button);
this.backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
//Loads the location list
LocationListManager.INSTANCE.setContext(this.getContext());
LocationListManager.INSTANCE.load();
this.locationList = LocationListManager.INSTANCE.getLocationList();
//Initialises the adapter
this.locationAdapter = new LocationAdapter(this.getContext(), this.locationList, clickedPosition -> {
LocationDetailFragment locationDetailFragment = new LocationDetailFragment();
locationDetailFragment.setLocation(this.locationList.get(clickedPosition));
LocationDetailFragment locationDetailFragment = new LocationDetailFragment(this.locationList.get(clickedPosition));
Bundle locationBundle = new Bundle();
//Gives the clicked location to the adapter
locationBundle.putParcelable("location", this.locationList.get(clickedPosition));
locationDetailFragment.setLocation(this.locationList.get(clickedPosition));
locationDetailFragment.setArguments(locationBundle);
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationDetailFragment).addToBackStack(null).commit();
});

View File

@@ -22,17 +22,18 @@ import com.a1.nextlocation.data.Route;
import com.a1.nextlocation.data.RouteHandler;
import com.a1.nextlocation.network.ApiHandler;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class RouteDetailFragment extends Fragment {
private Route route;
private ImageView imageView;
private Refreshable refreshable;
@Override
public void onAttach(Context context) {
public void onAttach(@NotNull Context context) {
super.onAttach(context);
if (context instanceof Refreshable)
this.refreshable = (Refreshable) context;
@@ -51,10 +52,11 @@ public class RouteDetailFragment extends Fragment {
this.route = getArguments().getParcelable("route");
}
this.imageView = view.findViewById(R.id.route_detail_image);
Context context = this.imageView.getContext();
//Sets the image of the RouteDetail
ImageView imageView = view.findViewById(R.id.route_detail_image);
Context context = imageView.getContext();
int id = context.getResources().getIdentifier(this.route.getImageURL(), "drawable", context.getPackageName());
this.imageView.setImageResource(id);
imageView.setImageResource(id);
TextView routeName = view.findViewById(R.id.route_title);
routeName.setText(this.route.getName());
@@ -66,8 +68,9 @@ public class RouteDetailFragment extends Fragment {
String distance_tekst = getResources().getString(R.string.total_distance_route);
totalDistance.setText(distance_tekst + " " + calculateRoute(this.route.getLocations()) + "m");
ImageButton imageButton = view.findViewById(R.id.route_detail_back_button);
imageButton.setOnClickListener(v -> {
//Initialises the back button
ImageButton backButton = view.findViewById(R.id.route_detail_back_button);
backButton.setOnClickListener(v -> {
RouteFragment routeFragment = new RouteFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeFragment).addToBackStack(null).commit();
});

View File

@@ -30,11 +30,7 @@ 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;
private ImageButton imageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -46,15 +42,16 @@ public class RouteFragment extends Fragment {
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.route_recyclerview);
this.routeRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
RecyclerView routeRecyclerView = view.findViewById(R.id.route_recyclerview);
routeRecyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager 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 -> {
//Sets the adapter for the route
RouteAdapter routeAdapter = new RouteAdapter(this.getContext(), this.routeList, clickedPosition -> {
RouteDetailFragment routeDetailFragment = new RouteDetailFragment();
Bundle routeBundle = new Bundle();
routeBundle.putParcelable("route", this.routeList.get(clickedPosition));
@@ -62,31 +59,19 @@ public class RouteFragment extends Fragment {
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeDetailFragment).addToBackStack(null).commit();
});
this.imageButton = view.findViewById(R.id.route_back_button);
this.imageButton.setOnClickListener(v -> {
ImageButton backButton = view.findViewById(R.id.route_back_button);
backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
this.routeRecyclerView.setLayoutManager(this.layoutManager);
this.routeRecyclerView.setAdapter(this.routeAdapter);
routeRecyclerView.setLayoutManager(layoutManager);
routeRecyclerView.setAdapter(routeAdapter);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// ApiHandler.INSTANCE.getDirections(51.49017262451581, 4.289038164073164,51.47337383133509, 4.303535222390562);
// Route r = new Route("test");
// r.addLocation(new Location("test",51.574473766034046, 4.7628379328055175,"route",null));
// r.addLocation(new Location("test",51.577354223919876, 4.771120593941968,"route",null));
// r.addLocation(new Location("test",51.573033468635174, 4.782750651807139,"route",null));
// r.addLocation(new Location("test",51.56519104881196, 4.748246716295709,"route",null));
// r.addLocation(new Location("test",51.57367360644676, 4.74404101271347,"route",null));
// r.addLocation(new Location("test",51.57852769146427, 4.739878224473907,"route",null));
//// r.addLocation(new Location("test",51.489063681658145, 4.289596063527951,"route",null));
//// r.addLocation(new Location("test",51.483012677667766, 4.28003245468457,"route",null));
// ApiHandler.INSTANCE.getDirections(r);
}
}

View File

@@ -1,5 +1,6 @@
package com.a1.nextlocation.fragments;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@@ -27,7 +28,6 @@ import java.util.Locale;
public class SettingsFragment extends Fragment {
private SharedPreferences.Editor editor;
private ImageView imageButton;
SwitchCompat fontChanger;
private Refreshable refreshable;
@@ -37,6 +37,7 @@ public class SettingsFragment extends Fragment {
refreshable = (Refreshable) context;
}
@SuppressLint("CommitPrefEdits")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -51,14 +52,14 @@ public class SettingsFragment extends Fragment {
initializeLanguageDropdown(view);
this.imageButton = view.findViewById(R.id.settings_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialises back button
ImageView backButton = view.findViewById(R.id.settings_back_button);
backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
fontChanger = view.findViewById(R.id.BigFont);
this.fontChanger = view.findViewById(R.id.BigFont);
SharedPreferences sharedPreferences = requireActivity().getSharedPreferences("com.a1.nextlocation",0);
SharedPreferences.Editor editor = sharedPreferences.edit();