2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/15508: Show error when trying to save empty or invalid bookmark URL (https://github.com/mozilla-mobile/fenix/pull/15674)

This commit is contained in:
Jocelyne Abi Haidar 2020-10-23 00:22:37 +03:00 committed by GitHub
parent f64cef61e8
commit 089fe7a9fd
3 changed files with 57 additions and 14 deletions

View File

@ -5,7 +5,10 @@
package org.mozilla.fenix.library.bookmarks.edit package org.mozilla.fenix.library.bookmarks.edit
import android.content.DialogInterface import android.content.DialogInterface
import android.content.res.ColorStateList
import android.os.Bundle import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
@ -13,6 +16,7 @@ import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
@ -134,6 +138,23 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
placeCursorAtEnd() placeCursorAtEnd()
showKeyboard() showKeyboard()
} }
view.bookmarkUrlEdit.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
// NOOP
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
bookmarkUrlEdit.onTextChanged(s)
inputLayoutBookmarkUrl.error = null
inputLayoutBookmarkUrl.errorIconDrawable = null
}
override fun afterTextChanged(s: Editable?) {
// NOOP
}
})
} }
} }
@ -245,13 +266,24 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
) )
) )
} }
withContext(Main) {
inputLayoutBookmarkUrl.error = null
inputLayoutBookmarkUrl.errorIconDrawable = null
findNavController().popBackStack()
}
} catch (e: UrlParseFailed) { } catch (e: UrlParseFailed) {
withContext(Main) { withContext(Main) {
bookmarkUrlEdit.error = getString(R.string.bookmark_invalid_url_error) inputLayoutBookmarkUrl.error = getString(R.string.bookmark_invalid_url_error)
inputLayoutBookmarkUrl.setErrorIconDrawable(R.drawable.mozac_ic_warning_with_bottom_padding)
inputLayoutBookmarkUrl.setErrorIconTintList(
ColorStateList.valueOf(
ContextCompat.getColor(requireContext(), R.color.design_error)
)
)
} }
} }
} }
progress_bar_bookmark.visibility = View.INVISIBLE progress_bar_bookmark.visibility = View.INVISIBLE
findNavController().popBackStack()
} }
} }

View File

@ -46,6 +46,10 @@ class ClearableEditText @JvmOverloads constructor(
* Displays a clear icon if text has been entered. * Displays a clear icon if text has been entered.
*/ */
override fun onTextChanged(text: CharSequence?, start: Int, lengthBefore: Int, lengthAfter: Int) { override fun onTextChanged(text: CharSequence?, start: Int, lengthBefore: Int, lengthAfter: Int) {
onTextChanged(text)
}
fun onTextChanged(text: CharSequence?) {
// lengthAfter has inconsistent behaviour when there are spaces in the entered text, so we'll use text.length. // lengthAfter has inconsistent behaviour when there are spaces in the entered text, so we'll use text.length.
val textLength = text?.length ?: 0 val textLength = text?.length ?: 0
val drawable = if (shouldShowClearButton(textLength)) { val drawable = if (shouldShowClearButton(textLength)) {

View File

@ -59,19 +59,26 @@
android:textColor="?primaryText" android:textColor="?primaryText"
android:textSize="12sp" /> android:textSize="12sp" />
<org.mozilla.fenix.utils.ClearableEditText <com.google.android.material.textfield.TextInputLayout
android:id="@+id/bookmarkUrlEdit" android:id="@+id/inputLayoutBookmarkUrl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/bookmark_edit_text_height" android:layout_height="wrap_content">
android:layout_marginBottom="8dp"
android:drawablePadding="8dp" <org.mozilla.fenix.utils.ClearableEditText
android:ellipsize="none" android:id="@+id/bookmarkUrlEdit"
android:fadingEdgeLength="8dp" android:layout_width="match_parent"
android:inputType="textUri" android:layout_height="@dimen/bookmark_edit_text_height"
android:requiresFadingEdge="horizontal" android:layout_marginBottom="8dp"
android:textColor="?secondaryText" android:drawablePadding="8dp"
android:textSize="15sp" android:ellipsize="none"
tools:text="https://www.mozilla.org/en-US/" /> android:fadingEdgeLength="8dp"
android:inputType="textUri"
android:requiresFadingEdge="horizontal"
android:textColor="?secondaryText"
android:textSize="15sp"
tools:text="https://www.mozilla.org/en-US/" />
</com.google.android.material.textfield.TextInputLayout>
<TextView <TextView
android:id="@+id/bookmark_folder_label" android:id="@+id/bookmark_folder_label"