Skip to content
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

Jump to correct heading via id, other tweaks, bugfixes #2307

Merged
merged 39 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
db2581e
Jump to correct heading via id
harshad1 May 25, 2024
0e1c90e
No need to track lines
harshad1 May 25, 2024
dc23d15
Clanups
harshad1 May 26, 2024
bc2d84c
As link checkbox to top bar
harshad1 May 26, 2024
ed067ff
Simplify heading, checkbox to title, task filter literal
harshad1 May 26, 2024
7f35212
Cleanups
harshad1 May 26, 2024
58df0fa
Unified and cleaned up link formatting
harshad1 May 30, 2024
4900732
new file dialog fixes, no folder in select qn / todo
harshad1 Jun 1, 2024
5c7b194
launch in new activity
harshad1 Jun 3, 2024
0188154
Improvement to launching activities
harshad1 Jun 3, 2024
e947739
Added comment on preview states
harshad1 Jun 3, 2024
ddfdbb2
Fixed + improved isFileOutOfThisFormat
harshad1 Jun 4, 2024
f0506b4
Switching from blink to ripple
harshad1 Jun 5, 2024
ec4de19
Logic to save and restore file browser position
harshad1 Jun 7, 2024
fb65503
Cleanups to code
harshad1 Jun 8, 2024
984f992
cleanups
harshad1 Jun 9, 2024
7862ce1
Small features and fixes
harshad1 Jun 14, 2024
b95d2c2
Can scroll action bar on repeat items
harshad1 Jun 16, 2024
9c6ed68
Handle unknown formats better
harshad1 Jun 19, 2024
b4857cd
Handle virtual folders better
harshad1 Jun 19, 2024
7cf1c04
Rounded dialogs, fixes for launching files
harshad1 Jun 24, 2024
f27d0ea
Changes per android studio
harshad1 Jun 25, 2024
b22a046
Improved show and flash
harshad1 Jun 30, 2024
ac9eaae
Fixes for remember ext
harshad1 Jul 2, 2024
16dc5f0
imports
harshad1 Jul 2, 2024
3650cf8
Improved keyboard showing
harshad1 Jul 2, 2024
66d6bef
Improved how we test for compatible files
harshad1 Jul 3, 2024
a9f39cc
Cleaner way to do dialog radius
harshad1 Jul 3, 2024
d0c494a
xml
harshad1 Jul 3, 2024
3c04b36
Better showing of folders
harshad1 Jul 4, 2024
64aa257
Rounded corners for all dialogs, cleaner structure
harshad1 Jul 5, 2024
3aadca4
Better text file detection
harshad1 Jul 6, 2024
d1f9313
Better text file detection
harshad1 Jul 6, 2024
cebf97f
Cleaner style system
harshad1 Jul 7, 2024
3a7f816
Matching colour
harshad1 Jul 13, 2024
bce6cb2
Match system bars with UI colors
harshad1 Jul 13, 2024
167d5e9
Rounded widget corners, hide text actions bar
harshad1 Jul 16, 2024
686ab20
Reformat code
gsantner Jul 16, 2024
066330d
make plaintext last check in hierachy again
gsantner Jul 16, 2024
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
146 changes: 64 additions & 82 deletions app/src/main/java/net/gsantner/markor/activity/DocumentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import android.text.Html;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.TextView;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentManager;
Expand All @@ -32,9 +32,9 @@
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.frontend.base.GsFragmentBase;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserListAdapter;
import net.gsantner.opoc.util.GsContextUtils;
import net.gsantner.opoc.util.GsFileUtils;
import net.gsantner.opoc.wrapper.GsCallback;

import java.io.File;

Expand All @@ -44,101 +44,82 @@ public class DocumentActivity extends MarkorBaseActivity {
public static final String EXTRA_DO_PREVIEW = "EXTRA_DO_PREVIEW";

private Toolbar _toolbar;
private TextView _toolbarTitleText;
gsantner marked this conversation as resolved.
Show resolved Hide resolved

private FragmentManager _fragManager;

private static boolean nextLaunchTransparentBg = false;

public static void launch(Activity activity, File path, Boolean doPreview, Intent intent, final Integer lineNumber) {
final AppSettings as = ApplicationObject.settings();
if (intent == null) {
intent = new Intent(activity, DocumentActivity.class);
public static void launch(
final Activity activity,
final File file,
final Boolean doPreview,
final Integer lineNumber
) {
launch(activity, file, doPreview, lineNumber, false);
}

private static void launch(
final Activity activity,
final File file,
final Boolean doPreview,
final Integer lineNumber,
final boolean forceOpenInThisApp
) {
if (activity == null || file == null) {
return;
}

if (GsFileUtils.getFilenameExtension(file).equals(".apk")) {
GsContextUtils.instance.requestApkInstallation(activity, file);
return;
}

if (!forceOpenInThisApp && file.isFile() && !FormatRegistry.isFileSupported(file)) {
askUserIfWantsToOpenFileInThisApp(activity, file);
return;
}
if (path != null) {
intent.putExtra(Document.EXTRA_FILE, path);

final AppSettings as = ApplicationObject.settings();

final Intent intent;
if (GsFileBrowserListAdapter.isVirtualFolder(file) || file.isDirectory()) {
intent = new Intent(activity, MainActivity.class);
} else {
path = intent.hasExtra(Document.EXTRA_FILE) ? ((File) intent.getSerializableExtra(Document.EXTRA_FILE)) : null;
intent = new Intent(activity, DocumentActivity.class);
}

intent.putExtra(Document.EXTRA_FILE, file);

if (lineNumber != null && lineNumber >= 0) {
intent.putExtra(Document.EXTRA_FILE_LINE_NUMBER, lineNumber);
}

if (doPreview != null) {
intent.putExtra(DocumentActivity.EXTRA_DO_PREVIEW, doPreview);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ApplicationObject.settings().isMultiWindowEnabled()) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && as.isMultiWindowEnabled()) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
if (path != null && path.isDirectory()) {
intent = new Intent(activity, MainActivity.class).putExtra(Document.EXTRA_FILE, path);
}
if (path != null && path.isFile() && as.isPreferViewMode()) {
as.setDocumentPreviewState(path.getAbsolutePath(), true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
gsantner marked this conversation as resolved.
Show resolved Hide resolved

nextLaunchTransparentBg = (activity instanceof MainActivity);
GsContextUtils.instance.animateToActivity(activity, intent, false, null);
}

public static void handleFileClick(Activity activity, File file, Integer lineNumber) {
gsantner marked this conversation as resolved.
Show resolved Hide resolved
if (activity == null || file == null) {
return;
}

if (file.isDirectory()) {
if (file.canRead()) {
launch(activity, file, null, null, null);
}
} else if (FormatRegistry.isFileSupported(file) && GsFileUtils.canCreate(file)) {
launch(activity, file, null, null, lineNumber);
} else if (GsFileUtils.getFilenameExtension(file).equals(".apk")) {
GsContextUtils.instance.requestApkInstallation(activity, file);
} else {
askUserIfWantsToOpenFileInThisApp(activity, file);
}
}

public static Object[] checkIfLikelyTextfileAndGetExt(File file) {
String fn = file.getName().toLowerCase();
if (!fn.contains(".")) {
return new Object[]{true, ""};
}
String ext = fn.substring(fn.lastIndexOf("."));
for (String ce : new String[]{".dummy"}) {
if (ext.equals(ce)) {
return new Object[]{true, ext};
}
}
return new Object[]{false, ext};
}

public static void askUserIfWantsToOpenFileInThisApp(final Activity activity, final File file) {
final Object[] fret = checkIfLikelyTextfileAndGetExt(file);
final boolean isLikelyTextfile = (boolean) fret[0];
final String ext = (String) fret[1];
final boolean isYes = ApplicationObject.settings().isExtOpenWithThisApp(ext);

final GsCallback.a1<Boolean> openFile = (openInThisApp) -> {
if (openInThisApp) {
DocumentActivity.launch(activity, file, null, null, null);
} else {
new MarkorContextUtils(activity).viewFileInOtherApp(activity, file, null);
}
};

if (isYes) {
openFile.callback(true);
} else if (isLikelyTextfile) {
AlertDialog.Builder dialog = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog);
dialog.setTitle(R.string.open_with)
if (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)
.setIcon(R.drawable.ic_open_in_browser_black_24dp)
.setPositiveButton(R.string.app_name, (dialog1, which) -> openFile.callback(true))
.setNegativeButton(R.string.other, (dialog1, which) -> openFile.callback(false));
dialog.create().show();
.setPositiveButton(R.string.app_name, (dialog1, which) -> DocumentActivity.launch(activity, file, null, null, true))
.setNegativeButton(R.string.other, (dialog1, which) -> new MarkorContextUtils(activity).viewFileInOtherApp(activity, file, null))
.create()
.show();
} else {
openFile.callback(false);
new MarkorContextUtils(activity).viewFileInOtherApp(activity, file, null);
}
}

Expand All @@ -153,7 +134,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.document__activity);
_toolbar = findViewById(R.id.toolbar);
_toolbarTitleText = findViewById(R.id.note__activity__text_note_title);
gsantner marked this conversation as resolved.
Show resolved Hide resolved

if (_appSettings.isHideSystemStatusbar()) {
AndroidBug5497Workaround.assistActivity(this);
Expand Down Expand Up @@ -203,12 +183,8 @@ private void handleLaunchingIntent(final Intent intent) {

// Decide what to do with the file
// -----------------------------------------------------------------------
if (file == null) {
if (file == null || !_cu.canWriteFile(this, file, false, true)) {
showNotSupportedMessage();
} else if (file.isDirectory() || !FormatRegistry.isFileSupported(file)) {
// File readable but is not a text-file (and not a supported binary-embed type)
handleFileClick(this, file, null);
finish();
} else {
// Open in editor/viewer
final Document doc = new Document(file);
Expand Down Expand Up @@ -237,7 +213,7 @@ private void handleLaunchingIntent(final Intent intent) {

private void showNotSupportedMessage() {
final String notSupportedMessage = (getString(R.string.filemanager_doesnot_supply_required_data__appspecific) + "\n\n" + getString(R.string.sync_to_local_folder_notice)).replace("\n", "<br/>");
new AlertDialog.Builder(this)
new AlertDialog.Builder(this, R.style.Theme_AppCompat_DayNight_Dialog_Rounded)
.setMessage(Html.fromHtml(notSupportedMessage))
.setNegativeButton(R.string.more_info, (di, i) -> _cu.openWebpageInExternalBrowser(this, getString(R.string.sync_client_support_issue_url)))
.setPositiveButton(android.R.string.ok, null)
Expand Down Expand Up @@ -281,8 +257,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
_cu.extractResultFromActivityResult(this, requestCode, resultCode, data);
}

public void setTitle(final CharSequence title) {
final ActionBar bar = getSupportActionBar();
if (bar != null) {
bar.setTitle(title);
gsantner marked this conversation as resolved.
Show resolved Hide resolved
}
}

public void setDocumentTitle(final String title) {
_toolbarTitleText.setText(title);
setTitle(title);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && _appSettings.isMultiWindowEnabled()) {
setTaskDescription(new ActivityManager.TaskDescription(title));
}
Expand All @@ -301,8 +284,7 @@ public void showTextEditor(final Document document, final Integer lineNumber, fi
}

public void showShareInto(Intent intent) {
// Disable edittext when going to shareinto
_toolbarTitleText.setText(R.string.share_into);
setTitle(getString(R.string.share_into));
showFragment(DocumentShareIntoFragment.newInstance(intent));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,21 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {

// We set the keyboard to be hidden if it was hidden when we lost focus
// This works well to preserve keyboard state.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && activity != null) {
final Window window = activity.getWindow();
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 int shown = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | adjustResize;

_hlEditor.getViewTreeObserver().addOnWindowFocusChangeListener(hasFocus -> {
if (hasFocus) {
// Restore old state
_hlEditor.postDelayed(() -> window.setSoftInputMode(unchanged), 500);
} else {
final Boolean isOpen = TextViewUtils.isImeOpen(_hlEditor);
if (isOpen != null && !isOpen) {
window.setSoftInputMode(hidden);
if (isOpen != null) {
window.setSoftInputMode(isOpen ? shown : hidden);
}
}
});
Expand Down Expand Up @@ -557,8 +558,8 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
_document.setFormat(itemId);
applyTextFormat(itemId);
_appSettings.setDocumentFormat(_document.getPath(), _document.getFormat());
return true;
}
return true;
}
case R.id.action_search: {
setViewModeVisibility(false);
Expand Down Expand Up @@ -668,6 +669,34 @@ public void applyTextFormat(final int textFormatId) {
.setUiReferences(activity, _hlEditor, _webView)
.recreateActionButtons(_textActionsBar, _isPreviewVisible ? ActionButtonBase.ActionItem.DisplayMode.VIEW : ActionButtonBase.ActionItem.DisplayMode.EDIT);
updateMenuToggleStates(_format.getFormatId());
showHideActionBar();
}

private void showHideActionBar() {
final Activity activity = getActivity();
if (activity != null) {
final View bar = activity.findViewById(R.id.document__fragment__edit__text_actions_bar);
final View parent = activity.findViewById(R.id.document__fragment__edit__text_actions_bar__scrolling_parent);
final View editScroll = activity.findViewById(R.id.document__fragment__edit__content_editor__scrolling_parent);
final View viewScroll = activity.findViewById(R.id.document__fragment_view_webview);

if (bar != null && parent != null && editScroll != null && viewScroll != null) {
final boolean hide = _textActionsBar.getChildCount() == 0;
parent.setVisibility(hide ? View.GONE : View.VISIBLE);
final int marginBottom = hide ? 0 : (int) getResources().getDimension(R.dimen.textactions_bar_height);
setMarginBottom(editScroll, marginBottom);
setMarginBottom(viewScroll, marginBottom);

}
}
}

private void setMarginBottom(final View view, final int marginBottom) {
final ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
if (params != null) {
params.setMargins(params.leftMargin, params.topMargin, params.rightMargin, marginBottom);
view.setLayoutParams(params);
}
}

private void updateMenuToggleStates(final int selectedFormatActionId) {
Expand Down Expand Up @@ -762,7 +791,6 @@ public boolean isStateBad() {
return (_document == null ||
_hlEditor == null ||
_appSettings == null ||
!_document.testCreateParent() ||
!_cu.canWriteFile(getContext(), _document.getFile(), false, true));
}

Expand Down Expand Up @@ -813,6 +841,7 @@ public void setViewModeVisibility(boolean show, final boolean animate) {
show |= _document.isBinaryFileNoTextLoading();

_format.getActions().recreateActionButtons(_textActionsBar, show ? ActionButtonBase.ActionItem.DisplayMode.VIEW : ActionButtonBase.ActionItem.DisplayMode.EDIT);
showHideActionBar();
if (show) {
updateViewModeText();
_cu.showSoftKeyboard(activity, false, _hlEditor);
Expand Down
Loading
Loading