Skip to content

Commit

Permalink
Rounded dialogs, fixes for launching files
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Jun 24, 2024
1 parent b4857cd commit 7cf1c04
Show file tree
Hide file tree
Showing 26 changed files with 122 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.text.Html;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
Expand Down Expand Up @@ -50,18 +51,39 @@ public class DocumentActivity extends MarkorBaseActivity {

private static boolean nextLaunchTransparentBg = false;

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

if (path != null) {
intent.putExtra(Document.EXTRA_FILE, path);
final boolean isVirtualDir = GsFileBrowserListAdapter.isVirtualFolder(file);

if (!file.exists() && !GsFileUtils.canCreate(file) && !isVirtualDir) {
Toast.makeText(activity, R.string.error_could_not_open_file, Toast.LENGTH_SHORT).show();
return;
}

if (path != null && (path.isDirectory() || GsFileBrowserListAdapter.isVirtualFolder(path))) {
intent.setClass(activity, MainActivity.class);
if (GsFileUtils.getFilenameExtension(file).equals(".apk")) {
GsContextUtils.instance.requestApkInstallation(activity, file);
return;
}

if (file.isFile() && !FormatRegistry.isFileSupported(file)) {
askUserIfWantsToOpenFileInThisApp(activity, file);
return;
}

final AppSettings as = ApplicationObject.settings();

final Intent intent;
if (isVirtualDir || file.isDirectory()) {
intent = new Intent(activity, MainActivity.class);
} else {
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);
}
Expand All @@ -80,24 +102,6 @@ public static void launch(final Activity activity, final File path, final Boolea
GsContextUtils.instance.animateToActivity(activity, intent, false, null);
}

public static void handleFileClick(Activity activity, File file, Integer lineNumber) {
if (activity == null || file == null) {
return;
}

if (file.isDirectory()) {
if (file.canRead()) {
launch(activity, file, null, null);
}
} else if (FormatRegistry.isFileSupported(file) && GsFileUtils.canCreate(file)) {
launch(activity, file, 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(".")) {
Expand Down Expand Up @@ -129,7 +133,7 @@ public static void askUserIfWantsToOpenFileInThisApp(final Activity activity, fi
if (isYes) {
openFile.callback(true);
} else if (isLikelyTextfile) {
AlertDialog.Builder dialog = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog);
AlertDialog.Builder dialog = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
dialog.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)
Expand Down Expand Up @@ -201,12 +205,8 @@ private void handleLaunchingIntent(final Intent intent) {

// Decide what to do with the file
// -----------------------------------------------------------------------
if (file == null) {
if (file == null || file.isDirectory() || !FormatRegistry.isFileSupported(file)) {
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 @@ -235,7 +235,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
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public void onFsViewerDoUiUpdate(final GsFileBrowserListAdapter adapter) {

@Override
public void onFsViewerSelected(String request, File file, final Integer lineNumber) {
DocumentActivity.handleFileClick(MainActivity.this, file, lineNumber);
DocumentActivity.launch(MainActivity.this, file, null, lineNumber);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onActivityFirstTimeVisible() {
}

private void askForPermissions() {
final AlertDialog d = new AlertDialog.Builder(this)
final AlertDialog d = new AlertDialog.Builder(this, R.style.Theme_AppCompat_DayNight_Dialog_Rounded)
.setMessage(R.string.storage_permission_required)
.setNegativeButton(R.string.exit, (dialog, which) -> finish())
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ protected final boolean runCommonAction(final @StringRes int action) {
} else {
final File f = GsFileUtils.makeAbsolute(resource, _document.getFile().getParentFile());
if (f.canRead()) {
DocumentActivity.handleFileClick(getActivity(), f, null);
DocumentActivity.launch(getActivity(), f, null, null);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public static boolean isFileSupported(final File file, final boolean... textOnly
return true;
}
}
// If we have a valid format saved, we can still likely open it
return ApplicationObject.settings().getDocumentFormat(file.getAbsolutePath(), -1) != -1;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private boolean followLinkUnderCursor() {
} else {
final File f = GsFileUtils.makeAbsolute(link.link, _document.getFile().getParentFile());
if (GsFileUtils.canCreate(f)) {
DocumentActivity.handleFileClick(getActivity(), f, null);
DocumentActivity.launch(getActivity(), f, null, null);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MarkdownSyntaxHighlighter extends SyntaxHighlighterBase {
public final static Pattern HEADING = Pattern.compile("(?m)((^#{1,6}[^\\S\\n][^\\n]+)|((\\n|^)[^\\s]+.*?\\n(-{2,}|={2,})[^\\S\\n]*$))");
public final static Pattern HEADING_SIMPLE = Pattern.compile("(?m)^(#{1,6}\\s.*$)");
// Group 1 matches image, Group 2 matches text, group 3 matches path
public static final Pattern LINK = Pattern.compile("(?m)(!)?\\[([^\\]]*)\\]\\((.+?)\\)(:?\\s|$)");
public static final Pattern LINK = Pattern.compile("(?m)(!)?\\[([^]]*)]\\(([^()]*(?:\\([^()]*\\)[^()]*)*)\\)");
public final static Pattern LIST_UNORDERED = Pattern.compile("(\\n|^)\\s{0,16}([*+-])( \\[[ xX]\\])?(?= )");
public final static Pattern LIST_ORDERED = Pattern.compile("(?m)^\\s{0,16}(\\d+)(:?\\.|\\))\\s");
public final static Pattern QUOTATION = Pattern.compile("(\\n|^)>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.frontend.GsAudioRecordOmDialog;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions;
import net.gsantner.opoc.util.GsContextUtils;
import net.gsantner.opoc.util.GsFileUtils;
import net.gsantner.opoc.wrapper.GsCallback;

Expand Down Expand Up @@ -83,7 +84,7 @@ public static void showInsertImageOrLinkDialog(
) {
final int[] sel = TextViewUtils.getSelection(edit);

final androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(activity);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
final View view = activity.getLayoutInflater().inflate(R.layout.select_path_dialog, null);
final EditText inputPathName = view.findViewById(R.id.ui__select_path_dialog__name);
final EditText inputPathUrl = view.findViewById(R.id.ui__select_path_dialog__url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class DatetimeFormatDialog {
*/
@SuppressLint({"ClickableViewAccessibility", "SetTextI18n, InflateParams"})
public static void showDatetimeFormatDialog(final Activity activity, final HighlightingEditor hlEditor) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
final View viewRoot = activity.getLayoutInflater().inflate(R.layout.time_format_dialog, null);

final GsContextUtils cu = new GsContextUtils();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
private AlertDialog.Builder setUpDialog(final File file, LayoutInflater inflater) {
View root;
AlertDialog.Builder dialogBuilder;
dialogBuilder = new AlertDialog.Builder(inflater.getContext(), R.style.Theme_AppCompat_DayNight_Dialog);
dialogBuilder = new AlertDialog.Builder(inflater.getContext(), R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
root = inflater.inflate(R.layout.file_info_dialog, null);

dialogBuilder.setView(root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ public static void showSttSortDialogue(Activity activity, final GsCallback.a2<St
dopt.data = availableData;
dopt.highlightData = Collections.singletonList(as().getString(optLastSelected, o_context + d_desc));
dopt.iconsForData = availableDataToIconMap;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.dialogHeightDp = 530;
dopt.okButtonText = 0;

dopt.titleText = R.string.sort_tasks_by_selected_order;
Expand Down Expand Up @@ -282,6 +280,7 @@ public static void showSttFilteringDialog(final Activity activity, final EditTex
final String title = savedViews.get(i).first;
final String query = savedViews.get(i).second;
options.add(title);
icons.add(R.drawable.empty_blank);
callbacks.add(() -> {
final DialogOptions doptView = makeSttLineSelectionDialog(activity, text, t -> TodoTxtFilter.isMatchQuery(t, query));
setQueryTitle(doptView, title, query);
Expand Down Expand Up @@ -310,7 +309,6 @@ public static void showSttFilteringDialog(final Activity activity, final EditTex
dopt.positionCallback = (posn) -> callbacks.get(posn.get(0)).callback();
dopt.isSearchEnabled = false;
dopt.titleText = R.string.browse_todo;
dopt.dialogWidthDp = WindowManager.LayoutParams.MATCH_PARENT;

GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}
Expand Down Expand Up @@ -856,7 +854,6 @@ public static void showHeadlineDialog(
dopt2.titleText = R.string.filter;
dopt2.isSearchEnabled = false;
dopt2.isMultiSelectEnabled = true;
dopt2.dialogWidthDp = 250;
dopt2.positionCallback = (selected) -> {
// Update levels so the selected ones are true
state.disabledLevels.clear();
Expand Down Expand Up @@ -893,9 +890,8 @@ public static void showIndentSizeDialog(final Activity activity, final int inden
dopt.data = Arrays.asList("1", "2", "4", "8");
dopt.highlightData = Collections.singletonList(Integer.toString(indent));
dopt.isSearchEnabled = false;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.dialogHeightDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.titleText = R.string.indent;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}

Expand All @@ -912,9 +908,9 @@ public static void showFontSizeDialog(final Activity activity, final int current
dopt.data = sizes;
dopt.highlightData = Collections.singletonList(Integer.toString(currentSize));
dopt.isSearchEnabled = false;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.dialogHeightDp = 400;
dopt.titleText = R.string.font_size;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}

Expand Down Expand Up @@ -970,11 +966,8 @@ public static void showCopyMoveConflictDialog(final Activity activity, final Str
}
dopt.data = data;
dopt.isSearchEnabled = false;
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.dialogHeightDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.messageText = activity.getString(R.string.copy_move_conflict_message, fileName, destName);
dopt.dialogWidthDp = WindowManager.LayoutParams.WRAP_CONTENT;
dopt.dialogHeightDp = WindowManager.LayoutParams.WRAP_CONTENT;
GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}

Expand All @@ -997,7 +990,6 @@ public static void showSetPasswordDialog(final Activity activity) {
}
}


public static void showInsertSnippetDialog(final Activity activity, final GsCallback.a1<String> callback) {
final DialogOptions dopt = new DialogOptions();
baseConf(activity, dopt);
Expand All @@ -1017,5 +1009,6 @@ public static void baseConf(Activity activity, DialogOptions dopt) {
dopt.clearInputIcon = R.drawable.ic_baseline_clear_24;
dopt.textColor = ContextCompat.getColor(activity, R.color.primary_text);
dopt.highlightColor = ContextCompat.getColor(activity, R.color.accent);
dopt.dialogStyle = R.style.Theme_AppCompat_DayNight_Dialog_Rounded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
private AlertDialog.Builder makeDialog(final File basedir, final boolean allowCreateDir, LayoutInflater inflater) {
final Activity activity = getActivity();
final AppSettings appSettings = ApplicationObject.settings();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(inflater.getContext(), R.style.Theme_AppCompat_DayNight_Dialog);
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(inflater.getContext(), R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
final View root = inflater.inflate(R.layout.new_file_dialog, null);

final EditText titleEdit = root.findViewById(R.id.new_file_dialog__name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.gsantner.markor.R;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.model.GsSharedPreferencesPropertyBackend;
import net.gsantner.opoc.util.GsContextUtils;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -106,7 +107,7 @@ private SearchAndReplaceTextDialog(final Activity activity, final Editable edit,
}

final Resources res = activity.getResources();
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
final View viewRoot = activity.getLayoutInflater().inflate(R.layout.search_replace_dialog, null);
final AtomicReference<Dialog> dialog = new AtomicReference<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void showDialog(
final FileSearchDialog.Options options,
final GsCallback.a1<FileSearchEngine.SearchOptions> dialogCallback
) {
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog);
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
final AppSettings appSettings = ApplicationObject.settings();

final ScrollView scrollView = new ScrollView(activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void showDialog(
final List<FileSearchEngine.FitFile> searchResults,
final GsCallback.a3<String, Integer, Boolean> callback
) {
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog);
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_DayNight_Dialog_Rounded);

final LinearLayout dialogLayout = new LinearLayout(activity);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
Expand Down Expand Up @@ -98,8 +98,8 @@ public void afterTextChanged(final Editable arg0) {

final Window window = dialog.getWindow();
if (window != null) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
}

expandableListView.setOnGroupClickListener((parent, view, groupPosition, id) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ public static Boolean isImeOpen(final View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final WindowInsets insets = view.getRootWindowInsets();
if (insets != null) {
insets.isVisible(WindowInsets.Type.ime());
return insets.isVisible(WindowInsets.Type.ime());
}
}
return null; // Uncertain
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/net/gsantner/markor/util/MarkorContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
package net.gsantner.markor.util;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.print.PrintJob;
import android.text.TextUtils;
import android.webkit.WebView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -112,4 +114,13 @@ public static File getValidIntentFile(final Intent intent, final File fallback)
final File f = getIntentFile(intent, null);
return f != null && (f.exists() || GsFileBrowserListAdapter.isVirtualFolder(f)) ? f : fallback;
}

@Override
public void startActivity(final Context context, final Intent intent) {
try {
super.startActivity(context, intent);
} catch (ActivityNotFoundException ignored) {
Toast.makeText(context, R.string.error_could_not_open_file, Toast.LENGTH_SHORT).show();
}
}
}
Loading

0 comments on commit 7cf1c04

Please sign in to comment.