mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-10-25 22:26:00 +03:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
11be26bf80
1 changed files with 43 additions and 23 deletions
|
@ -4,6 +4,7 @@ import android.content.SharedPreferences;
|
|||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -75,28 +76,46 @@ public class NotePreviewFragment extends BaseNoteFragment {
|
|||
markdownProcessor.factory(TextFactory.create());
|
||||
markdownProcessor.config(
|
||||
MarkDownUtil.getMarkDownConfiguration(noteContent.getContext())
|
||||
// .setOnTodoClickCallback((view, line, lineNumber) -> {
|
||||
// String[] lines = TextUtils.split(note.getContent(), "\\r?\\n");
|
||||
// /*
|
||||
// * Workaround for a bug when checkbox is the last line:
|
||||
// * When (un)checking a checkbox which is in the last line, every time it gets toggled, the last character of the line gets lost.
|
||||
// */
|
||||
// if ((lines.length - 1) == lineNumber) {
|
||||
// if(lines[lineNumber].contains("- [ ]")) {
|
||||
// lines[lineNumber] = lines[lineNumber].replace("- [ ]", "- [x]");
|
||||
// } else {
|
||||
// lines[lineNumber] = lines[lineNumber].replace("- [x]", "- [ ]");
|
||||
// }
|
||||
//
|
||||
// } else if (lines.length >= lineNumber) {
|
||||
// lines[lineNumber] = line;
|
||||
// }
|
||||
// changedText = TextUtils.join("\n", lines);
|
||||
// noteContent.setText(markdownProcessor.parse(changedText));
|
||||
// saveNote(null);
|
||||
// return line;
|
||||
// }
|
||||
// )
|
||||
.setOnTodoClickCallback((view, line, lineNumber) -> {
|
||||
try {
|
||||
String[] lines = TextUtils.split(note.getContent(), "\\r?\\n");
|
||||
/*
|
||||
* Workaround for RxMarkdown-bug:
|
||||
* When (un)checking a checkbox in a note which contains code-blocks, the "`"-characters get stripped out in the TextView and therefore the given lineNumber is wrong
|
||||
* Find number of lines starting with ``` before lineNumber
|
||||
*/
|
||||
for(int i = 0; i < lines.length; i++) {
|
||||
if(lines[i].startsWith("```")) {
|
||||
lineNumber++;
|
||||
}
|
||||
if(i == lineNumber) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Workaround for multiple RxMarkdown-bugs:
|
||||
* When (un)checking a checkbox which is in the last line, every time it gets toggled, the last character of the line gets lost.
|
||||
* When (un)checking a checkbox, every markdown gets stripped in the given line argument
|
||||
*/
|
||||
if (lines[lineNumber].startsWith("- [ ]") || lines[lineNumber].startsWith("* [ ]")) {
|
||||
lines[lineNumber] = lines[lineNumber].replace("- [ ]", "- [x]");
|
||||
lines[lineNumber] = lines[lineNumber].replace("* [ ]", "* [x]");
|
||||
} else {
|
||||
lines[lineNumber] = lines[lineNumber].replace("- [x]", "- [ ]");
|
||||
lines[lineNumber] = lines[lineNumber].replace("* [x]", "* [ ]");
|
||||
}
|
||||
|
||||
changedText = TextUtils.join("\n", lines);
|
||||
noteContent.setText(markdownProcessor.parse(changedText));
|
||||
saveNote(null);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Toast.makeText(getActivity(), "Checkbox could not be toggled.", Toast.LENGTH_SHORT).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return line;
|
||||
}
|
||||
)
|
||||
.build());
|
||||
setActiveTextView(noteContent);
|
||||
noteContent.setText(markdownProcessor.parse(note.getContent()));
|
||||
|
@ -111,7 +130,8 @@ public class NotePreviewFragment extends BaseNoteFragment {
|
|||
db.getNoteServerSyncHelper().addCallbackPull(new ICallback() {
|
||||
@Override
|
||||
public void onFinish() {
|
||||
noteContent.setText(markdownProcessor.parse(db.getNote(note.getAccountId(), note.getId()).getContent()));
|
||||
note = db.getNote(note.getAccountId(), note.getId());
|
||||
noteContent.setText(markdownProcessor.parse(note.getContent()));
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue