Validate server URLs
This commit is contained in:
parent
2b0fa4f9ec
commit
fc27b0ce99
4 changed files with 14 additions and 3 deletions
|
@ -1,7 +1,6 @@
|
||||||
package io.heckel.ntfy.ui
|
package io.heckel.ntfy.ui
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
|
@ -10,6 +9,7 @@ import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
|
import android.widget.Button
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
|
@ -297,6 +297,13 @@ class SettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.OnPrefere
|
||||||
return repository.getDefaultBaseUrl()
|
return repository.getDefaultBaseUrl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
defaultBaseUrl?.setOnBindEditTextListener { editText ->
|
||||||
|
editText.addTextChangedListener(AfterChangedTextWatcher {
|
||||||
|
val okayButton: Button = editText.rootView.findViewById(android.R.id.button1)
|
||||||
|
val value = editText.text.toString()
|
||||||
|
okayButton.isEnabled = value.isEmpty() || validUrl(value)
|
||||||
|
})
|
||||||
|
}
|
||||||
defaultBaseUrl?.summaryProvider = Preference.SummaryProvider<EditTextPreference> { pref ->
|
defaultBaseUrl?.summaryProvider = Preference.SummaryProvider<EditTextPreference> { pref ->
|
||||||
if (TextUtils.isEmpty(pref.text)) {
|
if (TextUtils.isEmpty(pref.text)) {
|
||||||
getString(R.string.settings_general_default_base_url_default_summary, appBaseUrl)
|
getString(R.string.settings_general_default_base_url_default_summary, appBaseUrl)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.fragment.app.DialogFragment
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
import io.heckel.ntfy.R
|
import io.heckel.ntfy.R
|
||||||
import io.heckel.ntfy.db.User
|
import io.heckel.ntfy.db.User
|
||||||
|
import io.heckel.ntfy.util.validUrl
|
||||||
|
|
||||||
class UserFragment : DialogFragment() {
|
class UserFragment : DialogFragment() {
|
||||||
private var user: User? = null
|
private var user: User? = null
|
||||||
|
@ -167,7 +168,7 @@ class UserFragment : DialogFragment() {
|
||||||
val username = usernameView.text?.toString() ?: ""
|
val username = usernameView.text?.toString() ?: ""
|
||||||
val password = passwordView.text?.toString() ?: ""
|
val password = passwordView.text?.toString() ?: ""
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
positiveButton.isEnabled = (baseUrl.startsWith("http://") || baseUrl.startsWith("https://"))
|
positiveButton.isEnabled = validUrl(baseUrl)
|
||||||
&& !baseUrlsInUse.contains(baseUrl)
|
&& !baseUrlsInUse.contains(baseUrl)
|
||||||
&& username.isNotEmpty() && password.isNotEmpty()
|
&& username.isNotEmpty() && password.isNotEmpty()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -71,7 +71,7 @@ fun validTopic(topic: String): Boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validUrl(url: String): Boolean {
|
fun validUrl(url: String): Boolean {
|
||||||
return "^https?://.+".toRegex().matches(url)
|
return "^https?://\\S+".toRegex().matches(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun formatDateShort(timestampSecs: Long): String {
|
fun formatDateShort(timestampSecs: Long): String {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
Features:
|
Features:
|
||||||
* Support for ntfy:// deep links (#20, thanks to @Copephobia for reporting)
|
* Support for ntfy:// deep links (#20, thanks to @Copephobia for reporting)
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
* Validate URLs when changing default server and server in user management (#193, thanks to @StoyanDimitrov)
|
||||||
|
|
||||||
Translations:
|
Translations:
|
||||||
* Japanese (thanks to @shak)
|
* Japanese (thanks to @shak)
|
||||||
|
|
Loading…
Reference in a new issue