Skip to content

Commit

Permalink
Using canonical paths and and static members
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Aug 18, 2024
1 parent 00eae25 commit 4268201
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void showTextEditor(final Document document, final Integer lineNumber, fi

final boolean sameDocumentRequested = (
currentFragment instanceof DocumentEditAndViewFragment &&
document.getPath().equals(((DocumentEditAndViewFragment) currentFragment).getDocument().getPath()));
document.path.equals(((DocumentEditAndViewFragment) currentFragment).getDocument().path));

if (!sameDocumentRequested) {
showFragment(DocumentEditAndViewFragment.newInstance(document, lineNumber, startPreview));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {

// Upon construction, the document format has been determined from extension etc
// Here we replace it with the last saved format.
_document.setFormat(_appSettings.getDocumentFormat(_document.getPath(), _document.getFormat()));
_document.setFormat(_appSettings.getDocumentFormat(_document.path, _document.getFormat()));
applyTextFormat(_document.getFormat());
_format.getActions().setDocument(_document);

if (activity instanceof DocumentActivity) {
((DocumentActivity) activity).setDocumentTitle(_document.getTitle());
((DocumentActivity) activity).setDocumentTitle(_document.title);
}

// Preview mode set before loadDocument to prevent flicker
final Bundle args = getArguments();
final boolean startInPreview = _appSettings.getDocumentPreviewState(_document.getPath());
final boolean startInPreview = _appSettings.getDocumentPreviewState(_document.path);
if (args != null && savedInstanceState == null) { // Use the launch flag on first launch
setViewModeVisibility(args.getBoolean(START_PREVIEW, startInPreview), false);
} else {
Expand All @@ -205,22 +205,22 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
// Configure the editor. Doing so after load helps prevent some errors
// ---------------------------------------------------------
_hlEditor.setLineSpacing(0, _appSettings.getEditorLineSpacing());
_hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, _appSettings.getDocumentFontSize(_document.getPath()));
_hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, _appSettings.getDocumentFontSize(_document.path));
_hlEditor.setTypeface(GsFontPreferenceCompat.typeface(getContext(), _appSettings.getFontFamily(), Typeface.NORMAL));
_hlEditor.setBackgroundColor(_appSettings.getEditorBackgroundColor());
_hlEditor.setTextColor(_appSettings.getEditorForegroundColor());
_hlEditor.setGravity(_appSettings.isEditorStartEditingInCenter() ? Gravity.CENTER : Gravity.NO_GRAVITY);
_hlEditor.setHighlightingEnabled(_appSettings.getDocumentHighlightState(_document.getPath(), _hlEditor.getText()));
_hlEditor.setLineNumbersEnabled(_appSettings.getDocumentLineNumbersEnabled(_document.getPath()));
_hlEditor.setAutoFormatEnabled(_appSettings.getDocumentAutoFormatEnabled(_document.getPath()));
_hlEditor.setHighlightingEnabled(_appSettings.getDocumentHighlightState(_document.path, _hlEditor.getText()));
_hlEditor.setLineNumbersEnabled(_appSettings.getDocumentLineNumbersEnabled(_document.path));
_hlEditor.setAutoFormatEnabled(_appSettings.getDocumentAutoFormatEnabled(_document.path));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Do not need to send contents to accessibility
_hlEditor.setImportantForAccessibility(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
}
_webView.setBackgroundColor(Color.TRANSPARENT);

// Various settings
setHorizontalScrollMode(isDisplayedAtMainActivity() || _appSettings.getDocumentWrapState(_document.getPath()));
setHorizontalScrollMode(isDisplayedAtMainActivity() || _appSettings.getDocumentWrapState(_document.path));
updateMenuToggleStates(0);
// ---------------------------------------------------------

Expand Down Expand Up @@ -253,7 +253,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
}

if (savedInstanceState == null) {
int startPos = _appSettings.getLastEditPosition(_document.getPath(), _hlEditor.length());
int startPos = _appSettings.getLastEditPosition(_document.path, _hlEditor.length());
if (args != null && args.containsKey(Document.EXTRA_FILE_LINE_NUMBER)) {
final int lno = args.getInt(Document.EXTRA_FILE_LINE_NUMBER);
if (lno >= 0) {
Expand All @@ -278,9 +278,9 @@ public void onResume() {
public void onPause() {
saveDocument(false);
_webView.onPause();
_appSettings.addRecentFile(_document.getFile());
_appSettings.setDocumentPreviewState(_document.getPath(), _isPreviewVisible);
_appSettings.setLastEditPosition(_document.getPath(), _hlEditor.getSelectionStart());
_appSettings.addRecentFile(_document.file);
_appSettings.setDocumentPreviewState(_document.path, _isPreviewVisible);
_appSettings.setLastEditPosition(_document.path, _hlEditor.getSelectionStart());
super.onPause();
}

Expand Down Expand Up @@ -494,7 +494,7 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
return true;
}
case R.id.action_share_path: {
_cu.shareText(getActivity(), _document.getFile().getAbsolutePath(), GsContextUtils.MIME_TEXT_PLAIN);
_cu.shareText(getActivity(), _document.file.getAbsolutePath(), GsContextUtils.MIME_TEXT_PLAIN);
return true;
}
case R.id.action_share_text: {
Expand All @@ -505,7 +505,7 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
}
case R.id.action_share_file: {
if (saveDocument(false)) {
_cu.shareStream(getActivity(), _document.getFile(), GsContextUtils.MIME_TEXT_PLAIN);
_cu.shareStream(getActivity(), _document.file, GsContextUtils.MIME_TEXT_PLAIN);
}
return true;
}
Expand All @@ -514,15 +514,15 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
if (saveDocument(false)) {
TextConverterBase converter = FormatRegistry.getFormat(_document.getFormat(), activity, _document).getConverter();
_cu.shareText(getActivity(),
converter.convertMarkup(getTextString(), getActivity(), false, _hlEditor.getLineNumbersEnabled(), _document.getFile()),
converter.convertMarkup(getTextString(), getActivity(), false, _hlEditor.getLineNumbersEnabled(), _document.file),
"text/" + (item.getItemId() == R.id.action_share_html ? "html" : "plain")
);
}
return true;
}
case R.id.action_share_calendar_event: {
if (saveDocument(false)) {
if (!_cu.createCalendarAppointment(getActivity(), _document.getTitle(), getTextString(), null)) {
if (!_cu.createCalendarAppointment(getActivity(), _document.title, getTextString(), null)) {
Toast.makeText(activity, R.string.no_calendar_app_is_installed, Toast.LENGTH_SHORT).show();
}
}
Expand Down Expand Up @@ -559,7 +559,7 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
if (itemId != _document.getFormat()) {
_document.setFormat(itemId);
applyTextFormat(itemId);
_appSettings.setDocumentFormat(_document.getPath(), _document.getFormat());
_appSettings.setDocumentFormat(_document.path, _document.getFormat());
}
return true;
}
Expand Down Expand Up @@ -595,49 +595,49 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
}
case R.id.action_wrap_words: {
final boolean newState = !isWrapped();
_appSettings.setDocumentWrapState(_document.getPath(), newState);
_appSettings.setDocumentWrapState(_document.path, newState);
setHorizontalScrollMode(newState);
updateMenuToggleStates(0);
return true;
}
case R.id.action_line_numbers: {
final boolean newState = !_hlEditor.getLineNumbersEnabled();
_appSettings.setDocumentLineNumbersEnabled(_document.getPath(), newState);
_appSettings.setDocumentLineNumbersEnabled(_document.path, newState);
_hlEditor.setLineNumbersEnabled(newState);
updateMenuToggleStates(0);
return true;
}
case R.id.action_enable_highlighting: {
final boolean newState = !_hlEditor.getHighlightingEnabled();
_hlEditor.setHighlightingEnabled(newState);
_appSettings.setDocumentHighlightState(_document.getPath(), newState);
_appSettings.setDocumentHighlightState(_document.path, newState);
updateMenuToggleStates(0);
return true;
}
case R.id.action_enable_auto_format: {
final boolean newState = !_hlEditor.getAutoFormatEnabled();
_hlEditor.setAutoFormatEnabled(newState);
_appSettings.setDocumentAutoFormatEnabled(_document.getPath(), newState);
_appSettings.setDocumentAutoFormatEnabled(_document.path, newState);
updateMenuToggleStates(0);
return true;
}
case R.id.action_info: {
if (saveDocument(false)) { // In order to have the correct info displayed
FileInfoDialog.show(_document.getFile(), getParentFragmentManager());
FileInfoDialog.show(_document.file, getParentFragmentManager());
}
return true;
}
case R.id.action_set_font_size: {
MarkorDialogFactory.showFontSizeDialog(activity, _appSettings.getDocumentFontSize(_document.getPath()), (newSize) -> {
MarkorDialogFactory.showFontSizeDialog(activity, _appSettings.getDocumentFontSize(_document.path), (newSize) -> {
_hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) newSize);
_appSettings.setDocumentFontSize(_document.getPath(), newSize);
_appSettings.setDocumentFontSize(_document.path, newSize);
});
return true;
}
case R.id.action_show_file_browser: {
// Delay because I want menu to close before we open the file browser
_hlEditor.postDelayed(() -> {
final Intent intent = new Intent(activity, MainActivity.class).putExtra(Document.EXTRA_FILE, _document.getFile());
final Intent intent = new Intent(activity, MainActivity.class).putExtra(Document.EXTRA_FILE, _document.file);
GsContextUtils.instance.animateToActivity(activity, intent, false, null);
}, 250);
return true;
Expand Down Expand Up @@ -667,7 +667,7 @@ public void applyTextFormat(final int textFormatId) {
_hlEditor.setHighlighter(_format.getHighlighter());
_hlEditor.setDynamicHighlightingEnabled(_appSettings.isDynamicHighlightingEnabled());
_hlEditor.setAutoFormatters(_format.getAutoFormatInputFilter(), _format.getAutoFormatTextWatcher());
_hlEditor.setAutoFormatEnabled(_appSettings.getDocumentAutoFormatEnabled(_document.getPath()));
_hlEditor.setAutoFormatEnabled(_appSettings.getDocumentAutoFormatEnabled(_document.path));
_format.getActions()
.setUiReferences(activity, _hlEditor, _webView)
.recreateActionButtons(_textActionsBar, _isPreviewVisible ? ActionButtonBase.ActionItem.DisplayMode.VIEW : ActionButtonBase.ActionItem.DisplayMode.EDIT);
Expand Down Expand Up @@ -780,7 +780,7 @@ public void errorClipText() {
}

public boolean isSdStatusBad() {
if (_cu.isUnderStorageAccessFolder(getContext(), _document.getFile(), false) &&
if (_cu.isUnderStorageAccessFolder(getContext(), _document.file, false) &&
_cu.getStorageAccessFrameworkTreeUri(getContext()) == null) {
_cu.showMountSdDialog(getActivity());
return true;
Expand All @@ -793,7 +793,7 @@ public boolean isStateBad() {
return (_document == null ||
_hlEditor == null ||
_appSettings == null ||
!_cu.canWriteFile(getContext(), _document.getFile(), false, true));
!_cu.canWriteFile(getContext(), _document.file, false, true));
}

// Save the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private void appendToExistingDocumentAndClose(final File file, final boolean sho
}

final Document document = new Document(file);
final int format = _appSettings.getDocumentFormat(document.getPath(), document.getFormat());
final int format = _appSettings.getDocumentFormat(document.path, document.getFormat());
final String formatted = getFormatted(shareAsLink(), file, format);

final String oldContent = document.loadContent(activity);
Expand All @@ -256,7 +256,7 @@ private void appendToExistingDocumentAndClose(final File file, final boolean sho
_appSettings.addRecentFile(file);

if (showEditor) {
DocumentActivity.launch(activity, document.getFile(), null, -1);
DocumentActivity.launch(activity, document.file, null, -1);
}

activity.finish();
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ActionButtonBase(@NonNull final Context context, final Document document)
_document = document;
_appSettings = ApplicationObject.settings();
_buttonHorizontalMargin = GsContextUtils.instance.convertDpToPx(context, _appSettings.getEditorActionButtonItemPadding());
_indent = _appSettings.getDocumentIndentSize(_document != null ? _document.getPath() : null);
_indent = _appSettings.getDocumentIndentSize(_document != null ? _document.path : null);
}

// Override to implement custom onClick
Expand Down Expand Up @@ -641,15 +641,15 @@ protected final boolean runCommonAction(final @StringRes int action) {
return true;
}
case R.string.abid_common_insert_audio: {
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.AUDIO_ACTION, _document.getFormat(), _activity, text, _document.getFile());
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.AUDIO_ACTION, _document.getFormat(), _activity, text, _document.file);
return true;
}
case R.string.abid_common_insert_link: {
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.FILE_OR_LINK_ACTION, _document.getFormat(), _activity, text, _document.getFile());
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.FILE_OR_LINK_ACTION, _document.getFormat(), _activity, text, _document.file);
return true;
}
case R.string.abid_common_insert_image: {
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.IMAGE_ACTION, _document.getFormat(), _activity, text, _document.getFile());
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.IMAGE_ACTION, _document.getFormat(), _activity, text, _document.file);
return true;
}
case R.string.abid_common_ordered_list_renumber: {
Expand All @@ -670,7 +670,7 @@ protected final boolean runCommonAction(final @StringRes int action) {
}
case R.string.abid_common_insert_snippet: {
MarkorDialogFactory.showInsertSnippetDialog(_activity, (snip) -> {
_hlEditor.insertOrReplaceTextOnCursor(TextViewUtils.interpolateSnippet(snip, _document.getTitle(), TextViewUtils.getSelectedText(_hlEditor)));
_hlEditor.insertOrReplaceTextOnCursor(TextViewUtils.interpolateSnippet(snip, _document.title, TextViewUtils.getSelectedText(_hlEditor)));
_lastSnip = snip;
});
return true;
Expand All @@ -687,7 +687,7 @@ protected final boolean runCommonAction(final @StringRes int action) {
if (WEB_URL.matcher(resource).matches()) {
url = resource;
} else {
final File f = GsFileUtils.makeAbsolute(resource, _document.getFile().getParentFile());
final File f = GsFileUtils.makeAbsolute(resource, _document.file.getParentFile());
if (f.canRead()) {
DocumentActivity.launch(getActivity(), f, null, null);
return true;
Expand Down Expand Up @@ -741,7 +741,7 @@ protected final boolean runCommonAction(final @StringRes int action) {
return true;
}
case R.string.abid_common_view_file_in_other_app: {
_cu.viewFileInOtherApp(getContext(), _document.getFile(), GsFileUtils.getMimeType(_document.getFile()));
_cu.viewFileInOtherApp(getContext(), _document.file, GsFileUtils.getMimeType(_document.file));
return true;
}
case R.string.abid_common_rotate_screen: {
Expand All @@ -761,7 +761,7 @@ protected final boolean runCommonLongPressAction(@StringRes int action) {
case R.string.abid_common_indent: {
MarkorDialogFactory.showIndentSizeDialog(_activity, _indent, (size) -> {
_indent = Integer.parseInt(size);
_appSettings.setDocumentIndentSize(_document.getPath(), _indent);
_appSettings.setDocumentIndentSize(_document.path, _indent);
});
return true;
}
Expand Down Expand Up @@ -790,20 +790,20 @@ protected final boolean runCommonLongPressAction(@StringRes int action) {
}
case R.string.abid_common_insert_snippet: {
if (!TextUtils.isEmpty(_lastSnip)) {
_hlEditor.insertOrReplaceTextOnCursor(TextViewUtils.interpolateSnippet(_lastSnip, _document.getTitle(), TextViewUtils.getSelectedText(_hlEditor)));
_hlEditor.insertOrReplaceTextOnCursor(TextViewUtils.interpolateSnippet(_lastSnip, _document.title, TextViewUtils.getSelectedText(_hlEditor)));
}
return true;
}
case R.string.abid_common_insert_audio: {
AttachLinkOrFileDialog.insertAudioRecording(_activity, _document.getFormat(), _hlEditor.getText(), _document.getFile());
AttachLinkOrFileDialog.insertAudioRecording(_activity, _document.getFormat(), _hlEditor.getText(), _document.file);
return true;
}
case R.string.abid_common_insert_link: {
AttachLinkOrFileDialog.insertGalleryPhoto(_activity, _document.getFormat(), _hlEditor.getText(), _document.getFile());
AttachLinkOrFileDialog.insertGalleryPhoto(_activity, _document.getFormat(), _hlEditor.getText(), _document.file);
return true;
}
case R.string.abid_common_insert_image: {
AttachLinkOrFileDialog.insertCameraPhoto(_activity, _document.getFormat(), _hlEditor.getText(), _document.getFile());
AttachLinkOrFileDialog.insertCameraPhoto(_activity, _document.getFormat(), _hlEditor.getText(), _document.file);
return true;
}
case R.string.abid_common_new_line_below: {
Expand Down
Loading

0 comments on commit 4268201

Please sign in to comment.