Skip to content

Commit

Permalink
Bug fixes: messed up setlist order and save song in setlist mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AndInTheClouds committed May 16, 2023
1 parent 9896fff commit 0658a32
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.hollowbamboo.chordreader2"
android:versionCode="4"
android:versionName="2.1.2">
android:versionCode="5"
android:versionName="2.1.3">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static String openFile(Context context, String filename) {

public static List<String> openSetlist(Context context, String setlist) {

ArrayList<String> filesList = new ArrayList<>();
final String[][] tempList2 = {new String[0]};

// do in background to avoid jankiness
final CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -324,6 +324,8 @@ public static List<String> openSetlist(Context context, String setlist) {
public void handleMessage(Message msg) {
super.handleMessage(msg);

tempList2[0] = (String[]) msg.obj;

latch.countDown();

handlerThread.quit();
Expand All @@ -340,28 +342,34 @@ public void handleMessage(Message msg) {

ArrayList<String> existingFiles = SaveFileHelper.getExistingFiles(context, files);

ArrayList<String> tempList = new ArrayList<>();

for (String file : existingFiles) {
filesList.add(file.replace(".txt", ""));
tempList.add(file.replace(".txt", ""));
}

if (filesList.size() == 1 && filesList.get(0).equals(""))
filesList.remove(0);
if (tempList.size() == 1 && tempList.get(0).equals(""))
tempList.remove(0);

message.obj = "ready";
String[] stringArray = new String[tempList.size()];
tempList.toArray(stringArray);
message.obj = stringArray;

asyncHandler.sendMessage(message);
};

asyncHandler.post(runnable);

// wait for async saving result
// wait for async opening result
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}

return filesList.isEmpty() ? new ArrayList<>() : filesList;
ArrayList<String> fileList = new ArrayList<>(Arrays.asList(tempList2[0]));

return fileList.isEmpty() ? new ArrayList<>() : fileList;
}

public static boolean saveFile(Context context, String fileText, String filename) {
Expand Down Expand Up @@ -522,7 +530,7 @@ private static ArrayList<Uri> getFileUri(Context context, List<String> requested
DocumentsContract.Document.COLUMN_DISPLAY_NAME
}, null, null, null);

ArrayList<Uri> existingFilesUris = new ArrayList<>();
Uri[] existingFilesUris = new Uri[requestedFileNames.size()];

while (cursor.moveToNext()) {
final String fileName = cursor.getString(1);
Expand All @@ -534,11 +542,12 @@ private static ArrayList<Uri> getFileUri(Context context, List<String> requested
DocumentsContract.buildDocumentUriUsingTree(
PreferenceHelper.getStorageLocation(context), documentId);

existingFilesUris.add(documentUri);
int index = requestedFileNames.indexOf(fileName);
existingFilesUris[index] = documentUri;
}
}

return existingFilesUris;
return new ArrayList<>(Arrays.asList(existingFilesUris));

} catch (Exception e) {
Log.w("SaveFileHelper_getUri", "Failed query: " + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public class SongViewFragment extends Fragment implements View.OnClickListener {
private static final String LOG_TAG = "SongViewFragment";
private static final int PROGRESS_DIALOG_MIN_TIME = 600;
private static final int POST_SAVE_PROCEEDING_EXIT = 100;
private static final int POST_SAVE_PROCEEDING_NEXT_SONG = 200;
private static final int POST_SAVE_PROCEEDING_PREVIOUS_SONG = 201;

private int howToProceedAfterSaving = 0;

Expand Down Expand Up @@ -205,16 +207,8 @@ public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
createSetListDialog();
return true;
} else if(itemId == android.R.id.home) {
if(songViewFragmentViewModel.isEditedTextToSave) {
howToProceedAfterSaving = POST_SAVE_PROCEEDING_EXIT;
if (songViewFragmentViewModel.autoSave) {
saveFile(songViewFragmentViewModel.filename, songViewFragmentViewModel.chordText);
} else {
showSavePromptDialog();
}
} else if (getParentFragment() != null) {
Navigation.findNavController(getParentFragment().requireView()).popBackStack();
}
howToProceedAfterSaving = POST_SAVE_PROCEEDING_EXIT;
checkForSaving();

return true;
}
Expand All @@ -240,9 +234,11 @@ public void onClick(View view) {
animationBlink(autoScrollFasterButton);
changeAutoScrollFactor(true);
} else if(id == R.id.setlist_next) {
openNextSong(true);
howToProceedAfterSaving = POST_SAVE_PROCEEDING_NEXT_SONG;
checkForSaving();
} else if(id == R.id.setlist_previous) {
openNextSong(false);
howToProceedAfterSaving = POST_SAVE_PROCEEDING_PREVIOUS_SONG;
checkForSaving();
}
}

Expand Down Expand Up @@ -467,19 +463,24 @@ private void handleBackButton() {
public void handleOnBackPressed() {
howToProceedAfterSaving = POST_SAVE_PROCEEDING_EXIT;

if(songViewFragmentViewModel.isEditedTextToSave) {
if (songViewFragmentViewModel.autoSave)
saveFile(songViewFragmentViewModel.filename, songViewFragmentViewModel.chordText);
else {
showSavePromptDialog();
}
} else
proceedAfterSaving();
checkForSaving();
}
};
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), callback);
}

private void checkForSaving() {

if(songViewFragmentViewModel.isEditedTextToSave) {
if (songViewFragmentViewModel.autoSave)
saveFile(songViewFragmentViewModel.filename, songViewFragmentViewModel.chordText);
else {
showSavePromptDialog();
}
} else
proceedAfterSaving();
}

private void saveFile(final String filename, final String fileText) {

// Save text size
Expand Down Expand Up @@ -526,6 +527,10 @@ private void proceedAfterSaving() {
if (getParentFragment() != null) {
Navigation.findNavController(getParentFragment().requireView()).popBackStack();
}
} else if (howToProceedAfterSaving == POST_SAVE_PROCEEDING_NEXT_SONG) {
openNextSong(true);
} else if (howToProceedAfterSaving == POST_SAVE_PROCEEDING_PREVIOUS_SONG) {
openNextSong(false);
} else
setTitle(songViewFragmentViewModel.filename);
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/raw/about_body_de.htm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<b>Changelog</b>
</center>

<i>2.1.3</i>
<ul>
<li>Fehlerbehebung: durcheinandergebrachte Song-Reihenfolge der Setlist beim Öffnen</li>
<li>Fehlerbehebung: Speichern geänderter Songs beim Songwechsel im Setlist-Modus</li>
</ul>

<i>2.1.2</i>
<ul>
<li>Wechsel zu Android Storage Access Framework ab Android 8.1</li>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/raw/about_body_en.htm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
<b>Changelog</b>
</center>

<i>2.1.3</i>
<ul>
<li>Bug fix: messed up song order of the setlist when opening it</li>
<li>Bug fix: saving edited songs when changing songs in setlist mode</li>
</ul>

<i>2.1.2</i>
<ul>
<li>Switch to Android Storage Access Framework as of Android 8.1</li>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/raw/about_body_fr.htm
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@
<b>Changelog</b>
</center>

<i>2.1.3</i>
<ul>
<li>Correction d'un problème de désorganisation de l'ordre des chansons dans la setlist à l'ouverture</li>
<li>Correction d'un problème de sauvegarde des chansons éditées lors du changement de chanson en mode Setlist</li>
</ul>

<i>2.1.2</i>
<ul>
<li>Passage à Android Storage Access Framework à partir d'Android 8.1</li>
<li>Possibilité d'un chemin de stockage personnalisé</li>

</ul>

<i>2.1.1</i>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
<string name="pref_first_run_title">Einführung zurücksetzen</string>
<string name="pref_first_run_summary">Willkommensnachricht nochmal zeigen.</string>
<string name="first_run_title">Willkommen zu Chord Reader 2!</string>
<string name="first_run_message">\n<b>Was ist neu in Version 2.1.2?</b>\n\n
<li>Wechsel zu Android Storage Access Framework ab Android 8.1</li>\n
<li>Möglichkeit für individuellen Speicherpfad</li>\n\n
ChordReader 2 ist eine <b>Open Source Software</b>.</string>
<string name="first_run_message">\n<b>Was ist neu in Version 2.1.3?</b>\n\n
<li>Fehlerbehebung: durcheinandergebrachte Song-Reihenfolge der Setlist beim Öffnen</li>\n
<li>Fehlerbehebung: Speichern geänderter Songs beim Songwechsel im Setlist-Modus</li>\n
\nChordReader 2 ist eine <b>Open Source Software</b>.</string>
<string name="unsaved_changes">Ungespeicherte Änderungen</string>
<string name="unsaved_changes_message">Möchtest du deine Änderungen speichern?</string>
<string name="closing_chordreader">ChordReader schließen</string>
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
<string name="pref_first_run_title">Réinitialiser l\'introduction</string>
<string name="pref_first_run_summary">Montrer de nouveau le message d\'introduction.</string>
<string name="first_run_title">Bienvenue dans Chord Reader 2!</string>
<string name="first_run_message">\n<b>Quoi de neuf dans la version 2.1.2 ?</b>\n\n
<li>Passage à Android Storage Access Framework à partir d\'Android 8.1</li>\n
<li>Possibilité d\'un emplacement de stockage individuel</li>\n\n
<string name="first_run_message">\n<b>Quoi de neuf dans la version 2.1.3 ?</b>\n\n
<li>Correction d\'un problème de désorganisation de l\'ordre des chansons dans la setlist à l\'ouverture</li>\n
<li>Correction d\'un problème de sauvegarde des chansons éditées lors du changement de chanson en mode Setlist</li>\n\n
Chord Reader 2 est un <b>logiciel open source</b>.\n</string>
<string name="unsaved_changes">Modifications non enregistrées</string>
<string name="unsaved_changes_message">Voulez-vous enregistrer vos modifications?</string>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@
<string name="pref_first_run_title">Reset Introduction</string>
<string name="pref_first_run_summary">Show introductory message again.</string>
<string name="first_run_title">Welcome to Chord Reader 2!</string>
<string name="first_run_message">\n<b>What\'s new in version 2.1.2?</b> \n\n
<li>Switch to Android Storage Access Framework as of Android 8.1</li>\n
<li>Possibility for custom storage path</li>\n
<li>Minor bugfixes and optimizations</li>\n \nChord Reader 2 is <b>open source software</b>. \n</string>
<string name="first_run_message">\n<b>What\'s new in version 2.1.3?</b> \n\n
<li>Bug fix: messed up song order of the setlist when opening it</li>\n
<li>Bug fix: saving edited songs when changing songs in setlist mode</li>\n
\nChord Reader 2 is <b>open source software</b>. \n</string>
<string name="unsaved_changes">Unsaved Changes</string>
<string name="unsaved_changes_message">Do you want to save your changes?</string>
<string name="closing_chordreader">Closing ChordReader</string>
Expand Down
11 changes: 11 additions & 0 deletions fastlane/metadata/org.hollowbamboo.chordreader2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ RepoType: git
Repo: https://github.com/AndInTheClouds/chordreader2

Builds:
- versionName: 2.1.3
versionCode: 5
commit: v2.1.3
subdir: app
sudo:
- apt-get update || apt-get update
- apt-get install -y openjdk-11-jdk-headless
- update-alternatives --auto java
gradle:
- yes

- versionName: 2.1.2
versionCode: 4
commit: v2.1.2
Expand Down

0 comments on commit 0658a32

Please sign in to comment.