Ask for old apssword in SetupWizard
This commit is contained in:
parent
02b77ae554
commit
4b6d4d287c
|
@ -127,7 +127,7 @@ class SetupWizardActivity : NoSplashAppCompatActivity() {
|
|||
override fun updateButtons() {
|
||||
runOnUiThread {
|
||||
val currentScreen = screens[currentWizardPage]
|
||||
if (currentScreen.validator == null || currentScreen.validator!!.isValid || currentScreen.skippable) {
|
||||
if (currentScreen.validator == null || currentScreen.validator?.isValid == true || currentScreen.skippable) {
|
||||
if (currentWizardPage == nextPage(null)) {
|
||||
findViewById<View>(R.id.finish_button).visibility = View.VISIBLE
|
||||
findViewById<View>(R.id.next_button).visibility = View.GONE
|
||||
|
@ -184,7 +184,7 @@ class SetupWizardActivity : NoSplashAppCompatActivity() {
|
|||
private fun nextPage(view: View?): Int {
|
||||
var page = currentWizardPage + 1
|
||||
while (page < screens.size) {
|
||||
if (screens[page].visibility == null || screens[page].visibility!!.isValid) return page
|
||||
if (screens[page].visibility == null || screens[page].visibility?.isValid == true) return page
|
||||
page++
|
||||
}
|
||||
return min(currentWizardPage, screens.size - 1)
|
||||
|
@ -194,7 +194,7 @@ class SetupWizardActivity : NoSplashAppCompatActivity() {
|
|||
private fun previousPage(view: View?): Int {
|
||||
var page = currentWizardPage - 1
|
||||
while (page >= 0) {
|
||||
if (screens[page].visibility == null || screens[page].visibility!!.isValid) return page
|
||||
if (screens[page].visibility == null || screens[page].visibility?.isValid == true) return page
|
||||
page--
|
||||
}
|
||||
return max(currentWizardPage, 0)
|
||||
|
|
|
@ -5,11 +5,13 @@ import android.text.Editable
|
|||
import android.text.InputType
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.setupwizard.SWTextValidator
|
||||
import info.nightscout.androidaps.utils.CryptoUtil
|
||||
|
||||
|
@ -17,36 +19,71 @@ class SWEditEncryptedPassword(injector: HasAndroidInjector, private val cryptoUt
|
|||
|
||||
private var validator: SWTextValidator = SWTextValidator(String::isNotEmpty)
|
||||
private var updateDelay = 0L
|
||||
private var button: Button? = null
|
||||
private var editText: EditText? = null
|
||||
private var editText2: EditText? = null
|
||||
private var l: TextView? = null
|
||||
private var c: TextView? = null
|
||||
private var c2: TextView? = null
|
||||
|
||||
override fun generateDialog(layout: LinearLayout) {
|
||||
val context = layout.context
|
||||
val l = TextView(context)
|
||||
l.id = View.generateViewId()
|
||||
label?.let { l.setText(it) }
|
||||
l.setTypeface(l.typeface, Typeface.BOLD)
|
||||
layout.addView(l)
|
||||
val c = TextView(context)
|
||||
c.id = View.generateViewId()
|
||||
comment?.let { c.setText(it) }
|
||||
c.setTypeface(c.typeface, Typeface.ITALIC)
|
||||
layout.addView(c)
|
||||
val editText = EditText(context)
|
||||
editText.id = View.generateViewId()
|
||||
editText.inputType = InputType.TYPE_CLASS_TEXT
|
||||
editText.maxLines = 1
|
||||
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
val isPasswordSet = sp.contains(R.string.key_master_password) && sp.getString(R.string.key_master_password, "") != ""
|
||||
|
||||
button = Button(context)
|
||||
button?.setText(R.string.unlock_settings)
|
||||
button?.setOnClickListener {
|
||||
scanForActivity(context)?.let { activity ->
|
||||
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, {
|
||||
button?.visibility = View.GONE
|
||||
editText?.visibility = View.VISIBLE
|
||||
editText2?.visibility = View.VISIBLE
|
||||
l?.visibility = View.VISIBLE
|
||||
c?.visibility = View.VISIBLE
|
||||
c2?.visibility = View.VISIBLE
|
||||
})
|
||||
}
|
||||
}
|
||||
button?.visibility = isPasswordSet.toVisibility()
|
||||
layout.addView(button)
|
||||
|
||||
label?.let {
|
||||
l = TextView(context)
|
||||
l?.id = View.generateViewId()
|
||||
l?.setText(it)
|
||||
l?.setTypeface(l?.typeface, Typeface.BOLD)
|
||||
layout.addView(l)
|
||||
}
|
||||
|
||||
comment?.let {
|
||||
c = TextView(context)
|
||||
c?.id = View.generateViewId()
|
||||
c?.setText(it)
|
||||
c?.setTypeface(c?.typeface, Typeface.ITALIC)
|
||||
c?.visibility = isPasswordSet.not().toVisibility()
|
||||
layout.addView(c)
|
||||
}
|
||||
|
||||
editText = EditText(context)
|
||||
editText?.id = View.generateViewId()
|
||||
editText?.inputType = InputType.TYPE_CLASS_TEXT
|
||||
editText?.maxLines = 1
|
||||
editText?.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
editText?.visibility = isPasswordSet.not().toVisibility()
|
||||
layout.addView(editText)
|
||||
|
||||
val c2 = TextView(context)
|
||||
c2.id = View.generateViewId()
|
||||
c2.setText(R.string.confirm)
|
||||
c2 = TextView(context)
|
||||
c2?.id = View.generateViewId()
|
||||
c2?.setText(R.string.confirm)
|
||||
c2?.visibility = isPasswordSet.not().toVisibility()
|
||||
layout.addView(c2)
|
||||
|
||||
val editText2 = EditText(context)
|
||||
editText2.id = View.generateViewId()
|
||||
editText2.inputType = InputType.TYPE_CLASS_TEXT
|
||||
editText2.maxLines = 1
|
||||
editText2.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
editText2 = EditText(context)
|
||||
editText2?.id = View.generateViewId()
|
||||
editText2?.inputType = InputType.TYPE_CLASS_TEXT
|
||||
editText2?.maxLines = 1
|
||||
editText2?.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
editText2?.visibility = isPasswordSet.not().toVisibility()
|
||||
layout.addView(editText2)
|
||||
|
||||
super.generateDialog(layout)
|
||||
|
@ -55,14 +92,14 @@ class SWEditEncryptedPassword(injector: HasAndroidInjector, private val cryptoUt
|
|||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
sp.remove(preferenceId)
|
||||
scheduleChange(updateDelay)
|
||||
if (validator.isValid(editText.text.toString()) && validator.isValid(editText2.text.toString()) && editText.text.toString() == editText2.text.toString())
|
||||
if (validator.isValid(editText?.text.toString()) && validator.isValid(editText2?.text.toString()) && editText?.text.toString() == editText2?.text.toString())
|
||||
save(s.toString(), updateDelay)
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
}
|
||||
editText.addTextChangedListener(watcher)
|
||||
editText2.addTextChangedListener(watcher)
|
||||
editText?.addTextChangedListener(watcher)
|
||||
editText2?.addTextChangedListener(watcher)
|
||||
}
|
||||
|
||||
fun preferenceId(preferenceId: Int): SWEditEncryptedPassword {
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package info.nightscout.androidaps.setupwizard.elements
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
|
||||
import info.nightscout.androidaps.utils.protection.PasswordCheck
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import java.util.concurrent.Executors
|
||||
|
@ -22,6 +26,7 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) {
|
|||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var passwordCheck: PasswordCheck
|
||||
|
||||
private val eventWorker = Executors.newSingleThreadScheduledExecutor()
|
||||
private var scheduledEventPost: ScheduledFuture<*>? = null
|
||||
|
@ -33,6 +38,7 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) {
|
|||
|
||||
@Suppress("unused")
|
||||
enum class Type {
|
||||
|
||||
NONE, TEXT, HTML_LINK, BREAK, LISTENER, URL, STRING, NUMBER, DECIMAL_NUMBER, RADIOBUTTON, PLUGIN, BUTTON, FRAGMENT, UNIT_NUMBER, PREFERENCE
|
||||
}
|
||||
|
||||
|
@ -79,4 +85,13 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) {
|
|||
val task: Runnable = PostRunnable()
|
||||
scheduledEventPost = eventWorker.schedule(task, updateDelay, TimeUnit.SECONDS)
|
||||
}
|
||||
|
||||
fun scanForActivity(cont: Context?): AppCompatActivity? {
|
||||
return when (cont) {
|
||||
null -> null
|
||||
is AppCompatActivity -> cont
|
||||
is ContextWrapper -> scanForActivity(cont.baseContext)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
|||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
init {
|
||||
@Suppress("LeakingThis")
|
||||
injector.androidInjector().inject(this)
|
||||
}
|
||||
|
||||
|
@ -55,16 +56,12 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
|||
abstract fun icon(): Optional<Int?>
|
||||
abstract fun duplicate(): Trigger
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
fun scanForActivity(cont: Context?): AppCompatActivity? {
|
||||
return when (cont) {
|
||||
null -> null
|
||||
is AppCompatActivity -> cont
|
||||
is ContextWrapper -> scanForActivity(cont.baseContext)
|
||||
else -> null
|
||||
}
|
||||
private fun scanForActivity(cont: Context?): AppCompatActivity? {
|
||||
return when (cont) {
|
||||
null -> null
|
||||
is AppCompatActivity -> cont
|
||||
is ContextWrapper -> scanForActivity(cont.baseContext)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,26 +77,34 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
|||
.put("data", dataJSON())
|
||||
.toString()
|
||||
|
||||
fun instantiate(obj: JSONObject): Trigger? {
|
||||
fun instantiate(obj: JSONObject): Trigger {
|
||||
val type = obj.getString("type")
|
||||
val data = obj.getJSONObject("data")
|
||||
//val clazz = Class.forName(type).kotlin
|
||||
//return (clazz.primaryConstructor?.call(injector) as Trigger).fromJSON(data?.toString() ?: "")
|
||||
return when (type) {
|
||||
TriggerAutosensValue::class.java.name, // backward compatibility
|
||||
TriggerAutosensValue::class.java.simpleName -> TriggerAutosensValue(injector).fromJSON(data.toString())
|
||||
TriggerAutosensValue::class.java.simpleName -> TriggerAutosensValue(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerBg::class.java.name,
|
||||
TriggerBg::class.java.simpleName -> TriggerBg(injector).fromJSON(data.toString())
|
||||
TriggerBolusAgo::class.java.name,
|
||||
TriggerBolusAgo::class.java.simpleName -> TriggerBolusAgo(injector).fromJSON(data.toString())
|
||||
TriggerBolusAgo::class.java.simpleName -> TriggerBolusAgo(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerBTDevice::class.java.name,
|
||||
TriggerBTDevice::class.java.simpleName -> TriggerBTDevice(injector).fromJSON(data.toString())
|
||||
TriggerBTDevice::class.java.simpleName -> TriggerBTDevice(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerIob::class.java.name,
|
||||
TriggerIob::class.java.simpleName -> TriggerIob(injector).fromJSON(data.toString())
|
||||
TriggerCOB::class.java.name,
|
||||
TriggerCOB::class.java.simpleName -> TriggerCOB(injector).fromJSON(data.toString())
|
||||
TriggerConnector::class.java.name,
|
||||
TriggerConnector::class.java.simpleName -> TriggerConnector(injector).fromJSON(data.toString())
|
||||
TriggerConnector::class.java.simpleName -> TriggerConnector(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerDelta::class.java.name,
|
||||
TriggerDelta::class.java.simpleName -> TriggerDelta(injector).fromJSON(data.toString())
|
||||
TriggerDummy::class.java.name,
|
||||
|
@ -107,21 +112,35 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
|||
TriggerIob::class.java.name,
|
||||
TriggerIob::class.java.simpleName -> TriggerIob(injector).fromJSON(data.toString())
|
||||
TriggerLocation::class.java.name,
|
||||
TriggerLocation::class.java.simpleName -> TriggerLocation(injector).fromJSON(data.toString())
|
||||
TriggerLocation::class.java.simpleName -> TriggerLocation(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerProfilePercent::class.java.name,
|
||||
TriggerProfilePercent::class.java.simpleName -> TriggerProfilePercent(injector).fromJSON(data.toString())
|
||||
TriggerProfilePercent::class.java.simpleName -> TriggerProfilePercent(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerPumpLastConnection::class.java.name,
|
||||
TriggerPumpLastConnection::class.java.simpleName -> TriggerPumpLastConnection(injector).fromJSON(data.toString())
|
||||
TriggerPumpLastConnection::class.java.simpleName -> TriggerPumpLastConnection(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerRecurringTime::class.java.name,
|
||||
TriggerRecurringTime::class.java.simpleName -> TriggerRecurringTime(injector).fromJSON(data.toString())
|
||||
TriggerRecurringTime::class.java.simpleName -> TriggerRecurringTime(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerTempTarget::class.java.name,
|
||||
TriggerTempTarget::class.java.simpleName -> TriggerTempTarget(injector).fromJSON(data.toString())
|
||||
TriggerTempTarget::class.java.simpleName -> TriggerTempTarget(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerTime::class.java.name,
|
||||
TriggerTime::class.java.simpleName -> TriggerTime(injector).fromJSON(data.toString())
|
||||
TriggerTimeRange::class.java.name,
|
||||
TriggerTimeRange::class.java.simpleName -> TriggerTimeRange(injector).fromJSON(data.toString())
|
||||
TriggerTimeRange::class.java.simpleName -> TriggerTimeRange(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
TriggerWifiSsid::class.java.name,
|
||||
TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON(data.toString())
|
||||
TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON(
|
||||
data.toString()
|
||||
)
|
||||
else -> throw ClassNotFoundException(type)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue