mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-10 11:08:52 -06:00
Compare commits
3 Commits
35097e1263
...
4bbb20e18e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bbb20e18e | ||
|
|
4f9ab6d263 | ||
|
|
af21fd25db |
@@ -3,7 +3,6 @@ plugins {
|
|||||||
id("com.android.application") version "7.4.2" apply (false)
|
id("com.android.application") version "7.4.2" apply (false)
|
||||||
id("org.jetbrains.kotlin.android") version kotlinVersion apply (false)
|
id("org.jetbrains.kotlin.android") version kotlinVersion apply (false)
|
||||||
id("org.jetbrains.kotlin.kapt") version kotlinVersion apply (false)
|
id("org.jetbrains.kotlin.kapt") version kotlinVersion apply (false)
|
||||||
id("org.jetbrains.kotlin.android.extensions") version kotlinVersion apply (false)
|
|
||||||
id("org.jetbrains.kotlin.multiplatform") version kotlinVersion apply (false)
|
id("org.jetbrains.kotlin.multiplatform") version kotlinVersion apply (false)
|
||||||
id("org.jlleitschuh.gradle.ktlint") version "11.4.2"
|
id("org.jlleitschuh.gradle.ktlint") version "11.4.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ plugins {
|
|||||||
id("com.android.application") version "7.4.2"
|
id("com.android.application") version "7.4.2"
|
||||||
id("org.jetbrains.kotlin.android")
|
id("org.jetbrains.kotlin.android")
|
||||||
id("org.jetbrains.kotlin.kapt")
|
id("org.jetbrains.kotlin.kapt")
|
||||||
id("org.jetbrains.kotlin.android.extensions")
|
|
||||||
id("org.jlleitschuh.gradle.ktlint")
|
id("org.jlleitschuh.gradle.ktlint")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,97 +22,101 @@ package org.isoron.uhabits.activities.common.dialogs
|
|||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.RadioButton
|
import android.widget.RadioButton
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatDialogFragment
|
import androidx.appcompat.app.AppCompatDialogFragment
|
||||||
import kotlinx.android.synthetic.main.frequency_picker_dialog.view.*
|
|
||||||
import org.isoron.uhabits.R
|
import org.isoron.uhabits.R
|
||||||
|
import org.isoron.uhabits.databinding.FrequencyPickerDialogBinding
|
||||||
|
|
||||||
class FrequencyPickerDialog(
|
class FrequencyPickerDialog(
|
||||||
var freqNumerator: Int,
|
var freqNumerator: Int,
|
||||||
var freqDenominator: Int
|
var freqDenominator: Int
|
||||||
) : AppCompatDialogFragment() {
|
) : AppCompatDialogFragment() {
|
||||||
|
private var _binding: FrequencyPickerDialogBinding? = null
|
||||||
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
lateinit var contentView: View
|
|
||||||
var onFrequencyPicked: (num: Int, den: Int) -> Unit = { _, _ -> }
|
var onFrequencyPicked: (num: Int, den: Int) -> Unit = { _, _ -> }
|
||||||
|
|
||||||
constructor() : this(1, 1)
|
constructor() : this(1, 1)
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
_binding = null
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val inflater = LayoutInflater.from(requireActivity())
|
_binding = FrequencyPickerDialogBinding.inflate(LayoutInflater.from(requireActivity()))
|
||||||
contentView = inflater.inflate(R.layout.frequency_picker_dialog, null)
|
|
||||||
|
|
||||||
addBeforeAfterText(
|
addBeforeAfterText(
|
||||||
this.getString(R.string.every_x_days),
|
this.getString(R.string.every_x_days),
|
||||||
contentView.everyXDaysContainer
|
binding.everyXDaysContainer
|
||||||
)
|
)
|
||||||
|
|
||||||
addBeforeAfterText(
|
addBeforeAfterText(
|
||||||
this.getString(R.string.x_times_per_week),
|
this.getString(R.string.x_times_per_week),
|
||||||
contentView.xTimesPerWeekContainer
|
binding.xTimesPerWeekContainer
|
||||||
)
|
)
|
||||||
|
|
||||||
addBeforeAfterText(
|
addBeforeAfterText(
|
||||||
this.getString(R.string.x_times_per_month),
|
this.getString(R.string.x_times_per_month),
|
||||||
contentView.xTimesPerMonthContainer
|
binding.xTimesPerMonthContainer
|
||||||
)
|
)
|
||||||
|
|
||||||
addBeforeAfterText(
|
addBeforeAfterText(
|
||||||
this.getString(R.string.x_times_per_y_days),
|
this.getString(R.string.x_times_per_y_days),
|
||||||
contentView.xTimesPerYDaysContainer
|
binding.xTimesPerYDaysContainer
|
||||||
)
|
)
|
||||||
|
|
||||||
contentView.everyDayRadioButton.setOnClickListener {
|
binding.everyDayRadioButton.setOnClickListener {
|
||||||
check(contentView.everyDayRadioButton)
|
check(binding.everyDayRadioButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.everyXDaysRadioButton.setOnClickListener {
|
binding.everyXDaysRadioButton.setOnClickListener {
|
||||||
check(contentView.everyXDaysRadioButton)
|
check(binding.everyXDaysRadioButton)
|
||||||
val everyXDaysTextView = contentView.everyXDaysTextView
|
val everyXDaysTextView = binding.everyXDaysTextView
|
||||||
selectInputField(everyXDaysTextView)
|
selectInputField(everyXDaysTextView)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.everyXDaysTextView.setOnFocusChangeListener { v, hasFocus ->
|
binding.everyXDaysTextView.setOnFocusChangeListener { v, hasFocus ->
|
||||||
if (hasFocus) check(contentView.everyXDaysRadioButton)
|
if (hasFocus) check(binding.everyXDaysRadioButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.xTimesPerWeekRadioButton.setOnClickListener {
|
binding.xTimesPerWeekRadioButton.setOnClickListener {
|
||||||
check(contentView.xTimesPerWeekRadioButton)
|
check(binding.xTimesPerWeekRadioButton)
|
||||||
selectInputField(contentView.xTimesPerWeekTextView)
|
selectInputField(binding.xTimesPerWeekTextView)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.xTimesPerWeekTextView.setOnFocusChangeListener { v, hasFocus ->
|
binding.xTimesPerWeekTextView.setOnFocusChangeListener { v, hasFocus ->
|
||||||
if (hasFocus) check(contentView.xTimesPerWeekRadioButton)
|
if (hasFocus) check(binding.xTimesPerWeekRadioButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.xTimesPerMonthRadioButton.setOnClickListener {
|
binding.xTimesPerMonthRadioButton.setOnClickListener {
|
||||||
check(contentView.xTimesPerMonthRadioButton)
|
check(binding.xTimesPerMonthRadioButton)
|
||||||
selectInputField(contentView.xTimesPerMonthTextView)
|
selectInputField(binding.xTimesPerMonthTextView)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.xTimesPerMonthTextView.setOnFocusChangeListener { v, hasFocus ->
|
binding.xTimesPerMonthTextView.setOnFocusChangeListener { v, hasFocus ->
|
||||||
if (hasFocus) check(contentView.xTimesPerMonthRadioButton)
|
if (hasFocus) check(binding.xTimesPerMonthRadioButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.xTimesPerYDaysRadioButton.setOnClickListener {
|
binding.xTimesPerYDaysRadioButton.setOnClickListener {
|
||||||
check(contentView.xTimesPerYDaysRadioButton)
|
check(binding.xTimesPerYDaysRadioButton)
|
||||||
selectInputField(contentView.xTimesPerYDaysXTextView)
|
selectInputField(binding.xTimesPerYDaysXTextView)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.xTimesPerYDaysXTextView.setOnFocusChangeListener { v, hasFocus ->
|
binding.xTimesPerYDaysXTextView.setOnFocusChangeListener { v, hasFocus ->
|
||||||
if (hasFocus) check(contentView.xTimesPerYDaysRadioButton)
|
if (hasFocus) check(binding.xTimesPerYDaysRadioButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.xTimesPerYDaysYTextView.setOnFocusChangeListener { v, hasFocus ->
|
binding.xTimesPerYDaysYTextView.setOnFocusChangeListener { v, hasFocus ->
|
||||||
if (hasFocus) check(contentView.xTimesPerYDaysRadioButton)
|
if (hasFocus) check(binding.xTimesPerYDaysRadioButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
return AlertDialog.Builder(requireActivity())
|
return AlertDialog.Builder(requireActivity())
|
||||||
.setView(contentView)
|
.setView(binding.root)
|
||||||
.setPositiveButton(R.string.save) { _, _ -> onSaveClicked() }
|
.setPositiveButton(R.string.save) { _, _ -> onSaveClicked() }
|
||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
@@ -134,31 +138,35 @@ class FrequencyPickerDialog(
|
|||||||
var numerator = 1
|
var numerator = 1
|
||||||
var denominator = 1
|
var denominator = 1
|
||||||
when {
|
when {
|
||||||
contentView.everyDayRadioButton.isChecked -> {
|
binding.everyDayRadioButton.isChecked -> {
|
||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
contentView.everyXDaysRadioButton.isChecked -> {
|
|
||||||
if (contentView.everyXDaysTextView.text.isNotEmpty()) {
|
binding.everyXDaysRadioButton.isChecked -> {
|
||||||
denominator = Integer.parseInt(contentView.everyXDaysTextView.text.toString())
|
if (binding.everyXDaysTextView.text.isNotEmpty()) {
|
||||||
|
denominator = Integer.parseInt(binding.everyXDaysTextView.text.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contentView.xTimesPerWeekRadioButton.isChecked -> {
|
|
||||||
if (contentView.xTimesPerWeekTextView.text.isNotEmpty()) {
|
binding.xTimesPerWeekRadioButton.isChecked -> {
|
||||||
numerator = Integer.parseInt(contentView.xTimesPerWeekTextView.text.toString())
|
if (binding.xTimesPerWeekTextView.text.isNotEmpty()) {
|
||||||
|
numerator = Integer.parseInt(binding.xTimesPerWeekTextView.text.toString())
|
||||||
denominator = 7
|
denominator = 7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contentView.xTimesPerYDaysRadioButton.isChecked -> {
|
|
||||||
if (contentView.xTimesPerYDaysXTextView.text.isNotEmpty() && contentView.xTimesPerYDaysYTextView.text.isNotEmpty()) {
|
binding.xTimesPerYDaysRadioButton.isChecked -> {
|
||||||
|
if (binding.xTimesPerYDaysXTextView.text.isNotEmpty() && binding.xTimesPerYDaysYTextView.text.isNotEmpty()) {
|
||||||
numerator =
|
numerator =
|
||||||
Integer.parseInt(contentView.xTimesPerYDaysXTextView.text.toString())
|
Integer.parseInt(binding.xTimesPerYDaysXTextView.text.toString())
|
||||||
denominator =
|
denominator =
|
||||||
Integer.parseInt(contentView.xTimesPerYDaysYTextView.text.toString())
|
Integer.parseInt(binding.xTimesPerYDaysYTextView.text.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
if (contentView.xTimesPerMonthTextView.text.isNotEmpty()) {
|
if (binding.xTimesPerMonthTextView.text.isNotEmpty()) {
|
||||||
numerator = Integer.parseInt(contentView.xTimesPerMonthTextView.text.toString())
|
numerator = Integer.parseInt(binding.xTimesPerMonthTextView.text.toString())
|
||||||
denominator = 30
|
denominator = 30
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,27 +193,27 @@ class FrequencyPickerDialog(
|
|||||||
private fun populateViews() {
|
private fun populateViews() {
|
||||||
uncheckAll()
|
uncheckAll()
|
||||||
if (freqDenominator == 30 || freqDenominator == 31) {
|
if (freqDenominator == 30 || freqDenominator == 31) {
|
||||||
contentView.xTimesPerMonthRadioButton.isChecked = true
|
binding.xTimesPerMonthRadioButton.isChecked = true
|
||||||
contentView.xTimesPerMonthTextView.setText(freqNumerator.toString())
|
binding.xTimesPerMonthTextView.setText(freqNumerator.toString())
|
||||||
selectInputField(contentView.xTimesPerMonthTextView)
|
selectInputField(binding.xTimesPerMonthTextView)
|
||||||
} else {
|
} else {
|
||||||
if (freqNumerator == 1) {
|
if (freqNumerator == 1) {
|
||||||
if (freqDenominator == 1) {
|
if (freqDenominator == 1) {
|
||||||
contentView.everyDayRadioButton.isChecked = true
|
binding.everyDayRadioButton.isChecked = true
|
||||||
} else {
|
} else {
|
||||||
contentView.everyXDaysRadioButton.isChecked = true
|
binding.everyXDaysRadioButton.isChecked = true
|
||||||
contentView.everyXDaysTextView.setText(freqDenominator.toString())
|
binding.everyXDaysTextView.setText(freqDenominator.toString())
|
||||||
selectInputField(contentView.everyXDaysTextView)
|
selectInputField(binding.everyXDaysTextView)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (freqDenominator == 7) {
|
if (freqDenominator == 7) {
|
||||||
contentView.xTimesPerWeekRadioButton.isChecked = true
|
binding.xTimesPerWeekRadioButton.isChecked = true
|
||||||
contentView.xTimesPerWeekTextView.setText(freqNumerator.toString())
|
binding.xTimesPerWeekTextView.setText(freqNumerator.toString())
|
||||||
selectInputField(contentView.xTimesPerWeekTextView)
|
selectInputField(binding.xTimesPerWeekTextView)
|
||||||
} else {
|
} else {
|
||||||
contentView.xTimesPerYDaysRadioButton.isChecked = true
|
binding.xTimesPerYDaysRadioButton.isChecked = true
|
||||||
contentView.xTimesPerYDaysXTextView.setText(freqNumerator.toString())
|
binding.xTimesPerYDaysXTextView.setText(freqNumerator.toString())
|
||||||
contentView.xTimesPerYDaysYTextView.setText(freqDenominator.toString())
|
binding.xTimesPerYDaysYTextView.setText(freqDenominator.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,10 +224,10 @@ class FrequencyPickerDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun uncheckAll() {
|
private fun uncheckAll() {
|
||||||
contentView.everyDayRadioButton.isChecked = false
|
binding.everyDayRadioButton.isChecked = false
|
||||||
contentView.everyXDaysRadioButton.isChecked = false
|
binding.everyXDaysRadioButton.isChecked = false
|
||||||
contentView.xTimesPerWeekRadioButton.isChecked = false
|
binding.xTimesPerWeekRadioButton.isChecked = false
|
||||||
contentView.xTimesPerMonthRadioButton.isChecked = false
|
binding.xTimesPerMonthRadioButton.isChecked = false
|
||||||
contentView.xTimesPerYDaysRadioButton.isChecked = false
|
binding.xTimesPerYDaysRadioButton.isChecked = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.android.datetimepicker.time.RadialPickerLayout
|
import com.android.datetimepicker.time.RadialPickerLayout
|
||||||
import com.android.datetimepicker.time.TimePickerDialog
|
import com.android.datetimepicker.time.TimePickerDialog
|
||||||
import kotlinx.android.synthetic.main.activity_edit_habit.nameInput
|
|
||||||
import kotlinx.android.synthetic.main.activity_edit_habit.notesInput
|
|
||||||
import kotlinx.android.synthetic.main.activity_edit_habit.questionInput
|
|
||||||
import kotlinx.android.synthetic.main.activity_edit_habit.targetInput
|
|
||||||
import kotlinx.android.synthetic.main.activity_edit_habit.unitInput
|
|
||||||
import org.isoron.platform.gui.toInt
|
import org.isoron.platform.gui.toInt
|
||||||
import org.isoron.uhabits.HabitsApplication
|
import org.isoron.uhabits.HabitsApplication
|
||||||
import org.isoron.uhabits.R
|
import org.isoron.uhabits.R
|
||||||
@@ -271,9 +266,9 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
habit.copyFrom(original)
|
habit.copyFrom(original)
|
||||||
}
|
}
|
||||||
|
|
||||||
habit.name = nameInput.text.trim().toString()
|
habit.name = binding.nameInput.text.trim().toString()
|
||||||
habit.question = questionInput.text.trim().toString()
|
habit.question = binding.questionInput.text.trim().toString()
|
||||||
habit.description = notesInput.text.trim().toString()
|
habit.description = binding.notesInput.text.trim().toString()
|
||||||
habit.color = color
|
habit.color = color
|
||||||
if (reminderHour >= 0) {
|
if (reminderHour >= 0) {
|
||||||
habit.reminder = Reminder(reminderHour, reminderMin, reminderDays)
|
habit.reminder = Reminder(reminderHour, reminderMin, reminderDays)
|
||||||
@@ -283,9 +278,9 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
habit.frequency = Frequency(freqNum, freqDen)
|
habit.frequency = Frequency(freqNum, freqDen)
|
||||||
if (habitType == HabitType.NUMERICAL) {
|
if (habitType == HabitType.NUMERICAL) {
|
||||||
habit.targetValue = targetInput.text.toString().toDouble()
|
habit.targetValue = binding.targetInput.text.toString().toDouble()
|
||||||
habit.targetType = targetType
|
habit.targetType = targetType
|
||||||
habit.unit = unitInput.text.trim().toString()
|
habit.unit = binding.unitInput.text.trim().toString()
|
||||||
}
|
}
|
||||||
habit.type = habitType
|
habit.type = habitType
|
||||||
|
|
||||||
@@ -308,13 +303,13 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun validate(): Boolean {
|
private fun validate(): Boolean {
|
||||||
var isValid = true
|
var isValid = true
|
||||||
if (nameInput.text.isEmpty()) {
|
if (binding.nameInput.text.isEmpty()) {
|
||||||
nameInput.error = getFormattedValidationError(R.string.validation_cannot_be_blank)
|
binding.nameInput.error = getFormattedValidationError(R.string.validation_cannot_be_blank)
|
||||||
isValid = false
|
isValid = false
|
||||||
}
|
}
|
||||||
if (habitType == HabitType.NUMERICAL) {
|
if (habitType == HabitType.NUMERICAL) {
|
||||||
if (targetInput.text.isEmpty()) {
|
if (binding.targetInput.text.isEmpty()) {
|
||||||
targetInput.error = getString(R.string.validation_cannot_be_blank)
|
binding.targetInput.error = getString(R.string.validation_cannot_be_blank)
|
||||||
isValid = false
|
isValid = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user