Skip to content

Commit

Permalink
Merge pull request #3920 from bimalkaf/bugfix/open_new_task_broken_2783
Browse files Browse the repository at this point in the history
BugFix :  #2783 Open text files in new task is broken
  • Loading branch information
VishalNehra authored Sep 4, 2023
2 parents 9755072 + d2e52df commit 9348d3e
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ public static void openFile(
mainActivity.startActivity(intent);
} else {
try {
openFileDialogFragmentFor(f, mainActivity);
openFileDialogFragmentFor(f, mainActivity, useNewStack);
} catch (Exception e) {
Toast.makeText(
mainActivity, mainActivity.getString(R.string.no_app_found), Toast.LENGTH_LONG)
Expand All @@ -760,30 +760,42 @@ public static void openFile(
}

private static void openFileDialogFragmentFor(
@NonNull File file, @NonNull MainActivity mainActivity) {
@NonNull File file, @NonNull MainActivity mainActivity, @NonNull Boolean useNewStack) {
openFileDialogFragmentFor(
file, mainActivity, MimeTypes.getMimeType(file.getAbsolutePath(), false));
file, mainActivity, MimeTypes.getMimeType(file.getAbsolutePath(), false), useNewStack);
}

private static void openFileDialogFragmentFor(
@NonNull File file, @NonNull MainActivity mainActivity, @NonNull String mimeType) {
@NonNull File file,
@NonNull MainActivity mainActivity,
@NonNull String mimeType,
@NonNull Boolean useNewStack) {
OpenFileDialogFragment.Companion.openFileOrShow(
FileProvider.getUriForFile(mainActivity, mainActivity.getPackageName(), file),
mimeType,
false,
useNewStack,
mainActivity,
false);
}

private static void openFileDialogFragmentFor(
@NonNull DocumentFile file, @NonNull MainActivity mainActivity) {
@NonNull DocumentFile file,
@NonNull MainActivity mainActivity,
@NonNull Boolean useNewStack) {
openFileDialogFragmentFor(
file.getUri(), mainActivity, MimeTypes.getMimeType(file.getUri().toString(), false));
file.getUri(),
mainActivity,
MimeTypes.getMimeType(file.getUri().toString(), false),
useNewStack);
}

private static void openFileDialogFragmentFor(
@NonNull Uri uri, @NonNull MainActivity mainActivity, @NonNull String mimeType) {
OpenFileDialogFragment.Companion.openFileOrShow(uri, mimeType, false, mainActivity, false);
@NonNull Uri uri,
@NonNull MainActivity mainActivity,
@NonNull String mimeType,
@NonNull Boolean useNewStack) {
OpenFileDialogFragment.Companion.openFileOrShow(
uri, mimeType, useNewStack, mainActivity, false);
}

private static boolean isSelfDefault(File f, Context c) {
Expand All @@ -804,7 +816,7 @@ public static void openFile(
boolean useNewStack =
sharedPrefs.getBoolean(PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK, false);
try {
openFileDialogFragmentFor(f, m);
openFileDialogFragmentFor(f, m, useNewStack);
} catch (Exception e) {
Toast.makeText(m, m.getString(R.string.no_app_found), Toast.LENGTH_LONG).show();
openWith(f, m, useNewStack);
Expand Down

0 comments on commit 9348d3e

Please sign in to comment.