forked from upstream-mirrors/OpenTracks
Interval statistics: show unit in dropdown.
This commit is contained in:
@@ -18,8 +18,6 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.TrackRecordingActivity;
|
import de.dennisguse.opentracks.TrackRecordingActivity;
|
||||||
import de.dennisguse.opentracks.adapters.IntervalStatisticsAdapter;
|
import de.dennisguse.opentracks.adapters.IntervalStatisticsAdapter;
|
||||||
@@ -42,17 +40,18 @@ public class IntervalsFragment extends Fragment {
|
|||||||
private ListView intervalListView;
|
private ListView intervalListView;
|
||||||
protected IntervalStatisticsAdapter.StackMode stackModeListView;
|
protected IntervalStatisticsAdapter.StackMode stackModeListView;
|
||||||
private IntervalStatisticsModel.IntervalOption selectedInterval;
|
private IntervalStatisticsModel.IntervalOption selectedInterval;
|
||||||
private IntervalStatisticsAdapter adapter;
|
|
||||||
|
|
||||||
|
private String intervalUnit;
|
||||||
|
private IntervalStatisticsAdapter adapter;
|
||||||
protected Spinner spinnerIntervals;
|
protected Spinner spinnerIntervals;
|
||||||
protected TextView spinnerIntervalsUnit;
|
|
||||||
|
|
||||||
private Track.Id trackId;
|
private Track.Id trackId;
|
||||||
|
|
||||||
protected final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
|
protected final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
|
||||||
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
||||||
if (spinnerIntervalsUnit != null) {
|
intervalUnit = PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile);
|
||||||
spinnerIntervalsUnit.setText(PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile));
|
if (adapter != null) {
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
intervalChanged();
|
intervalChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +76,7 @@ public class IntervalsFragment extends Fragment {
|
|||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
PreferencesUtils.register(getContext(), sharedPreferenceChangeListener);
|
PreferencesUtils.register(getContext(), sharedPreferenceChangeListener);
|
||||||
|
intervalUnit = PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
trackId = savedInstanceState.getParcelable(TRACK_ID_KEY);
|
trackId = savedInstanceState.getParcelable(TRACK_ID_KEY);
|
||||||
@@ -93,11 +93,22 @@ public class IntervalsFragment extends Fragment {
|
|||||||
|
|
||||||
spinnerIntervals = view.findViewById(R.id.spinner_intervals);
|
spinnerIntervals = view.findViewById(R.id.spinner_intervals);
|
||||||
|
|
||||||
int[] intValues = Arrays.stream(IntervalStatisticsModel.IntervalOption.values()).mapToInt(i -> i.getValue()).toArray();
|
spinnerIntervals.setAdapter(new ArrayAdapter(getContext(), android.R.layout.simple_spinner_dropdown_item, IntervalStatisticsModel.IntervalOption.values()) {
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
|
TextView v = (TextView) super.getView(position, convertView, parent);
|
||||||
|
v.setText(v.getText() + " " + intervalUnit);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
spinnerIntervals.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, Arrays.stream(intValues).mapToObj(String::valueOf).toArray(String[]::new)));
|
@Override
|
||||||
spinnerIntervalsUnit = view.findViewById(R.id.spinner_intervals_unit);
|
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
spinnerIntervalsUnit.setText(PreferencesUtils.isMetricUnits(getContext()) ? getContext().getString(R.string.unit_kilometer) : getContext().getString(R.string.unit_mile));
|
TextView v = (TextView) super.getDropDownView(position, convertView, parent);
|
||||||
|
v.setText(v.getText() + " " + intervalUnit);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
spinnerIntervals.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
spinnerIntervals.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -124,7 +135,6 @@ public class IntervalsFragment extends Fragment {
|
|||||||
intervalListView = null;
|
intervalListView = null;
|
||||||
adapter = null;
|
adapter = null;
|
||||||
spinnerIntervals = null;
|
spinnerIntervals = null;
|
||||||
spinnerIntervalsUnit = null;
|
|
||||||
viewModel = null;
|
viewModel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,5 +75,10 @@ public class IntervalStatisticsModel extends AndroidViewModel {
|
|||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "" + value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -24,13 +23,6 @@
|
|||||||
style="@style/SpinnerCustomText"
|
style="@style/SpinnerCustomText"
|
||||||
android:gravity="center" />
|
android:gravity="center" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/spinner_intervals_unit"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
tools:text="@string/unit_kilometer"
|
|
||||||
style="@style/TextMedium" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
Reference in New Issue
Block a user