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

New folder in copy/move dialog, closes #2093 #2098

Merged
merged 7 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -65,7 +65,7 @@
android:label="@string/app_name"
android:launchMode="singleTop"
android:taskAffinity=".activity.MainActivity"
android:windowSoftInputMode="stateUnchanged|adjustResize">
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ private void showAppendDialog(int keyId) {
@Override
public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
dopt.rootFolder = startFolder;
dopt.newDirButtonEnable = false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(Context context,
opts.doSelectFolder = doSelectFolder;
opts.doSelectFile = !doSelectFolder;

opts.searchHint = R.string.search_documents;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the best default in many cases

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
gsantner marked this conversation as resolved.
Show resolved Hide resolved

public static boolean isViewVisible(final View view) {
if (view == null || !view.isShown()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
*/
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.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.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.ColorRes;
Expand All @@ -38,7 +38,11 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import net.gsantner.markor.R;
import net.gsantner.opoc.frontend.GsSearchOrCustomTextDialog;
import net.gsantner.opoc.util.GsContextUtils;
import net.gsantner.opoc.wrapper.GsTextWatcherAdapter;

import java.io.File;
Expand All @@ -64,10 +68,9 @@ 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 FloatingActionButton _homeButton;
private FloatingActionButton _buttonSearch;
private FloatingActionButton _buttonNewDir;
private EditText _searchEdit;

private GsFileBrowserListAdapter _filesystemViewerAdapter;
Expand All @@ -80,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;
}
Expand All @@ -90,22 +96,21 @@ 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);
_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);

_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;
Expand All @@ -132,13 +137,20 @@ 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));
_searchEdit.setOnFocusChangeListener((v, isFocussed) -> {
GsContextUtils.instance.showSoftKeyboard(getActivity(), isFocussed, _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);

Expand Down Expand Up @@ -173,19 +185,54 @@ 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 (_searchEdit.getVisibility() == View.GONE) {
_searchEdit.setText("");
_searchEdit.setVisibility(View.VISIBLE);
_searchEdit.requestFocus();
} else {
_searchEdit.setText("");
_searchEdit.setVisibility(View.GONE);
_searchEdit.clearFocus();
}
break;
}
case R.id.ui__filesystem_dialog__button_cancel: {
onFsViewerNothingSelected(_dopt.requestId);
break;
}
case R.id.ui__filesystem_dialog__new_dir: {
showNewDirDialog();
break;
}
}
}

@Override
public void onDismiss(final DialogInterface dialog) {
super.onDismiss(dialog);
GsContextUtils.instance.showSoftKeyboard(getActivity(), false, _searchEdit);
}

private void showNewDirDialog() {
final Activity activity = getActivity();

if (activity == null) {
return;
}

final GsSearchOrCustomTextDialog.DialogOptions dopt = new GsSearchOrCustomTextDialog.DialogOptions();
dopt.isDarkDialog = GsContextUtils.instance.isDarkModeEnabled(activity);
dopt.titleText = _dopt.newDirButtonText;
dopt.textColor = rcolor(_dopt.primaryTextColor);
dopt.searchHintText = android.R.string.untitled;
dopt.callback = (name) -> {
final File file = _filesystemViewerAdapter.createDirectoryHere(name);
if (file != null) {
_recyclerList.postDelayed(() -> _filesystemViewerAdapter.showAndBlink(file, _recyclerList), 100);
}
};

GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt);
}

private void checkOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
}


Expand Down Expand Up @@ -479,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;
}
Expand All @@ -488,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;
}
Expand Down Expand Up @@ -546,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) {
Expand Down Expand Up @@ -586,7 +596,7 @@ public void onFsViewerDoUiUpdate(GsFileBrowserListAdapter adapter) {
}
}
}
}, getActivity().getSupportFragmentManager(), getActivity());
}, getChildFragmentManager(), getActivity());
}

private void showImportDialog() {
Expand All @@ -612,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) {
Expand All @@ -625,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);
Expand All @@ -642,24 +650,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();
}
}
gsantner marked this conversation as resolved.
Show resolved Hide resolved

private void showAndBlink(final File file) {
gsantner marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -684,14 +675,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);
}
}

Expand Down
Loading
Loading