Merge branch 'develop' of https://github.com/SemvdH/Next-Location into develop

This commit is contained in:
Sem van der Hoeven
2021-01-07 11:20:58 +01:00
7 changed files with 63 additions and 39 deletions

View File

@@ -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);
@@ -114,7 +115,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;
}
}

View File

@@ -27,7 +27,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
@@ -50,7 +51,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 -> {
@@ -58,37 +64,47 @@ 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) {

View File

@@ -1,6 +1,7 @@
package com.a1.nextlocation.fragments;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -32,9 +33,10 @@ 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());
@@ -75,4 +77,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");
}
}