Skip to content

WIP: Improving view mode and rendering #2566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class DocumentEditAndViewFragment extends MarkorBaseFragment implements F
public static final String SAVESTATE_DOCUMENT = "DOCUMENT";
public static final String START_PREVIEW = "START_PREVIEW";

public static float VIEW_FONT_SCALE = 100f / 15.7f;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Do you see that scale still fitting quite good?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. But I do all my testing just my own primary device - a pixel 7 pro


public static DocumentEditAndViewFragment newInstance(final @NonNull Document document, final Integer lineNumber, final Boolean preview) {
DocumentEditAndViewFragment f = new DocumentEditAndViewFragment();
Bundle args = new Bundle();
Expand Down Expand Up @@ -169,7 +171,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
WebSettings webSettings = _webView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setTextZoom((int) (_appSettings.getViewFontSize() / 15.7f * 100f));
webSettings.setTextZoom((int) (_appSettings.getDocumentViewFontSize(_document.path) * VIEW_FONT_SCALE));
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setDatabaseEnabled(true);
webSettings.setGeolocationEnabled(false);
Expand Down Expand Up @@ -641,9 +643,15 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
return true;
}
case R.id.action_set_font_size: {
MarkorDialogFactory.showFontSizeDialog(activity, _appSettings.getDocumentFontSize(_document.path), (newSize) -> {
_hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) newSize);
_appSettings.setDocumentFontSize(_document.path, newSize);
final int current = _isPreviewVisible ? _appSettings.getDocumentViewFontSize(_document.path) : _appSettings.getDocumentFontSize(_document.path);
MarkorDialogFactory.showFontSizeDialog(activity, current, (newSize) -> {
if (_isPreviewVisible) {
_webView.getSettings().setTextZoom((int) (newSize * VIEW_FONT_SCALE));
_appSettings.setDocumentViewFontSize(_document.path, newSize);
} else {
_hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) newSize);
_appSettings.setDocumentFontSize(_document.path, newSize);
}
});
return true;
}
Expand All @@ -652,18 +660,6 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
_hlEditor.postDelayed(() -> MainActivity.launch(activity, _document.file, false), 250);
return true;
}
case R.id.action_toggle_case:
TextViewUtils.toggleSelectionCase(_hlEditor.getText());
return true;
case R.id.action_switch_case:
TextViewUtils.switchSelectionCase(_hlEditor.getText());
return true;
case R.id.action_capitalize_words:
TextViewUtils.capitalizeSelectionWords(_hlEditor.getText());
return true;
case R.id.action_capitalize_sentences:
TextViewUtils.capitalizeSelectionSentences(_hlEditor.getText());
return true;
default: {
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.text.Editable;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.HapticFeedbackConstants;
Expand Down Expand Up @@ -169,6 +170,7 @@ private List<ActionItem> getActionList() {
new ActionItem(R.string.abid_common_special_key, R.drawable.ic_keyboard_black_24dp, R.string.special_key),
new ActionItem(R.string.abid_common_time, R.drawable.ic_access_time_black_24dp, R.string.date_and_time),
new ActionItem(R.string.abid_common_open_link_browser, R.drawable.ic_open_in_browser_black_24dp, R.string.open_link),
new ActionItem(R.string.abid_common_change_case, R.drawable.ic_format_text_case_black_24dp, R.string.switch_case),

new ActionItem(R.string.abid_common_web_jump_to_very_top_or_bottom, R.drawable.ic_vertical_align_center_black_24dp, R.string.jump_to_bottom).setDisplayMode(ActionItem.DisplayMode.VIEW),
new ActionItem(R.string.abid_common_view_file_in_other_app, R.drawable.ic_baseline_open_in_new_24, R.string.open_with).setDisplayMode(ActionItem.DisplayMode.VIEW),
Expand Down Expand Up @@ -765,6 +767,10 @@ protected final boolean runCommonAction(final @StringRes int action) {
_cu.nextScreenRotationSetting(_activity);
return true;
}
case R.string.abid_common_change_case: {
MarkorDialogFactory.showCaseDialog(_activity, _hlEditor.getText());
return true;
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private boolean followLinkUnderCursor() {
return true;
} else {
final File f = GsFileUtils.makeAbsolute(link.link, _document.file.getParentFile());
if (GsFileUtils.canCreate(f)) {
if (GsFileUtils.isDirectory(f) || f.isFile() || GsFileUtils.canCreate(f)) {
DocumentActivity.launch(getActivity(), f, null, null);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ private static void fetchAndInsertItem(
case AUDIO_BROWSE: {
if (activity instanceof AppCompatActivity && nameEdit != null && pathEdit != null) {
final GsFileBrowserOptions.SelectionListener fsListener = new GsFileBrowserOptions.SelectionListenerAdapter() {
GsFileBrowserOptions.Options _dopt = null;

@Override
public void onFsViewerSelected(final String request, final File file, final Integer lineNumber) {
setFields.callback(file);
Expand All @@ -462,6 +464,20 @@ public void onFsViewerSelected(final String request, final File file, final Inte
public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
dopt.startFolder = currentFile.getParentFile();
dopt.rootFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_ROOT;

if (action == InsertType.LINK_BROWSE) {
dopt.neutralButtonText = R.string.folder;
}

_dopt = dopt;
}

@Override
public void onFsViewerNeutralButtonPressed(File currentFolder) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select folder

setFields.callback(currentFolder);
if (_dopt != null) {
_dopt.dialogInterface.dismiss();;
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.gsantner.markor.format.todotxt.TodoTxtBasicSyntaxHighlighter;
import net.gsantner.markor.format.todotxt.TodoTxtFilter;
import net.gsantner.markor.format.todotxt.TodoTxtTask;
import net.gsantner.markor.frontend.filebrowser.MarkorFileBrowserFactory;
import net.gsantner.markor.frontend.filesearch.FileSearchDialog;
import net.gsantner.markor.frontend.filesearch.FileSearchEngine;
import net.gsantner.markor.frontend.filesearch.FileSearchResultSelectorDialog;
Expand Down Expand Up @@ -919,6 +920,44 @@ public static void showPriorityDialog(Activity activity, char selectedPriority,
GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}

public static void showCaseDialog(final Activity activity, final Editable edit) {
if (activity == null || edit == null) {
return;
}

final DialogOptions dopt = baseConf(activity);

dopt.titleText = R.string.text_case;
dopt.isSearchEnabled = false;

final List<String> options = new ArrayList<>();
options.add(activity.getString(R.string.toggle_case));
options.add(activity.getString(R.string.switch_case));
options.add(activity.getString(R.string.capitalize_words));
options.add(activity.getString(R.string.capitalize_sentences));
dopt.data = options;

dopt.positionCallback = (result) -> {
final int index = result.get(0);
switch (index) {
case 0:
TextViewUtils.toggleSelectionCase(edit);
break;
case 1:
TextViewUtils.switchSelectionCase(edit);
break;
case 2:
TextViewUtils.capitalizeSelectionWords(edit);
break;
case 3:
TextViewUtils.capitalizeSelectionSentences(edit);
break;
}
};

GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}

@SuppressLint("StringFormatMatches")
public static void showCopyMoveConflictDialog(final Activity activity, final String fileName, final String destName, final boolean multiple, final GsCallback.a1<Integer> callback) {
final DialogOptions dopt = baseConf(activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#########################################################*/
package net.gsantner.markor.frontend.filebrowser;

import android.app.Activity;
import android.content.Context;
import android.os.Environment;

import androidx.fragment.app.FragmentManager;

import net.gsantner.markor.ApplicationObject;
import net.gsantner.markor.R;
import net.gsantner.markor.frontend.filesearch.FileSearchEngine;
import net.gsantner.markor.model.AppSettings;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserDialog;
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/net/gsantner/markor/model/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.graphics.Color;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Pair;

import androidx.annotation.ColorRes;
Expand Down Expand Up @@ -136,11 +137,26 @@ public int getFontSize() {
return getInt(R.string.pref_key__editor_font_size, 15);
}

public int getViewFontSize() {
private int getDefaultViewFontSize() {
int size = getInt(R.string.pref_key__view_font_size, -1);
return size < 2 ? getFontSize() : size;
}

public void setDocumentViewFontSize(final String path, int size) {
if (fexists(path)) {
setInt(PREF_PREFIX_VIEW_FONT_SIZE + path, size);
}
}

public int getDocumentViewFontSize(final String path) {
final int _default = getDefaultViewFontSize();
if (!fexists(path)) {
return _default;
} else {
return getInt(PREF_PREFIX_VIEW_FONT_SIZE + path, _default);
}
}

public boolean isHighlightingEnabled() {
return getBool(R.string.pref_key__is_highlighting_activated, true);
}
Expand Down Expand Up @@ -406,6 +422,7 @@ public void toggleFavouriteFile(File file) {
private static final String PREF_PREFIX_VIEW_SCROLL_Y = "PREF_PREFIX_VIEW_SCROLL_Y";
private static final String PREF_PREFIX_TODO_DONE_NAME = "PREF_PREFIX_TODO_DONE_NAME";
private static final String PREF_PREFIX_LINE_NUM_STATE = "PREF_PREFIX_LINE_NUM_STATE";
private static final String PREF_PREFIX_VIEW_FONT_SIZE = "PREF_PREFIX_VIEW_FONT_SIZE";

public void setLastTodoDoneName(final String path, final String name) {
if (fexists(path)) {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/net/gsantner/opoc/format/GsTextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,31 @@ public static List<String> jsonStringToList(final String jsonString) {
}
return list;
}

public static boolean endsWith(final CharSequence text, final CharSequence suffix) {
if (text == null || suffix == null) {
return false;
}

if (text.length() < suffix.length()) {
return false;
}

if (suffix.length() == 0) {
return true;
}

if (text == suffix) {
return true;
}

final int offset = text.length() - suffix.length();
for (int i = 0; i < suffix.length(); i++) {
if (text.charAt(offset + i) != suffix.charAt(i)) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public void onViewCreated(final View root, final @Nullable Bundle savedInstanceS
// Setup callbacks
_dopt.setSubtitle = _toolBar::setSubtitle;
_dopt.setTitle = _toolBar::setTitle;
_dopt.dialogInterface = getDialog();

_recyclerList.post(() -> onFsViewerDoUiUpdate(_filesystemViewerAdapter));
}
Expand Down Expand Up @@ -321,6 +322,9 @@ public void onFsViewerItemLongPressed(File file, boolean doSelectMultiple) {
if (_callback != null) {
_callback.onFsViewerItemLongPressed(file, doSelectMultiple);
}
if (_dopt.dismissAfterCallback) {
dismiss();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.gsantner.opoc.frontend.filebrowser;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Environment;

import androidx.annotation.ColorRes;
Expand Down Expand Up @@ -140,6 +141,8 @@ public void addVirtualFile(final String name, final File target, final int icon)
storageMaps.put(file, target);
iconMaps.put(file, icon);
}

public DialogInterface dialogInterface = null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@

import com.google.android.material.snackbar.Snackbar;

import net.gsantner.markor.model.Document;
import net.gsantner.opoc.format.GsSimpleMarkdownParser;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.wrapper.GsCallback;
Expand Down
Loading