diff --git a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java index e14b188..92e4fba 100644 --- a/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java +++ b/app/src/androidTest/java/com/a1/nextlocation/SettingsFragmentTest.java @@ -6,18 +6,10 @@ 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.*; @@ -25,7 +17,6 @@ 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 { @@ -54,14 +45,14 @@ public class SettingsFragmentTest { @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.BigFont)).check(matches(isClickable())); + onView(withId(R.id.imperial_button)).check(matches(isClickable())); + onView(withId(R.id.font_changer)).check(matches(isClickable())); - onView(withId(R.id.settingsImperialButton)).perform(click()); - onView(withId(R.id.settingsImperialButton)).check(matches(isChecked())); + onView(withId(R.id.imperial_button)).perform(click()); + onView(withId(R.id.imperial_button)).check(matches(isChecked())); - onView(withId(R.id.BigFont)).perform(click()); - onView(withId(R.id.BigFont)).check(matches(isChecked())); + onView(withId(R.id.font_changer)).perform(click()); + onView(withId(R.id.font_changer)).check(matches(isChecked())); } } diff --git a/app/src/main/assets/routes.json b/app/src/main/assets/routes.json index bc4a15e..5619f4f 100644 --- a/app/src/main/assets/routes.json +++ b/app/src/main/assets/routes.json @@ -35,7 +35,7 @@ ], "totalDistance": 1073.0, "totalTime": 342342, - "description": "Deze route laat u leuke events verspreid door breda zien! Probeer de escaperooms uit, een event bij de koepel, of een leuk feest bij MEZZ! Met deze route loopt u langs ze allemaal.", + "description": "This route will show you different and fun events scattered all around Breda! Try the escape rooms, an event at the dome or a fun party at MEZZ! With this route you walk past them all!", "imageURL": "escaping_room" }, { @@ -86,7 +86,7 @@ ], "totalDistance": 955.0, "totalTime": 342342, - "description": "With this route you can visit all snackbars and restaurants in the centrum of Breda!", + "description": "With this route you can visit all snackbars and restaurants in the centre of Breda!", "imageURL": "kees_kroket" } ] \ No newline at end of file diff --git a/app/src/main/java/com/a1/nextlocation/MainActivity.java b/app/src/main/java/com/a1/nextlocation/MainActivity.java index b9e5747..9314332 100644 --- a/app/src/main/java/com/a1/nextlocation/MainActivity.java +++ b/app/src/main/java/com/a1/nextlocation/MainActivity.java @@ -134,7 +134,7 @@ public class MainActivity extends AppCompatActivity implements Refreshable { FragmentManager fragment = getSupportFragmentManager(); DialogFragment helpPopupFragment = new HelpPopup(); - helpPopupFragment.show(fragment, "YEET"); + helpPopupFragment.show(fragment, ""); } }; } \ No newline at end of file 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 630620d..6b2aaa0 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java @@ -65,7 +65,8 @@ public class RouteDetailFragment extends Fragment { TextView totalDistance = view.findViewById(R.id.total_distance); String distance_tekst = getResources().getString(R.string.total_distance_route); - totalDistance.setText(distance_tekst + " " + calculateRoute(this.route.getLocations()) + "m"); + boolean imperialChecked = getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getBoolean("imperialSwitch", false); + totalDistance.setText(distance_tekst + " " + String.format("%.1f", calculateRoute(this.route.getLocations())) + (imperialChecked ? "ft" : "m")); //Initialises the back button ImageButton backButton = view.findViewById(R.id.route_detail_back_button); @@ -112,7 +113,12 @@ public class RouteDetailFragment extends Fragment { totalDistance += Location.getDistance(firstLocation.getLat(), firstLocation.getLong(), secondLocation.getLat(), secondLocation.getLong()); } System.out.println("Total Distance: " + totalDistance); - return totalDistance; + + // if the imperialSwitch is checked, return feet, if not, return meters + if (getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getBoolean("imperialSwitch", false)) + return totalDistance *3.28084; + else + return totalDistance; } } \ 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 68192d0..a82e782 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -28,7 +28,8 @@ import java.util.Locale; public class SettingsFragment extends Fragment { private SharedPreferences.Editor editor; - SwitchCompat fontChanger; + private SwitchCompat fontSwitch; + private SwitchCompat imperialSwitch; private Refreshable refreshable; @Override @@ -51,7 +52,12 @@ public class SettingsFragment extends Fragment { View view = inflater.inflate(R.layout.fragment_settings, container, false); initializeLanguageDropdown(view); + initializeButtons(view); + return view; + } + + private void initializeButtons(View view) { //Initialises back button ImageView backButton = view.findViewById(R.id.settings_back_button); backButton.setOnClickListener(v -> { @@ -59,39 +65,46 @@ public class SettingsFragment extends Fragment { ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit(); }); - //Initialises 65+ switchCompat - this.fontChanger = view.findViewById(R.id.BigFont); + SharedPreferences sharedPreferences = getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE); - //Initialises sharedpreference to save state of 65+ mode - SharedPreferences sharedPreferences = requireActivity().getSharedPreferences("com.a1.nextlocation",0); - SharedPreferences.Editor editor = sharedPreferences.edit(); - fontChanger.setChecked(sharedPreferences.getBoolean("switch", false)); + //Initialises imperial switchCompat + this.imperialSwitch = view.findViewById(R.id.imperial_button); + this.imperialSwitch.setChecked(sharedPreferences.getBoolean("imperialSwitch", false)); + + this.imperialSwitch.setOnClickListener(view1 -> { + editor.putBoolean("imperialSwitch", imperialSwitch.isChecked()); + editor.apply(); + editor.commit(); + }); + + //Initialises 65+ switchCompat + this.fontSwitch = view.findViewById(R.id.font_changer); + + fontSwitch.setChecked(sharedPreferences.getBoolean("fontSwitch", false)); //Initial check to see what setting was last chosen - if (fontChanger.isChecked()){ + if (fontSwitch.isChecked()){ requireActivity().setTheme(R.style.Theme_NextLocationBig); - }else if (!fontChanger.isChecked()){ + }else if (!fontSwitch.isChecked()){ requireActivity().setTheme(R.style.Theme_NextLocation); } //Changes the font settings depending on the state of the toggle - fontChanger.setOnClickListener(view1 -> { - if(fontChanger.isChecked()) + fontSwitch.setOnClickListener(view1 -> { + if(fontSwitch.isChecked()) { requireActivity().setTheme(R.style.Theme_NextLocationBig); - editor.putBoolean("switch",true); + editor.putBoolean("fontSwitch",true); editor.apply(); } - if(!fontChanger.isChecked()) + if(!fontSwitch.isChecked()) { requireActivity().setTheme(R.style.Theme_NextLocation); - editor.putBoolean("switch",false); + editor.putBoolean("fontSwitch",false); editor.apply(); } editor.commit(); }); - - return view; } private void initializeLanguageDropdown(View view) { 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 aa91d75..354cd23 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/StatisticFragment.java @@ -1,6 +1,7 @@ package com.a1.nextlocation.fragments; import android.annotation.SuppressLint; +import android.content.Context; import android.os.Bundle; import androidx.constraintlayout.widget.ConstraintLayout; @@ -33,11 +34,9 @@ public class StatisticFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_statistic, container, false); - TextView distance = view.findViewById(R.id.statistics_km); + initializeDistanceTextView(view); TextView locs = view.findViewById(R.id.statistics_locations_visited); TextView timeText = view.findViewById(R.id.statistics_time_value); - double dist = Data.INSTANCE.getDistanceTraveled()/1000; - distance.setText("" + String.format("%.1f",dist) + " km"); locs.setText("" + Data.INSTANCE.getLocationsVisited()); long seconds = Data.INSTANCE.getTotalTime() / 1000; @@ -76,4 +75,13 @@ public class StatisticFragment extends Fragment { }); return view; } + + private void initializeDistanceTextView(View view){ + TextView distance = view.findViewById(R.id.statistics_km); + double dist = Data.INSTANCE.getDistanceTraveled()/1000; + if (getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getBoolean("imperialSwitch", false)) + distance.setText("" + String.format("%.1f",dist * 0.621371) + " mi"); + else + distance.setText("" + String.format("%.1f",dist) + " km"); + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 95ab677..155cdff 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -115,7 +115,7 @@ app:layout_constraintVertical_bias="0.0" />