From f2360677061f7ffaa3701355bef63f57184dee2f Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 5 Jan 2021 10:45:32 +0100 Subject: [PATCH 01/22] Added English string.xml --- app/src/main/res/layout/fragment_settings.xml | 8 +++---- .../main/res/layout/fragment_statistic.xml | 10 ++++----- app/src/main/res/values-en/strings.xml | 17 +++++++++++++++ app/src/main/res/values/strings.xml | 21 ++++++++----------- 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/values-en/strings.xml diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 6d629eb..3ceecd5 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -45,7 +45,7 @@ + + Location + Total time: + Total distance: + Language + Statistics + Start Route + Routes + Colorblind + Settings + Imperial system + Coupons collected: + Visited locations: + 65+ mode + Coupons + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c322028..9b25e32 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,20 +1,17 @@ - Next Location - - Hello blank fragment + Next Location Locaties Routes Statistieken Instellingen - Taal - Imperiaal systeem - 65+ stand - Kleurenblind - Statistieken - Totale afstand: - Bezochte locaties: - Totale tijd: - Coupons gespaard: + Taal + Imperiaal systeem + 65+ stand + Kleurenblind + Totale afstand: + Bezochte locaties: + Totale tijd: + Coupons gespaard: Coupons Start Route \ No newline at end of file From d3cab8c70db03fd1a75dc8fe1d2858ff5a51e55a Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 10:58:33 +0100 Subject: [PATCH 02/22] [ADD] Location Tests + ID at every XML file --- app/build.gradle | 3 ++ .../a1/nextlocation/LocationFragmentTest.java | 41 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 1 + app/src/main/res/layout/coupon_item.xml | 1 + app/src/main/res/layout/fragment_coupon.xml | 1 + app/src/main/res/layout/fragment_home.xml | 1 + app/src/main/res/layout/fragment_location.xml | 3 +- .../res/layout/fragment_location_detail.xml | 1 + app/src/main/res/layout/fragment_route.xml | 1 + .../main/res/layout/fragment_route_detail.xml | 1 + app/src/main/res/layout/fragment_settings.xml | 1 + .../main/res/layout/fragment_statistic.xml | 1 + app/src/main/res/layout/location_item.xml | 1 + app/src/main/res/layout/route_item.xml | 1 + 14 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java diff --git a/app/build.gradle b/app/build.gradle index 003cd15..a5eb575 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,4 +56,7 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' testImplementation 'org.mockito:mockito-core:2.7.22' + androidTestImplementation 'com.21buttons:fragment-test-rule:2.0.1' + androidTestImplementation 'androidx.test:rules:1.3.0-beta01' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha02' } \ No newline at end of file diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java new file mode 100644 index 0000000..f6d1e55 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java @@ -0,0 +1,41 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static androidx.test.espresso.Espresso.*; +import static androidx.test.espresso.action.ViewActions.*; +import static androidx.test.espresso.assertion.ViewAssertions.*; +import static androidx.test.espresso.matcher.ViewMatchers.*; + + +public class LocationFragmentTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); + onView(withId(R.id.locationBackButton)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + + } + + @Test + public void clickDetailButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); + onView(withId(R.id.locationRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + onView(withId(R.id.locationDetailFragment)).check(matches(isDisplayed())); + + } + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 97123a3..21c68f8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:id="@+id/mainActivity" tools:context=".MainActivity"> diff --git a/app/src/main/res/layout/fragment_location.xml b/app/src/main/res/layout/fragment_location.xml index 7f03472..dd633d8 100644 --- a/app/src/main/res/layout/fragment_location.xml +++ b/app/src/main/res/layout/fragment_location.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primaryColour" + android:id="@+id/locationFragment" tools:context=".fragments.LocationFragment"> + app:layout_constraintTop_toBottomOf="@+id/locationBackButton" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_location_detail.xml b/app/src/main/res/layout/fragment_location_detail.xml index 17b7203..bbf0508 100644 --- a/app/src/main/res/layout/fragment_location_detail.xml +++ b/app/src/main/res/layout/fragment_location_detail.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primaryColour" + android:id="@+id/locationDetailFragment" tools:context=".fragments.LocationDetailFragment"> Date: Tue, 5 Jan 2021 11:44:25 +0100 Subject: [PATCH 03/22] [ADD] Coupon test --- .../a1/nextlocation/CouponFragmentTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java new file mode 100644 index 0000000..b27e97b --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java @@ -0,0 +1,47 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.Root; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.RootMatchers; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.CouponFragment; +import com.a1.nextlocation.fragments.LocationFragment; + +import org.junit.Rule; +import org.junit.Test; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isChecked; +import static androidx.test.espresso.matcher.ViewMatchers.isClickable; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +public class CouponFragmentTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new CouponFragment()).commit(); + onView(withId(R.id.couponBackButton)).perform(click()); + onView(withId(R.id.statisticsFragment)).check(matches(isDisplayed())); + } + + @Test + public void clickDetailButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new CouponFragment()).commit(); + onView(withId(R.id.couponRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + onView(withText("activeren")).inRoot(RootMatchers.isDialog()).perform(click()); + onView(withText("Klaar")).inRoot(RootMatchers.isDialog()).check(matches(isDisplayed())); + + + } + +} From 3b363b3f33026e0644f64672246c38406a576eb8 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 12:07:15 +0100 Subject: [PATCH 04/22] [ADD] Location Detail Fragment Test --- .../a1/nextlocation/CouponFragmentTest.java | 4 +-- .../nextlocation/LocationDetailFragment.java | 26 +++++++++++++++++++ .../a1/nextlocation/LocationFragmentTest.java | 4 +-- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java index b27e97b..e5d4342 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java @@ -30,14 +30,14 @@ public class CouponFragmentTest { @Test public void clickBackButton() throws Exception{ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new CouponFragment()).commit(); - onView(withId(R.id.couponBackButton)).perform(click()); + onView(withId(R.id.coupon_back_button)).perform(click()); onView(withId(R.id.statisticsFragment)).check(matches(isDisplayed())); } @Test public void clickDetailButton() throws Exception{ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new CouponFragment()).commit(); - onView(withId(R.id.couponRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + 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())); diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java b/app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java new file mode 100644 index 0000000..aae88e4 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java @@ -0,0 +1,26 @@ +package com.a1.nextlocation; + +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.CouponFragment; + +import org.junit.Rule; +import org.junit.Test; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +public class LocationDetailFragment { + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new com.a1.nextlocation.fragments.LocationDetailFragment()).commit(); + onView(withId(R.id.detail_location_back_button)).perform(click()); + onView(withId(R.id.locationFragment)).check(matches(isDisplayed())); + } +} diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java index f6d1e55..19dedd2 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java @@ -25,7 +25,7 @@ public class LocationFragmentTest { @Test public void clickBackButton() throws Exception{ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); - onView(withId(R.id.locationBackButton)).perform(click()); + onView(withId(R.id.location_back_button)).perform(click()); onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); } @@ -33,7 +33,7 @@ public class LocationFragmentTest { @Test public void clickDetailButton() throws Exception{ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); - onView(withId(R.id.locationRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + onView(withId(R.id.location_recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); onView(withId(R.id.locationDetailFragment)).check(matches(isDisplayed())); } From e36e85387551ead50e57aefc96bbb4451cc2d0b3 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 13:19:27 +0100 Subject: [PATCH 05/22] [ADD] Route Fragment test --- .../a1/nextlocation/RouteFragmentTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java new file mode 100644 index 0000000..49e9e61 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java @@ -0,0 +1,37 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; +import com.a1.nextlocation.fragments.RouteFragment; + +import org.junit.Rule; +import org.junit.Test; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +public class RouteFragmentTest { + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new RouteFragment()).commit(); + onView(withId(R.id.route_back_button)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + + } + + @Test + public void clickDetailButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new RouteFragment()).commit(); + onView(withId(R.id.route_recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click())); + onView(withId(R.id.routeDetailFragment)).check(matches(isDisplayed())); + + } +} From 08902472a360484ebb0d483f2ea69e0f499c98b1 Mon Sep 17 00:00:00 2001 From: Bipin Date: Tue, 5 Jan 2021 13:27:25 +0100 Subject: [PATCH 06/22] Added Settings and Statistics, started detail --- .../a1/nextlocation/LocationFragmentTest.java | 1 - .../nextlocation/RouteDetailFragmentTest.java | 43 ++++++++++++ .../a1/nextlocation/SettingsFragmentTest.java | 70 +++++++++++++++++++ .../nextlocation/StatisticFragmentTest.java | 38 ++++++++++ app/src/main/res/layout/fragment_settings.xml | 4 ++ 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java create mode 100644 app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java create mode 100644 app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java index f6d1e55..611a1d7 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java @@ -27,7 +27,6 @@ public class LocationFragmentTest { mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); onView(withId(R.id.locationBackButton)).perform(click()); onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); - } @Test diff --git a/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java new file mode 100644 index 0000000..b756bd8 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java @@ -0,0 +1,43 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.RootMatchers; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; +import com.a1.nextlocation.fragments.RouteDetailFragment; +import com.a1.nextlocation.fragments.SettingsFragment; +import com.a1.nextlocation.fragments.StatisticFragment; + +import org.hamcrest.core.AllOf; +import org.hamcrest.core.Is; +import org.hamcrest.core.IsInstanceOf; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static androidx.test.espresso.Espresso.*; +import static androidx.test.espresso.action.ViewActions.*; +import static androidx.test.espresso.assertion.ViewAssertions.*; +import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup; +import static androidx.test.espresso.matcher.ViewMatchers.*; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; + +public class RouteDetailFragmentTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new RouteDetailFragment()).commit(); + onView(withId(R.id.routeDetailBackButton)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + } +} diff --git a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java new file mode 100644 index 0000000..365e6ad --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java @@ -0,0 +1,70 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.RootMatchers; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; +import com.a1.nextlocation.fragments.SettingsFragment; +import com.a1.nextlocation.fragments.StatisticFragment; + +import org.hamcrest.core.AllOf; +import org.hamcrest.core.Is; +import org.hamcrest.core.IsInstanceOf; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static androidx.test.espresso.Espresso.*; +import static androidx.test.espresso.action.ViewActions.*; +import static androidx.test.espresso.assertion.ViewAssertions.*; +import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup; +import static androidx.test.espresso.matcher.ViewMatchers.*; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; + +public class SettingsFragmentTest { + + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + //Tests if the back button sends you back home + @Test + public void clickBackButton() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); + onView(withId(R.id.settingsBackButton)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + } + + //Checks if the dropdown is clickable, and checks if it has children + @Test + public void dropdownTest(){ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); + onView(withId(R.id.dropdown_menu_Settings)).check(matches(isClickable())); + onView(withId(R.id.dropdown_menu_Settings)).check(matches(hasMinimumChildCount(1))); + } + + //Tests if all buttons are clickable, and if they get checked after being clicked. + @Test + 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.settingsEyeButton)).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.settingsEyeButton)).perform(click()); + onView(withId(R.id.settingsEyeButton)).check(matches(isChecked())); + } +} diff --git a/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java new file mode 100644 index 0000000..f13909b --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java @@ -0,0 +1,38 @@ +package com.a1.nextlocation; + +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.LocationFragment; +import com.a1.nextlocation.fragments.StatisticFragment; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static androidx.test.espresso.Espresso.*; +import static androidx.test.espresso.action.ViewActions.*; +import static androidx.test.espresso.assertion.ViewAssertions.*; +import static androidx.test.espresso.matcher.ViewMatchers.*; + +public class StatisticFragmentTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + //Tests to see if all boxes get created + @Test + public void checkText() throws Exception{ + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new StatisticFragment()).commit(); + onView(withId(R.id.textView)).check(matches(isDisplayed())); + onView(withId(R.id.Box1)).check(matches(isDisplayed())); + onView(withId(R.id.Box2)).check(matches(isDisplayed())); + onView(withId(R.id.Box3)).check(matches(isDisplayed())); + onView(withId(R.id.Box4)).check(matches(isDisplayed())); + } + + + +} diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 84ca1c0..81f6f43 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -9,6 +9,7 @@ tools:context=".fragments.SettingsFragment"> Date: Tue, 5 Jan 2021 13:29:33 +0100 Subject: [PATCH 07/22] fixie --- .../java/com/a1/nextlocation/SettingsFragmentTest.java | 8 ++++---- .../java/com/a1/nextlocation/StatisticFragmentTest.java | 2 +- app/src/main/res/layout/fragment_settings.xml | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java index 365e6ad..e2d99dd 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java @@ -38,7 +38,7 @@ public class SettingsFragmentTest { @Test public void clickBackButton() throws Exception{ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit(); - onView(withId(R.id.settingsBackButton)).perform(click()); + onView(withId(R.id.settings_back_button)).perform(click()); onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); } @@ -56,7 +56,7 @@ 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.settingsOldButton)).check(matches(isClickable())); - onView(withId(R.id.settingsEyeButton)).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())); @@ -64,7 +64,7 @@ public class SettingsFragmentTest { onView(withId(R.id.settingsOldButton)).perform(click()); onView(withId(R.id.settingsOldButton)).check(matches(isChecked())); - onView(withId(R.id.settingsEyeButton)).perform(click()); - onView(withId(R.id.settingsEyeButton)).check(matches(isChecked())); + onView(withId(R.id.settingsEyesButton)).perform(click()); + onView(withId(R.id.settingsEyesButton)).check(matches(isChecked())); } } diff --git a/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java index f13909b..e04ac58 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/StatisticFragmentTest.java @@ -27,7 +27,7 @@ public class StatisticFragmentTest { public void checkText() throws Exception{ mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new StatisticFragment()).commit(); onView(withId(R.id.textView)).check(matches(isDisplayed())); - onView(withId(R.id.Box1)).check(matches(isDisplayed())); + onView(withId(R.id.name_box)).check(matches(isDisplayed())); onView(withId(R.id.Box2)).check(matches(isDisplayed())); onView(withId(R.id.Box3)).check(matches(isDisplayed())); onView(withId(R.id.Box4)).check(matches(isDisplayed())); diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index bafe6f4..5510e08 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -115,6 +115,7 @@ app:layout_constraintVertical_bias="0.0" /> Date: Tue, 5 Jan 2021 13:32:44 +0100 Subject: [PATCH 08/22] [ADD] Comments --- .../java/com/a1/nextlocation/CouponFragmentTest.java | 3 +++ .../java/com/a1/nextlocation/LocationDetailFragment.java | 1 + .../java/com/a1/nextlocation/LocationFragmentTest.java | 2 ++ .../java/com/a1/nextlocation/RouteFragmentTest.java | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java index e5d4342..49b7ee5 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/CouponFragmentTest.java @@ -29,6 +29,7 @@ public class CouponFragmentTest { @Test public void clickBackButton() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new CouponFragment()).commit(); onView(withId(R.id.coupon_back_button)).perform(click()); onView(withId(R.id.statisticsFragment)).check(matches(isDisplayed())); @@ -36,6 +37,8 @@ public class CouponFragmentTest { @Test public void clickDetailButton() throws Exception{ + //Here we click a coupon and then a popup dialog shows, we press the "activeren" button in it and if the next dialog with the code and with + //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()); diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java b/app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java index aae88e4..3942ba0 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationDetailFragment.java @@ -19,6 +19,7 @@ public class LocationDetailFragment { @Test public void clickBackButton() throws Exception{ + //Here we click the back button and then we check if the locationFragment is shown mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new com.a1.nextlocation.fragments.LocationDetailFragment()).commit(); onView(withId(R.id.detail_location_back_button)).perform(click()); onView(withId(R.id.locationFragment)).check(matches(isDisplayed())); diff --git a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java index 19dedd2..5f13c79 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/LocationFragmentTest.java @@ -24,6 +24,7 @@ public class LocationFragmentTest { @Test public void clickBackButton() throws Exception{ + //Here we click the back button and then we check if the homeFragment is shown mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); onView(withId(R.id.location_back_button)).perform(click()); onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); @@ -32,6 +33,7 @@ public class LocationFragmentTest { @Test public void clickDetailButton() throws Exception{ + //Here we click an item in the recyclerview and then check if the routeDetailFragment is called mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit(); onView(withId(R.id.location_recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); onView(withId(R.id.locationDetailFragment)).check(matches(isDisplayed())); diff --git a/app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java index 49e9e61..c42c59f 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/RouteFragmentTest.java @@ -21,6 +21,7 @@ public class RouteFragmentTest { @Test public void clickBackButton() throws Exception{ + //Here we click the back button and then we check if the homeFragment is shown mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new RouteFragment()).commit(); onView(withId(R.id.route_back_button)).perform(click()); onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); @@ -29,6 +30,7 @@ public class RouteFragmentTest { @Test public void clickDetailButton() throws Exception{ + //Here we click an item in the recyclerview and then check if the routeDetailFragment is called mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new RouteFragment()).commit(); onView(withId(R.id.route_recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click())); onView(withId(R.id.routeDetailFragment)).check(matches(isDisplayed())); From 804bdddbef7ae8bb661c0b4c3b921f5b5fb65e74 Mon Sep 17 00:00:00 2001 From: Bipin Date: Tue, 5 Jan 2021 13:36:14 +0100 Subject: [PATCH 09/22] Remove detail --- .../nextlocation/RouteDetailFragmentTest.java | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java deleted file mode 100644 index b756bd8..0000000 --- a/app/src/androidTest/java/com/a1/nextlocation/RouteDetailFragmentTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.a1.nextlocation; - -import androidx.test.espresso.action.ViewActions; -import androidx.test.espresso.contrib.RecyclerViewActions; -import androidx.test.espresso.matcher.RootMatchers; -import androidx.test.espresso.matcher.ViewMatchers; -import androidx.test.rule.ActivityTestRule; - -import com.a1.nextlocation.fragments.LocationFragment; -import com.a1.nextlocation.fragments.RouteDetailFragment; -import com.a1.nextlocation.fragments.SettingsFragment; -import com.a1.nextlocation.fragments.StatisticFragment; - -import org.hamcrest.core.AllOf; -import org.hamcrest.core.Is; -import org.hamcrest.core.IsInstanceOf; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import javax.inject.Inject; - -import static androidx.test.espresso.Espresso.*; -import static androidx.test.espresso.action.ViewActions.*; -import static androidx.test.espresso.assertion.ViewAssertions.*; -import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup; -import static androidx.test.espresso.matcher.ViewMatchers.*; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.*; -import static org.hamcrest.Matchers.is; - -public class RouteDetailFragmentTest { - - @Rule - public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); - - @Test - public void clickBackButton() throws Exception{ - mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new RouteDetailFragment()).commit(); - onView(withId(R.id.routeDetailBackButton)).perform(click()); - onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); - } -} From fe5a5b6dfd63aecd27825319abf1749074e8cf3f Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 5 Jan 2021 13:38:21 +0100 Subject: [PATCH 10/22] Added functionality to the dropdown in settings. Language preference is stored in the sharedPreferences --- .../com/a1/nextlocation/MainActivity.java | 28 ++++++ .../fragments/SettingsFragment.java | 89 ++++++++++++++++--- 2 files changed, 107 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/a1/nextlocation/MainActivity.java b/app/src/main/java/com/a1/nextlocation/MainActivity.java index 9f7821e..dc3b7cf 100644 --- a/app/src/main/java/com/a1/nextlocation/MainActivity.java +++ b/app/src/main/java/com/a1/nextlocation/MainActivity.java @@ -5,6 +5,9 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; +import android.app.Activity; +import android.content.SharedPreferences; +import android.content.res.Configuration; import android.os.Bundle; import android.util.Log; import android.view.MenuItem; @@ -25,6 +28,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView; import java.io.File; import java.util.Arrays; +import java.util.Locale; public class MainActivity extends AppCompatActivity { private static final String TAG = MainActivity.class.getName(); @@ -54,9 +58,33 @@ public class MainActivity extends AppCompatActivity { RouteListManager.INSTANCE.setContext(this); RouteListManager.INSTANCE.load(); + // initialize saved language from sharedPreferences + setLocale(loadLocale()); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit(); } + /** + * loads the saved language from SharedPreferences + * @return the language as string + */ + private String loadLocale(){ + SharedPreferences sharedPreferences = getSharedPreferences("Settings", Activity.MODE_PRIVATE); + return sharedPreferences.getString("Language", ""); + } + + /** + * sets the language of the application to the desired one + * @param language the desired language + */ + private void setLocale(String language){ + Locale locale = new Locale(language); + Locale.setDefault(locale); + Configuration configuration = new Configuration(); + configuration.setLocale(locale); + getBaseContext().getResources().getConfiguration().updateFrom(configuration); + } + private BottomNavigationView.OnNavigationItemSelectedListener navListener = item -> { Fragment selectedFragment = null; 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 721ba3e..236ea8c 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,8 @@ package com.a1.nextlocation.fragments; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.Configuration; import android.os.Bundle; import androidx.annotation.NonNull; @@ -9,36 +12,102 @@ import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import com.a1.nextlocation.MainActivity; import com.a1.nextlocation.R; +import java.util.Locale; + public class SettingsFragment extends Fragment { + private SharedPreferences.Editor editor; + private String language; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + editor = getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).edit(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - return inflater.inflate(R.layout.fragment_settings, container, false); + + View view = inflater.inflate(R.layout.fragment_settings, container, false); + + initializeLanguageDropdown(view); + + return view; } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - // Inflate the layout for this fragment - Spinner dropdown = view.findViewById(R.id.dropdown_menu_Settings); - + private void initializeLanguageDropdown(View view) { + Spinner languageDropdown = view.findViewById(R.id.dropdown_menu_Settings); String[] items = new String[]{"Nederlands", "Engels", "Chinees"}; ArrayAdapter arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, items); + languageDropdown.setAdapter(arrayAdapter); - dropdown.setAdapter(arrayAdapter); + // set the language dropdown on the currently selected language stored in the sharedPreferences + languageDropdown.setSelection(languageToDropdownPosition(getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", ""))); + + languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + setLocale(dropdownPositionToLanguage(position)); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + } + + /** + * converts the languageDropdown position to the belonging language + * @param position desired position to convert + * @return the language belonging to the position of the languageDropdown + */ + private String dropdownPositionToLanguage(int position) { + switch (position){ + case 0: + return "nl"; + case 1: + return "en"; + default: + return ""; + } + } + + /** + * converts language to the languageDropdown position + * @param language desired language to convert + * @return the position of the language in the languageDropdown + */ + private int languageToDropdownPosition(String language) { + switch (language) { + case "nl": + return 0; + case "en": + return 1; + default: + return 1; + } + } + + /** + * changes the current language to the desired language and saves this setting in SharedPreferences + * @param language the desired language to translate to + */ + private void setLocale(String language){ + Locale locale = new Locale(language); + Locale.setDefault(locale); + Configuration config = new Configuration(); + config.setLocale(locale); + getContext().getResources().getConfiguration().updateFrom(config); + editor.putString("Language", language); + editor.apply(); } } \ No newline at end of file From f381a292741c6df25ca33c26e3cc3bd751f535b4 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 16:04:25 +0100 Subject: [PATCH 11/22] [ADD] DirectionsStep test --- .../a1/nextlocation/DirectionsStepTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java diff --git a/app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java b/app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java new file mode 100644 index 0000000..d719f4e --- /dev/null +++ b/app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java @@ -0,0 +1,69 @@ +package com.a1.nextlocation; + +import com.a1.nextlocation.json.DirectionsStep; + +import org.junit.Before; +import org.junit.Test; +import org.osmdroid.util.GeoPoint; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class DirectionsStepTest { + private DirectionsStep directionsStep; + @Before + public void init(){ + directionsStep = new DirectionsStep(); + } + + @Test + public void testDistance(){ + directionsStep.setDistance(432.56); + double expected = 432.56; + assertEquals(expected, directionsStep.getDistance(), 0.01); + } + + @Test + public void testDuration(){ + directionsStep.setDuration(531.89); + double expected = 531.89; + assertEquals(expected, directionsStep.getDuration(), 0.01); + } + + @Test + public void testInstuction(){ + directionsStep.setInstruction("TESTINGINSTUCTION"); + String expected = "TESTINGINSTUCTION"; + assertEquals(expected, directionsStep.getInstruction()); + } + + @Test + public void testName(){ + directionsStep.setName("TESTINGNAME"); + String expected = "TESTINGNAME"; + assertEquals(expected, directionsStep.getName()); + } + + @Test + public void testWay_Points(){ + ArrayList expected = new ArrayList<>(); + expected.add(56); + expected.add(1123); + expected.add(23); + expected.add(73); + directionsStep.setWay_points(expected); + + assertEquals(expected, directionsStep.getWay_points()); + } + + @Test + public void testWayPoints(){ + GeoPoint[] expected = {new GeoPoint(5.1658, 4.163), new GeoPoint(2.0896, 7.158), + new GeoPoint(4.0168, 6.1450), new GeoPoint(7.1498, 9.1586), }; + directionsStep.setWaypoints(expected); + + assertEquals(expected, directionsStep.getWaypoints()); + } +} From e71c1955731e69c12a836a99ef0b5994e02440e4 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 16:11:19 +0100 Subject: [PATCH 12/22] [ADD] DirectionResultTest --- .../a1/nextlocation/DirectionsResultTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java diff --git a/app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java b/app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java new file mode 100644 index 0000000..ad4588f --- /dev/null +++ b/app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java @@ -0,0 +1,50 @@ +package com.a1.nextlocation; + +import com.a1.nextlocation.json.DirectionsResult; +import com.a1.nextlocation.json.DirectionsStep; + +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class DirectionsResultTest { + private DirectionsResult directionsResult; + + @Before + public void init(){ + directionsResult = new DirectionsResult(); + } + + @Test + public void testDistance(){ + directionsResult.setDistance(45.32); + double expected = 45.32; + + assertEquals(expected, directionsResult.getDistance(), 0.01); + } + + @Test + public void testDuration(){ + directionsResult.setDuration(95.123); + double expected = 95.123; + + assertEquals(expected, directionsResult.getDuration(), 0.01); + } + + @Test + public void testSteps(){ + List expected = new ArrayList<>(); + directionsResult.addStep(new DirectionsStep()); + directionsResult.addStep(new DirectionsStep()); + directionsResult.addStep(new DirectionsStep()); + directionsResult.setSteps(expected); + + assertEquals(expected, directionsResult.getSteps()); + } + + +} From f7a2a79d0011af7f391ce8285ac72005e6afbac6 Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 5 Jan 2021 16:20:43 +0100 Subject: [PATCH 13/22] Language can be changed, doesn't refresh automatically yet --- .../com/a1/nextlocation/MainActivity.java | 4 ++-- .../fragments/SettingsFragment.java | 11 +++++----- app/src/main/res/values-nl/strings.xml | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/values-nl/strings.xml diff --git a/app/src/main/java/com/a1/nextlocation/MainActivity.java b/app/src/main/java/com/a1/nextlocation/MainActivity.java index dc3b7cf..91268f0 100644 --- a/app/src/main/java/com/a1/nextlocation/MainActivity.java +++ b/app/src/main/java/com/a1/nextlocation/MainActivity.java @@ -70,7 +70,7 @@ public class MainActivity extends AppCompatActivity { */ private String loadLocale(){ SharedPreferences sharedPreferences = getSharedPreferences("Settings", Activity.MODE_PRIVATE); - return sharedPreferences.getString("Language", ""); + return sharedPreferences.getString("Language", "nl"); } /** @@ -82,7 +82,7 @@ public class MainActivity extends AppCompatActivity { Locale.setDefault(locale); Configuration configuration = new Configuration(); configuration.setLocale(locale); - getBaseContext().getResources().getConfiguration().updateFrom(configuration); + getBaseContext().getResources().updateConfiguration(configuration, getBaseContext().getResources().getDisplayMetrics()); } 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 236ea8c..eaffcb0 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -55,7 +55,8 @@ public class SettingsFragment extends Fragment { languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - setLocale(dropdownPositionToLanguage(position)); + setLocale(dropdownPositionToLanguage(id)); + } @Override @@ -67,11 +68,11 @@ public class SettingsFragment extends Fragment { /** * converts the languageDropdown position to the belonging language - * @param position desired position to convert + * @param id desired position to convert * @return the language belonging to the position of the languageDropdown */ - private String dropdownPositionToLanguage(int position) { - switch (position){ + private String dropdownPositionToLanguage(long id) { + switch ((int) id){ case 0: return "nl"; case 1: @@ -106,7 +107,7 @@ public class SettingsFragment extends Fragment { Locale.setDefault(locale); Configuration config = new Configuration(); config.setLocale(locale); - getContext().getResources().getConfiguration().updateFrom(config); + getContext().getResources().updateConfiguration(config, getContext().getResources().getDisplayMetrics()); editor.putString("Language", language); editor.apply(); } diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml new file mode 100644 index 0000000..289db4c --- /dev/null +++ b/app/src/main/res/values-nl/strings.xml @@ -0,0 +1,20 @@ + + + + Next Location + Locaties + Routes + Statistieken + Instellingen + Taal + Imperiaal systeem + 65+ stand + Kleurenblind + Totale afstand: + Bezochte locaties: + Totale tijd: + Coupons gespaard: + Coupons + Start Route + + \ No newline at end of file From 20c09c3458867ebf695ad5a489a52442442cc32c Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 16:52:48 +0100 Subject: [PATCH 14/22] [TRIED] MainActivity Test --- .../com/a1/nextlocation/MainActivityTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java b/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java new file mode 100644 index 0000000..b0fa343 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java @@ -0,0 +1,64 @@ +package com.a1.nextlocation; + +import android.app.LauncherActivity; +import android.widget.Button; + +import androidx.test.espresso.contrib.NavigationViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.RootMatchers; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.CouponFragment; +import com.google.android.material.bottomnavigation.BottomNavigationItemView; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +public class MainActivityTest { + + + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickLocationsNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.locations)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + } + + @Test + public void clickRouteNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.routes)).perform(NavigationViewActions.navigateTo(R.id.routes)); + onView(withId(R.id.routeFragment)).check(matches(isDisplayed())); + } + + @Test + public void clickStatisticsNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.statistics)).perform(click()); + onView(withId(R.id.statisticsFragment)).check(matches(isDisplayed())); + } + + @Test + public void clickSettingNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.settings)).perform(click()); + onView(withId(R.id.settingFragment)).check(matches(isDisplayed())); + } + +} From 00d306631b873e74338cd6594ed77acb2e35f522 Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 5 Jan 2021 17:19:09 +0100 Subject: [PATCH 15/22] Finished language functionality --- .../fragments/SettingsFragment.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 eaffcb0..9b5d16a 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -8,6 +8,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; @@ -52,16 +53,22 @@ public class SettingsFragment extends Fragment { // set the language dropdown on the currently selected language stored in the sharedPreferences languageDropdown.setSelection(languageToDropdownPosition(getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", ""))); + long previousID = languageDropdown.getSelectedItemId(); languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { setLocale(dropdownPositionToLanguage(id)); - + if (id != previousID){ + Fragment currentFragment = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_layout); + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.detach(currentFragment); + fragmentTransaction.attach(currentFragment); + fragmentTransaction.commit(); + } } @Override public void onNothingSelected(AdapterView parent) { - } }); } @@ -98,6 +105,17 @@ public class SettingsFragment extends Fragment { } } + /** + * reloads the fragment + */ + private void refresh(){ + Fragment currentFragment = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_layout); + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.detach(currentFragment); + fragmentTransaction.attach(currentFragment); + fragmentTransaction.commit(); + } + /** * changes the current language to the desired language and saves this setting in SharedPreferences * @param language the desired language to translate to From d9a6e1eff0f5609b5553ba02c02b84e8304a9756 Mon Sep 17 00:00:00 2001 From: Bipin Date: Wed, 6 Jan 2021 10:41:07 +0100 Subject: [PATCH 16/22] GeometryStart --- .../a1/nextlocation/GeometryDecoderTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/src/test/java/com/a1/nextlocation/GeometryDecoderTest.java diff --git a/app/src/test/java/com/a1/nextlocation/GeometryDecoderTest.java b/app/src/test/java/com/a1/nextlocation/GeometryDecoderTest.java new file mode 100644 index 0000000..2a12c8c --- /dev/null +++ b/app/src/test/java/com/a1/nextlocation/GeometryDecoderTest.java @@ -0,0 +1,22 @@ +package com.a1.nextlocation; + +import com.a1.nextlocation.json.GeometryDecoder; +import com.google.gson.JsonArray; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class GeometryDecoderTest { + + @Test + public void geometryDecoderTest(){ + String encodedGeometryTest = ""; + + JsonArray expected = new JsonArray(); + + + + assertEquals(expected, GeometryDecoder.decodeGeometry(encodedGeometryTest, true)); + } +} From 6dd2f5de40e246ccb160e15b9caf32626d8bc955 Mon Sep 17 00:00:00 2001 From: Bart Date: Wed, 6 Jan 2021 10:48:23 +0100 Subject: [PATCH 17/22] default strings.xml is now English, added more string resources --- .../fragments/CouponFragment.java | 12 +++------ .../fragments/SettingsFragment.java | 14 +++++----- app/src/main/res/values-en/strings.xml | 17 ------------ app/src/main/res/values-nl/strings.xml | 5 +++- app/src/main/res/values/strings.xml | 26 +++++++++++-------- 5 files changed, 31 insertions(+), 43 deletions(-) delete mode 100644 app/src/main/res/values-en/strings.xml 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 1faea7f..62c9432 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/CouponFragment.java @@ -62,22 +62,18 @@ public class CouponFragment extends Fragment { 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.setMessage(getResources().getString(R.string.activate_question)); activateBuilder.setCancelable(true); - // TODO: use string resources instead of hardcoded strings - activateBuilder.setPositiveButton("activeren", (dialog, which) -> { - // TODO: use string resources instead of hardcoded strings + activateBuilder.setPositiveButton(R.string.activate, (dialog, which) -> { dialog.cancel(); couponCodeBuilder.setMessage("Code: " + coupon.getCode()); - couponCodeBuilder.setPositiveButton("Klaar", (dialog1, which1) -> { + couponCodeBuilder.setPositiveButton(R.string.done, (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()); + activateBuilder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.cancel()); AlertDialog couponPopup = activateBuilder.create(); couponPopup.show(); 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 9b5d16a..9c0f42b 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -25,8 +25,7 @@ import java.util.Locale; public class SettingsFragment extends Fragment { private SharedPreferences.Editor editor; - private String language; - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -58,7 +57,7 @@ public class SettingsFragment extends Fragment { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { setLocale(dropdownPositionToLanguage(id)); - if (id != previousID){ + if (id != previousID) { Fragment currentFragment = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_layout); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.detach(currentFragment); @@ -75,11 +74,12 @@ public class SettingsFragment extends Fragment { /** * converts the languageDropdown position to the belonging language + * * @param id desired position to convert * @return the language belonging to the position of the languageDropdown */ private String dropdownPositionToLanguage(long id) { - switch ((int) id){ + switch ((int) id) { case 0: return "nl"; case 1: @@ -91,6 +91,7 @@ public class SettingsFragment extends Fragment { /** * converts language to the languageDropdown position + * * @param language desired language to convert * @return the position of the language in the languageDropdown */ @@ -108,7 +109,7 @@ public class SettingsFragment extends Fragment { /** * reloads the fragment */ - private void refresh(){ + private void refresh() { Fragment currentFragment = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_layout); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.detach(currentFragment); @@ -118,9 +119,10 @@ public class SettingsFragment extends Fragment { /** * changes the current language to the desired language and saves this setting in SharedPreferences + * * @param language the desired language to translate to */ - private void setLocale(String language){ + private void setLocale(String language) { Locale locale = new Locale(language); Locale.setDefault(locale); Configuration config = new Configuration(); diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml deleted file mode 100644 index 94b8326..0000000 --- a/app/src/main/res/values-en/strings.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - Location - Total time: - Total distance: - Language - Statistics - Start Route - Routes - Colorblind - Settings - Imperial system - Coupons collected: - Visited locations: - 65+ mode - Coupons - \ No newline at end of file diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 289db4c..893ffe7 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -16,5 +16,8 @@ Coupons gespaard: Coupons Start Route - + Weet je zeker dat je deze coupon wilt activeren? + activeren + Klaar + annuleren \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b25e32..1cfcd8d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,17 +1,21 @@ Next Location - Locaties + Location Routes - Statistieken - Instellingen - Taal - Imperiaal systeem - 65+ stand - Kleurenblind - Totale afstand: - Bezochte locaties: - Totale tijd: - Coupons gespaard: + Statistics + Settings + Language + Imperial system + 65+ mode + Colorblind + Total distance: + Visited locations: + Total time: + Coupons collected: Coupons Start Route + Are you sure you want to activate this coupon? + activate + Done + cancel \ No newline at end of file From 3d1cfd244be5dc7854c41c6003fc334988d579b2 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 10:50:14 +0100 Subject: [PATCH 18/22] [ADD] Main Activity Test --- .../androidTest/java/com/a1/nextlocation/MainActivityTest.java | 2 +- .../java/com/a1/nextlocation/fragments/SettingsFragment.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java b/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java index b0fa343..c448f9f 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java @@ -41,7 +41,7 @@ public class MainActivityTest { public void clickRouteNavBar() throws Exception{ //Here we click the back button and then we check if the statisticsFragment is shown mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); - onView(withId(R.id.routes)).perform(NavigationViewActions.navigateTo(R.id.routes)); + onView(withId(R.id.routes)).perform((click())); onView(withId(R.id.routeFragment)).check(matches(isDisplayed())); } 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 0b80f41..232afa9 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -40,7 +40,7 @@ public class SettingsFragment extends Fragment { // Inflate the layout for this fragment Spinner dropdown = view.findViewById(R.id.dropdown_menu_Settings); - this.imageButton = view.findViewById(R.id.route_detail_back_button); + this.imageButton = view.findViewById(R.id.settings_back_button); this.imageButton.setOnClickListener(v -> { HomeFragment homeFragment = new HomeFragment(); ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit(); From 0ed16ee0693c4ad17b80d6ec1eb174b85f36af17 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 12:08:25 +0100 Subject: [PATCH 19/22] [CHANGED] String values --- app/build.gradle | 4 ++++ .../java/com/a1/nextlocation/fragments/HomeFragment.java | 8 +++++--- .../main/java/com/a1/nextlocation/network/ApiHandler.java | 2 +- app/src/main/res/layout-land/fragment_location_detail.xml | 4 ++-- app/src/main/res/layout/coupon_item.xml | 2 +- app/src/main/res/layout/fragment_coupon.xml | 3 +-- app/src/main/res/layout/fragment_location.xml | 3 +-- app/src/main/res/layout/fragment_location_detail.xml | 4 ++-- app/src/main/res/layout/fragment_route.xml | 2 +- app/src/main/res/layout/fragment_route_detail.xml | 2 +- app/src/main/res/layout/fragment_settings.xml | 2 +- app/src/main/res/layout/fragment_statistic.xml | 8 ++++---- app/src/main/res/layout/location_item.xml | 2 +- app/src/main/res/layout/route_item.xml | 2 +- app/src/main/res/menu/navmenu.xml | 6 +++--- 15 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a5eb575..8bcfb89 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,6 +53,10 @@ dependencies { //osm bonus pack implementation 'com.github.MKergall:osmbonuspack:6.6.0' + //BeforeEach + testImplementation(platform('org.junit:junit-bom:5.7.0')) + testImplementation 'org.junit.jupiter:junit-jupiter' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' testImplementation 'org.mockito:mockito-core:2.7.22' diff --git a/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java index 1786782..9212d47 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java @@ -28,6 +28,7 @@ import com.a1.nextlocation.R; import com.a1.nextlocation.data.StaticData; import com.a1.nextlocation.json.DirectionsResult; import com.a1.nextlocation.network.ApiHandler; +import com.a1.nextlocation.network.DirectionsListener; import com.a1.nextlocation.recyclerview.LocationListManager; import org.osmdroid.api.IMapController; @@ -46,7 +47,7 @@ import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay; import java.util.ArrayList; import java.util.List; -public class HomeFragment extends Fragment implements LocationListener{ +public class HomeFragment extends Fragment implements LocationListener, DirectionsListener { private final String userAgent = "com.ai.nextlocation.fragments"; public final static String MAPQUEST_API_KEY = "vuyXjqnAADpjeL9QwtgWGleIk95e36My"; private ImageButton imageButton; @@ -84,11 +85,12 @@ public class HomeFragment extends Fragment implements LocationListener{ ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit(); }); - ApiHandler.INSTANCE.addListener(this::onDirectionsAvailable); + ApiHandler.INSTANCE.addListener(this); return view; } - private void onDirectionsAvailable(DirectionsResult directionsResult) { + @Override + public void onDirectionsAvailable(DirectionsResult directionsResult) { Log.d(TAG, "onDirectionsAvailable: got result! " + directionsResult); ArrayList geoPoints = directionsResult.getGeoPoints(); roadOverlay = new Polyline(); diff --git a/app/src/main/java/com/a1/nextlocation/network/ApiHandler.java b/app/src/main/java/com/a1/nextlocation/network/ApiHandler.java index 570e683..00ff233 100644 --- a/app/src/main/java/com/a1/nextlocation/network/ApiHandler.java +++ b/app/src/main/java/com/a1/nextlocation/network/ApiHandler.java @@ -52,7 +52,7 @@ public enum ApiHandler { if (response.body() != null) { String responseString = Objects.requireNonNull(response.body()).string(); Log.d(TAG, "getDirections: got response: " + responseString); - + System.out.println(responseString); DirectionsResult result = new DirectionsResult(); result.parse(responseString); Log.d(TAG, "getDirections: " + result.getSteps().size()); diff --git a/app/src/main/res/layout-land/fragment_location_detail.xml b/app/src/main/res/layout-land/fragment_location_detail.xml index 6e87547..386d98a 100644 --- a/app/src/main/res/layout-land/fragment_location_detail.xml +++ b/app/src/main/res/layout-land/fragment_location_detail.xml @@ -12,7 +12,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" - android:text="@string/locatie_detail" + android:text="" android:textColor="@color/white" android:textSize="30sp" app:layout_constraintEnd_toEndOf="parent" @@ -35,7 +35,7 @@ android:layout_height="283dp" android:layout_marginEnd="30dp" android:background="@color/secondaryColour" - android:text="@string/locatie_detail_tekst" + android:text="" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/detail_location_name" /> diff --git a/app/src/main/res/layout/coupon_item.xml b/app/src/main/res/layout/coupon_item.xml index 2354e4c..76cff35 100644 --- a/app/src/main/res/layout/coupon_item.xml +++ b/app/src/main/res/layout/coupon_item.xml @@ -25,7 +25,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="20dp" - android:text="@string/naam" + android:text="" android:textColor="@color/black" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout/fragment_coupon.xml b/app/src/main/res/layout/fragment_coupon.xml index b3ac9cb..ba8db19 100644 --- a/app/src/main/res/layout/fragment_coupon.xml +++ b/app/src/main/res/layout/fragment_coupon.xml @@ -14,7 +14,7 @@ android:layout_height="wrap_content" android:layout_margin="9dp" android:layout_marginTop="20dp" - android:text="@string/statistieken" + android:text="@string/statistics" android:textSize="20sp" app:layout_constraintStart_toEndOf="@id/coupon_back_button" app:layout_constraintTop_toTopOf="parent" /> @@ -27,7 +27,6 @@ android:layout_marginTop="12dp" android:background="@drawable/ic_back_button_24" android:backgroundTint="@color/buttonColour" - android:text="@string/terug" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/fragment_location.xml b/app/src/main/res/layout/fragment_location.xml index 7732796..a0325ba 100644 --- a/app/src/main/res/layout/fragment_location.xml +++ b/app/src/main/res/layout/fragment_location.xml @@ -14,7 +14,7 @@ android:layout_height="wrap_content" android:layout_margin="9dp" android:layout_marginTop="20dp" - android:text="@string/locaties" + android:text="@string/locations" android:textSize="20sp" app:layout_constraintStart_toEndOf="@id/location_back_button" app:layout_constraintTop_toTopOf="parent" /> @@ -27,7 +27,6 @@ android:layout_marginTop="12dp" android:background="@drawable/ic_back_button_24" android:backgroundTint="@color/buttonColour" - android:text="@string/terug" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/fragment_location_detail.xml b/app/src/main/res/layout/fragment_location_detail.xml index 2af2f90..289ffd9 100644 --- a/app/src/main/res/layout/fragment_location_detail.xml +++ b/app/src/main/res/layout/fragment_location_detail.xml @@ -13,7 +13,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" - android:text="@string/locatie_detail" + android:text="" android:textColor="@color/white" android:textSize="30sp" app:layout_constraintEnd_toEndOf="parent" @@ -36,7 +36,7 @@ android:layout_margin="20dp" android:layout_height="wrap_content" android:background="@color/secondaryColour" - android:text="@string/locatie_detail_tekst" + android:text="" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/detail_location_image" /> diff --git a/app/src/main/res/layout/fragment_route.xml b/app/src/main/res/layout/fragment_route.xml index 0c79419..494defe 100644 --- a/app/src/main/res/layout/fragment_route.xml +++ b/app/src/main/res/layout/fragment_route.xml @@ -23,7 +23,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="9dp" - android:text="@string/titel" + android:text="@string/routes" android:textSize="20sp" app:layout_constraintStart_toEndOf="@id/route_back_button" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/fragment_route_detail.xml b/app/src/main/res/layout/fragment_route_detail.xml index 6cf1a4b..735dbcf 100644 --- a/app/src/main/res/layout/fragment_route_detail.xml +++ b/app/src/main/res/layout/fragment_route_detail.xml @@ -22,7 +22,7 @@ android:id="@+id/route_title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/titel" + android:text="" android:textSize="20sp" app:layout_constraintBottom_toTopOf="@+id/routeDetailImage" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 751fdc9..3cc8966 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -24,7 +24,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" - android:text="@string/instellingen" + android:text="@string/settings" android:textColor="@color/white" android:textSize="30sp" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/fragment_statistic.xml b/app/src/main/res/layout/fragment_statistic.xml index bef7ebb..e6e1afd 100644 --- a/app/src/main/res/layout/fragment_statistic.xml +++ b/app/src/main/res/layout/fragment_statistic.xml @@ -59,7 +59,7 @@ android:id="@+id/statistics_km" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/km" + android:text="" android:textColor="@color/black" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent" @@ -108,7 +108,7 @@ android:id="@+id/statistics_locations_visited" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/getal" + android:text="" android:textColor="@color/black" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent" @@ -155,7 +155,7 @@ @@ -15,13 +15,13 @@ From 192f1a4c6415b0efbc90ddb1fa21bf9d05dbce66 Mon Sep 17 00:00:00 2001 From: sebas Date: Wed, 6 Jan 2021 13:22:37 +0100 Subject: [PATCH 20/22] Route detail fragment now fills in the right name and text --- .../com/a1/nextlocation/fragments/RouteDetailFragment.java | 6 +++++- app/src/main/res/layout-land/fragment_route_detail.xml | 3 ++- app/src/main/res/layout/fragment_route_detail.xml | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) 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 0106d59..b7c5067 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java @@ -18,6 +18,7 @@ public class RouteDetailFragment extends Fragment { private Route route; private TextView routeDetailText; + private TextView routeName; private ImageButton imageButton; @Override @@ -33,8 +34,11 @@ public class RouteDetailFragment extends Fragment { this.route = getArguments().getParcelable("route"); } + this.routeName = view.findViewById(R.id.route_title); + this.routeName.setText(this.route.getName()); + this.routeDetailText = view.findViewById(R.id.reoute_detail_tekst); - this.routeDetailText.setText(this.route.getName()); + this.routeDetailText.setText(this.route.getDescription()); this.imageButton = view.findViewById(R.id.route_detail_back_button); this.imageButton.setOnClickListener(v -> { diff --git a/app/src/main/res/layout-land/fragment_route_detail.xml b/app/src/main/res/layout-land/fragment_route_detail.xml index 48263eb..3fe3a2d 100644 --- a/app/src/main/res/layout-land/fragment_route_detail.xml +++ b/app/src/main/res/layout-land/fragment_route_detail.xml @@ -38,7 +38,8 @@ android:layout_height="wrap_content" android:layout_marginEnd="250dp" android:text="titel" - android:textSize="20sp" + android:textColor="@color/white" + android:textSize="30sp" app:layout_constraintBottom_toTopOf="@+id/route_detail_image" app:layout_constraintEnd_toStartOf="@+id/reoute_detail_tekst" app:layout_constraintStart_toEndOf="@id/routeDetailBackButton" diff --git a/app/src/main/res/layout/fragment_route_detail.xml b/app/src/main/res/layout/fragment_route_detail.xml index e365bd9..6431efa 100644 --- a/app/src/main/res/layout/fragment_route_detail.xml +++ b/app/src/main/res/layout/fragment_route_detail.xml @@ -22,7 +22,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/titel" - android:textSize="20sp" + android:textColor="@color/white" + android:textSize="30sp" app:layout_constraintBottom_toTopOf="@+id/route_detail_image" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" From ca8d291262dca8f7a507f612ac15d086f945cd8e Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 13:44:17 +0100 Subject: [PATCH 21/22] [CHANGED] String values --- .../com/a1/nextlocation/fragments/LocationDetailFragment.java | 4 ++++ app/src/main/res/layout/fragment_location_detail.xml | 3 +-- app/src/main/res/layout/fragment_route.xml | 1 - app/src/main/res/layout/fragment_settings.xml | 1 - app/src/main/res/layout/fragment_statistic.xml | 3 --- 5 files changed, 5 insertions(+), 7 deletions(-) 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 19f73cd..dc58ce3 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/LocationDetailFragment.java @@ -49,4 +49,8 @@ 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/res/layout/fragment_location_detail.xml b/app/src/main/res/layout/fragment_location_detail.xml index 468aa89..a89a336 100644 --- a/app/src/main/res/layout/fragment_location_detail.xml +++ b/app/src/main/res/layout/fragment_location_detail.xml @@ -35,7 +35,6 @@ android:layout_width="match_parent" android:layout_height="200dp" android:layout_margin="20dp" - android:layout_height="wrap_content" android:background="@color/secondaryColour" android:text="" app:layout_constraintEnd_toEndOf="parent" @@ -47,7 +46,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/secondaryColour" - android:text="@string/locatie_detail_tekst" + android:text="" /> diff --git a/app/src/main/res/layout/fragment_route.xml b/app/src/main/res/layout/fragment_route.xml index 500edc2..3904b49 100644 --- a/app/src/main/res/layout/fragment_route.xml +++ b/app/src/main/res/layout/fragment_route.xml @@ -14,7 +14,6 @@ android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@drawable/ic_back_button_24" - android:text="@string/terug" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 11b0f61..343de74 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -160,7 +160,6 @@ app:layout_constraintTop_toTopOf="parent" /> @@ -234,7 +232,6 @@ android:background="@drawable/ic_back_button_24" android:backgroundTint="@color/buttonColour" android:src="@drawable/ic_back_button_24" - android:text="@string/terug" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> From 8a758f1d8d54b70c68e9d69a7ecae824600f9f18 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Wed, 6 Jan 2021 13:55:20 +0100 Subject: [PATCH 22/22] [ADD] Start Route button from other branch --- .../fragments/RouteDetailFragment.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 cbf4598..ad76a89 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java @@ -11,9 +11,12 @@ import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.Button; import android.widget.TextView; +import android.widget.Toast; import com.a1.nextlocation.R; import com.a1.nextlocation.data.Route; +import com.a1.nextlocation.data.RouteHandler; +import com.a1.nextlocation.network.ApiHandler; public class RouteDetailFragment extends Fragment { @@ -47,7 +50,18 @@ public class RouteDetailFragment extends Fragment { ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeFragment).addToBackStack(null).commit(); }); + Button startButton = view.findViewById(R.id.start_route_button); + startButton.setOnClickListener(this::startRoute); + return view; } + + public void startRoute(View view) { + 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(); + + } } \ No newline at end of file