Added support for imperial units
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
@@ -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, "");
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/settingsImperialButton"
|
||||
android:id="@+id/imperial_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@@ -162,7 +162,7 @@
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/BigFont"
|
||||
android:id="@+id/font_changer"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@id/Balk3"
|
||||
|
||||
Reference in New Issue
Block a user