mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-24 22:55:59 +00:00
Fix reminders for todos
This commit is contained in:
parent
3135c9f694
commit
9941c61532
3 changed files with 79 additions and 31 deletions
|
|
@ -225,6 +225,7 @@ class TaskFormActivity : BaseActivity() {
|
|||
|
||||
remindersTitleView.visibility = if (isChallengeTask) View.GONE else todoDailyViewsVisibility
|
||||
remindersContainer.visibility = if (isChallengeTask) View.GONE else todoDailyViewsVisibility
|
||||
remindersContainer.taskType = taskType
|
||||
|
||||
taskSchedulingTitleView.visibility = todoDailyViewsVisibility
|
||||
taskSchedulingControls.visibility = todoDailyViewsVisibility
|
||||
|
|
@ -302,6 +303,7 @@ class TaskFormActivity : BaseActivity() {
|
|||
}
|
||||
if (taskType == Task.TYPE_DAILY || taskType == Task.TYPE_TODO) {
|
||||
task.checklist?.let { checklistContainer.checklistItems = it }
|
||||
remindersContainer.taskType = taskType
|
||||
task.reminders?.let { remindersContainer.reminders = it }
|
||||
}
|
||||
task.attribute?.let { setSelectedAttribute(it) }
|
||||
|
|
|
|||
|
|
@ -9,11 +9,21 @@ import androidx.core.view.children
|
|||
import androidx.core.view.updateMargins
|
||||
import com.habitrpg.android.habitica.extensions.dpToPx
|
||||
import com.habitrpg.android.habitica.models.tasks.RemindersItem
|
||||
import com.habitrpg.android.habitica.models.tasks.Task
|
||||
import io.realm.RealmList
|
||||
|
||||
class ReminderContainer @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
var taskType = Task.TYPE_DAILY
|
||||
set(value) {
|
||||
field = value
|
||||
for (view in children) {
|
||||
if (view is ReminderItemFormView) {
|
||||
view.taskType = taskType
|
||||
}
|
||||
}
|
||||
}
|
||||
var reminders: RealmList<RemindersItem>
|
||||
get() {
|
||||
val list = RealmList<RemindersItem>()
|
||||
|
|
@ -51,6 +61,7 @@ class ReminderContainer @JvmOverloads constructor(
|
|||
|
||||
private fun addReminderViewAt(index: Int, item: RemindersItem? = null) {
|
||||
val view = ReminderItemFormView(context)
|
||||
view.taskType = taskType
|
||||
item?.let {
|
||||
view.item = it
|
||||
view.isAddButton = false
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.views.tasks.form
|
||||
|
||||
import android.app.DatePickerDialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
|
|
@ -8,15 +9,13 @@ import android.view.ViewGroup
|
|||
import android.view.animation.Animation
|
||||
import android.view.animation.LinearInterpolator
|
||||
import android.view.animation.RotateAnimation
|
||||
import android.widget.ImageButton
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.TimePicker
|
||||
import android.widget.*
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.dpToPx
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.models.tasks.RemindersItem
|
||||
import com.habitrpg.android.habitica.models.tasks.Task
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
|
|
@ -24,41 +23,49 @@ import java.util.*
|
|||
|
||||
class ReminderItemFormView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyleAttr), TimePickerDialog.OnTimeSetListener {
|
||||
) : LinearLayout(context, attrs, defStyleAttr), TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener {
|
||||
|
||||
|
||||
private val button: ImageButton by bindView(R.id.button)
|
||||
private val textView: TextView by bindView(R.id.text_view)
|
||||
|
||||
private val formatter = DateFormat.getTimeInstance(DateFormat.SHORT)
|
||||
private val formatter: DateFormat
|
||||
get() {
|
||||
return if (taskType == Task.TYPE_DAILY) {
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT)
|
||||
} else {
|
||||
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
|
||||
}
|
||||
}
|
||||
|
||||
var taskType = Task.TYPE_DAILY
|
||||
var item: RemindersItem = RemindersItem()
|
||||
set(value) {
|
||||
field = value
|
||||
textView.text = formatter.format(item.time)
|
||||
}
|
||||
set(value) {
|
||||
field = value
|
||||
textView.text = formatter.format(item.time)
|
||||
}
|
||||
|
||||
var tintColor: Int = ContextCompat.getColor(context, R.color.brand_300)
|
||||
var valueChangedListener: ((Date) -> Unit)? = null
|
||||
var animDuration = 0L
|
||||
var isAddButton: Boolean = true
|
||||
set(value) {
|
||||
field = value
|
||||
textView.text = if (value) context.getString(R.string.new_reminder) else formatter.format(item.time)
|
||||
if (value) {
|
||||
val rotate = RotateAnimation(135f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f)
|
||||
rotate.duration = animDuration
|
||||
rotate.interpolator = LinearInterpolator()
|
||||
rotate.fillAfter = true
|
||||
button.startAnimation(rotate)
|
||||
} else {
|
||||
val rotate = RotateAnimation(0f, 135f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f)
|
||||
rotate.duration = animDuration
|
||||
rotate.interpolator = LinearInterpolator()
|
||||
rotate.fillAfter = true
|
||||
button.startAnimation(rotate)
|
||||
set(value) {
|
||||
field = value
|
||||
textView.text = if (value) context.getString(R.string.new_reminder) else formatter.format(item.time)
|
||||
if (value) {
|
||||
val rotate = RotateAnimation(135f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f)
|
||||
rotate.duration = animDuration
|
||||
rotate.interpolator = LinearInterpolator()
|
||||
rotate.fillAfter = true
|
||||
button.startAnimation(rotate)
|
||||
} else {
|
||||
val rotate = RotateAnimation(0f, 135f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f)
|
||||
rotate.duration = animDuration
|
||||
rotate.interpolator = LinearInterpolator()
|
||||
rotate.fillAfter = true
|
||||
button.startAnimation(rotate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
minimumHeight = 38.dpToPx(context)
|
||||
|
|
@ -77,16 +84,25 @@ class ReminderItemFormView @JvmOverloads constructor(
|
|||
textView.setOnClickListener {
|
||||
val calendar = Calendar.getInstance()
|
||||
item.time?.let { calendar.time = it }
|
||||
val timePickerDialog = TimePickerDialog(context, this,
|
||||
calendar.get(Calendar.HOUR_OF_DAY),
|
||||
calendar.get(Calendar.MINUTE),
|
||||
android.text.format.DateFormat.is24HourFormat(context))
|
||||
timePickerDialog.show()
|
||||
if (taskType == Task.TYPE_DAILY) {
|
||||
val timePickerDialog = TimePickerDialog(context, this,
|
||||
calendar.get(Calendar.HOUR_OF_DAY),
|
||||
calendar.get(Calendar.MINUTE),
|
||||
android.text.format.DateFormat.is24HourFormat(context))
|
||||
timePickerDialog.show()
|
||||
} else {
|
||||
val timePickerDialog = DatePickerDialog(context, this,
|
||||
calendar.get(Calendar.YEAR),
|
||||
calendar.get(Calendar.MONTH),
|
||||
calendar.get(Calendar.DAY_OF_MONTH))
|
||||
timePickerDialog.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onTimeSet(view: TimePicker?, hourOfDay: Int, minute: Int) {
|
||||
valueChangedListener?.let {
|
||||
val calendar = Calendar.getInstance()
|
||||
item.time?.let { calendar.time = it }
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay)
|
||||
calendar.set(Calendar.MINUTE, minute)
|
||||
item.time = calendar.time
|
||||
|
|
@ -94,4 +110,23 @@ class ReminderItemFormView @JvmOverloads constructor(
|
|||
item.time?.let { date -> it(date) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDateSet(view: DatePicker?, year: Int, month: Int, dayOfMonth: Int) {
|
||||
valueChangedListener?.let {
|
||||
val calendar = Calendar.getInstance()
|
||||
item.time?.let { calendar.time = it }
|
||||
calendar.set(Calendar.YEAR, year)
|
||||
calendar.set(Calendar.MONTH, month)
|
||||
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth)
|
||||
item.time = calendar.time
|
||||
textView.text = formatter.format(item.time)
|
||||
item.time?.let { date -> it(date) }
|
||||
|
||||
val timePickerDialog = TimePickerDialog(context, this,
|
||||
calendar.get(Calendar.HOUR_OF_DAY),
|
||||
calendar.get(Calendar.MINUTE),
|
||||
android.text.format.DateFormat.is24HourFormat(context))
|
||||
timePickerDialog.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue