Check if category name is not empty
This commit is contained in:
@@ -7,7 +7,6 @@ import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.databinding.ItemStorageBinding
|
||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||
|
||||
@@ -6,11 +6,10 @@ import android.text.InputFilter
|
||||
import android.view.LayoutInflater
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.koitharu.kotatsu.databinding.DialogInputBinding
|
||||
|
||||
class TextInputDialog private constructor(
|
||||
private val delegate: AlertDialog
|
||||
private val delegate: AlertDialog,
|
||||
) : DialogInterface by delegate {
|
||||
|
||||
fun show() = delegate.show()
|
||||
@@ -33,7 +32,7 @@ class TextInputDialog private constructor(
|
||||
}
|
||||
|
||||
fun setHint(@StringRes hintResId: Int): Builder {
|
||||
binding.inputLayout.hint = binding.root.context.getString(hintResId)
|
||||
binding.inputEdit.hint = binding.root.context.getString(hintResId)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -64,7 +63,7 @@ class TextInputDialog private constructor(
|
||||
listener: (DialogInterface, String) -> Unit
|
||||
): Builder {
|
||||
delegate.setPositiveButton(textId) { dialog, _ ->
|
||||
listener(dialog, binding.inputEdit.text.toString().orEmpty())
|
||||
listener(dialog, binding.inputEdit.text?.toString().orEmpty())
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.favourites.ui.categories
|
||||
|
||||
import android.content.Context
|
||||
import android.text.InputType
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.base.ui.dialog.TextInputDialog
|
||||
@@ -32,7 +33,12 @@ class CategoriesEditDelegate(
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setMaxLength(MAX_TITLE_LENGTH, false)
|
||||
.setPositiveButton(R.string.rename) { _, name ->
|
||||
callback.onRenameCategory(category, name)
|
||||
val trimmed = name.trim()
|
||||
if (trimmed.isEmpty()) {
|
||||
Toast.makeText(context, R.string.error_empty_name, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
callback.onRenameCategory(category, name)
|
||||
}
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
@@ -45,7 +51,12 @@ class CategoriesEditDelegate(
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setMaxLength(MAX_TITLE_LENGTH, false)
|
||||
.setPositiveButton(R.string.add) { _, name ->
|
||||
callback.onCreateCategory(name)
|
||||
val trimmed = name.trim()
|
||||
if (trimmed.isEmpty()) {
|
||||
Toast.makeText(context, R.string.error_empty_name, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
callback.onCreateCategory(trimmed)
|
||||
}
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package org.koitharu.kotatsu.settings
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.preference.*
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
|
||||
import org.koitharu.kotatsu.base.ui.dialog.StorageSelectDialog
|
||||
import org.koitharu.kotatsu.base.ui.dialog.TextInputDialog
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||
import org.koitharu.kotatsu.settings.protect.ProtectSetupActivity
|
||||
import org.koitharu.kotatsu.utils.ext.*
|
||||
import org.koitharu.kotatsu.utils.ext.getStorageName
|
||||
import org.koitharu.kotatsu.utils.ext.names
|
||||
import org.koitharu.kotatsu.utils.ext.setDefaultValueCompat
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
@@ -134,53 +132,4 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
|
||||
settings.setStorageDir(context ?: return, file)
|
||||
}
|
||||
|
||||
private fun enableAppProtection(preference: SwitchPreference) {
|
||||
val ctx = preference.context ?: return
|
||||
val cancelListener =
|
||||
object : DialogInterface.OnCancelListener, DialogInterface.OnClickListener {
|
||||
|
||||
override fun onCancel(dialog: DialogInterface?) {
|
||||
settings.appPassword = null
|
||||
preference.isChecked = false
|
||||
preference.isEnabled = true
|
||||
}
|
||||
|
||||
override fun onClick(dialog: DialogInterface?, which: Int) = onCancel(dialog)
|
||||
}
|
||||
preference.isEnabled = false
|
||||
TextInputDialog.Builder(ctx)
|
||||
.setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
|
||||
.setHint(R.string.enter_password)
|
||||
.setNegativeButton(android.R.string.cancel, cancelListener)
|
||||
.setOnCancelListener(cancelListener)
|
||||
.setPositiveButton(android.R.string.ok) { d, password ->
|
||||
if (password.isBlank()) {
|
||||
cancelListener.onCancel(d)
|
||||
return@setPositiveButton
|
||||
}
|
||||
TextInputDialog.Builder(ctx)
|
||||
.setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
|
||||
.setHint(R.string.repeat_password)
|
||||
.setNegativeButton(android.R.string.cancel, cancelListener)
|
||||
.setOnCancelListener(cancelListener)
|
||||
.setPositiveButton(android.R.string.ok) { d2, password2 ->
|
||||
if (password == password2) {
|
||||
settings.appPassword = password.md5()
|
||||
preference.isChecked = true
|
||||
preference.isEnabled = true
|
||||
} else {
|
||||
cancelListener.onCancel(d2)
|
||||
Snackbar.make(
|
||||
listView,
|
||||
R.string.passwords_mismatch,
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}.setTitle(preference.title)
|
||||
.create()
|
||||
.show()
|
||||
}.setTitle(preference.title)
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user