diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index d2d6a654c..fdf0ead18 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -1322,7 +1322,6 @@ class EventActivity : SimpleActivity() { private fun setupStartDate() { hideKeyboard() - config.backgroundColor.getContrastColor() val datepicker = DatePickerDialog( this, mDialogTheme, startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1, mEventStartDateTime.dayOfMonth diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt index e10f4da60..dfaedf5df 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt @@ -1,5 +1,7 @@ package com.simplemobiletools.calendar.pro.activities +import android.app.DatePickerDialog +import android.app.TimePickerDialog import android.os.Bundle import android.view.Menu import android.view.WindowManager @@ -8,11 +10,14 @@ import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.TASK_ID import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.mydebug import kotlinx.android.synthetic.main.activity_task.* import org.joda.time.DateTime +import java.util.* class TaskActivity : SimpleActivity() { + private var mDialogTheme = 0 + private lateinit var mTaskDateTime: DateTime + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_task) @@ -22,7 +27,9 @@ class TaskActivity : SimpleActivity() { } val intent = intent ?: return + mDialogTheme = getDialogTheme() val taskId = intent.getLongExtra(TASK_ID, 0L) + mTaskDateTime = DateTime.now() updateColors() gotTask() } @@ -38,9 +45,12 @@ class TaskActivity : SimpleActivity() { task_all_day.toggle() } - task_start_date.text = Formatter.getDate(this, DateTime.now()) - task_start_time.text = Formatter.getTime(this, DateTime.now()) + task_date.setOnClickListener { setupDate() } + task_time.setOnClickListener { setupTime() } + setupNewTask() + updateDateText() + updateTimeText() } private fun setupNewTask() { @@ -49,9 +59,52 @@ class TaskActivity : SimpleActivity() { updateActionBarTitle(getString(R.string.new_task)) } + private fun setupDate() { + hideKeyboard() + val datepicker = DatePickerDialog( + this, mDialogTheme, dateSetListener, mTaskDateTime.year, mTaskDateTime.monthOfYear - 1, mTaskDateTime.dayOfMonth + ) + + datepicker.datePicker.firstDayOfWeek = if (config.isSundayFirst) Calendar.SUNDAY else Calendar.MONDAY + datepicker.show() + } + + private fun setupTime() { + hideKeyboard() + TimePickerDialog( + this, mDialogTheme, timeSetListener, mTaskDateTime.hourOfDay, mTaskDateTime.minuteOfHour, config.use24HourFormat + ).show() + } + + private val dateSetListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth -> + dateSet(year, monthOfYear, dayOfMonth) + } + + private val timeSetListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute -> + timeSet(hourOfDay, minute) + } + + private fun dateSet(year: Int, month: Int, day: Int) { + mTaskDateTime = mTaskDateTime.withDate(year, month + 1, day) + updateDateText() + } + + private fun timeSet(hours: Int, minutes: Int) { + mTaskDateTime = mTaskDateTime.withHourOfDay(hours).withMinuteOfHour(minutes) + updateTimeText() + } + + private fun updateDateText() { + task_date.text = Formatter.getDate(this, mTaskDateTime) + } + + private fun updateTimeText() { + task_time.text = Formatter.getTime(this, mTaskDateTime) + } + private fun toggleAllDay(isChecked: Boolean) { hideKeyboard() - task_start_time.beGoneIf(isChecked) + task_time.beGoneIf(isChecked) } private fun updateColors() { diff --git a/app/src/main/res/layout/activity_task.xml b/app/src/main/res/layout/activity_task.xml index 526cabf8f..0838bce5d 100644 --- a/app/src/main/res/layout/activity_task.xml +++ b/app/src/main/res/layout/activity_task.xml @@ -89,7 +89,7 @@