Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/res/layout/start_basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,22 @@
android:prompt="@string/Type"
android:text="@string/Target_heart_rate_zone"
android:visibility="gone" />

<CheckBox
android:id="@+id/tab_basic_enable_autolap_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Enable_autolap_time" />

<org.runnerup.widget.TitleSpinner
android:id="@+id/tab_basic_autolap_time_duration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:key="@string/pref_basic_autolap_time_duration"
android:prompt="@string/Type"
android:text="@string/Autolap_time"
android:defaultValue="00:10:00"
android:inputType="time"
runnerup:type="durationpicker" />

</LinearLayout>
2 changes: 2 additions & 0 deletions app/res/values/pref_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<string name="pref_basic_target_pace_max">basic_target_pace_max</string>
<string name="pref_basic_target_pace_min_range">basic_target_pace_min_range</string>
<string name="pref_basic_target_hrz">basic_target_hrz</string>
<string name="pref_basic_enable_autolap_time">basic_enable_autolap_time</string>
<string name="pref_basic_autolap_time_duration">basic_autolap_time_duration</string>

<string name="pref_interval_audio">intervalAudio</string>
<string name="pref_interval_repetitions">intervalRepetitions</string>
Expand Down
44 changes: 35 additions & 9 deletions app/src/main/org/runnerup/view/StartFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
Expand Down Expand Up @@ -147,6 +148,8 @@ private enum GpsLevel {
TitleSpinner simpleTargetType = null;
TitleSpinner simpleTargetPaceValue = null;
TitleSpinner simpleTargetHrz = null;
CheckBox simpleEnableAutolapTime = null;
TitleSpinner simpleAutolapTime = null;
AudioSchemeListAdapter simpleAudioListAdapter = null;
HRZonesListAdapter hrZonesAdapter = null;

Expand All @@ -166,6 +169,7 @@ private enum GpsLevel {
AudioSchemeListAdapter advancedAudioListAdapter = null;

SQLiteDatabase mDB = null;
SharedPreferences prefs = null;

Formatter formatter = null;
private NotificationStateManager notificationStateManager;
Expand All @@ -190,6 +194,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
Context context = requireContext();
mDB = DBHelper.getWritableDatabase(context);
formatter = new Formatter(context);
prefs = PreferenceManager.getDefaultSharedPreferences(context);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context is ot fixed, so I do not think this can be shared,


bindGpsTracker();
mGpsStatus = new org.runnerup.tracker.GpsStatus(context);
Expand All @@ -206,7 +211,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
context, R.layout.actionbar_spinner, Sport.getStringArray(getResources()));
adapter.setDropDownViewResource(R.layout.actionbar_dropdown_spinner);
sportSpinner.setAdapter(adapter);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
sportSpinner.setViewSelection(
prefs.getInt(getResources().getString(R.string.pref_sport), DB.ACTIVITY.SPORT_RUNNING));

Expand Down Expand Up @@ -271,6 +275,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
simpleTargetHrz = view.findViewById(R.id.tab_basic_target_hrz);
simpleTargetHrz.setAdapter(hrZonesAdapter);
simpleTargetType.setOnCloseDialogListener(simpleTargetTypeClick);
simpleEnableAutolapTime = view.findViewById(R.id.tab_basic_enable_autolap_time);
simpleAutolapTime = view.findViewById(R.id.tab_basic_autolap_time_duration);
simpleAutolapTime.setOnSetValueListener(onSetTimeValidator);

intervalType = view.findViewById(R.id.interval_type);
intervalTime = view.findViewById(R.id.start_interval_time);
Expand Down Expand Up @@ -321,6 +328,17 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mWearNotifier = new TrackerWear.WearNotifier(requireActivity().getApplicationContext());
mWearNotifier.onViewCreated();

var enable_autolap_time_key = getString(R.string.pref_basic_enable_autolap_time);
simpleEnableAutolapTime.setChecked(prefs.getBoolean(enable_autolap_time_key, true));
simpleEnableAutolapTime.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
prefs.edit().putBoolean(enable_autolap_time_key, b).apply();
simpleAutolapTime.setEnabled(b);
}
});

var listener = sportSpinner.getViewOnItemSelectedListener();
sportSpinner.setViewOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
Expand Down Expand Up @@ -555,9 +573,7 @@ private void onGpsTrackerBound() {
}

public boolean getAutoStartGps() {
Context ctx = requireActivity().getApplicationContext();
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(ctx);
return pref.getBoolean(getString(R.string.pref_startgps), false);
return prefs.getBoolean(getString(R.string.pref_startgps), false);
}

private void startGps() {
Expand Down Expand Up @@ -611,7 +627,6 @@ private void notificationBatteryLevel(int batteryLevel) {

Context context = requireContext();
final String pref_key = getString(R.string.pref_battery_level_low_notification_discard);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

int batteryLevelHighThreshold =
SafeParse.parseInt(
Expand Down Expand Up @@ -689,6 +704,13 @@ private Workout prepareWorkout() {
}
if (w != null) {
WorkoutBuilder.prepareWorkout(getResources(), pref, w);
if (sportWithoutGps && simpleEnableAutolapTime.isChecked()) {
long seconds =
SafeParse.parseSeconds(String.valueOf(simpleAutolapTime.getViewValueText()), 0);
if (seconds > 0) {
WorkoutBuilder.setAutolapTime(w, seconds);
}
}
WorkoutBuilder.addAudioCuesToWorkout(getResources(), w, audioPref, pref);
}
return w;
Expand Down Expand Up @@ -742,7 +764,6 @@ private List<String> getPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
requiredPerms.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION);

final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
boolean enabled =
prefs.getBoolean(
this.getString(org.runnerup.R.string.pref_use_cadence_step_sensor), true);
Expand All @@ -755,7 +776,6 @@ private List<String> getPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S /* Android12, sdk31*/
&& (packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)
|| packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
final String btDeviceName = prefs.getString(getString(R.string.pref_bt_name), null);
if (btDeviceName != null && !btDeviceName.isEmpty()) {
requiredPerms.add(Manifest.permission.BLUETOOTH_CONNECT);
Expand Down Expand Up @@ -856,7 +876,6 @@ private boolean checkPermissions(boolean popup) {

// https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases
// Permission REQUEST_IGNORE_BATTERY_OPTIMIZATIONS requires special approval in Play
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
final Resources res = this.getResources();
final boolean suppressOptimizeBatteryPopup =
prefs.getBoolean(res.getString(R.string.pref_suppress_battery_optimization_popup), false);
Expand Down Expand Up @@ -947,6 +966,14 @@ public void updateView() {
} else {
noDevicesConnected.setVisibility(View.GONE);
}
if (sportWithoutGps) {
simpleEnableAutolapTime.setVisibility(View.VISIBLE);
simpleAutolapTime.setVisibility(View.VISIBLE);
simpleAutolapTime.setEnabled(simpleEnableAutolapTime.isChecked());
} else {
simpleEnableAutolapTime.setVisibility(View.GONE);
simpleAutolapTime.setVisibility(View.GONE);
}
}

private void updateStartButtonView() {
Expand Down Expand Up @@ -1195,7 +1222,6 @@ public String getGpsAccuracyString(float accuracy) {
private String getHRDetailString() {
StringBuilder str = new StringBuilder();

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
final String btDeviceName = prefs.getString(getString(R.string.pref_bt_name), null);

if (btDeviceName != null) {
Expand Down
39 changes: 25 additions & 14 deletions app/src/main/org/runnerup/workout/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public class Step implements TickComponent {
Range targetValue = null;

/** Autolap (m) */
private double autolap = 0;
private double autolap_distance = 0;

/** Autolap (s) */
private double autolap_time = 0;

/** Triggers */
final ArrayList<Trigger> triggers = new ArrayList<>();
Expand Down Expand Up @@ -129,18 +132,19 @@ public void setIntensity(Intensity intensity) {
this.intensity = intensity;
}

/**
* @return the autolap distance (may be set in workouts too)
*/
double getAutolap() {
return autolap;
}

/**
* @param val the autolap to set
*/
void setAutolap(double val) {
this.autolap = val;
this.autolap_distance = val;
}

double getAutolapDistance() {
return autolap_distance;
}

void setAutolapTime(double val) {
this.autolap_time = val;
}

@Override
Expand Down Expand Up @@ -302,7 +306,7 @@ private boolean exceedDistance(
}

private boolean checkFinished(Workout s) {
if (this.getAutolap() == 0 && durationType == null) {
if (autolap_distance == 0 && durationType == null) {
return false;
}

Expand All @@ -325,11 +329,18 @@ private boolean checkFinished(Workout s) {
newStep = s.get(Scope.STEP, durationType) + diff >= this.durationValue;
}

if (!newStep && this.getAutolap() > 0) {
if (!newStep) {
double distance = s.getDistance(Scope.LAP);
double lapDist = getAutolap();
if (exceedDistance(distance, mPrevTickLapDistance, lapDist, time)) {
newLap = true;
if (autolap_distance > 0) {
if (exceedDistance(distance, mPrevTickLapDistance, autolap_distance, time)) {
newLap = true;
}
}
if (autolap_time > 0) {
double lap_time = s.getTime(Scope.LAP);
if (lap_time >= autolap_time) {
newLap = true;
}
}
mPrevTickLapDistance = distance;
}
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/org/runnerup/workout/WorkoutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private static void addAudioCuesToWorkout(
// Periodic distance/time and end of lap/step
// Some suppressions for each intensity for related lap started/completed
// endOfLap is related to the autolap
boolean endOfLap = step.getIntensity() == Intensity.ACTIVE || step.getAutolap() > 0;
boolean endOfLap = step.getIntensity() == Intensity.ACTIVE || step.getAutolapDistance() > 0;
ArrayList<Trigger> defaultTriggers = createDefaultTriggers(res, audioPrefs, endOfLap);

step.triggers.addAll(defaultTriggers);
Expand Down Expand Up @@ -415,8 +415,8 @@ private static void checkDuplicateTriggers(Step step) {
* trigger
*/
ArrayList<TriggerSuppression> list = new ArrayList<>();
if (step.getAutolap() > 0) {
list.add(new EndOfLapSuppression(step.getAutolap()));
if (step.getAutolapDistance() > 0) {
list.add(new EndOfLapSuppression(step.getAutolapDistance()));
}

if (step.getDurationType() == Dimension.DISTANCE) {
Expand Down Expand Up @@ -663,6 +663,15 @@ public static void prepareWorkout(Resources res, SharedPreferences prefs, Workou
}
}

public static void setAutolapTime(Workout w, double seconds) {
for (StepListEntry s : w.getStepList()) {
if (s.step().getIntensity() == Intensity.ACTIVE
|| s.step().getIntensity() == Intensity.COOLDOWN) {
s.step().setAutolapTime(seconds);
}
}
}

public static void addFeedbackFromPreferences(
SharedPreferences prefs, Resources res, ArrayList<Feedback> feedback) {
int feedbackStart = feedback.size();
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
<string name="Heart_Rate_Monitor">Heart rate monitor</string>
<string name="Heart_Rate_Zones">Heart rate zones</string>
<string name="Autolap">Autolap</string>
<string name="Enable_autolap_time">Enable autolap by time</string>
<string name="Autolap_time">time</string>
<string name="Autolap_m">Autolap (m)</string>
<string name="Autopause">Autopause</string>
<string name="Autopause_summary">Autopause in basic workouts and Warmup and Cooldown steps</string>
Expand Down