From ebde0c58154c98e0b70d0c2835baa739701ae608 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 17:34:32 +0100 Subject: [PATCH 1/9] [UPDATED] DataTest --- .../java/com/a1/nextlocation/DataTest.java | 37 +++++---- .../com/a1/nextlocation/DataTestClass.java | 81 ------------------- 2 files changed, 23 insertions(+), 95 deletions(-) delete mode 100644 app/src/test/java/com/a1/nextlocation/DataTestClass.java diff --git a/app/src/test/java/com/a1/nextlocation/DataTest.java b/app/src/test/java/com/a1/nextlocation/DataTest.java index dd7d137..3354a64 100644 --- a/app/src/test/java/com/a1/nextlocation/DataTest.java +++ b/app/src/test/java/com/a1/nextlocation/DataTest.java @@ -11,39 +11,48 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotSame; public class DataTest { - private Data Data; + private Data data; @Before public void init(){ - Data = Data.INSTANCE; + data = Data.INSTANCE; } @Test public void testDistance(){ - Data.addDistance(2356.234); + data.addDistance(2356.234); double expected = 2356.234; - assertEquals(expected, Data.getDistanceTraveled(), 0.01); - Data.addDistance(234342.1); - assertNotEquals(expected, Data.getDistanceTraveled()); + assertEquals(expected, data.getDistanceTraveled(), 0.01); + data.addDistance(234342.1); + assertNotEquals(expected, data.getDistanceTraveled()); } @Test public void testTimeWalked(){ - Data.addTimeWalked(3456); + data.addTimeWalked(3456); long expected = 3456; - assertEquals(expected, Data.getTimeWalked()); - Data.addTimeWalked(3445); - assertNotEquals(expected, Data.getTimeWalked()); + assertEquals(expected, data.getTotalTime()); + data.addTimeWalked(3445); + assertNotEquals(expected, data.getTotalTime()); } @Test public void testVisitedLocation(){ Location testLocation = new Location("test", "test", "test", "test"); - Data.visitLocation(testLocation); + data.visitLocation(testLocation); int expected = 1; - assertEquals(expected, Data.getLocationsVisited()); - Data.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE")); - assertNotEquals(expected, Data.getLocationsVisited()); + assertEquals(expected, data.getLocationsVisited()); + data.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE")); + assertNotEquals(expected, data.getLocationsVisited()); + } + + @Test + public void testZoom(){ + data.setZoom(234.63); + double expected = 234.63; + assertEquals(expected, data.getZoom(), 0.01); + data.setZoom(342.55); + assertNotEquals(expected, data.getZoom()); } } diff --git a/app/src/test/java/com/a1/nextlocation/DataTestClass.java b/app/src/test/java/com/a1/nextlocation/DataTestClass.java deleted file mode 100644 index 576f00a..0000000 --- a/app/src/test/java/com/a1/nextlocation/DataTestClass.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.a1.nextlocation; - -import com.a1.nextlocation.data.Coupon; -import com.a1.nextlocation.data.Data; -import com.a1.nextlocation.data.Location; -import com.a1.nextlocation.data.Route; - -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -public class DataTestClass { - private Data data; - - @Before - public void init(){ - data = new Data(); - } - - - @Test - public void testSetDistanceTraveled() { - data.setDistanceTraveled(100); - - int expected = 100; - assertEquals(expected, data.getDistanceTraveled(), 0.1); - } - - @Test - public void testSetLocationsVisited() { - data.setLocationsVisited(16); - - int expected = 16; - assertEquals(expected, data.getLocationsVisited()); - } - - @Test - public void testSetTotalTime() { - data.setTotalTime(120); - - int expected = 120; - assertEquals(expected, data.getTotalTime()); - } - - @Test - public void testSetCouponList() { - List expected = new ArrayList<>(); - expected.add(new Coupon("CODE1", "REWARD1")); - expected.add(new Coupon("CODE2", "REWARD2")); - expected.add(new Coupon("CODE3", "REWARD3")); - - data.setCouponList(expected); - assertEquals(expected, data.getCouponList()); - } - - @Test - public void testNextLocation() { - Location expected = new Location("name1", "cord1", "desc1", null); - data.setNextLocation(expected); - assertEquals(expected, data.getNextLocation()); - } - - @Test - public void testLastLocation() { - Location expected = new Location("name2", "cord2", "desc2", null); - data.setLastLocation(expected); - assertEquals(expected, data.getLastLocation()); - } - - @Test - public void testCurrentRoute() { - Route expected = new Route("testRoute1"); - data.setCurrentRoute(expected); - assertEquals(expected, data.getCurrentRoute()); - } - - -} \ No newline at end of file From 08b0ca191bc5db8217fcfb90548b3e6fb4421098 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 17:39:16 +0100 Subject: [PATCH 2/9] [UPDATED] Name of button --- .../java/com/a1/nextlocation/SettingsFragmentTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java index e2d99dd..e405785 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java @@ -55,14 +55,14 @@ public class SettingsFragmentTest { public void buttonTest(){ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); onView(withId(R.id.settingsImperialButton)).check(matches(isClickable())); - onView(withId(R.id.settingsOldButton)).check(matches(isClickable())); + onView(withId(R.id.settingsImperialButton)).check(matches(isClickable())); onView(withId(R.id.settingsEyesButton)).check(matches(isClickable())); onView(withId(R.id.settingsImperialButton)).perform(click()); onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); - onView(withId(R.id.settingsOldButton)).perform(click()); - onView(withId(R.id.settingsOldButton)).check(matches(isChecked())); + onView(withId(R.id.settingsImperialButton)).perform(click()); + onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); onView(withId(R.id.settingsEyesButton)).perform(click()); onView(withId(R.id.settingsEyesButton)).check(matches(isChecked())); From f868302d30683565f7979ada09b0eb26f44e36ad Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 17:41:25 +0100 Subject: [PATCH 3/9] [UPDATED] CouponFragment test with string values --- .../java/com/a1/nextlocation/CouponFragmentTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java index 49b7ee5..d0aeb9a 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java @@ -41,8 +41,8 @@ public class CouponFragmentTest { //the button "Klaar" is shown then the test works mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new CouponFragment()).commit(); onView(withId(R.id.coupon_recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); - onView(withText("activeren")).inRoot(RootMatchers.isDialog()).perform(click()); - onView(withText("Klaar")).inRoot(RootMatchers.isDialog()).check(matches(isDisplayed())); + onView(withId(R.string.activate)).inRoot(RootMatchers.isDialog()).perform(click()); + onView(withId(R.string.done)).inRoot(RootMatchers.isDialog()).check(matches(isDisplayed())); } From 56a14c2482015e65f42658d62c91386ad1f9af1f Mon Sep 17 00:00:00 2001 From: Bart Date: Wed, 6 Jan 2021 18:31:55 +0100 Subject: [PATCH 4/9] Fixed the bottomNavigation refresh when a route is started --- .../main/java/com/a1/nextlocation/MainActivity.java | 4 ++-- .../com/a1/nextlocation/fragments/Refreshable.java | 2 +- .../a1/nextlocation/fragments/RouteDetailFragment.java | 10 +++++++++- .../a1/nextlocation/fragments/SettingsFragment.java | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/a1/nextlocation/MainActivity.java b/app/src/main/java/com/a1/nextlocation/MainActivity.java index 9097ac9..b9e5747 100644 --- a/app/src/main/java/com/a1/nextlocation/MainActivity.java +++ b/app/src/main/java/com/a1/nextlocation/MainActivity.java @@ -113,10 +113,10 @@ public class MainActivity extends AppCompatActivity implements Refreshable { * refreshes bottom navigation */ @Override - public void refresh() { + public void refreshAndNavigateTo(int id) { bottomNav.getMenu().clear(); bottomNav.inflateMenu(R.menu.navmenu); - bottomNav.setSelectedItemId(R.id.settings); + bottomNav.setSelectedItemId(id); } private View.OnClickListener onInfoClickListener = new View.OnClickListener() { diff --git a/app/src/main/java/com/a1/nextlocation/fragments/Refreshable.java b/app/src/main/java/com/a1/nextlocation/fragments/Refreshable.java index 2d4be7b..bbedd3b 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/Refreshable.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/Refreshable.java @@ -1,5 +1,5 @@ package com.a1.nextlocation.fragments; public interface Refreshable { - void refresh(); + void refreshAndNavigateTo(int id); } diff --git a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java index 1c258e9..c2b0fde 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java @@ -29,7 +29,14 @@ public class RouteDetailFragment extends Fragment { private Route route; private ImageView imageView; + private Refreshable refreshable; + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof Refreshable) + this.refreshable = (Refreshable) context; + } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -79,7 +86,8 @@ public class RouteDetailFragment extends Fragment { ApiHandler.INSTANCE.getDirections(route); RouteHandler.INSTANCE.followRoute(route); Toast.makeText(requireContext(),"Route started!",Toast.LENGTH_SHORT).show(); - ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).addToBackStack(null).commit(); + // navigates to the HomeFragment and refreshes the BottomNavigation + refreshable.refreshAndNavigateTo(R.id.locations); } /** diff --git a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java index 3bdb3d4..c1e9ddd 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -158,7 +158,7 @@ public class SettingsFragment extends Fragment { fragmentTransaction.attach(currentFragment); fragmentTransaction.commit(); - refreshable.refresh(); + refreshable.refreshAndNavigateTo(R.id.settings); } /** From 0d94d17b2f80e2aa09a3470c31153f6e2731e1bc Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 19:17:21 +0100 Subject: [PATCH 5/9] [REMOVED] Color blind --- .../a1/nextlocation/SettingsFragmentTest.java | 5 +- app/src/main/res/layout/fragment_settings.xml | 50 +------------------ 2 files changed, 2 insertions(+), 53 deletions(-) diff --git a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java index e405785..98a3548 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java @@ -56,15 +56,12 @@ public class SettingsFragmentTest { mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); onView(withId(R.id.settingsImperialButton)).check(matches(isClickable())); onView(withId(R.id.settingsImperialButton)).check(matches(isClickable())); - onView(withId(R.id.settingsEyesButton)).check(matches(isClickable())); + onView(withId(R.id.settingsImperialButton)).perform(click()); onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); onView(withId(R.id.settingsImperialButton)).perform(click()); onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); - - onView(withId(R.id.settingsEyesButton)).perform(click()); - onView(withId(R.id.settingsEyesButton)).check(matches(isChecked())); } } diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 343de74..95ab677 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -132,7 +132,7 @@ android:layout_height="70dp" android:layout_marginHorizontal="20dp" android:background="@color/secondaryColour" - app:layout_constraintBottom_toTopOf="@id/Box4" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/Box2" @@ -171,52 +171,4 @@ - - - - - - - - - - - \ No newline at end of file From ae2aab72759f0a1867b03a1837a7c99dcd9613c7 Mon Sep 17 00:00:00 2001 From: RemoMeijer Date: Wed, 6 Jan 2021 19:18:23 +0100 Subject: [PATCH 6/9] Added comments --- .../fragments/CouponFragment.java | 14 ++++++-- .../fragments/LocationDetailFragment.java | 14 +++----- .../fragments/LocationFragment.java | 15 +++++---- .../fragments/RouteDetailFragment.java | 17 ++++++---- .../nextlocation/fragments/RouteFragment.java | 33 +++++-------------- .../fragments/SettingsFragment.java | 11 ++++--- 6 files changed, 49 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java index d97bc31..907f4a9 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java @@ -26,7 +26,7 @@ public class CouponFragment extends Fragment { private RecyclerView.LayoutManager layoutManager; private List 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()); diff --git a/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java index e56e6d4..c0ee7bd 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java @@ -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; - } } \ No newline at end of file diff --git a/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java index 067c759..34c6c35 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/LocationFragment.java @@ -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 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(); }); diff --git a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java index c2b0fde..6470d54 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java @@ -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(); }); diff --git a/app/src/main/java/com/a1/nextlocation/fragments/RouteFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/RouteFragment.java index 2369e6d..7062e30 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/RouteFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/RouteFragment.java @@ -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 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); } } \ No newline at end of file diff --git a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java index c1e9ddd..4db58f4 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -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(); From 5f927a55500567e5ea7af160b54d83d90bc8b728 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 19:19:54 +0100 Subject: [PATCH 7/9] [FIXED] Test works again --- .../java/com/a1/nextlocation/SettingsFragmentTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java index 98a3548..e14b188 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java @@ -55,13 +55,13 @@ public class SettingsFragmentTest { public void buttonTest(){ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); onView(withId(R.id.settingsImperialButton)).check(matches(isClickable())); - onView(withId(R.id.settingsImperialButton)).check(matches(isClickable())); + onView(withId(R.id.BigFont)).check(matches(isClickable())); onView(withId(R.id.settingsImperialButton)).perform(click()); onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); - onView(withId(R.id.settingsImperialButton)).perform(click()); - onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); + onView(withId(R.id.BigFont)).perform(click()); + onView(withId(R.id.BigFont)).check(matches(isChecked())); } } From 4021f9903dd36d33d453399261ffd6bbc0339f4a Mon Sep 17 00:00:00 2001 From: RemoMeijer Date: Wed, 6 Jan 2021 19:24:51 +0100 Subject: [PATCH 8/9] Removed custOverlay, Added comments --- .../recyclerview/CustomOverlay.java | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 app/src/main/java/com/a1/nextlocation/recyclerview/CustomOverlay.java diff --git a/app/src/main/java/com/a1/nextlocation/recyclerview/CustomOverlay.java b/app/src/main/java/com/a1/nextlocation/recyclerview/CustomOverlay.java deleted file mode 100644 index ccf5fe1..0000000 --- a/app/src/main/java/com/a1/nextlocation/recyclerview/CustomOverlay.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.a1.nextlocation.recyclerview; - -import android.graphics.Point; -import android.graphics.drawable.Drawable; - -import org.osmdroid.api.IMapView; -import org.osmdroid.views.MapView; -import org.osmdroid.views.overlay.ItemizedOverlay; -import org.osmdroid.views.overlay.OverlayItem; - -import java.util.ArrayList; - -public class CustomOverlay extends ItemizedOverlay { - private final MapView mapView; - private ArrayList overlayItems = new ArrayList<>(); - - public CustomOverlay(Drawable pDefaultMarker, MapView mapView) { - super(pDefaultMarker); - this.mapView = mapView; - - } - - public void addOverlayItem(OverlayItem item) { - overlayItems.add(item); - populate(); - } - - @Override - protected OverlayItem createItem(int i) { - return overlayItems.get(i); - } - - @Override - public int size() { - return overlayItems.size(); - } - - @Override - public boolean onSnapToItem(int x, int y, Point snapPoint, IMapView mapView) { - return true; - } -} From 5f3fcf2889eb8fb7c0c811a65075a9f000d3a24c Mon Sep 17 00:00:00 2001 From: RemoMeijer Date: Wed, 6 Jan 2021 19:25:04 +0100 Subject: [PATCH 9/9] Added comments --- .../fragments/StatisticFragment.java | 24 +++++++++---------- .../recyclerview/CouponAdapter.java | 10 ++++---- .../recyclerview/CouponListManager.java | 7 +++--- .../recyclerview/CouponLoader.java | 4 ++++ .../recyclerview/LocationAdapter.java | 10 +++++++- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java index f1215ab..aa91d75 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java @@ -1,5 +1,6 @@ package com.a1.nextlocation.fragments; +import android.annotation.SuppressLint; import android.os.Bundle; import androidx.constraintlayout.widget.ConstraintLayout; @@ -22,16 +23,12 @@ import java.util.List; public class StatisticFragment extends Fragment { - private List couponList; - private ImageView imageButton; - private ImageView couponButton; - - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } + @SuppressLint({"DefaultLocale", "SetTextI18n"}) @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_statistic, container, false); @@ -51,24 +48,27 @@ public class StatisticFragment extends Fragment { timeText.setText(p2 + ":" + p3 + ":" + p1); - this.couponList = CouponListManager.INSTANCE.getCouponList(); - CouponAdapter adapter = new CouponAdapter(this.getContext(), this.couponList); + //loads the couponList + List couponList = CouponListManager.INSTANCE.getCouponList(); + CouponAdapter adapter = new CouponAdapter(this.getContext(), couponList); TextView couponNumber = view.findViewById(R.id.couponAmount); couponNumber.setText(String.valueOf(adapter.getItemCount())); - - this.imageButton = view.findViewById(R.id.statistics_back_button); - this.imageButton.setOnClickListener(v -> { + //Initialises the back button + ImageView backButton = view.findViewById(R.id.statistics_back_button); + backButton.setOnClickListener(v -> { HomeFragment homeFragment = new HomeFragment(); ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit(); }); - this.couponButton = view.findViewById(R.id.coupon_button); - this.couponButton.setOnClickListener(v -> { + //Initialises the coupon button + ImageView couponButton = view.findViewById(R.id.coupon_button); + couponButton.setOnClickListener(v -> { CouponFragment couponFragment = new CouponFragment(); ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, couponFragment).addToBackStack(null).commit(); }); + //Makes the constraintlayout clickable and opens the same layout as the coupon button ConstraintLayout constraintLayout = view.findViewById(R.id.Box4); constraintLayout.setOnClickListener(v -> { CouponFragment couponFragment = new CouponFragment(); diff --git a/app/src/main/java/com/a1/nextlocation/recyclerview/CouponAdapter.java b/app/src/main/java/com/a1/nextlocation/recyclerview/CouponAdapter.java index 95ede65..3a2728c 100644 --- a/app/src/main/java/com/a1/nextlocation/recyclerview/CouponAdapter.java +++ b/app/src/main/java/com/a1/nextlocation/recyclerview/CouponAdapter.java @@ -27,17 +27,19 @@ public class CouponAdapter extends RecyclerView.Adapter> { this.context = context; } + /** + * Loads the Arraylist of coupons out of the JSON + * @return Arraylist of coupons + */ @Override public ArrayList load() { FileIO> fileIO = new FileIO<>(); diff --git a/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java b/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java index 897aa27..4a86ee7 100644 --- a/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java +++ b/app/src/main/java/com/a1/nextlocation/recyclerview/LocationAdapter.java @@ -42,11 +42,19 @@ public class LocationAdapter extends RecyclerView.Adapter