mirror of
https://github.com/afollestad/nock-nock.git
synced 2025-08-17 07:50:15 +00:00
Don't save changes to existing site if validation doesn't pass. Resolves #22.
This commit is contained in:
parent
a8bcc60496
commit
c7096e8746
1 changed files with 12 additions and 5 deletions
|
@ -17,6 +17,7 @@ import android.util.Patterns.WEB_URL
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
|
import androidx.annotation.CheckResult
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
|
@ -285,7 +286,7 @@ class ViewSiteActivity : AppCompatActivity(),
|
||||||
safeUnregisterReceiver(intentReceiver)
|
safeUnregisterReceiver(intentReceiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateModelFromInput(withValidation: Boolean) {
|
@CheckResult private fun updateModelFromInput(withValidation: Boolean): Boolean {
|
||||||
currentModel = currentModel.copy(
|
currentModel = currentModel.copy(
|
||||||
name = inputName.trimmedText(),
|
name = inputName.trimmedText(),
|
||||||
url = inputUrl.trimmedText(),
|
url = inputUrl.trimmedText(),
|
||||||
|
@ -294,19 +295,19 @@ class ViewSiteActivity : AppCompatActivity(),
|
||||||
|
|
||||||
if (withValidation && currentModel.name.isEmpty()) {
|
if (withValidation && currentModel.name.isEmpty()) {
|
||||||
inputName.error = getString(R.string.please_enter_name)
|
inputName.error = getString(R.string.please_enter_name)
|
||||||
return
|
return false
|
||||||
} else {
|
} else {
|
||||||
inputName.error = null
|
inputName.error = null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withValidation && currentModel.url.isEmpty()) {
|
if (withValidation && currentModel.url.isEmpty()) {
|
||||||
inputUrl.error = getString(R.string.please_enter_url)
|
inputUrl.error = getString(R.string.please_enter_url)
|
||||||
return
|
return false
|
||||||
} else {
|
} else {
|
||||||
inputUrl.error = null
|
inputUrl.error = null
|
||||||
if (withValidation && !WEB_URL.matcher(currentModel.url).find()) {
|
if (withValidation && !WEB_URL.matcher(currentModel.url).find()) {
|
||||||
inputUrl.error = getString(R.string.please_enter_valid_url)
|
inputUrl.error = getString(R.string.please_enter_valid_url)
|
||||||
return
|
return false
|
||||||
} else {
|
} else {
|
||||||
val uri = Uri.parse(currentModel.url)
|
val uri = Uri.parse(currentModel.url)
|
||||||
if (uri.scheme == null) {
|
if (uri.scheme == null) {
|
||||||
|
@ -325,6 +326,8 @@ class ViewSiteActivity : AppCompatActivity(),
|
||||||
validationMode = selectedValidationMode,
|
validationMode = selectedValidationMode,
|
||||||
validationContent = selectedValidationContent
|
validationContent = selectedValidationContent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save button
|
// Save button
|
||||||
|
@ -332,7 +335,11 @@ class ViewSiteActivity : AppCompatActivity(),
|
||||||
rootView.scopeWhileAttached(Main) {
|
rootView.scopeWhileAttached(Main) {
|
||||||
launch(coroutineContext) {
|
launch(coroutineContext) {
|
||||||
content_loading_progress.show()
|
content_loading_progress.show()
|
||||||
updateModelFromInput(true)
|
if (!updateModelFromInput(true)) {
|
||||||
|
// Validation didn't pass
|
||||||
|
content_loading_progress.hide()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
async(IO) { serverModelStore.update(currentModel) }.await()
|
async(IO) { serverModelStore.update(currentModel) }.await()
|
||||||
checkStatusManager.cancelCheck(currentModel)
|
checkStatusManager.cancelCheck(currentModel)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue