Added support for imperial units
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user