Skip to content

Commit

Permalink
GH-36: merge Reminder.displayTime and Reminder.displayString properties
Browse files Browse the repository at this point in the history
  • Loading branch information
physphil committed Aug 23, 2019
1 parent 7692fbc commit c44940d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ import com.physphil.android.remindme.models.Recurrence
import com.physphil.android.remindme.models.Reminder
import com.physphil.android.remindme.util.SingleLiveEvent
import com.physphil.android.remindme.util.ViewString
import com.physphil.android.remindme.util.isNow
import com.physphil.android.remindme.util.isToday
import com.physphil.android.remindme.util.isTomorrow
import com.physphil.android.remindme.util.displayDate
import com.physphil.android.remindme.util.displayTime
import com.physphil.android.remindme.util.millis
import org.threeten.bp.LocalDateTime
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.format.FormatStyle

/**
* Copyright (c) 2017 Phil Shadlyn
Expand Down Expand Up @@ -201,19 +198,6 @@ class ReminderViewModel(
recurrence = recurrence.displayString
)

private val Reminder.displayTime: ViewString
get() = when {
time.isNow() -> ViewString.Integer(R.string.reminder_time_now)
else -> ViewString.String(time.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)))
}

private val Reminder.displayDate: ViewString
get() = when {
time.isToday() -> ViewString.Integer(R.string.reminder_repeat_today)
time.isTomorrow() -> ViewString.Integer(R.string.reminder_repeat_tomorrow)
else -> ViewString.String(time.format(DateTimeFormatter.ofPattern("EEE MMM d, yyyy")))
}

data class Time(val hour: Int, val minute: Int)
data class Date(val year: Int, val month: Int, val day: Int)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import androidx.recyclerview.widget.RecyclerView
import com.physphil.android.remindme.R
import com.physphil.android.remindme.models.Recurrence
import com.physphil.android.remindme.models.Reminder
import com.physphil.android.remindme.util.getDisplayDate
import com.physphil.android.remindme.util.getDisplayTime
import com.physphil.android.remindme.util.ViewString
import com.physphil.android.remindme.util.displayDate
import com.physphil.android.remindme.util.displayTime
import com.physphil.android.remindme.util.setVisibility
import kotlinx.android.synthetic.main.view_header_reminder_list.view.*
import kotlinx.android.synthetic.main.view_row_reminder_list.view.*
Expand Down Expand Up @@ -54,8 +55,14 @@ class ReminderListAdapter : RecyclerView.Adapter<ReminderListAdapter.ViewHolder>
listener?.onDeleteReminder(reminder)
}

reminderItemDateView.text = reminder.getDisplayDate(context)
reminderItemTimeView.text = reminder.getDisplayTime(context)
reminderItemDateView.text = when (val date = reminder.displayDate) {
is ViewString.String -> date.value
is ViewString.Integer -> context.getString(date.resId)
}
reminderItemTimeView.text = when (val time = reminder.displayTime) {
is ViewString.String -> time.value
is ViewString.Integer -> context.getString(time.resId)
}
reminderItemTitleView.text = reminder.title

// Hide description if not entered
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.physphil.android.remindme.util

import com.physphil.android.remindme.R
import com.physphil.android.remindme.models.Reminder
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.format.FormatStyle

val Reminder.displayTime: ViewString
get() = when {
time.isNow() -> ViewString.Integer(R.string.reminder_time_now)
else -> ViewString.String(time.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)))
}

val Reminder.displayDate: ViewString
get() = when {
time.isToday() -> ViewString.Integer(R.string.reminder_repeat_today)
time.isTomorrow() -> ViewString.Integer(R.string.reminder_repeat_tomorrow)
else -> ViewString.String(time.format(DateTimeFormatter.ofPattern("EEE MMM d, yyyy")))
}

This file was deleted.

0 comments on commit c44940d

Please sign in to comment.