forked from upstream-mirrors/OpenTracks
Cleanup: use ActivityType instead of passing it's id around as String.
Part of #1608.
This commit is contained in:
+6
-5
@@ -37,7 +37,7 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
||||
return -1;
|
||||
}
|
||||
String iconValue = ActivityType.findByLocalizedString(context, category)
|
||||
.getId();
|
||||
.getIconId();
|
||||
|
||||
return getAllActivityTypeIds().indexOf(iconValue);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
||||
|
||||
List<Integer> iconDrawableIds = new ArrayList<>();
|
||||
for (String iconValue : getAllActivityTypeIds()) {
|
||||
iconDrawableIds.add(ActivityType.findByActivityTypeId(iconValue)
|
||||
iconDrawableIds.add(ActivityType.findBy(iconValue)
|
||||
.getIconDrawableId());
|
||||
}
|
||||
|
||||
@@ -98,13 +98,14 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
||||
chooseActivityTypeCaller.onChooseActivityTypeDone(getAllActivityTypeIds().get(position));
|
||||
chooseActivityTypeCaller.onChooseActivityTypeDone(ActivityType.findBy(getAllActivityTypeIds().get(position)));
|
||||
dismiss();
|
||||
}
|
||||
|
||||
// TODO Return List<ActivityType>
|
||||
public static List<String> getAllActivityTypeIds() {
|
||||
return Arrays.stream(ActivityType.values())
|
||||
.map(ActivityType::getId)
|
||||
.map(ActivityType::getIconId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -113,6 +114,6 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements
|
||||
*/
|
||||
public interface ChooseActivityTypeCaller {
|
||||
|
||||
void onChooseActivityTypeDone(String iconValue);
|
||||
void onChooseActivityTypeDone(ActivityType activityType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class StatisticsRecordedFragment extends Fragment {
|
||||
|
||||
if (PreferencesUtils.isKey(R.string.stats_rate_key, key) && track != null) {
|
||||
updateUInecessary = true;
|
||||
preferenceReportSpeed = PreferencesUtils.isReportSpeed(track.getActivityType());
|
||||
preferenceReportSpeed = PreferencesUtils.isReportSpeed(track.getActivityTypeLocalized());
|
||||
}
|
||||
|
||||
if (key != null && updateUInecessary && isResumed()) {
|
||||
@@ -156,7 +156,7 @@ public class StatisticsRecordedFragment extends Fragment {
|
||||
|
||||
sensorStatistics = contentProviderUtils.getSensorStats(trackId);
|
||||
|
||||
boolean prefsChanged = this.track == null || (!this.track.getActivityType().equals(track.getActivityType()));
|
||||
boolean prefsChanged = this.track == null || (!this.track.getActivityTypeLocalized().equals(track.getActivityTypeLocalized()));
|
||||
this.track = track;
|
||||
if (prefsChanged) {
|
||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, getString(R.string.stats_rate_key));
|
||||
@@ -193,10 +193,10 @@ public class StatisticsRecordedFragment extends Fragment {
|
||||
// Set activity type
|
||||
{
|
||||
Context context = getContext();
|
||||
String localizedActivityType = track.getActivityType();
|
||||
String localizedActivityType = track.getActivityTypeLocalized();
|
||||
String trackIconValue = ActivityType.findByLocalizedString(context, localizedActivityType)
|
||||
.getId();
|
||||
viewBinding.statsActivityTypeIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), ActivityType.findByActivityTypeId(trackIconValue)
|
||||
.getIconId();
|
||||
viewBinding.statsActivityTypeIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), ActivityType.findBy(trackIconValue)
|
||||
.getIconDrawableId()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user