Skip to content

Commit

Permalink
MainActivity todo/quicknote scroll to bottom via setUserVisibleHint
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Nov 20, 2021
1 parent d3e91a8 commit 7f3c4bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
new ActivityUtils(getActivity()).hideSoftKeyboard().freeContextRef();
_hlEditor.clearFocus();
_hlEditor.setLineSpacing(0, _appSettings.getEditorLineSpacing());

setupAppearancePreferences(view);

if (savedInstanceState != null && savedInstanceState.containsKey(SAVESTATE_PREVIEW_ON)) {
Expand All @@ -222,26 +221,22 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
}

// Set the correct position after everything else done
if (!Arrays.asList(_hlEditor, _webView, _document.getFile()).contains(null)) {
if (isDisplayedAtMainActivity()) {
// Scroll to the bottom
_primaryScrollView.post(() -> _primaryScrollView.fullScroll(View.FOCUS_DOWN));
} else {
// Scroll to position
// If Intent contains line number, jump to it
// intentLineNumber only created with document reconstructed from intent
if (intentLineNumber >= 0) {
_hlEditor.smoothMoveCursorToLine(intentLineNumber);
}
if (!isDisplayedAtMainActivity() && !Arrays.asList(_hlEditor, _webView, _document.getFile()).contains(null)) {
// Scroll to position
// If Intent contains line number, jump to it
// intentLineNumber only created with document reconstructed from intent
if (intentLineNumber >= 0) {
_hlEditor.smoothMoveCursorToLine(intentLineNumber);
}

// Set cursor if saved cursor state present
final int pos = savedInstanceState != null ? savedInstanceState.getInt(SAVESTATE_CURSOR_POS, -1) : -1;
final CharSequence text = _hlEditor.getText();
if (_hlEditor.indexesValid(pos) && text != null) {
_hlEditor.smoothMoveCursorToLine(StringUtils.getLineOffsetFromIndex(text, pos)[0]);
_hlEditor.setSelection(pos);
}
// Set cursor if saved cursor state present
final int pos = savedInstanceState != null ? savedInstanceState.getInt(SAVESTATE_CURSOR_POS, -1) : -1;
final CharSequence text = _hlEditor.getText();
if (_hlEditor.indexesValid(pos) && text != null) {
_hlEditor.smoothMoveCursorToLine(StringUtils.getLineOffsetFromIndex(text, pos)[0]);
_hlEditor.setSelection(pos);
}

}
}

Expand Down Expand Up @@ -727,6 +722,7 @@ public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser && isDisplayedAtMainActivity()) {
loadDocument();
_primaryScrollView.postDelayed(() -> _primaryScrollView.fullScroll(View.FOCUS_DOWN), 100);
} else if (!isVisibleToUser && _document != null) {
saveDocument(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public boolean isCurrentLineEmpty() {
return posLineBegin == posEndBegin;
}

interface OnTextChangedListener {
void onTextChanged(String text);
}

private boolean _modified = true;
private boolean _hlEnabled = false;
private boolean _accessibilityEnabled = true;
Expand Down

0 comments on commit 7f3c4bf

Please sign in to comment.