From 9dccd293f16a3d8cb4b8b2344e50d1eb8242bf17 Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Sun, 20 Aug 2023 16:43:16 -0700 Subject: [PATCH 1/6] Reworked dialog layout and UI --- .../filebrowser/MarkorFileBrowserFactory.java | 2 + .../filebrowser/GsFileBrowserDialog.java | 88 +++++++++--- .../filebrowser/GsFileBrowserFragment.java | 1 + .../filebrowser/GsFileBrowserListAdapter.java | 22 +++ .../filebrowser/GsFileBrowserOptions.java | 7 +- .../baseline_create_new_folder_24.xml | 5 + .../res/layout/opoc_filesystem_dialog.xml | 126 ++++++++++-------- 7 files changed, 176 insertions(+), 75 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_create_new_folder_24.xml diff --git a/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java b/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java index f18d5229c..0a4b6ed40 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java +++ b/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java @@ -42,8 +42,10 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(Context context, opts.searchHint = R.string.search_documents; opts.searchButtonImage = R.drawable.ic_search_black_24dp; + opts.newDirButtonImage = R.drawable.baseline_create_new_folder_24; opts.homeButtonImage = R.drawable.ic_home_black_24dp; opts.selectedItemImage = R.drawable.ic_check_black_24dp; + opts.newDirButtonText = R.string.create_folder; opts.upButtonEnable = true; opts.homeButtonEnable = true; opts.mustStartWithRootFolder = false; diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index 63d35b32e..81de252d2 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -17,6 +17,7 @@ */ package net.gsantner.opoc.frontend.filebrowser; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -28,19 +29,29 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toolbar; import androidx.annotation.ColorRes; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + import net.gsantner.markor.R; +import net.gsantner.opoc.util.GsContextUtils; import net.gsantner.opoc.wrapper.GsTextWatcherAdapter; +import org.w3c.dom.Text; + import java.io.File; public class GsFileBrowserDialog extends DialogFragment implements GsFileBrowserOptions.SelectionListener { @@ -64,11 +75,11 @@ public static GsFileBrowserDialog newInstance(GsFileBrowserOptions.Options optio public TextView _dialogTitle; private TextView _buttonCancel; private TextView _buttonOk; - private LinearLayout _utilBar; - private LinearLayout _buttonBar; - private ImageView _homeButton; - private ImageView _buttonSearch; - private EditText _searchEdit; + private FloatingActionButton _homeButton; + private FloatingActionButton _buttonSearch; + private FloatingActionButton _buttonNewDir; + private TextInputEditText _searchEdit; + private TextInputLayout _searchHolder; private GsFileBrowserListAdapter _filesystemViewerAdapter; private GsFileBrowserOptions.Options _dopt; @@ -91,21 +102,20 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); Context context = getContext(); _recyclerList = root.findViewById(R.id.ui__filesystem_dialog__list); - _dialogTitle = root.findViewById(R.id.ui__filesystem_dialog__title); + _dialogTitle = root.findViewById(R.id.ui__filesystem_dialog__title_text); _buttonCancel = root.findViewById(R.id.ui__filesystem_dialog__button_cancel); _buttonOk = root.findViewById(R.id.ui__filesystem_dialog__button_ok); - _utilBar = root.findViewById(R.id.ui__filesystem_dialog__utilbar); - _buttonBar = root.findViewById(R.id.ui__filesystem_dialog__buttons); _homeButton = root.findViewById(R.id.ui__filesystem_dialog__home); + _buttonNewDir = root.findViewById(R.id.ui__filesystem_dialog__new_dir); _buttonSearch = root.findViewById(R.id.ui__filesystem_dialog__search_button); _searchEdit = root.findViewById(R.id.ui__filesystem_dialog__search_edit); + _searchHolder = root.findViewById(R.id.ui__filesystem_dialog__search_holder); _searchEdit.addTextChangedListener(GsTextWatcherAdapter.on(this::changeAdapterFilter)); - for (final View v : new View[]{_homeButton, _buttonSearch, _buttonCancel, _buttonOk}) { + for (final View v : new View[]{_homeButton, _buttonSearch, _buttonNewDir, _buttonCancel, _buttonOk}) { v.setOnClickListener(this::onClicked); } - if (_dopt == null || _buttonCancel == null) { dismiss(); return; @@ -132,6 +142,10 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { _buttonSearch.setVisibility(_dopt.searchEnable ? View.VISIBLE : View.GONE); _buttonSearch.setColorFilter(rcolor(_dopt.primaryTextColor), android.graphics.PorterDuff.Mode.SRC_ATOP); + _buttonNewDir.setImageResource(_dopt.newDirButtonImage); + _buttonNewDir.setVisibility(_dopt.newDirButtonEnable ? View.VISIBLE : View.GONE); + _buttonNewDir.setColorFilter(rcolor(_dopt.primaryTextColor), android.graphics.PorterDuff.Mode.SRC_ATOP); + _searchEdit.setHint(_dopt.searchHint); _searchEdit.setTextColor(rcolor(_dopt.primaryTextColor)); _searchEdit.setHintTextColor(rcolor(_dopt.secondaryTextColor)); @@ -173,19 +187,63 @@ public void onClicked(View view) { break; } case R.id.ui__filesystem_dialog__search_button: { - _buttonSearch.setVisibility(View.GONE); - _searchEdit.setVisibility(View.VISIBLE); - _searchEdit.requestFocus(); - InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.showSoftInput(_searchEdit, InputMethodManager.SHOW_IMPLICIT); + if (_searchHolder.getVisibility() == View.VISIBLE) { + _searchHolder.setVisibility(View.GONE); + _searchEdit.clearFocus(); + _searchEdit.setText(""); + } else { + _searchHolder.setVisibility(View.VISIBLE); + _searchEdit.requestFocus(); + final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(_searchEdit, InputMethodManager.SHOW_IMPLICIT); + } + break; } case R.id.ui__filesystem_dialog__button_cancel: { onFsViewerNothingSelected(_dopt.requestId); break; } + case R.id.ui__filesystem_dialog__new_dir: { + showNewDirDialog(); + break; + } + } + } + private void showNewDirDialog() { + final Activity activity = getActivity(); + + if (activity == null) { + return; } + + // Make the view + final EditText nameBox = new EditText(activity); + final int padding = GsContextUtils.instance.convertDpToPx(activity, 20); + nameBox.setPadding(padding, nameBox.getPaddingTop(), nameBox.getPaddingBottom(), padding); + + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + + if (_dopt.newDirButtonText != 0) { + builder.setTitle(_dopt.newDirButtonText); + } + + if (_dopt.newDirButtonImage != 0) { + builder.setIcon(_dopt.newDirButtonImage); + } + + builder.setCancelable(true) + .setView(nameBox) + .setCancelable(true) + .setPositiveButton(android.R.string.ok, (d, w) -> { + _filesystemViewerAdapter.createDirectoryHere(nameBox.getText()); + _filesystemViewerAdapter.reloadCurrentFolder(); + }); + + final AlertDialog dialog = builder.create(); + dialog.setOnShowListener((d) -> nameBox.requestFocus()); + dialog.show(); } private void checkOptions() { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java index bd6398d15..9742e7751 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java @@ -568,6 +568,7 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { _doptMoC.titleText = isMove ? R.string.move : R.string.copy; _doptMoC.rootFolder = _appSettings.getNotebookDirectory(); _doptMoC.startFolder = getCurrentFolder(); + _doptMoC.newDirButtonEnable = true; // Directories cannot be moved into themselves. Don't give users the option final Set selSet = new HashSet<>(); for (final File f : files) { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java index 9f5999309..24f0c9383 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java @@ -451,6 +451,28 @@ public boolean onLongClick(View view) { return false; } + public void createDirectoryHere(final CharSequence name) { + if (name == null || _currentFolder == null || !_currentFolder.canWrite()) { + return; + } + + final String trimmed = name.toString().trim(); + + if (trimmed.length() == 0) { + return; + } + + boolean success = false; + try { + success = new File(_currentFolder, trimmed).mkdir(); + } catch (SecurityException ignored) { + } + + if (!success) { + Toast.makeText(_context, R.string.file_does_not_exist_and_cant_be_created, Toast.LENGTH_LONG).show(); + } + } + // Get the position of a file in the current view // -1 if file is not a child of the current directory public int getFilePosition(final File file) { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java index cd68caed8..8b96ec6b1 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java @@ -71,7 +71,8 @@ public static class Options { upButtonEnable = true, homeButtonEnable = true, cancelButtonEnable = true, - okButtonEnable = true; + okButtonEnable = true, + newDirButtonEnable = false; public GsCallback.b2 fileOverallFilter = (context, file) -> true; @@ -89,11 +90,15 @@ public static class Options { public int contentDescriptionSelected = 0; @StringRes public int contentDescriptionFile = 0; + @StringRes + public int newDirButtonText = 0; @DrawableRes public int homeButtonImage = android.R.drawable.star_big_on; @DrawableRes public int searchButtonImage = android.R.drawable.ic_menu_search; @DrawableRes + public int newDirButtonImage = android.R.drawable.ic_menu_add; + @DrawableRes public int folderImage = android.R.drawable.ic_menu_view; @DrawableRes public int selectedItemImage = android.R.drawable.checkbox_on_background; diff --git a/app/src/main/res/drawable/baseline_create_new_folder_24.xml b/app/src/main/res/drawable/baseline_create_new_folder_24.xml new file mode 100644 index 000000000..df53c39b8 --- /dev/null +++ b/app/src/main/res/drawable/baseline_create_new_folder_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/opoc_filesystem_dialog.xml b/app/src/main/res/layout/opoc_filesystem_dialog.xml index 0891489b8..9610d3a2c 100644 --- a/app/src/main/res/layout/opoc_filesystem_dialog.xml +++ b/app/src/main/res/layout/opoc_filesystem_dialog.xml @@ -17,77 +17,86 @@ android:layout_height="match_parent" android:layout_marginTop="4dp"> - - - + android:layout_height="?attr/actionBarSize" + android:background="?attr/colorPrimary" + android:theme="@style/ThemeOverlay.AppCompat.ActionBar"> - + + + - + - + android:textSize="15sp" + android:singleLine="true"/> - + + + + + + + @@ -98,8 +107,7 @@ android:layout_alignParentBottom="true" android:gravity="end" android:orientation="horizontal" - android:padding="16dp"> - + android:padding="4dp"> + tools:text="Select" /> From 24f6815ff8e13cf0b0357feab96b8f2207114881 Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Sun, 20 Aug 2023 16:47:07 -0700 Subject: [PATCH 2/6] Enabling in other places too --- .../net/gsantner/markor/activity/DocumentShareIntoFragment.java | 1 + .../opoc/frontend/filebrowser/GsFileBrowserFragment.java | 1 - .../opoc/frontend/filebrowser/GsFileBrowserOptions.java | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java index a8822e712..f3a3268d7 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java @@ -268,6 +268,7 @@ private void showAppendDialog(int keyId) { @Override public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { dopt.rootFolder = startFolder; + dopt.newDirButtonEnable = false; } @Override diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java index 9742e7751..bd6398d15 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java @@ -568,7 +568,6 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { _doptMoC.titleText = isMove ? R.string.move : R.string.copy; _doptMoC.rootFolder = _appSettings.getNotebookDirectory(); _doptMoC.startFolder = getCurrentFolder(); - _doptMoC.newDirButtonEnable = true; // Directories cannot be moved into themselves. Don't give users the option final Set selSet = new HashSet<>(); for (final File f : files) { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java index 8b96ec6b1..f814f8031 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java @@ -72,7 +72,7 @@ public static class Options { homeButtonEnable = true, cancelButtonEnable = true, okButtonEnable = true, - newDirButtonEnable = false; + newDirButtonEnable = true; public GsCallback.b2 fileOverallFilter = (context, file) -> true; From 0af55a3dad01fb1259852a96e7552a7f1829da82 Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Sun, 20 Aug 2023 23:49:55 -0700 Subject: [PATCH 3/6] Experimenting with constraint layout --- .../filebrowser/GsFileBrowserDialog.java | 27 ++++---- .../res/layout/opoc_filesystem_dialog.xml | 63 ++++++++++++------- 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index 81de252d2..39bef3f21 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -19,6 +19,7 @@ import android.app.Activity; import android.content.Context; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -78,8 +79,7 @@ public static GsFileBrowserDialog newInstance(GsFileBrowserOptions.Options optio private FloatingActionButton _homeButton; private FloatingActionButton _buttonSearch; private FloatingActionButton _buttonNewDir; - private TextInputEditText _searchEdit; - private TextInputLayout _searchHolder; + private EditText _searchEdit; private GsFileBrowserListAdapter _filesystemViewerAdapter; private GsFileBrowserOptions.Options _dopt; @@ -101,6 +101,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); Context context = getContext(); + _recyclerList = root.findViewById(R.id.ui__filesystem_dialog__list); _dialogTitle = root.findViewById(R.id.ui__filesystem_dialog__title_text); _buttonCancel = root.findViewById(R.id.ui__filesystem_dialog__button_cancel); @@ -109,7 +110,6 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { _buttonNewDir = root.findViewById(R.id.ui__filesystem_dialog__new_dir); _buttonSearch = root.findViewById(R.id.ui__filesystem_dialog__search_button); _searchEdit = root.findViewById(R.id.ui__filesystem_dialog__search_edit); - _searchHolder = root.findViewById(R.id.ui__filesystem_dialog__search_holder); _searchEdit.addTextChangedListener(GsTextWatcherAdapter.on(this::changeAdapterFilter)); for (final View v : new View[]{_homeButton, _buttonSearch, _buttonNewDir, _buttonCancel, _buttonOk}) { @@ -187,17 +187,15 @@ public void onClicked(View view) { break; } case R.id.ui__filesystem_dialog__search_button: { - if (_searchHolder.getVisibility() == View.VISIBLE) { - _searchHolder.setVisibility(View.GONE); + if (_searchEdit.getVisibility() == View.VISIBLE) { + _searchEdit.setVisibility(View.GONE); _searchEdit.clearFocus(); _searchEdit.setText(""); } else { - _searchHolder.setVisibility(View.VISIBLE); + _searchEdit.setVisibility(View.VISIBLE); + _searchEdit.setText(""); _searchEdit.requestFocus(); - final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.showSoftInput(_searchEdit, InputMethodManager.SHOW_IMPLICIT); } - break; } case R.id.ui__filesystem_dialog__button_cancel: { @@ -230,12 +228,15 @@ private void showNewDirDialog() { } if (_dopt.newDirButtonImage != 0) { - builder.setIcon(_dopt.newDirButtonImage); + final Drawable icon = ContextCompat.getDrawable(activity, _dopt.newDirButtonImage); + if (icon != null) { + icon.setColorFilter(rcolor(_dopt.primaryTextColor), android.graphics.PorterDuff.Mode.SRC_ATOP); + builder.setIcon(icon); + } } - builder.setCancelable(true) - .setView(nameBox) - .setCancelable(true) + builder.setView(nameBox) + .setNegativeButton(android.R.string.cancel, (d, w) -> d.dismiss()) .setPositiveButton(android.R.string.ok, (d, w) -> { _filesystemViewerAdapter.createDirectoryHere(nameBox.getText()); _filesystemViewerAdapter.reloadCurrentFolder(); diff --git a/app/src/main/res/layout/opoc_filesystem_dialog.xml b/app/src/main/res/layout/opoc_filesystem_dialog.xml index 9610d3a2c..d7d773e08 100644 --- a/app/src/main/res/layout/opoc_filesystem_dialog.xml +++ b/app/src/main/res/layout/opoc_filesystem_dialog.xml @@ -9,23 +9,23 @@ * #########################################################*/ --> - + - + + + + + + - - @@ -132,4 +147,4 @@ - + From 0c9993fd91c33263c299f971118d4149346e8da7 Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Sat, 26 Aug 2023 15:57:25 -0700 Subject: [PATCH 4/6] Fixed behavior as best as I could --- .../filebrowser/MarkorFileBrowserFactory.java | 1 - .../frontend/textview/TextViewUtils.java | 7 -- .../frontend/GsSearchOrCustomTextDialog.java | 2 +- .../filebrowser/GsFileBrowserDialog.java | 75 ++++++++----------- .../filebrowser/GsFileBrowserFragment.java | 31 +++----- .../filebrowser/GsFileBrowserListAdapter.java | 46 ++++++++++-- .../gsantner/opoc/util/GsContextUtils.java | 12 ++- .../res/layout/opoc_filesystem_dialog.xml | 37 +++------ 8 files changed, 103 insertions(+), 108 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java b/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java index 0a4b6ed40..8e3ee7a65 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java +++ b/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java @@ -40,7 +40,6 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(Context context, opts.doSelectFolder = doSelectFolder; opts.doSelectFile = !doSelectFolder; - opts.searchHint = R.string.search_documents; opts.searchButtonImage = R.drawable.ic_search_black_24dp; opts.newDirButtonImage = R.drawable.baseline_create_new_folder_24; opts.homeButtonImage = R.drawable.ic_home_black_24dp; diff --git a/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java b/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java index 6b1a0bb32..c787f12bc 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java +++ b/app/src/main/java/net/gsantner/markor/frontend/textview/TextViewUtils.java @@ -693,13 +693,6 @@ public static boolean checkRange(final int length, final int... indices) { return indices != null && indices.length >= 2 && inRange(0, length, indices) && indices[1] > indices[0]; } - public static void blinkView(final View view) { - if (view != null) { - final float init = view.getAlpha(); - ObjectAnimator.ofFloat(view, View.ALPHA, init, 0.1f, 1.0f, 0.1f, 1.0f, init).setDuration(1000).start(); - } - } - public static boolean isViewVisible(final View view) { if (view == null || !view.isShown()) { return false; diff --git a/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java index 38b259843..4f3754efe 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java @@ -115,7 +115,7 @@ public static class DialogOptions { @StringRes public int searchHintText = android.R.string.search_go; @DrawableRes - public int clearInputIcon = android.R.drawable.ic_input_delete; + public int clearInputIcon = android.R.drawable.ic_menu_close_clear_cancel; } public static class Adapter extends BaseAdapter { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index 39bef3f21..56ec0bf69 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -19,8 +19,9 @@ import android.app.Activity; import android.content.Context; -import android.graphics.drawable.Drawable; +import android.content.DialogInterface; import android.os.Bundle; +import android.text.InputType; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -28,15 +29,10 @@ import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toolbar; import androidx.annotation.ColorRes; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; import androidx.recyclerview.widget.DividerItemDecoration; @@ -44,15 +40,13 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.textfield.TextInputEditText; -import com.google.android.material.textfield.TextInputLayout; import net.gsantner.markor.R; +import net.gsantner.markor.frontend.textview.TextViewUtils; +import net.gsantner.opoc.frontend.GsSearchOrCustomTextDialog; import net.gsantner.opoc.util.GsContextUtils; import net.gsantner.opoc.wrapper.GsTextWatcherAdapter; -import org.w3c.dom.Text; - import java.io.File; public class GsFileBrowserDialog extends DialogFragment implements GsFileBrowserOptions.SelectionListener { @@ -149,10 +143,13 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { _searchEdit.setHint(_dopt.searchHint); _searchEdit.setTextColor(rcolor(_dopt.primaryTextColor)); _searchEdit.setHintTextColor(rcolor(_dopt.secondaryTextColor)); + _searchEdit.setOnFocusChangeListener((edit, hasFocus) -> { + GsContextUtils.instance.showSoftKeyboard(getActivity(), hasFocus, _searchEdit); + }); root.setBackgroundColor(rcolor(_dopt.backgroundColor)); - LinearLayoutManager lam = (LinearLayoutManager) _recyclerList.getLayoutManager(); + final LinearLayoutManager lam = (LinearLayoutManager) _recyclerList.getLayoutManager(); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getActivity(), lam.getOrientation()); _recyclerList.addItemDecoration(dividerItemDecoration); @@ -187,14 +184,14 @@ public void onClicked(View view) { break; } case R.id.ui__filesystem_dialog__search_button: { - if (_searchEdit.getVisibility() == View.VISIBLE) { - _searchEdit.setVisibility(View.GONE); - _searchEdit.clearFocus(); + if (_searchEdit.getVisibility() == View.GONE) { _searchEdit.setText(""); - } else { _searchEdit.setVisibility(View.VISIBLE); - _searchEdit.setText(""); _searchEdit.requestFocus(); + } else { + _searchEdit.setText(""); + _searchEdit.setVisibility(View.GONE); + _searchEdit.clearFocus(); } break; } @@ -209,6 +206,12 @@ public void onClicked(View view) { } } + @Override + public void onDismiss(final DialogInterface dialog) { + GsContextUtils.instance.showSoftKeyboard(getActivity(), false); + super.onDismiss(dialog); + } + private void showNewDirDialog() { final Activity activity = getActivity(); @@ -216,35 +219,21 @@ private void showNewDirDialog() { return; } - // Make the view - final EditText nameBox = new EditText(activity); - final int padding = GsContextUtils.instance.convertDpToPx(activity, 20); - nameBox.setPadding(padding, nameBox.getPaddingTop(), nameBox.getPaddingBottom(), padding); - - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - - if (_dopt.newDirButtonText != 0) { - builder.setTitle(_dopt.newDirButtonText); - } - - if (_dopt.newDirButtonImage != 0) { - final Drawable icon = ContextCompat.getDrawable(activity, _dopt.newDirButtonImage); - if (icon != null) { - icon.setColorFilter(rcolor(_dopt.primaryTextColor), android.graphics.PorterDuff.Mode.SRC_ATOP); - builder.setIcon(icon); + final GsSearchOrCustomTextDialog.DialogOptions dopt = new GsSearchOrCustomTextDialog.DialogOptions(); + dopt.isDarkDialog = GsContextUtils.instance.isDarkModeEnabled(activity); + dopt.titleText = _dopt.newDirButtonText; + dopt.searchInputType = InputType.TYPE_CLASS_TEXT; + dopt.textColor = rcolor(_dopt.primaryTextColor); + dopt.searchHintText = android.R.string.untitled; + dopt.data = null; + dopt.callback = (name) -> { + final File file = _filesystemViewerAdapter.createDirectoryHere(name); + if (file != null) { + _recyclerList.postDelayed(() -> _filesystemViewerAdapter.showAndBlink(file, _recyclerList), 100); } - } - - builder.setView(nameBox) - .setNegativeButton(android.R.string.cancel, (d, w) -> d.dismiss()) - .setPositiveButton(android.R.string.ok, (d, w) -> { - _filesystemViewerAdapter.createDirectoryHere(nameBox.getText()); - _filesystemViewerAdapter.reloadCurrentFolder(); - }); + }; - final AlertDialog dialog = builder.create(); - dialog.setOnShowListener((d) -> nameBox.requestFocus()); - dialog.show(); + GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt); } private void checkOptions() { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java index bd6398d15..705b1580f 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java @@ -18,8 +18,10 @@ package net.gsantner.opoc.frontend.filebrowser; import android.annotation.SuppressLint; +import android.app.Activity; import android.content.Context; import android.graphics.Color; +import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.util.Pair; @@ -29,6 +31,7 @@ import android.view.View; import android.widget.TextView; import android.widget.Toast; +import android.widget.Toolbar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -316,6 +319,13 @@ public void onResume() { onFsViewerDoUiUpdate(_filesystemViewerAdapter); firstResume = false; + + final File folder = getCurrentFolder(); + final Activity activity = getActivity(); + if (isVisible() && folder != null && activity != null) { + activity.setTitle(folder.getName()); + reloadCurrentFolder(); + } } @@ -642,24 +652,7 @@ private void importFileToCurrentDirectory(Context context, File sourceFile) { @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); - if (isVisibleToUser && getCurrentFolder() != null && !TextUtils.isEmpty(getCurrentFolder().getName()) && getToolbar() != null) { - getToolbar().setTitle(getCurrentFolder().getName()); - reloadCurrentFolder(); - } - } - private void showAndBlink(final File file) { - final int pos = getAdapter().getFilePosition(file); - final LinearLayoutManager manager = (LinearLayoutManager) _recyclerList.getLayoutManager(); - if (manager != null && pos >= 0) { - manager.scrollToPositionWithOffset(pos, 1); - _recyclerList.postDelayed(() -> { - final RecyclerView.ViewHolder holder = _recyclerList.findViewHolderForLayoutPosition(pos); - if (holder != null) { - TextViewUtils.blinkView(holder.itemView); - } - }, 250); - } } // Switch to folder and show the file @@ -684,14 +677,14 @@ public void showFile(final File file) { public void onChanged() { super.onChanged(); if ((System.currentTimeMillis() - init) < 2000) { - _recyclerList.postDelayed(() -> showAndBlink(file), 250); + _recyclerList.postDelayed(() -> adapter.showAndBlink(file, _recyclerList), 250); } adapter.unregisterAdapterDataObserver(this); } }); adapter.setCurrentFolder(dir); } else { - showAndBlink(file); + adapter.showAndBlink(file, _recyclerList); } } diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java index 24f0c9383..c5f845103 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java @@ -31,6 +31,7 @@ import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import net.gsantner.markor.R; @@ -96,6 +97,9 @@ public GsFileBrowserListAdapter(GsFileBrowserOptions.Options options, Context co _recyclerView = recyclerView; _prefApp = _context.getSharedPreferences("app", Context.MODE_PRIVATE); + // Prevents view flicker - https://stackoverflow.com/a/32488059 + setHasStableIds(true); + GsContextUtils cu = GsContextUtils.instance; if (_dopt.primaryColor == 0) { _dopt.primaryColor = cu.getResId(context, GsContextUtils.ResType.COLOR, "primary"); @@ -284,6 +288,13 @@ public TagContainer(File file_, int position_) { } } + + // Prevents view flicker - https://stackoverflow.com/a/32488059 + @Override + public long getItemId(final int position) { + return _adapterData.get(position).hashCode(); + } + public File getCurrentFolder() { return _currentFolder; } @@ -451,25 +462,46 @@ public boolean onLongClick(View view) { return false; } - public void createDirectoryHere(final CharSequence name) { + public File createDirectoryHere(final CharSequence name) { if (name == null || _currentFolder == null || !_currentFolder.canWrite()) { - return; + return null; } final String trimmed = name.toString().trim(); if (trimmed.length() == 0) { - return; + return null; } - boolean success = false; try { - success = new File(_currentFolder, trimmed).mkdir(); + final File file = new File(_currentFolder, trimmed); + if (file.exists() || file.mkdir()) { + reloadCurrentFolder(); + return file; + } } catch (SecurityException ignored) { } - if (!success) { - Toast.makeText(_context, R.string.file_does_not_exist_and_cant_be_created, Toast.LENGTH_LONG).show(); + Toast.makeText(_context, R.string.file_does_not_exist_and_cant_be_created, Toast.LENGTH_LONG).show(); + return null; + } + + /** + * Show a file in the current folder and blink it + * @param file File to blink + * @param recycler RecyclerView which holds the file items + */ + public void showAndBlink(final File file, final RecyclerView recycler) { + final int pos = getFilePosition(file); + final LinearLayoutManager manager = (LinearLayoutManager) recycler.getLayoutManager(); + if (manager != null && pos >= 0) { + manager.scrollToPositionWithOffset(pos, 1); + recycler.postDelayed(() -> { + final RecyclerView.ViewHolder holder = recycler.findViewHolderForLayoutPosition(pos); + if (holder != null) { + GsContextUtils.blinkView(holder.itemView); + } + }, 250); } } diff --git a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java index 74e6b622b..2664a2633 100644 --- a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java @@ -12,6 +12,7 @@ import static android.graphics.Bitmap.CompressFormat; import android.Manifest; +import android.animation.ObjectAnimator; import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; @@ -2513,9 +2514,9 @@ public T showSoftKeyboard(final Activity activity, fi final View focus = (view != null && view.length > 0) ? view[0] : activity.getCurrentFocus(); if (imm != null && focus != null && focus.getWindowToken() != null) { if (show) { - imm.showSoftInput(focus, 0); + imm.showSoftInput(focus, InputMethodManager.SHOW_IMPLICIT); } else if (focus.getWindowToken() != null) { - imm.hideSoftInputFromWindow(focus.getWindowToken(), 0); + imm.hideSoftInputFromWindow(focus.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); } } } @@ -2821,4 +2822,11 @@ public boolean isDarkModeEnabled(final Context context) { } return false; } + + public static void blinkView(final View view) { + if (view != null) { + final float init = view.getAlpha(); + ObjectAnimator.ofFloat(view, View.ALPHA, init, 0.1f, 1.0f, 0.1f, 1.0f, init).setDuration(1000).start(); + } + } } diff --git a/app/src/main/res/layout/opoc_filesystem_dialog.xml b/app/src/main/res/layout/opoc_filesystem_dialog.xml index d7d773e08..9b006859c 100644 --- a/app/src/main/res/layout/opoc_filesystem_dialog.xml +++ b/app/src/main/res/layout/opoc_filesystem_dialog.xml @@ -15,8 +15,8 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginTop="4dp"> - + android:layout_marginTop="4dp" + android:animateLayoutChanges="true"> - - - + android:maxLines="1" + android:importantForAutofill="no" /> Date: Sat, 26 Aug 2023 16:12:16 -0700 Subject: [PATCH 5/6] bugfixeswq --- .../frontend/filebrowser/GsFileBrowserListAdapter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java index c5f845103..c4d2dd3e3 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java @@ -171,7 +171,6 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos } } - //String tmp = descriptionFile.getAbsolutePath().startsWith("/storage/emulated/0/") && getCurrentFolder().getAbsolutePath().startsWith("/storage/emulated/0/") ? "/storage/emulated/0/" : ""; holder.description.setTextColor(ContextCompat.getColor(_context, _dopt.secondaryTextColor)); holder.image.postDelayed(() -> { @@ -292,7 +291,7 @@ public TagContainer(File file_, int position_) { // Prevents view flicker - https://stackoverflow.com/a/32488059 @Override public long getItemId(final int position) { - return _adapterData.get(position).hashCode(); + return _adapterDataFiltered.get(position).hashCode(); } public File getCurrentFolder() { @@ -400,8 +399,8 @@ public boolean isFilesOnlySelected() { public boolean toggleSelection(TagContainer data) { boolean clickHandled = false; - if (data != null && data.file != null && getCurrentFolder() != null) { - if (data.file.isDirectory() && getCurrentFolder().getParentFile() != null && getCurrentFolder().getParentFile().equals(data.file)) { + if (data != null && data.file != null && _currentFolder != null) { + if (data.file.isDirectory() && _currentFolder.getParentFile() != null && _currentFolder.getParentFile().equals(data.file)) { // goUp clickHandled = true; } else if (_currentSelection.contains(data.file)) { From 5e1ef2c31b9bb9848217b1b4ffc02fe770224a21 Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Sun, 27 Aug 2023 11:38:58 -0700 Subject: [PATCH 6/6] Cleanups --- app/src/main/AndroidManifest.xml | 2 +- .../filebrowser/GsFileBrowserDialog.java | 19 +++++++++---------- .../filebrowser/GsFileBrowserFragment.java | 14 ++++++-------- .../gsantner/opoc/util/GsContextUtils.java | 8 +++++--- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 92bf7f97b..82329f24b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -65,7 +65,7 @@ android:label="@string/app_name" android:launchMode="singleTop" android:taskAffinity=".activity.MainActivity" - android:windowSoftInputMode="stateUnchanged|adjustResize"> + android:windowSoftInputMode="stateAlwaysHidden|adjustResize"> diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index 56ec0bf69..d5bb4a393 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -18,16 +18,15 @@ package net.gsantner.opoc.frontend.filebrowser; import android.app.Activity; +import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; -import android.text.InputType; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; @@ -42,7 +41,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import net.gsantner.markor.R; -import net.gsantner.markor.frontend.textview.TextViewUtils; import net.gsantner.opoc.frontend.GsSearchOrCustomTextDialog; import net.gsantner.opoc.util.GsContextUtils; import net.gsantner.opoc.wrapper.GsTextWatcherAdapter; @@ -85,8 +83,11 @@ public static GsFileBrowserDialog newInstance(GsFileBrowserOptions.Options optio @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.opoc_filesystem_dialog, container, false); - if (getDialog() != null && getDialog().getWindow() != null) { - getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + final Dialog dialog = getDialog(); + final Window window = dialog != null ? dialog.getWindow() : null; + if (window != null) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + setStyle(STYLE_NORMAL, R.style.AppTheme_Unified); } return root; } @@ -143,8 +144,8 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { _searchEdit.setHint(_dopt.searchHint); _searchEdit.setTextColor(rcolor(_dopt.primaryTextColor)); _searchEdit.setHintTextColor(rcolor(_dopt.secondaryTextColor)); - _searchEdit.setOnFocusChangeListener((edit, hasFocus) -> { - GsContextUtils.instance.showSoftKeyboard(getActivity(), hasFocus, _searchEdit); + _searchEdit.setOnFocusChangeListener((v, isFocussed) -> { + GsContextUtils.instance.showSoftKeyboard(getActivity(), isFocussed, _searchEdit); }); root.setBackgroundColor(rcolor(_dopt.backgroundColor)); @@ -208,8 +209,8 @@ public void onClicked(View view) { @Override public void onDismiss(final DialogInterface dialog) { - GsContextUtils.instance.showSoftKeyboard(getActivity(), false); super.onDismiss(dialog); + GsContextUtils.instance.showSoftKeyboard(getActivity(), false, _searchEdit); } private void showNewDirDialog() { @@ -222,10 +223,8 @@ private void showNewDirDialog() { final GsSearchOrCustomTextDialog.DialogOptions dopt = new GsSearchOrCustomTextDialog.DialogOptions(); dopt.isDarkDialog = GsContextUtils.instance.isDarkModeEnabled(activity); dopt.titleText = _dopt.newDirButtonText; - dopt.searchInputType = InputType.TYPE_CLASS_TEXT; dopt.textColor = rcolor(_dopt.primaryTextColor); dopt.searchHintText = android.R.string.untitled; - dopt.data = null; dopt.callback = (name) -> { final File file = _filesystemViewerAdapter.createDirectoryHere(name); if (file != null) { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java index 705b1580f..b58ae0abf 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java @@ -489,7 +489,7 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.action_info_selected_item: { if (_filesystemViewerAdapter.areItemsSelected()) { File file = new ArrayList<>(_filesystemViewerAdapter.getCurrentSelection()).get(0); - FileInfoDialog.show(file, getFragmentManager()); + FileInfoDialog.show(file, getChildFragmentManager()); } return true; } @@ -498,7 +498,7 @@ public boolean onOptionsItemSelected(MenuItem item) { if (_filesystemViewerAdapter.areItemsSelected()) { File file = new ArrayList<>(_filesystemViewerAdapter.getCurrentSelection()).get(0); WrRenameDialog renameDialog = WrRenameDialog.newInstance(file, renamedFile -> reloadCurrentFolder()); - renameDialog.show(getFragmentManager(), WrRenameDialog.FRAGMENT_TAG); + renameDialog.show(getChildFragmentManager(), WrRenameDialog.FRAGMENT_TAG); } return true; } @@ -556,7 +556,7 @@ public void askForDeletingFilesRecursive(WrConfirmDialog.ConfirmDialogCallback c } WrConfirmDialog confirmDialog = WrConfirmDialog.newInstance(getString(R.string.confirm_delete), message.toString(), itemsToDelete, confirmCallback); - confirmDialog.show(getParentFragmentManager(), WrConfirmDialog.FRAGMENT_TAG); + confirmDialog.show(getChildFragmentManager(), WrConfirmDialog.FRAGMENT_TAG); } private void askForMoveOrCopy(final boolean isMove) { @@ -596,7 +596,7 @@ public void onFsViewerDoUiUpdate(GsFileBrowserListAdapter adapter) { } } } - }, getActivity().getSupportFragmentManager(), getActivity()); + }, getChildFragmentManager(), getActivity()); } private void showImportDialog() { @@ -622,7 +622,7 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { dopt.doSelectFile = true; dopt.doSelectFolder = true; } - }, getFragmentManager(), getActivity(), null); + }, getChildFragmentManager(), getActivity(), null); } private void importFile(final File file) { @@ -635,9 +635,7 @@ private void importFile(final File file) { importFileToCurrentDirectory(getActivity(), file); } }); - if (getFragmentManager() != null) { - d.show(getFragmentManager(), WrConfirmDialog.FRAGMENT_TAG); - } + d.show(getChildFragmentManager(), WrConfirmDialog.FRAGMENT_TAG); } else { // Import importFileToCurrentDirectory(getActivity(), file); diff --git a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java index 2664a2633..8c39ccf2d 100644 --- a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java @@ -56,6 +56,7 @@ import android.net.Uri; import android.os.Build; import android.os.Environment; +import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.SystemClock; import android.os.VibrationEffect; @@ -2512,11 +2513,12 @@ public T showSoftKeyboard(final Activity activity, fi if (activity != null) { final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); final View focus = (view != null && view.length > 0) ? view[0] : activity.getCurrentFocus(); - if (imm != null && focus != null && focus.getWindowToken() != null) { + final IBinder token = focus != null ? focus.getWindowToken() : null; + if (imm != null && focus != null) { if (show) { imm.showSoftInput(focus, InputMethodManager.SHOW_IMPLICIT); - } else if (focus.getWindowToken() != null) { - imm.hideSoftInputFromWindow(focus.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); + } else if (token != null) { + imm.hideSoftInputFromWindow(token, InputMethodManager.HIDE_IMPLICIT_ONLY); } } }