|
|
|
|
@ -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()
|
|
|
|
|
}
|
|
|
|
|
}
|