|
|
@ -14,6 +14,9 @@ import android.text.TextWatcher |
|
|
import android.view.LayoutInflater |
|
|
import android.view.LayoutInflater |
|
|
import android.view.View |
|
|
import android.view.View |
|
|
import android.view.ViewGroup |
|
|
import android.view.ViewGroup |
|
|
|
|
|
import android.view.MotionEvent |
|
|
|
|
|
import android.os.Handler |
|
|
|
|
|
import android.os.Looper |
|
|
import androidx.appcompat.app.AlertDialog |
|
|
import androidx.appcompat.app.AlertDialog |
|
|
import androidx.core.view.isVisible |
|
|
import androidx.core.view.isVisible |
|
|
import androidx.fragment.app.DialogFragment |
|
|
import androidx.fragment.app.DialogFragment |
|
|
@ -197,6 +200,54 @@ class SettingsDialogFragment : DialogFragment(), DialogInterface.OnClickListener |
|
|
updateValidity(newValue) |
|
|
updateValidity(newValue) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun attachRepeat(button: View, delta: Int) { |
|
|
|
|
|
val handler = Handler(Looper.getMainLooper()) |
|
|
|
|
|
var runnable: Runnable? = null |
|
|
|
|
|
val initialDelay = 400L |
|
|
|
|
|
val minDelay = 40L |
|
|
|
|
|
val accelerationFactor = 0.75f |
|
|
|
|
|
|
|
|
|
|
|
button.setOnTouchListener { v, event -> |
|
|
|
|
|
when (event.action) { |
|
|
|
|
|
MotionEvent.ACTION_DOWN -> { |
|
|
|
|
|
val current = spinboxBinding.editValue.text.toString().toIntOrNull() ?: currentValue |
|
|
|
|
|
val newValue = (current + delta) |
|
|
|
|
|
spinboxBinding.editValue.setText(newValue.toString()) |
|
|
|
|
|
updateValidity(newValue) |
|
|
|
|
|
|
|
|
|
|
|
var delay = initialDelay |
|
|
|
|
|
runnable = object : Runnable { |
|
|
|
|
|
override fun run() { |
|
|
|
|
|
val curr = spinboxBinding.editValue.text.toString().toIntOrNull() ?: currentValue |
|
|
|
|
|
val next = curr + delta |
|
|
|
|
|
spinboxBinding.editValue.setText(next.toString()) |
|
|
|
|
|
updateValidity(next) |
|
|
|
|
|
// accelerate |
|
|
|
|
|
delay = (delay * accelerationFactor).toLong().coerceAtLeast(minDelay) |
|
|
|
|
|
handler.postDelayed(this, delay) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
handler.postDelayed(runnable!!, initialDelay) |
|
|
|
|
|
true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { |
|
|
|
|
|
if (runnable != null) { |
|
|
|
|
|
handler.removeCallbacks(runnable!!) |
|
|
|
|
|
runnable = null |
|
|
|
|
|
} |
|
|
|
|
|
v.performClick() |
|
|
|
|
|
true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else -> false |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
attachRepeat(spinboxBinding.buttonDecrement, -1) |
|
|
|
|
|
attachRepeat(spinboxBinding.buttonIncrement, 1) |
|
|
|
|
|
|
|
|
spinboxBinding.editValue.addTextChangedListener(object : TextWatcher { |
|
|
spinboxBinding.editValue.addTextChangedListener(object : TextWatcher { |
|
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} |
|
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} |
|
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} |
|
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} |
|
|
|