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
29 changes: 19 additions & 10 deletions app/src/main/org/runnerup/tracker/component/TrackerGPS.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import android.location.LocationManager;
import android.os.Handler;
import android.text.TextUtils;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import org.runnerup.R;
Expand Down Expand Up @@ -108,19 +110,24 @@ private Integer parseAndFixInteger(
String s = preferences.getString(context.getString(resId), def);
if (TextUtils.isEmpty(s)) {
// Update the settings
SharedPreferences.Editor prefedit = preferences.edit();
prefedit.putString(context.getString(resId), def);
prefedit.apply();
SharedPreferences.Editor prefs = preferences.edit();
prefs.putString(context.getString(resId), def);
prefs.apply();
s = def;
}
return Integer.parseInt(s);
}

static Location getLastKnownLocation(LocationManager lm) {
private static Location getLastKnownLocation(LocationManager lm, Context context) {
String[] list = {GPS_PROVIDER, NETWORK_PROVIDER, PASSIVE_PROVIDER};
Location lastLocation = null;
for (String s : list) {
Location tmp = lm.getLastKnownLocation(s);
if (s.equals(GPS_PROVIDER)
&& (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
continue;
}
Location tmp = lm.getLastKnownLocation(s);
if (tmp == null) {
continue;
}
Expand All @@ -144,7 +151,7 @@ static Location getLastKnownLocation(LocationManager lm) {

@Override
public ResultCode onConnecting(final Callback callback, Context context) {
if (mWithoutGps == false &&
if (!mWithoutGps &&
ContextCompat.checkSelfPermission(this.tracker, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
mWithoutGps = true;
Expand All @@ -154,7 +161,7 @@ public ResultCode onConnecting(final Callback callback, Context context) {
var lm = locationManager;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
frequency_ms = parseAndFixInteger(preferences, R.string.pref_pollInterval, "1000", context);
mLastLocation = getLastKnownLocation(lm);
mLastLocation = getLastKnownLocation(lm, context);
if (!mWithoutGps) {
Integer frequency_meters =
parseAndFixInteger(preferences, R.string.pref_pollDistance, "0", context);
Expand Down Expand Up @@ -246,7 +253,7 @@ public void run() {

@Override
public void onTick() {
if (mWithoutGps == false) {
if (!mWithoutGps) {
if (mGpsStatus == null) {
return;
}
Expand All @@ -262,8 +269,10 @@ public void onTick() {

Callback tmp = mConnectCallback;
mConnectCallback = null;
mGpsStatus.stop(this);
// note: Don't reset mGpsStatus, it's used for isConnected()
if (mGpsStatus != null) {
mGpsStatus.stop(this);
// note: Don't reset mGpsStatus, it's used for isConnected()
}

tmp.run(this, ResultCode.RESULT_OK);
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/org/runnerup/view/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -76,6 +78,7 @@ private enum UpgradeState {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.main);

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/org/runnerup/view/ManageWorkoutsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ private String getFilename(Uri data) {
} else if (ContentResolver.SCHEME_CONTENT.contentEquals(data.getScheme())) {
String[] projection = {MediaStore.MediaColumns.DISPLAY_NAME};
Cursor c = getContentResolver().query(data, projection, null, null, null);
if (c != null) {
c.moveToFirst();
if (c != null && c.moveToFirst()) {
final int fileNameColumnId = c.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
if (fileNameColumnId >= 0) name = c.getString(fileNameColumnId);
c.close();
}
c.close();
}
return name;
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/org/runnerup/workout/TargetTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public void onRepeat(int current, int limit) {}
@Override
public void onStart(Scope what, Workout s) {
if (this.scope == what) {
paused = false;
reset();
for (Feedback f : triggerAction) {
f.onStart(s);
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/org/runnerup/workout/Workout.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ public void onEnd(Workout w) {
@Override
public void onRepeat(int current, int limit) {}

/**
* Start the ACTIVITY, the tracker starts this once. The activity starts the steps for STEP/LAP.
*
* @param s always ACTIVITY
* @param w current workout
*/
public void onStart(Scope s, Workout w) {
if (BuildConfig.DEBUG && w != this) {
throw new AssertionError();
Expand All @@ -151,10 +157,11 @@ public void onStart(Scope s, Workout w) {
}

currentStepNo = 0;
if (steps.size() > 0) {
if (!steps.isEmpty()) {
setCurrentStep(steps.get(currentStepNo));
}

// start STEP and LAP
if (currentStep != null) {
currentStep.onStart(Scope.ACTIVITY, this);
currentStep.onStart(Scope.STEP, this);
Expand Down
23 changes: 10 additions & 13 deletions app/src/main/org/runnerup/workout/WorkoutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,14 @@ public static Workout createDefaultIntervalWorkout(Resources res, SharedPreferen
}
repeat.steps.add(step);

Step rest = null;
switch (intervalRestType) {
case 0: // Time
rest = Step.createRestStep(Dimension.TIME, intervalRestTime, convertRestToRecovery);
break;
case 1: // Distance
rest =
Step.createRestStep(Dimension.DISTANCE, intervalRestDistance, convertRestToRecovery);
break;
}
repeat.steps.add(rest);
Step rest = switch (intervalRestType) {
case 0 -> // Time
Step.createRestStep(Dimension.TIME, intervalRestTime, convertRestToRecovery);
case 1 -> // Distance
Step.createRestStep(Dimension.DISTANCE, intervalRestDistance, convertRestToRecovery);
default -> null;
};
repeat.steps.add(rest);
}
w.steps.add(repeat);

Expand All @@ -214,7 +211,7 @@ public static boolean validateSeconds(String newValue) {
// TODO move this somewhere
long seconds = SafeParse.parseSeconds(newValue, -1);
long seconds2 = SafeParse.parseSeconds(DateUtils.formatElapsedTime(seconds), -1);
return seconds == seconds2;
return seconds >= 0 && seconds == seconds2;
}

public static SharedPreferences getAudioCuePreferences(
Expand Down Expand Up @@ -552,7 +549,7 @@ private static void createAudioCountdown(Step step) {
}

// Remove all values in list close to the step
while (list.size() > 0 && step.getDurationValue() < list.get(0) * 1.1d) {
while (!list.isEmpty() && step.getDurationValue() < list.get(0) * 1.1d) {
list.remove(0);
}
list.add(0, step.getDurationValue());
Expand Down
4 changes: 3 additions & 1 deletion wear/src/main/java/org/runnerup/service/StateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.runnerup.view.MainActivity;
import org.runnerup.wear.WearableClient;

import java.util.Objects;

public class StateService extends Service
implements MessageApi.MessageListener, DataApi.DataListener, ValueModel.ChangeListener<Bundle> {

Expand Down Expand Up @@ -213,7 +215,7 @@ public void onDataChanged(DataEventBuffer dataEvents) {
}

private void setPhoneNode(DataEvent ev) {
if (ev.getType() == DataEvent.TYPE_CHANGED) {
if (ev.getType() == DataEvent.TYPE_CHANGED && Objects.requireNonNull(ev.getDataItem().getData()).length > 0) {
phoneNode = new String(ev.getDataItem().getData());
} else if (ev.getType() == DataEvent.TYPE_DELETED) {
phoneNode = null;
Expand Down
29 changes: 14 additions & 15 deletions wear/src/main/java/org/runnerup/view/RunInfoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,20 @@ public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

int[] ids = null;
int card = 0;
switch (rowsOnScreen) {
case 3:
ids = card3ids;
card = R.layout.card3;
break;
case 2:
ids = card2ids;
card = R.layout.card2;
break;
case 1:
ids = card1ids;
card = R.layout.card1;
break;
}
int card = switch (rowsOnScreen) {
case 2 -> {
ids = card2ids;
yield R.layout.card2;
}
case 1 -> {
ids = card1ids;
yield R.layout.card1;
}
default -> {
ids = card3ids;
yield R.layout.card3;
}
};
View view = inflater.inflate(card, container, false);
for (int i = 0; i < rowsOnScreen; i++) {
textViews.add(
Expand Down
Loading