Skip to content

Commit

Permalink
Import workout: Name incorrect
Browse files Browse the repository at this point in the history
* Strip prefix for file printouts

* Incorrect suffixes if overwriting a workout
  • Loading branch information
gerhardol committed Nov 15, 2020
1 parent 5fb9a30 commit eb2aa96
Showing 1 changed file with 15 additions and 16 deletions.
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

0 comments on commit eb2aa96

Please sign in to comment.