Skip to content

Commit

Permalink
Merge pull request #985 from gerhardol/feature/import-workout-name
Browse files Browse the repository at this point in the history
import workout name had a prefix
  • Loading branch information
gerhardol authored Nov 15, 2020
2 parents 5fb9a30 + b7e580c commit f6a15ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/assets/bundled/app_workouts/4x4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"com.garmin.connect.workout.json.UserWorkoutJson":{"workoutSteps":[{"stepTypeKey":"warmup","endConditionTypeKey":"lap.button","endConditionUnitKey":"dimensionless","targetTypeKey":"no.target","targetValueUnitKey":"dimensionless","stepOrder":1,"groupId":1},{"stepTypeKey":"repeat","endConditionTypeKey":"iterations","endConditionValue":4,"endConditionUnitKey":"dimensionless","stepOrder":2,"groupId":2},{"stepTypeKey":"interval","endConditionTypeKey":"time","endConditionValue":240000,"endConditionUnitKey":"ms","targetTypeKey":"no.target","targetValueUnitKey":"dimensionless","stepOrder":3,"groupId":2,"parentGroupId":2},{"stepTypeKey":"recovery","endConditionTypeKey":"time","endConditionValue":180000,"endConditionUnitKey":"ms","targetTypeKey":"no.target","targetValueUnitKey":"dimensionless","stepOrder":4,"groupId":2,"parentGroupId":2},{"stepTypeKey":"cooldown","endConditionTypeKey":"lap.button","endConditionUnitKey":"dimensionless","targetTypeKey":"no.target","targetValueUnitKey":"dimensionless","stepOrder":5,"groupId":3}]}}
6 changes: 6 additions & 0 deletions app/assets/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
</head>
<body>
<h1>What's new</h1>
<h2>v2.2.7</h2>
<p>
<ul>
<li>#984 Edit workout steps</li>
<li>#985 Import workout: Prefix when importing from file</li>
</ul>
<h2>v2.2.6</h2>
<p>
<ul>
Expand Down
31 changes: 15 additions & 16 deletions app/src/main/org/runnerup/view/ManageWorkoutsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private String getFilename(Uri data) {
return name;
}

private void importData(final String fileName, final Uri data) throws Exception {
private void importData(String fileName, final Uri data) throws Exception {
final ContentResolver cr = getContentResolver();
InputStream is = cr.openInputStream(data);
if (is == null) {
Expand All @@ -192,36 +192,35 @@ private void importData(final String fileName, final Uri data) throws Exception
if (w == null)
throw new Exception("Failed to parse content");

if(fileName.endsWith(".json")) {
fileName = fileName.substring(0, fileName.length() - ".json".length());
}

final String prefix = getString(R.string.RunnerUp_workout) + ": ";
if (fileName.startsWith(prefix) && fileName.length() > prefix.length()) {
fileName = fileName.substring(prefix.length());
}

final boolean exists = WorkoutSerializer.getFile(this, fileName).exists();
final boolean[] selected = {
false
};

final String workoutName = fileName;
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(getString(R.string.Import_workout) + ": " + fileName)
.setTitle(getString(R.string.Import_workout) + ": " + workoutName)
.setPositiveButton(R.string.Yes,
(dialog, which) -> {
dialog.dismiss();
String saveName = fileName;
String saveName = workoutName;
try {
if (exists && !selected[0]) {
String name = "";
String[] tmp = fileName.split("\\.");
if (tmp.length > 0) {
for (int i = 0; i < tmp.length - 1; i++)
name = name.concat(tmp[i]);
} else {
name = fileName;
}
String ending = tmp.length > 0 ? ("." + tmp[tmp.length - 1]) : "";
String newName = fileName;
for (int i = 1; i < 25; i++) {
newName = name + "-" + i + ending;
saveName = workoutName + "-" + i;
if (!WorkoutSerializer.getFile(ManageWorkoutsActivity.this,
newName).exists())
saveName).exists())
break;
}
saveName = newName;
Toast.makeText(ManageWorkoutsActivity.this,
getString(R.string.Saving_as) + " " + saveName, Toast.LENGTH_SHORT).show();
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ project.ext {
mockitoVersion = '2.3.7'

//The Git tag for the release must be identical for F-Droid
versionName = '2.2.6.0'
versionCode = 292
versionName = '2.2.7.0'
versionCode = 294
latestBaseVersionCode = 15000000

travisBuild = System.getenv("TRAVIS") == "true"
Expand Down

0 comments on commit f6a15ef

Please sign in to comment.