implementing date and time picker at task activity
This commit is contained in:
parent
39a5283a97
commit
5d781d1f7c
|
@ -1322,7 +1322,6 @@ class EventActivity : SimpleActivity() {
|
||||||
|
|
||||||
private fun setupStartDate() {
|
private fun setupStartDate() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
config.backgroundColor.getContrastColor()
|
|
||||||
val datepicker = DatePickerDialog(
|
val datepicker = DatePickerDialog(
|
||||||
this, mDialogTheme, startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1,
|
this, mDialogTheme, startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1,
|
||||||
mEventStartDateTime.dayOfMonth
|
mEventStartDateTime.dayOfMonth
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.simplemobiletools.calendar.pro.activities
|
package com.simplemobiletools.calendar.pro.activities
|
||||||
|
|
||||||
|
import android.app.DatePickerDialog
|
||||||
|
import android.app.TimePickerDialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.WindowManager
|
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.Formatter
|
||||||
import com.simplemobiletools.calendar.pro.helpers.TASK_ID
|
import com.simplemobiletools.calendar.pro.helpers.TASK_ID
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.mydebug
|
|
||||||
import kotlinx.android.synthetic.main.activity_task.*
|
import kotlinx.android.synthetic.main.activity_task.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class TaskActivity : SimpleActivity() {
|
class TaskActivity : SimpleActivity() {
|
||||||
|
private var mDialogTheme = 0
|
||||||
|
private lateinit var mTaskDateTime: DateTime
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_task)
|
setContentView(R.layout.activity_task)
|
||||||
|
@ -22,7 +27,9 @@ class TaskActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val intent = intent ?: return
|
val intent = intent ?: return
|
||||||
|
mDialogTheme = getDialogTheme()
|
||||||
val taskId = intent.getLongExtra(TASK_ID, 0L)
|
val taskId = intent.getLongExtra(TASK_ID, 0L)
|
||||||
|
mTaskDateTime = DateTime.now()
|
||||||
updateColors()
|
updateColors()
|
||||||
gotTask()
|
gotTask()
|
||||||
}
|
}
|
||||||
|
@ -38,9 +45,12 @@ class TaskActivity : SimpleActivity() {
|
||||||
task_all_day.toggle()
|
task_all_day.toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
task_start_date.text = Formatter.getDate(this, DateTime.now())
|
task_date.setOnClickListener { setupDate() }
|
||||||
task_start_time.text = Formatter.getTime(this, DateTime.now())
|
task_time.setOnClickListener { setupTime() }
|
||||||
|
|
||||||
setupNewTask()
|
setupNewTask()
|
||||||
|
updateDateText()
|
||||||
|
updateTimeText()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNewTask() {
|
private fun setupNewTask() {
|
||||||
|
@ -49,9 +59,52 @@ class TaskActivity : SimpleActivity() {
|
||||||
updateActionBarTitle(getString(R.string.new_task))
|
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) {
|
private fun toggleAllDay(isChecked: Boolean) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
task_start_time.beGoneIf(isChecked)
|
task_time.beGoneIf(isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateColors() {
|
private fun updateColors() {
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/task_start_date"
|
android:id="@+id/task_date"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/task_time_image"
|
android:layout_below="@+id/task_time_image"
|
||||||
|
@ -102,7 +102,7 @@
|
||||||
tools:text="January 1 1970" />
|
tools:text="January 1 1970" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/task_start_time"
|
android:id="@+id/task_time"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/task_time_image"
|
android:layout_below="@+id/task_time_image"
|
||||||
|
|
Loading…
Reference in New Issue