|
|
|
@ -21,7 +21,6 @@ package org.isoron.uhabits.activities.common.dialogs
|
|
|
|
|
|
|
|
|
|
import android.app.Dialog
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.widget.EditText
|
|
|
|
@ -44,7 +43,7 @@ class FrequencyPickerDialog(
|
|
|
|
|
constructor() : this(1, 1)
|
|
|
|
|
|
|
|
|
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
|
|
|
val inflater = LayoutInflater.from(activity!!)
|
|
|
|
|
val inflater = LayoutInflater.from(requireActivity())
|
|
|
|
|
contentView = inflater.inflate(R.layout.frequency_picker_dialog, null)
|
|
|
|
|
|
|
|
|
|
addBeforeAfterText(
|
|
|
|
@ -62,6 +61,11 @@ class FrequencyPickerDialog(
|
|
|
|
|
contentView.xTimesPerMonthContainer,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
addBeforeAfterText(
|
|
|
|
|
this.getString(R.string.x_times_per_y_days),
|
|
|
|
|
contentView.xTimesPerYDaysContainer,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
contentView.everyDayRadioButton.setOnClickListener {
|
|
|
|
|
check(contentView.everyDayRadioButton)
|
|
|
|
|
unfocusAll()
|
|
|
|
@ -95,7 +99,20 @@ class FrequencyPickerDialog(
|
|
|
|
|
if (hasFocus) check(contentView.xTimesPerMonthRadioButton)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AlertDialog.Builder(activity!!)
|
|
|
|
|
contentView.xTimesPerYDaysRadioButton.setOnClickListener {
|
|
|
|
|
check(contentView.xTimesPerYDaysRadioButton)
|
|
|
|
|
focus(contentView.xTimesPerYDaysXTextView)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contentView.xTimesPerYDaysXTextView.setOnFocusChangeListener { v, hasFocus ->
|
|
|
|
|
if (hasFocus) check(contentView.xTimesPerYDaysRadioButton)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contentView.xTimesPerYDaysYTextView.setOnFocusChangeListener { v, hasFocus ->
|
|
|
|
|
if (hasFocus) check(contentView.xTimesPerYDaysRadioButton)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AlertDialog.Builder(requireActivity())
|
|
|
|
|
.setView(contentView)
|
|
|
|
|
.setPositiveButton(R.string.save) { _, _ -> onSaveClicked() }
|
|
|
|
|
.create()
|
|
|
|
@ -106,12 +123,11 @@ class FrequencyPickerDialog(
|
|
|
|
|
container: LinearLayout
|
|
|
|
|
) {
|
|
|
|
|
val parts = str.split("%d")
|
|
|
|
|
container.addView(
|
|
|
|
|
TextView(activity).apply { text = parts[0].trim() }, 1,
|
|
|
|
|
)
|
|
|
|
|
container.addView(
|
|
|
|
|
TextView(activity).apply { text = parts[1].trim() }, 3,
|
|
|
|
|
)
|
|
|
|
|
for (i in parts.indices) {
|
|
|
|
|
container.addView(
|
|
|
|
|
TextView(activity).apply { text = parts[i].trim() }, 2 * i + 1,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun onSaveClicked() {
|
|
|
|
@ -132,6 +148,12 @@ class FrequencyPickerDialog(
|
|
|
|
|
denominator = 7
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
contentView.xTimesPerYDaysRadioButton.isChecked -> {
|
|
|
|
|
if (contentView.xTimesPerYDaysXTextView.text.isNotEmpty() && contentView.xTimesPerYDaysYTextView.text.isNotEmpty()) {
|
|
|
|
|
numerator = Integer.parseInt(contentView.xTimesPerYDaysXTextView.text.toString())
|
|
|
|
|
denominator = Integer.parseInt(contentView.xTimesPerYDaysYTextView.text.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else -> {
|
|
|
|
|
if (contentView.xTimesPerMonthTextView.text.isNotEmpty()) {
|
|
|
|
|
numerator = Integer.parseInt(contentView.xTimesPerMonthTextView.text.toString())
|
|
|
|
@ -147,10 +169,10 @@ class FrequencyPickerDialog(
|
|
|
|
|
dismiss()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun check(view: RadioButton?) {
|
|
|
|
|
private fun check(view: RadioButton) {
|
|
|
|
|
uncheckAll()
|
|
|
|
|
view?.isChecked = true
|
|
|
|
|
view?.requestFocus()
|
|
|
|
|
view.isChecked = true
|
|
|
|
|
view.requestFocus()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
@ -179,8 +201,9 @@ class FrequencyPickerDialog(
|
|
|
|
|
contentView.xTimesPerWeekTextView.setText(freqNumerator.toString())
|
|
|
|
|
focus(contentView.xTimesPerWeekTextView)
|
|
|
|
|
} else {
|
|
|
|
|
Log.w("FrequencyPickerDialog", "Unknown frequency: $freqNumerator/$freqDenominator")
|
|
|
|
|
contentView.everyDayRadioButton.isChecked = true
|
|
|
|
|
contentView.xTimesPerYDaysRadioButton.isChecked = true
|
|
|
|
|
contentView.xTimesPerYDaysXTextView.setText(freqNumerator.toString())
|
|
|
|
|
contentView.xTimesPerYDaysYTextView.setText(freqDenominator.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -196,6 +219,7 @@ class FrequencyPickerDialog(
|
|
|
|
|
contentView.everyXDaysRadioButton.isChecked = false
|
|
|
|
|
contentView.xTimesPerWeekRadioButton.isChecked = false
|
|
|
|
|
contentView.xTimesPerMonthRadioButton.isChecked = false
|
|
|
|
|
contentView.xTimesPerYDaysRadioButton.isChecked = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun unfocusAll() {
|
|
|
|
|