Compare commits
1 Commits
88e9cb7deb
...
3ae71c36a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ae71c36a7 |
@@ -373,7 +373,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addSleepEvent(event: LunaEvent) {
|
fun addSleepEvent(event: LunaEvent) {
|
||||||
setToPreviousQuantity(event)
|
|
||||||
askSleepValue(event) { saveEvent(event) }
|
askSleepValue(event) { saveEvent(event) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,7 +387,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val toTextView = dialogView.findViewById<TextView>(R.id.dialog_date_to)
|
val toTextView = dialogView.findViewById<TextView>(R.id.dialog_date_to)
|
||||||
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
||||||
|
|
||||||
val currentDurationTextColor = durationTextView.currentTextColor
|
|
||||||
var pickedFromTime = Calendar.getInstance()
|
var pickedFromTime = Calendar.getInstance()
|
||||||
var pickedToTime = Calendar.getInstance()
|
var pickedToTime = Calendar.getInstance()
|
||||||
|
|
||||||
@@ -396,7 +394,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (fromSeconds < toSeconds) {
|
if (fromSeconds < toSeconds) {
|
||||||
val durationSeconds = toSeconds - fromSeconds
|
val durationSeconds = toSeconds - fromSeconds
|
||||||
// sleep between 0 seconds and 12 hours
|
// sleep between 0 seconds and 12 hours
|
||||||
return durationSeconds > 59 && durationSeconds < (12 * 60 * 60)
|
return durationSeconds > 0 && durationSeconds < (12 * 60 * 60)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -406,12 +404,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val fromSeconds = pickedFromTime.time.time / 1000
|
val fromSeconds = pickedFromTime.time.time / 1000
|
||||||
val toSeconds = pickedToTime.time.time / 1000
|
val toSeconds = pickedToTime.time.time / 1000
|
||||||
|
|
||||||
val invalidDateText = getString(R.string.toast_date_error)
|
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, toSeconds - fromSeconds)
|
||||||
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, toSeconds - fromSeconds, invalidDateText)
|
|
||||||
|
|
||||||
if (isValidTime(fromSeconds, toSeconds)) {
|
if (isValidTime(fromSeconds, toSeconds)) {
|
||||||
// valid duration: set default color
|
// valid duration: set default color
|
||||||
durationTextView.setTextColor(currentDurationTextColor)
|
durationTextView.setTextColor(durationTextView.textColors.defaultColor)
|
||||||
} else {
|
} else {
|
||||||
// invalid duration: set danger color
|
// invalid duration: set danger color
|
||||||
durationTextView.setTextColor(ContextCompat.getColor(this, R.color.danger))
|
durationTextView.setTextColor(ContextCompat.getColor(this, R.color.danger))
|
||||||
@@ -421,8 +418,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
pickedFromTime = datePickerHelper(event.time, fromTextView, onDateChange)
|
pickedFromTime = datePickerHelper(event.time, fromTextView, onDateChange)
|
||||||
pickedToTime = datePickerHelper(event.time + event.quantity, toTextView, onDateChange)
|
pickedToTime = datePickerHelper(event.time + event.quantity, toTextView, onDateChange)
|
||||||
|
|
||||||
onDateChange()
|
|
||||||
|
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
val fromSeconds = pickedFromTime.time.time / 1000
|
val fromSeconds = pickedFromTime.time.time / 1000
|
||||||
val toSeconds = pickedToTime.time.time / 1000
|
val toSeconds = pickedToTime.time.time / 1000
|
||||||
@@ -431,10 +426,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
event.time = fromSeconds
|
event.time = fromSeconds
|
||||||
event.quantity = (toSeconds - fromSeconds).toInt()
|
event.quantity = (toSeconds - fromSeconds).toInt()
|
||||||
onPositive()
|
onPositive()
|
||||||
dialogInterface.dismiss()
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, R.string.toast_date_error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.toast_date_error, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
dialogInterface.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ class DateUtils {
|
|||||||
* Used for the duration to the next/previous event in the event details dialog.
|
* Used for the duration to the next/previous event in the event details dialog.
|
||||||
*/
|
*/
|
||||||
fun formatTimeDuration(context: Context, secondsDiff: Long): String {
|
fun formatTimeDuration(context: Context, secondsDiff: Long): String {
|
||||||
return formatTimeDuration(context, secondsDiff, context.getString(R.string.now))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun formatTimeDuration(context: Context, secondsDiff: Long, fallbackText: String): String {
|
|
||||||
var seconds = secondsDiff
|
var seconds = secondsDiff
|
||||||
|
|
||||||
val years = (seconds / (365 * 24 * 60 * 60F)).toLong()
|
val years = (seconds / (365 * 24 * 60 * 60F)).toLong()
|
||||||
@@ -69,7 +65,7 @@ class DateUtils {
|
|||||||
} else if (minutes > 0) {
|
} else if (minutes > 0) {
|
||||||
return format(minutes, seconds, R.string.minute_ago, R.string.minute_ago, R.string.second_ago, R.string.seconds_ago)
|
return format(minutes, seconds, R.string.minute_ago, R.string.minute_ago, R.string.second_ago, R.string.seconds_ago)
|
||||||
} else {
|
} else {
|
||||||
return fallbackText
|
return context.getString(R.string.now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user