Fix #1276 Checkboxes using an uppercase X can not be toggled

Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
Stefan Niedermann 2021-06-23 10:09:57 +02:00
parent 110d841336
commit eae70001d1
6 changed files with 30 additions and 29 deletions

View file

@ -184,33 +184,22 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
// Verbose log output for https://github.com/stefan-niedermann/nextcloud-notes/issues/1256
runOnUiThread(() -> new AlertDialog.Builder(this)
.setTitle(NextcloudFilesAppAccountNotFoundException.class.getSimpleName())
.setMessage(R.string.backup_and_repair)
.setPositiveButton(R.string.simple_repair, (a, b) -> {
executor.submit(() -> {
for (Account account : mainViewModel.getAccounts()) {
SingleAccountHelper.setCurrentAccount(this, account.getAccountName());
runOnUiThread(this::recreate);
break;
}
});
})
.setNegativeButton(R.string.simple_backup, (a, b) -> {
executor.submit(() -> {
final List<Note> modifiedNotes = new LinkedList<>();
for (Account account : mainViewModel.getAccounts()) {
modifiedNotes.addAll(mainViewModel.getLocalModifiedNotes(account.getId()));
}
if (modifiedNotes.size() == 1) {
final Note note = modifiedNotes.get(0);
ShareUtil.openShareDialog(this, note.getTitle(), note.getContent());
} else {
ShareUtil.openShareDialog(this,
getResources().getQuantityString(R.plurals.share_multiple, modifiedNotes.size(), modifiedNotes.size()),
mainViewModel.collectNoteContents(modifiedNotes.stream().map(Note::getId).collect(Collectors.toList())));
}
});
})
.setNeutralButton(android.R.string.cancel, (a, b) -> {
.setMessage(R.string.backup)
.setPositiveButton(R.string.simple_backup, (a, b) -> executor.submit(() -> {
final List<Note> modifiedNotes = new LinkedList<>();
for (Account account : mainViewModel.getAccounts()) {
modifiedNotes.addAll(mainViewModel.getLocalModifiedNotes(account.getId()));
}
if (modifiedNotes.size() == 1) {
final Note note = modifiedNotes.get(0);
ShareUtil.openShareDialog(this, note.getTitle(), note.getContent());
} else {
ShareUtil.openShareDialog(this,
getResources().getQuantityString(R.plurals.share_multiple, modifiedNotes.size(), modifiedNotes.size()),
mainViewModel.collectNoteContents(modifiedNotes.stream().map(Note::getId).collect(Collectors.toList())));
}
}))
.setNegativeButton(R.string.simple_error, (a, b) -> {
final SharedPreferences ssoPreferences = AccountImporter.getSharedPreferences(getApplicationContext());
final StringBuilder ssoPreferencesString = new StringBuilder()
.append("Current SSO account: ").append(ssoPreferences.getString("PREF_CURRENT_ACCOUNT_STRING", null)).append("\n")

View file

@ -297,5 +297,5 @@
<string name="simple_prev">Previous</string>
<string name="simple_backup">Backup</string>
<string name="simple_repair">Repair</string>
<string name="backup_and_repair">We recommend to backup all unsynchronized notes and then try to repair the setup.</string>
<string name="backup">We detected an irrecoverably state of the app. Please backup your unsynchronized changes and clear the storage of the Notes app.</string>
</resources>

View file

@ -0,0 +1 @@
- ✅ Checkboxes using an uppercase X can not be toggled (#1276)

View file

@ -92,6 +92,7 @@ public class MarkdownUtil {
for (EListType listType : EListType.values()) {
if (checkboxCheckedEmoji != null) {
line = line.replace(listType.checkboxChecked, checkboxCheckedEmoji);
line = line.replace(listType.checkboxCheckedUpperCase, checkboxCheckedEmoji);
}
if (checkboxUncheckedEmoji != null) {
line = line.replace(listType.checkboxUnchecked, checkboxUncheckedEmoji);
@ -240,7 +241,7 @@ public class MarkdownUtil {
public static boolean lineStartsWithCheckbox(@NonNull String line, @NonNull EListType listType) {
final String trimmedLine = line.trim();
return (trimmedLine.startsWith(listType.checkboxUnchecked) || trimmedLine.startsWith(listType.checkboxChecked));
return (trimmedLine.startsWith(listType.checkboxUnchecked) || trimmedLine.startsWith(listType.checkboxChecked) || trimmedLine.startsWith(listType.checkboxCheckedUpperCase));
}
/**

View file

@ -8,6 +8,7 @@ public enum EListType {
public final String listSymbol;
public final String listSymbolWithTrailingSpace;
public final String checkboxChecked;
public final String checkboxCheckedUpperCase;
public final String checkboxUnchecked;
public final String checkboxUncheckedWithTrailingSpace;
@ -15,6 +16,7 @@ public enum EListType {
this.listSymbol = String.valueOf(listSymbol);
this.listSymbolWithTrailingSpace = listSymbol + " ";
this.checkboxChecked = listSymbolWithTrailingSpace + "[x]";
this.checkboxCheckedUpperCase = listSymbolWithTrailingSpace + "[X]";
this.checkboxUnchecked = listSymbolWithTrailingSpace + "[ ]";
this.checkboxUncheckedWithTrailingSpace = checkboxUnchecked + " ";
}

View file

@ -648,6 +648,14 @@ public class MarkdownUtilTest extends TestCase {
listType.checkboxUnchecked + " \n" +
listType.checkboxChecked + " Item";
assertEquals(expected_9, MarkdownUtil.setCheckboxStatus(origin_9, 1, true));
final String origin_10 = "" +
listType.checkboxChecked + " Item\n" +
listType.checkboxCheckedUpperCase + " Item";
final String expected_10 = "" +
listType.checkboxChecked + " Item\n" +
listType.checkboxUnchecked + " Item";
assertEquals(expected_10, MarkdownUtil.setCheckboxStatus(origin_10, 1, false));
}
}