Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void handleLaunchingIntent(final Intent intent) {
// Start in a specific mode if required. Otherwise let the fragment decide
Boolean startInPreview = null;
if (intent.getBooleanExtra(Document.EXTRA_DO_PREVIEW, false) ||
file.getName().startsWith("index.")
file.getName().startsWith("index.")
) {
startInPreview = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;

import net.gsantner.markor.ApplicationObject;
import net.gsantner.markor.BuildConfig;
Expand Down Expand Up @@ -103,7 +105,6 @@ public static DocumentEditAndViewFragment newInstance(final @NonNull Document do
private DraggableScrollbarScrollView _verticalScrollView;
private HorizontalScrollView _horizontalScrollView;
private LineNumbersTextView _lineNumbersView;
private SearchView _menuSearchViewForViewMode;
private Document _document;
private FormatRegistry _format;
private MarkorContextUtils _cu;
Expand Down Expand Up @@ -132,7 +133,6 @@ protected int getLayoutResId() {
return R.layout.document__fragment__edit;
}

@SuppressLint({"SetJavaScriptEnabled", "WrongConstant", "AddJavascriptInterface", "JavascriptInterface"})
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Expand Down Expand Up @@ -212,7 +212,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
// Setting via a window manager 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 @@ -328,35 +328,8 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.findItem(R.id.action_share_image).setVisible(true);
menu.findItem(R.id.action_load_epub).setVisible(isExperimentalFeaturesEnabled);

// SearchView (View Mode)
_menuSearchViewForViewMode = (SearchView) menu.findItem(R.id.action_search_view).getActionView();
if (_menuSearchViewForViewMode != null) {
_menuSearchViewForViewMode.setSubmitButtonEnabled(true);
_menuSearchViewForViewMode.setQueryHint(getString(R.string.search));
_menuSearchViewForViewMode.setOnQueryTextFocusChangeListener((v, searchHasFocus) -> {
if (!searchHasFocus) {
_menuSearchViewForViewMode.setQuery("", false);
_menuSearchViewForViewMode.setIconified(true);
}
});
_menuSearchViewForViewMode.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {
if (_webView != null) {
_webView.findNext(true);
}
return true;
}

@Override
public boolean onQueryTextChange(String text) {
if (_webView != null) {
_webView.findAllAsync(text);
}
return true;
}
});
}
// Setup SearchView for view-mode
setupSearchView((SearchView) menu.findItem(R.id.action_search_view).getActionView());

// Set various initial states
updateMenuToggleStates(_document.getFormat());
Expand Down Expand Up @@ -653,6 +626,7 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
}
}
}

public void checkTextChangeState() {
final boolean isTextChanged = !_document.isContentSame(_hlEditor.getText());
Drawable d;
Expand Down Expand Up @@ -700,6 +674,134 @@ private void showHideActionBar() {
}
}

/**
* Setup SearchView from OptionsMenu for view-mode.
*
* @param searchView the SearchView form OptionsMenu
*/
private void setupSearchView(SearchView searchView) {
if (searchView == null) {
return;
}
// Only setup SearchView for view-mode, to avoid unnecessary setup for edit-mode
if (!_isPreviewVisible || _webView == null) {
return;
}

searchView.setQueryHint(getString(R.string.search));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String searchText = "";
private Runnable searchTask;

private boolean search(String text) {
if (_webView == null) {
return false;
}
if (searchTask == null) {
searchTask = TextViewUtils.makeDebounced(_webView.getHandler(), 500, () -> _webView.findAllAsync(searchText));
}

searchText = text;
searchTask.run();
return true;
}

@Override
public boolean onQueryTextSubmit(String query) {
if (_webView != null) {
_webView.findNext(true);
return true;
}
return false;
}

@Override
public boolean onQueryTextChange(String text) {
return search(text);
}
});
searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(@NonNull View v) {
}

@Override
public void onViewDetachedFromWindow(@NonNull View v) {
// Clear search when SearchView is closed abnormally, e.g. switch from QuickNote to To-Do when SearchView is opened
if (searchView.getQuery().length() > 0) {
searchView.setQuery("", false); // This will make onQueryTextChange be called back
}
if (!searchView.isIconified()) {
searchView.setIconified(true);
}
}
});

// Because SearchView doesn't provide a public API to add custom buttons
// We must get the searchPlate (the layout containing the text field and close button) from SearchView
// This approach is more robust than reflection
ViewGroup searchPlate = searchView.findViewById(androidx.appcompat.R.id.search_plate);
if (searchPlate == null) {
// Ensure that SearchView is always available even if getting searchPlate fails
searchView.setSubmitButtonEnabled(true);
return;
}

Context searchViewContext = searchView.getContext();
LinearLayout linearLayout = new LinearLayout(searchViewContext);

// Add search result TextView
TextView resultTextView = new TextView(searchViewContext);
resultTextView.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
layoutParams.setMarginEnd(14);
resultTextView.setLayoutParams(layoutParams);
linearLayout.addView(resultTextView);

// Add previous match Button
ImageButton previousButton = new ImageButton(searchViewContext);
previousButton.setImageResource(R.drawable.ic_baseline_keyboard_arrow_up_24);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
previousButton.setTooltipText(getString(R.string.previous_match));
}
linearLayout.addView(previousButton);

// Add next match Button
ImageButton nextButton = new ImageButton(searchViewContext);
nextButton.setImageResource(R.drawable.ic_baseline_keyboard_arrow_down_24);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
nextButton.setTooltipText(getString(R.string.next_match));
}
linearLayout.addView(nextButton);

// Apply to SearchView
searchPlate.addView(linearLayout, 1);

// Set listeners
previousButton.setOnClickListener(v -> {
if (_webView != null) {
_webView.findNext(false);
}
});
nextButton.setOnClickListener(v -> {
if (_webView != null) {
_webView.findNext(true);
}
});
_webView.setFindListener((activeMatchOrdinal, numberOfMatches, isDoneCounting) -> {
if (isDoneCounting) {
String searchResult = "";
if (numberOfMatches > 0) {
searchResult = (activeMatchOrdinal + 1) + "/" + numberOfMatches;
}
resultTextView.setText(searchResult);
}
});
}

private void setMarginBottom(final View view, final int marginBottom) {
final ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
if (params != null) {
Expand Down Expand Up @@ -867,6 +969,7 @@ public void setViewModeVisibility(final boolean show) {
setViewModeVisibility(show, true);
}

@SuppressLint({"SetJavaScriptEnabled"})
private void setupWebViewIfNeeded(final Activity activity) {
if (_webView == null) {
_webView = (WebView) _webViewStub.inflate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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_change_case, R.drawable.ic_format_text_case_black_24dp, R.string.text_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
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import net.gsantner.markor.frontend.textview.AutoTextFormatter;
import net.gsantner.markor.frontend.textview.TextViewUtils;
import net.gsantner.markor.model.Document;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.util.GsContextUtils;
import net.gsantner.opoc.util.GsFileUtils;
import net.gsantner.opoc.format.GsTextUtils;

import java.io.File;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ private AlertDialog.Builder setUpDialog(final File file, LayoutInflater inflater
tv(root, R.id.ui__fileinfodialog__mimetype_description).setText(GsFileUtils.getMimeType(file));
tv(root, R.id.ui__fileinfodialog__sha_256).setText(GsFileUtils.sha256(file));
tv(root, R.id.ui__fileinfodialog__location).setOnLongClickListener(v -> {
GsContextUtils.instance.setClipboard(v.getContext(), file.getAbsolutePath());
Toast.makeText(v.getContext(), R.string.clipboard, Toast.LENGTH_SHORT).show();
return true;}
GsContextUtils.instance.setClipboard(v.getContext(), file.getAbsolutePath());
Toast.makeText(v.getContext(), R.string.clipboard, Toast.LENGTH_SHORT).show();
return true;
}
);
tv(root, R.id.ui__fileinfodialog__sha_256).setOnLongClickListener(v -> {
GsContextUtils.instance.setClipboard(v.getContext(), GsFileUtils.sha256(file));
Toast.makeText(v.getContext(), R.string.clipboard, Toast.LENGTH_SHORT).show();
return true;}
GsContextUtils.instance.setClipboard(v.getContext(), GsFileUtils.sha256(file));
Toast.makeText(v.getContext(), R.string.clipboard, Toast.LENGTH_SHORT).show();
return true;
}
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean isFastScrollEnabled() {
return _fastScrollEnabled;
}

////////
/// /////
// Feature Animated Scrolling
public void scrollAnimatedToXY(final int scrollX, final int scrollY, int... arg0Delay__arg1Duration) {
final int delay = Math.max(1, arg0Delay__arg1Duration != null && arg0Delay__arg1Duration.length > 0 ? arg0Delay__arg1Duration[0] : 500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ protected boolean appendPreference(Preference pref, @Nullable PreferenceGroup ta

//###############################
//### Divider
////###############################

/// /###############################


public boolean isDividerVisible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public void clearSelection() {
}


///////////////
/// ////////////

private void askForMoveOrCopy(final boolean isMove) {
final List<File> files = new ArrayList<>(_filesystemViewerAdapter.getCurrentSelection());
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected <T extends GsContextUtils> T thisp() {
protected static String m_chooserTitle = "➥";


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//########################
//## Resources
//########################
Expand Down Expand Up @@ -289,11 +289,10 @@ public boolean areResourcesAvailable(final Context context, final ResType resTyp
return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//########################
//## App & Device information
//########################

public static String getAndroidVersion() {
return Build.VERSION.RELEASE + " (" + Build.VERSION.SDK_INT + ")";
}
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/net/gsantner/opoc/util/GsFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,16 +672,16 @@ public static String sha256(final File file) {
while ((bytesRead = fis.read(buffer)) != -1) {
digest.update(buffer, 0, bytesRead);
}

byte[] hashBytes = digest.digest();
StringBuilder hexString = new StringBuilder();

for (byte b : hashBytes) {
hexString.append(String.format("%02x", b));
}

return hexString.toString();

} catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
Expand Down Expand Up @@ -740,6 +740,7 @@ public static String getFilenameExtension(final File file) {
}

/// Get the file extension of the file, with dot
///
/// @return "" -> "", "index" -> "", "index.html" -> ".html", "my.website.html" -> ".html"
public static String getFilenameExtension(String name) {
name = name.replace(".jenc", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onPageFinished(final WebView webView, final String url) {
super.onPageFinished(webView, url);
}

////////////////////////////////////////////////////////////////////////////////////
/// /////////////////////////////////////////////////////////////////////////////////
private final AtomicBoolean m_restoreScrollYEnabled = new AtomicBoolean(false);
private int m_restoreScrollY = 0;

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/document__edit__menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
android:id="@+id/action_search_view"
android:icon="@drawable/ic_search_black_24dp"
android:title="@string/search"
app:actionViewClass="android.widget.SearchView"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always" />

<item
Expand Down
Loading