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 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
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
4 changes: 2 additions & 2 deletions app/src/main/java/net/gsantner/markor/ApplicationObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public static ApplicationObject get() {
return _app;
}

public static AppSettings settings() {
public static AppSettings backupSettings() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Making it clear that these settings are to be used as a last resort

return _appSettings;
}

@Override
public void onCreate() {
super.onCreate();
_app = this;
_appSettings = new AppSettings().init(getApplicationContext());
_appSettings = AppSettings.get(getApplicationContext());

// Per https://stackoverflow.com/a/54191884/4717438
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class DocumentActivity extends MarkorBaseActivity {

private Toolbar _toolbar;
private FragmentManager _fragManager;
private Document _document = null;

public static void launch(final Activity activity, final Intent intent) {
final File file = MarkorContextUtils.getIntentFile(intent);
Expand All @@ -70,8 +69,6 @@ private static void launch(
final Integer lineNumber,
final boolean forceOpenInThisApp
) {

Log.i("Document", "Hitting launch");
if (activity == null || file == null) {
return;
}
Expand All @@ -86,7 +83,7 @@ private static void launch(
return;
}

final AppSettings as = ApplicationObject.settings();
final AppSettings as = AppSettings.get(activity);

final Intent intent;
if (GsFileUtils.isDirectory(file)) {
Expand All @@ -104,7 +101,6 @@ private static void launch(
} else if (lollipop && !fromDocumentActivity) {
// So we can potentially not open duplicate documents
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Log.i("Document", "Single top");
}

if (lineNumber != null) {
Expand All @@ -122,7 +118,7 @@ private static void launch(
}

public static void askUserIfWantsToOpenFileInThisApp(final Activity activity, final File file) {
if (GsFileUtils.isContentsPlainText(file)) {
if (!FormatRegistry.isExternalFile(file) && GsFileUtils.isContentsPlainText(file)) {
new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog_Rounded)
.setTitle(R.string.open_with)
.setMessage(R.string.selected_file_may_be_a_textfile_want_to_open_in_editor)
Expand Down Expand Up @@ -158,7 +154,6 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleLaunchingIntent(intent);
Log.i("Document", "in onNewIntent");
}

private void handleLaunchingIntent(final Intent intent) {
Expand Down Expand Up @@ -219,22 +214,18 @@ private void handleLaunchingIntent(final Intent intent) {
if (editFrag.getDocument().path.equals(doc.path)) {
if (startLine != null) {
// Same document requested, show the requested line
Log.i("Document", "select the line");
TextViewUtils.selectLines(editFrag.getEditor(), startLine);
}
} else {
// Current document is different - launch the new document
Log.i("Document", "launch");
launch(this, file, startInPreview, startLine);
}
} else {
// Current fragment is not an editor - launch the new document
Log.i("Document", "launch");
launch(this, file, startInPreview, startLine);
}
} else {
// No fragment open - open the document
Log.i("Document", "showFragment");
showFragment(DocumentEditAndViewFragment.newInstance(doc, startLine, startInPreview));
}
}
Expand Down
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 @@ -236,6 +238,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
// This works well to preserve keyboard state.
if (activity != null) {
final Window window = activity.getWindow();
// Setting via a windowmanager state is much more robust than using show/hide
final int adjustResize = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
final int unchanged = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | adjustResize;
final int hidden = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | adjustResize;
Expand Down Expand Up @@ -280,7 +283,8 @@ protected void onFragmentFirstTimeVisible() {
_hlEditor.recomputeHighlighting(); // Run before setting scroll position
TextViewUtils.setSelectionAndShow(_hlEditor, startPos);

_hlEditor.post(() -> _hlEditor.animate().alpha(1).setDuration(500).start());
// Fade in to hide initial jank
_hlEditor.post(() -> _hlEditor.animate().alpha(1).setDuration(250).start());
}

@Override
Expand Down Expand Up @@ -641,9 +645,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 +662,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 @@ -210,7 +210,7 @@ public String getFragmentTag() {

@Override
protected AppSettings getAppSettings(Context context) {
return ApplicationObject.settings();
return AppSettings.get(context);
}

@Override
Expand Down Expand Up @@ -299,7 +299,9 @@ private void attachOrCopyAndClose(final File dest, final boolean show) {
}

_appSettings.addRecentFile(dest);
if (attachment != null) {

// Only if not forced link due to attachment
if (attachment == null) {
_appSettings.setFormatShareAsLink(asLink);
}

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

import net.gsantner.markor.ApplicationObject;
import net.gsantner.markor.R;
import net.gsantner.markor.model.AppSettings;
import net.gsantner.opoc.util.GsContextUtils;

public class IntroActivity extends AppIntro {
Expand All @@ -38,7 +39,7 @@ public static boolean isFirstStart(final Context context) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GsContextUtils.instance.setAppLanguage(this, ApplicationObject.settings().getLanguage());
GsContextUtils.instance.setAppLanguage(this, AppSettings.get(this).getLanguage());

// Instead of fragments, you can also use our default slide
// Just set a title, description, background and image. AppIntro will do the rest
Expand Down
31 changes: 26 additions & 5 deletions app/src/main/java/net/gsantner/markor/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
Expand All @@ -36,6 +38,7 @@
import net.gsantner.markor.R;
import net.gsantner.markor.frontend.NewFileDialog;
import net.gsantner.markor.frontend.filebrowser.MarkorFileBrowserFactory;
import net.gsantner.markor.frontend.textview.TextViewUtils;
import net.gsantner.markor.model.Document;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.markor.widget.TodoWidgetProvider;
Expand Down Expand Up @@ -205,6 +208,7 @@ protected void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
final File file = MarkorContextUtils.getValidIntentFile(intent, null);
if (_notebook != null && file != null) {
forceHideKeyboard();
_viewPager.setCurrentItem(tabIdToPos(R.id.nav_notebook), false);
if (GsFileUtils.isDirectory(file)) {
_notebook.getAdapter().setCurrentFolder(file);
Expand Down Expand Up @@ -409,13 +413,27 @@ public void onViewPagerPageSelected(final int pos) {

if (pos == tabIdToPos(R.id.nav_notebook)) {
_fab.show();
_cu.showSoftKeyboard(this, false, _notebook.getView());
} else {
_fab.hide();
restoreDefaultToolbar();
forceHideKeyboard();
}
}

private void forceHideKeyboard() {
// Hide the soft keyboard
if (_quicknote != null && _todo != null) {
_cu.showSoftKeyboard(this, false, _quicknote.getEditor());
_cu.showSoftKeyboard(this, false, _todo.getEditor());
}

setTitle(getPosTitle(pos));
// This is needed here as DocumentEditAndViewFragment may have also set
// a soft input mode which would force the keyboard to show.
final int adjustResize = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
final int unchanged = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | adjustResize;
final int hidden = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | adjustResize;

final Window window = getWindow();
final View view = window.getDecorView();
window.setSoftInputMode(hidden);
view.postDelayed(() -> window.setSoftInputMode(unchanged), 2000);
}

private GsFileBrowserOptions.Options _filesystemDialogOptions = null;
Expand Down Expand Up @@ -497,6 +515,9 @@ protected void onPause() {
super.onPause();
WrMarkorWidgetProvider.updateLauncherWidgets();
TodoWidgetProvider.updateTodoWidgets();

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED |
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
public abstract class MarkorBaseActivity extends GsActivityBase<AppSettings, MarkorContextUtils> {

@Override
protected void onPreCreate(@Nullable Bundle savedInstanceState) {
super.onPreCreate(savedInstanceState); // _appSettings, _cu gets available
setTheme(R.style.AppTheme_Unified);
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

_appSettings.applyAppTheme();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setEnterTransition(null);
Expand All @@ -48,13 +48,13 @@ public Integer getNewActivityBackgroundColor() {
}

@Override
public AppSettings createAppSettingsInstance(Context applicationContext) {
return ApplicationObject.settings();
protected AppSettings createAppSettingsInstance() {
return new AppSettings(this);
}

@Override
public MarkorContextUtils createContextUtilsInstance(Context applicationContext) {
return new MarkorContextUtils(applicationContext);
protected MarkorContextUtils createContextUtilsInstance() {
return new MarkorContextUtils(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public abstract class MarkorBaseFragment extends GsFragmentBase<AppSettings, MarkorContextUtils> {
@Nullable
@Override
public AppSettings createAppSettingsInstance(Context applicationContext) {
return ApplicationObject.settings();
public AppSettings createAppSettingsInstance(Context context) {
return AppSettings.get(context);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getFragmentTag() {

@Override
protected AppSettings getAppSettings(Context context) {
return ApplicationObject.settings();
return AppSettings.get(context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected void onStop() {
public static abstract class MarkorSettingsFragment extends GsPreferenceFragmentBase<AppSettings> {
@Override
protected AppSettings getAppSettings(Context context) {
return ApplicationObject.settings();
return AppSettings.get(context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public abstract class ActionButtonBase {

public ActionButtonBase(@NonNull final Context context, final Document document) {
_document = document;
_appSettings = ApplicationObject.settings();
_appSettings = AppSettings.get(context);
_buttonHorizontalMargin = GsContextUtils.instance.convertDpToPx(context, _appSettings.getEditorActionButtonItemPadding());
_indent = _appSettings.getDocumentIndentSize(_document != null ? _document.path : null);
}
Expand Down Expand Up @@ -169,6 +169,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 +766,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
Loading