Merge pull request #9287 from liam-p-23/master

File rename input warning message
This commit is contained in:
Álvaro Brey 2021-11-25 14:14:37 +01:00 committed by GitHub
commit a98bdd69ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 141 additions and 102 deletions

View file

@ -29,7 +29,9 @@ package com.owncloud.android.ui.dialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
@ -55,7 +57,7 @@ import androidx.fragment.app.DialogFragment;
* Triggers the rename operation when name is confirmed.
*/
public class RenameFileDialogFragment
extends DialogFragment implements DialogInterface.OnClickListener {
extends DialogFragment implements DialogInterface.OnClickListener {
private static final String ARG_TARGET_FILE = "TARGET_FILE";
@ -107,12 +109,43 @@ public class RenameFileDialogFragment
ThemeTextInputUtils.colorTextInput(binding.userInputContainer,
binding.userInput,
ThemeColorUtils.primaryColor(getActivity()));
int selectionStart = 0;
int extensionStart = mTargetFile.isFolder() ? -1 : currentName.lastIndexOf('.');
int selectionEnd = extensionStart >= 0 ? extensionStart : currentName.length();
binding.userInput.setSelection(Math.min(selectionStart, selectionEnd), Math.max(selectionStart, selectionEnd));
binding.userInput.setSelection(0, selectionEnd);
binding.userInput.requestFocus();
// Add TextChangedListener to handle showing/hiding the input warning message
binding.userInput.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
/**
* When user enters a hidden file name, the 'hidden file' message is shown.
* Otherwise, the message is ensured to be hidden.
*/
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String newFileName = "";
if (binding.userInput.getText() != null) {
newFileName = binding.userInput.getText().toString().trim();
}
if (!TextUtils.isEmpty(newFileName) && newFileName.charAt(0) == '.') {
binding.userInputContainer.setError(getText(R.string.hidden_file_name_warning));
}
else if(binding.userInputContainer.getError() != null) {
binding.userInputContainer.setError(null);
// Called to remove extra padding
binding.userInputContainer.setErrorEnabled(false);
}
}
});
// Build the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
builder.setView(view)

View file

@ -27,6 +27,7 @@
android:id="@+id/user_input_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextInputLayoutInputWarning"
android:hint="@string/hint_name">
<com.google.android.material.textfield.TextInputEditText

View file

@ -779,6 +779,7 @@
<string name="file_rename">Rename</string>
<string name="fab_label">Add or upload</string>
<string name="account_creation_failed">Account creation failed</string>
<string name="hidden_file_name_warning">Name will result in a hidden file</string>
<string name="single_sign_on_request_token" formatted="true">Allow %1$s to access your Nextcloud account %2$s?</string>
<string name="permission_deny">Deny</string>
<string name="permission_allow">Allow</string>

View file

@ -19,10 +19,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- General ownCloud app style -->
<style name="BaseTheme.ownCloud" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
<item name="android:actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
<!-- General ownCloud app style -->
<style name="BaseTheme.ownCloud" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
<item name="android:actionBarStyle">@style/Theme.ownCloud.Widget.ActionBar</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppTheme.PopupMenu</item>
<item name="actionModeBackground">@color/action_mode_background</item>
<item name="alertDialogTheme">@style/ownCloud.AlertDialog</item>
@ -72,7 +72,11 @@
<item name="editTextStyle">@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox</item>
</style>
<style name="FallbackDatePickerDialogTheme" parent="Theme.MaterialComponents.DayNight.Dialog.Alert">
<style name="TextInputLayoutInputWarning" parent="Widget.App.TextInputLayout">
<item name="colorError">@color/primary</item>
</style>
<style name="FallbackDatePickerDialogTheme" parent="Theme.MaterialComponents.DayNight.Dialog.Alert">
<item name="colorPrimary">@color/bg_default</item>
<item name="android:textAllCaps">false</item>
<item name="android:windowBackground">@color/bg_default</item>
@ -96,14 +100,14 @@
<item name="android:textAllCaps">false</item>
<item name="textInputStyle">@style/Widget.App.TextInputLayout</item>
<item name="android:buttonBarButtonStyle">@style/FallbackTheming.Dialog.ButtonStyle</item>
</style>
</style>
<style name="FallbackTheming.Dialog.ButtonStyle"
parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/text_color</item>
</style>
<!-- separate action bar style for activities without an action bar -->
<!-- separate action bar style for activities without an action bar -->
<style name="BaseTheme.ownCloud.Toolbar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="actionModeBackground">@color/action_mode_background</item>
<item name="alertDialogTheme">@style/ownCloud.AlertDialog</item>
@ -137,48 +141,48 @@
</style>
<style name="Theme.ownCloud.noActionBar.LoginBase" parent="Theme.ownCloud.Toolbar">
<item name="android:windowBackground">@color/primary</item>
<item name="android:windowBackground">@color/primary</item>
<item name="colorControlNormal">@color/login_text_color</item>
<item name="colorControlActivated">@color/login_text_color</item>
<item name="colorControlHighlight">@color/login_text_color</item>
<item name="colorAccent">@color/login_text_hint_color</item>
<item name="android:textColorHint">@color/login_text_hint_color</item>
<item name="colorAccent">@color/login_text_hint_color</item>
<item name="android:textColorHint">@color/login_text_hint_color</item>
<item name="android:navigationBarColor">@color/primary</item>
</style>
</style>
<style name="Theme.ownCloud.noActionBar.Login" parent="Theme.ownCloud.noActionBar.LoginBase" />
<style name="ownCloud.AlertDialog" parent="Theme.MaterialComponents.DayNight.Dialog.Alert">
<item name="colorAccent">@color/color_accent</item>
<item name="searchViewStyle">@style/ownCloud.SearchView</item>
<style name="ownCloud.AlertDialog" parent="Theme.MaterialComponents.DayNight.Dialog.Alert">
<item name="colorAccent">@color/color_accent</item>
<item name="searchViewStyle">@style/ownCloud.SearchView</item>
<item name="android:textAllCaps">false</item>
<item name="android:windowBackground">@color/bg_default</item>
<item name="textInputStyle">@style/Widget.App.TextInputLayout</item>
</style>
<style name="ownCloud.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog">
<item name="searchViewStyle">@style/ownCloud.SearchView</item>
<style name="ownCloud.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog">
<item name="searchViewStyle">@style/ownCloud.SearchView</item>
<item name="android:textAllCaps">false</item>
<item name="textInputStyle">@style/Widget.App.TextInputLayout</item>
</style>
</style>
<style name="ProgressDialogTheme" parent="ownCloud.Dialog">
<item name="colorAccent">@color/color_accent</item>
<item name="android:windowFrame">@color/transparent</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowTitleBackgroundStyle">@drawable/process_dialog_background</item>
</style>
<style name="ProgressDialogTheme" parent="ownCloud.Dialog">
<item name="colorAccent">@color/color_accent</item>
<item name="android:windowFrame">@color/transparent</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowTitleBackgroundStyle">@drawable/process_dialog_background</item>
</style>
<style name="ownCloud.SearchView" parent="Widget.AppCompat.SearchView">
<!-- Close button icon -->
<item name="closeIcon">@drawable/ic_close</item>
<!-- Search button icon -->
<item name="searchIcon">@drawable/ic_search_grey</item>
<!-- Layout for query suggestion rows // unused for now, staying with the standard layout -->
<!--<item name="suggestionRowLayout">...</item>-->
</style>
<style name="ownCloud.SearchView" parent="Widget.AppCompat.SearchView">
<!-- Close button icon -->
<item name="closeIcon">@drawable/ic_close</item>
<!-- Search button icon -->
<item name="searchIcon">@drawable/ic_search_grey</item>
<!-- Layout for query suggestion rows // unused for now, staying with the standard layout -->
<!--<item name="suggestionRowLayout">...</item>-->
</style>
<style name="Button" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<style name="Button" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="colorButtonNormal">@color/secondary_button_background_color</item>
<item name="android:textColor">@color/secondary_button_text_color</item>
<item name="android:textAllCaps">false</item>
@ -237,85 +241,85 @@
<item name="android:textStyle">bold</item>
</style>
<!-- separat translucent action bar style -->
<style name="Theme.ownCloud.OverlayBase" parent="Theme.ownCloud">
<item name="android:actionBarStyle">@style/Theme.ownCloud.Overlay.ActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowFullscreen">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/Theme.ownCloud.Overlay.ActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- separate translucent action bar style -->
<style name="Theme.ownCloud.OverlayBase" parent="Theme.ownCloud">
<item name="android:actionBarStyle">@style/Theme.ownCloud.Overlay.ActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowFullscreen">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/Theme.ownCloud.Overlay.ActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="Theme.ownCloud.Overlay" parent="Theme.ownCloud.OverlayBase">
<item name="android:navigationBarColor">@color/black</item>
</style>
<!-- ACTION BAR STYLES -->
<style name="Theme.ownCloud.Overlay.ActionBar" parent="@style/Widget.MaterialComponents.Toolbar">
<item name="android:background">@color/color_transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="background">@color/color_transparent</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- ACTION BAR STYLES -->
<style name="Theme.ownCloud.Overlay.ActionBar" parent="@style/Widget.MaterialComponents.Toolbar">
<item name="android:background">@color/color_transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="background">@color/color_transparent</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- Launch screen -->
<style name="Theme.ownCloud.Launcher">
<!-- Launch screen -->
<style name="Theme.ownCloud.Launcher">
<item name="android:statusBarColor">@color/primary</item>
<item name="android:navigationBarColor">@color/primary</item>
<item name="android:windowBackground">@drawable/launch_screen</item>
<item name="android:textColorHint">@color/secondary_text_color</item>
</style>
<style name="Theme.ownCloud.Fullscreen" parent="@style/Theme.MaterialComponents.DayNight">
<item name="android:windowFullscreen">true</item>
<item name="colorAccent">@color/color_accent</item>
</style>
<style name="Theme.ownCloud.Widget.ActionBar"
parent="@style/Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<item name="android:background">@color/primary</item>
<item name="background">@color/primary</item>
<item name="android:textColor">@color/text_color</item>
<item name="android:shadowColor">@color/actionbar_shadow</item>
<item name="android:shadowRadius">1</item>
<item name="android:shadowDy">1</item>
<item name="android:backgroundSplit">@drawable/split_action_bg</item>
</style>
<style name="Theme.ownCloud.Fullscreen" parent="@style/Theme.MaterialComponents.DayNight">
<item name="android:windowFullscreen">true</item>
<item name="colorAccent">@color/color_accent</item>
</style>
<!-- Dialogs -->
<style name="Theme.ownCloud.Dialog" parent="@style/Theme.MaterialComponents.DayNight.Dialog.Alert">
<item name="windowNoTitle">false</item>
<item name="colorAccent">@color/color_accent</item>
<style name="Theme.ownCloud.Widget.ActionBar"
parent="@style/Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<item name="android:background">@color/primary</item>
<item name="background">@color/primary</item>
<item name="android:textColor">@color/text_color</item>
<item name="android:shadowColor">@color/actionbar_shadow</item>
<item name="android:shadowRadius">1</item>
<item name="android:shadowDy">1</item>
<item name="android:backgroundSplit">@drawable/split_action_bg</item>
</style>
<!-- Dialogs -->
<style name="Theme.ownCloud.Dialog" parent="@style/Theme.MaterialComponents.DayNight.Dialog.Alert">
<item name="windowNoTitle">false</item>
<item name="colorAccent">@color/color_accent</item>
<item name="android:windowBackground">@color/bg_default</item>
<item name="android:textAllCaps">false</item>
<item name="textInputStyle">@style/Widget.App.TextInputLayout</item>
</style>
<style name="Theme.ownCloud.Dialog.NoTitle" parent="@style/Theme.ownCloud.Dialog">
<item name="windowNoTitle">true</item>
<item name="colorAccent">@color/color_accent</item>
</style>
<style name="Theme.ownCloud.Dialog.NoTitle" parent="@style/Theme.ownCloud.Dialog">
<item name="windowNoTitle">true</item>
<item name="colorAccent">@color/color_accent</item>
</style>
<style name="NavigationView_ItemTextAppearance">
<item name="android:ellipsize">end</item>
<item name="android:listDivider">@color/transparent</item>
<style name="NavigationView_ItemTextAppearance">
<item name="android:ellipsize">end</item>
<item name="android:listDivider">@color/transparent</item>
<!-- Color of text and icon when selected -->
<item name="colorPrimary">@color/drawer_active_item_background</item>
</style>
</style>
<style name="PassCodeStyle">
<item name="android:layout_width">50dp</item>
<item name="android:layout_height">50dp</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">10dp</item>
<item name="android:inputType">numberDecimal</item>
<item name="android:numeric">decimal</item>
<item name="android:digits">1234567890</item>
<item name="android:maxLength">1</item>
<item name="android:password">true</item>
<item name="android:maxLines">1</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">10dp</item>
<item name="android:inputType">numberDecimal</item>
<item name="android:numeric">decimal</item>
<item name="android:digits">1234567890</item>
<item name="android:maxLength">1</item>
<item name="android:password">true</item>
<item name="android:maxLines">1</item>
<item name="colorPrimary">@color/text_color</item>
</style>
@ -324,13 +328,13 @@
<item name="windowNoTitle">true</item>
</style>
<!-- Text styles -->
<style name="NextcloudTextAppearanceHeadline" parent="@style/TextAppearance.AppCompat.Headline">
<item name="android:textSize">26sp</item>
<item name="android:textColor">@color/text_color</item>
</style>
<style name="NextcloudTextAppearanceMedium" parent="@style/TextAppearance.AppCompat.Medium">
</style>
<!-- Text styles -->
<style name="NextcloudTextAppearanceHeadline" parent="@style/TextAppearance.AppCompat.Headline">
<item name="android:textSize">26sp</item>
<item name="android:textColor">@color/text_color</item>
</style>
<style name="NextcloudTextAppearanceMedium" parent="@style/TextAppearance.AppCompat.Medium">
</style>
<style name="Widget.App.Login.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.Login.TextInputLayout</item>
@ -363,9 +367,9 @@
<item name="android:textColor">@color/white</item>
</style>
<style name="AppTabTextAppearance" parent="@style/TextAppearance.Design.Tab">
<item name="android:textSize">16sp</item>
<item name="textAllCaps">false</item>
<style name="AppTabTextAppearance" parent="@style/TextAppearance.Design.Tab">
<item name="android:textSize">16sp</item>
<item name="textAllCaps">false</item>
<item name="android:textColor">@color/text_color</item>
</style>