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

[pull] master from gsantner:master #213

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
android:name=".activity.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTop"
android:launchMode="singleInstance"
android:taskAffinity=".activity.MainActivity"
android:windowSoftInputMode="stateUnchanged|adjustResize">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.TextView;

Expand Down Expand Up @@ -55,9 +56,9 @@ public static void launch(Activity activity, File path, Boolean doPreview, Inten
intent = new Intent(activity, DocumentActivity.class);
}
if (path != null) {
intent.putExtra(Document.EXTRA_PATH, path);
intent.putExtra(Document.EXTRA_FILE, path);
} else {
path = intent.hasExtra(Document.EXTRA_PATH) ? ((File) intent.getSerializableExtra(Document.EXTRA_PATH)) : null;
path = intent.hasExtra(Document.EXTRA_FILE) ? ((File) intent.getSerializableExtra(Document.EXTRA_FILE)) : null;
}
if (lineNumber != null && lineNumber >= 0) {
intent.putExtra(Document.EXTRA_FILE_LINE_NUMBER, lineNumber);
Expand All @@ -71,7 +72,7 @@ public static void launch(Activity activity, File path, Boolean doPreview, Inten
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
if (path != null && path.isDirectory()) {
intent = new Intent(activity, MainActivity.class).putExtra(Document.EXTRA_PATH, path);
intent = new Intent(activity, MainActivity.class).putExtra(Document.EXTRA_FILE, path);
}
if (path != null && path.isFile() && as.isPreferViewMode()) {
as.setDocumentPreviewState(path.getAbsolutePath(), true);
Expand All @@ -87,7 +88,7 @@ public static void handleFileClick(Activity activity, File file, Integer lineNum

if (file.isDirectory()) {
if (file.canRead()) {
launch(activity, file, null, null, lineNumber);
launch(activity, file, null, null, null);
}
} else if (FormatRegistry.isFileSupported(file) && GsFileUtils.canCreate(file)) {
launch(activity, file, null, null, lineNumber);
Expand All @@ -113,12 +114,12 @@ public static Object[] checkIfLikelyTextfileAndGetExt(File file) {
}

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

GsCallback.a1<Boolean> openFile = (openInThisApp) -> {
final GsCallback.a1<Boolean> openFile = (openInThisApp) -> {
if (openInThisApp) {
DocumentActivity.launch(activity, file, null, null, null);
} else {
Expand Down Expand Up @@ -178,7 +179,7 @@ private void handleLaunchingIntent(final Intent intent) {

// Pull the file from the intent
// -----------------------------------------------------------------------
File file = (File) intent.getSerializableExtra(Document.EXTRA_PATH);
File file = (File) intent.getSerializableExtra(Document.EXTRA_FILE);

final boolean intentIsView = Intent.ACTION_VIEW.equals(intentAction);
final boolean intentIsSend = Intent.ACTION_SEND.equals(intentAction);
Expand Down Expand Up @@ -288,7 +289,7 @@ public void setDocumentTitle(final String title) {
}

public void showTextEditor(final Document document, final Integer lineNumber, final Boolean startPreview) {
GsFragmentBase currentFragment = getCurrentVisibleFragment();
final GsFragmentBase currentFragment = getCurrentVisibleFragment();

final boolean sameDocumentRequested = (
currentFragment instanceof DocumentEditAndViewFragment &&
Expand Down Expand Up @@ -339,10 +340,13 @@ public void onBackPressed() {
}
}

public GsFragmentBase showFragment(GsFragmentBase fragment) {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onReceiveKeyPress(getCurrentVisibleFragment(), keyCode, event) ? true : super.onKeyDown(keyCode, event);
}

public GsFragmentBase showFragment(GsFragmentBase fragment) {
if (fragment != getCurrentVisibleFragment()) {

_fragManager.beginTransaction()
.replace(R.id.document__placeholder_fragment, fragment, fragment.getFragmentTag())
.commit();
Expand All @@ -353,9 +357,7 @@ public GsFragmentBase showFragment(GsFragmentBase fragment) {
}

public synchronized GsFragmentBase getExistingFragment(final String fragmentTag) {
FragmentManager fmgr = getSupportFragmentManager();
GsFragmentBase fragment = (GsFragmentBase) fmgr.findFragmentByTag(fragmentTag);
return fragment;
return (GsFragmentBase) getSupportFragmentManager().findFragmentByTag(fragmentTag);
}

private GsFragmentBase getCurrentVisibleFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
Expand All @@ -21,6 +22,7 @@
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -87,20 +89,21 @@ public static DocumentEditAndViewFragment newInstance(final @NonNull Document do
}

private HighlightingEditor _hlEditor;
private ViewGroup _textActionsBar;
private WebView _webView;
private DraggableScrollbarScrollView _primaryScrollView;
private MarkorWebViewClient _webViewClient;
private ViewGroup _textActionsBar;

private DraggableScrollbarScrollView _primaryScrollView;
private HorizontalScrollView _hsView;
private SearchView _menuSearchViewForViewMode;
private Document _document;
private FormatRegistry _format;
private MarkorContextUtils _cu;
private TextViewUndoRedo _editTextUndoRedoHelper;
private MenuItem _saveMenuItem, _undoMenuItem, _redoMenuItem;
private boolean _isPreviewVisible;
private MarkorWebViewClient _webViewClient;
private boolean _nextConvertToPrintMode = false;
private MenuItem _saveMenuItem, _undoMenuItem, _redoMenuItem;


public DocumentEditAndViewFragment() {
super();
Expand Down Expand Up @@ -357,6 +360,33 @@ public boolean onQueryTextChange(String text) {
updateUndoRedoIconStates();
}

@Override
public boolean onReceiveKeyPress(int keyCode, KeyEvent event) {
if (event.isCtrlPressed()) {
if (event.isShiftPressed() && keyCode == KeyEvent.KEYCODE_Z) {
if (_editTextUndoRedoHelper != null && _editTextUndoRedoHelper.getCanRedo()) {
_hlEditor.withAutoFormatDisabled(_editTextUndoRedoHelper::redo);
updateUndoRedoIconStates();
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_S) {
saveDocument(true);
return true;
} else if (keyCode == KeyEvent.KEYCODE_Z) {
if (_editTextUndoRedoHelper != null && _editTextUndoRedoHelper.getCanUndo()) {
_hlEditor.withAutoFormatDisabled(_editTextUndoRedoHelper::undo);
updateUndoRedoIconStates();
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_SLASH) {
setViewModeVisibility(!_isPreviewVisible);
return true;
}
}

return false;
}

private void updateUndoRedoIconStates() {
final boolean canUndo = _editTextUndoRedoHelper != null && _editTextUndoRedoHelper.getCanUndo();
if (_undoMenuItem != null && _undoMenuItem.isEnabled() != canUndo) {
Expand Down Expand Up @@ -462,15 +492,19 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
setViewModeVisibility(!_isPreviewVisible);
return true;
}
case R.id.action_share_path: {
_cu.shareText(getActivity(), _document.getFile().getAbsolutePath(), GsContextUtils.MIME_TEXT_PLAIN);
return true;
}
case R.id.action_share_text: {
if (saveDocument(false)) {
_cu.shareText(getActivity(), getTextString(), "text/plain");
_cu.shareText(getActivity(), getTextString(), GsContextUtils.MIME_TEXT_PLAIN);
}
return true;
}
case R.id.action_share_file: {
if (saveDocument(false)) {
_cu.shareStream(getActivity(), _document.getFile(), "text/plain");
_cu.shareStream(getActivity(), _document.getFile(), GsContextUtils.MIME_TEXT_PLAIN);
}
return true;
}
Expand Down Expand Up @@ -597,6 +631,12 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
_hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) newSize);
_appSettings.setDocumentFontSize(_document.getPath(), newSize);
});
return true;
}
case R.id.action_show_file_browser: {
final Intent intent = new Intent(activity, MainActivity.class).putExtra(Document.EXTRA_FILE, _document.getFile());
GsContextUtils.instance.animateToActivity(activity, intent, false, null);
return true;
}
default: {
return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -819,6 +859,13 @@ public void onAnimationEnd(Animator animation) {
return true;
}

@Override
protected void onToolbarClicked(View v) {
if (!_isPreviewVisible && _format != null) {
_format.getActions().runTitleClick();
}
}

@Override
protected boolean onToolbarLongClicked(View v) {
if (isVisible() && isResumed()) {
Expand All @@ -828,21 +875,6 @@ protected boolean onToolbarLongClicked(View v) {
return false;
}

public Document getDocument() {
return _document;
}

public WebView getWebview() {
return _webView;
}

@Override
protected void onToolbarClicked(View v) {
if (!_isPreviewVisible && _format != null) {
_format.getActions().runTitleClick();
}
}

@Override
public void onDestroy() {
try {
Expand All @@ -853,6 +885,14 @@ public void onDestroy() {
super.onDestroy();
}

public Document getDocument() {
return _document;
}

public WebView getWebview() {
return _webView;
}

public String getTextString() {
final CharSequence text = _hlEditor != null ? _hlEditor.getText() : null;
return text != null ? text.toString() : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static DocumentShareIntoFragment newInstance(Intent intent) {

final String sharedText = formatLink(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT));

final Object intentFile = intent.getSerializableExtra(Document.EXTRA_PATH);
final Object intentFile = intent.getSerializableExtra(Document.EXTRA_FILE);
if (intentFile instanceof File && ((File) intentFile).isDirectory()) {
f.workingDir = (File) intentFile;
}
Expand Down
Loading
Loading