Merge pull request #2129 from Naveen3Singh/minor_readability_improvement
Rename method `getDatesWeekDateTime()` to `getFirstDayOfWeek()`
This commit is contained in:
commit
f3692cede3
|
@ -899,7 +899,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
|
|
||||||
private fun getDateCodeFormatForView(view: Int, date: DateTime): String {
|
private fun getDateCodeFormatForView(view: Int, date: DateTime): String {
|
||||||
return when (view) {
|
return when (view) {
|
||||||
WEEKLY_VIEW -> getDatesWeekDateTime(date)
|
WEEKLY_VIEW -> getFirstDayOfWeek(date)
|
||||||
YEARLY_VIEW -> date.toString()
|
YEARLY_VIEW -> date.toString()
|
||||||
else -> Formatter.getDayCodeFromDateTime(date)
|
else -> Formatter.getDayCodeFromDateTime(date)
|
||||||
}
|
}
|
||||||
|
@ -922,7 +922,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
|
|
||||||
when (config.storedView) {
|
when (config.storedView) {
|
||||||
DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode())
|
DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode())
|
||||||
WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, fixedDayCode ?: getDatesWeekDateTime(DateTime()))
|
WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, fixedDayCode ?: getFirstDayOfWeek(DateTime()))
|
||||||
MONTHLY_VIEW, MONTHLY_DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode())
|
MONTHLY_VIEW, MONTHLY_DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode())
|
||||||
YEARLY_VIEW -> bundle.putString(YEAR_TO_OPEN, fixedDayCode)
|
YEARLY_VIEW -> bundle.putString(YEAR_TO_OPEN, fixedDayCode)
|
||||||
}
|
}
|
||||||
|
@ -933,7 +933,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fixDayCode(dayCode: String? = null): String? = when {
|
private fun fixDayCode(dayCode: String? = null): String? = when {
|
||||||
config.storedView == WEEKLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> getDatesWeekDateTime(Formatter.getDateTimeFromCode(dayCode))
|
config.storedView == WEEKLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> getFirstDayOfWeek(Formatter.getDateTimeFromCode(dayCode))
|
||||||
config.storedView == YEARLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> Formatter.getYearFromDayCode(dayCode)
|
config.storedView == YEARLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> Formatter.getYearFromDayCode(dayCode)
|
||||||
else -> dayCode
|
else -> dayCode
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import kotlinx.android.synthetic.main.day_monthly_event_view.view.*
|
import kotlinx.android.synthetic.main.day_monthly_event_view.view.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeConstants
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
import org.joda.time.LocalDate
|
import org.joda.time.LocalDate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -765,18 +766,18 @@ fun Context.editEvent(event: ListEvent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getDatesWeekDateTime(date: DateTime): String {
|
fun Context.getFirstDayOfWeek(date: DateTime): String {
|
||||||
var startOfWeek = date.withZoneRetainFields(DateTimeZone.UTC).withTimeAtStartOfDay()
|
var startOfWeek = date.withZoneRetainFields(DateTimeZone.UTC).withTimeAtStartOfDay()
|
||||||
if (!config.startWeekWithCurrentDay) {
|
if (!config.startWeekWithCurrentDay) {
|
||||||
startOfWeek = if (config.isSundayFirst) {
|
startOfWeek = if (config.isSundayFirst) {
|
||||||
// a workaround for Joda-time's Monday-as-first-day-of-the-week
|
// a workaround for Joda-time's Monday-as-first-day-of-the-week
|
||||||
if (startOfWeek.dayOfWeek == 7) {
|
if (startOfWeek.dayOfWeek == DateTimeConstants.SUNDAY) {
|
||||||
startOfWeek
|
startOfWeek
|
||||||
} else {
|
} else {
|
||||||
startOfWeek.minusWeeks(1).withDayOfWeek(7)
|
startOfWeek.minusWeeks(1).withDayOfWeek(DateTimeConstants.SUNDAY)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
startOfWeek.withDayOfWeek(1)
|
startOfWeek.withDayOfWeek(DateTimeConstants.MONDAY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return startOfWeek.toString()
|
return startOfWeek.toString()
|
||||||
|
|
|
@ -44,7 +44,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val dateTimeString = arguments?.getString(WEEK_START_DATE_TIME) ?: return
|
val dateTimeString = arguments?.getString(WEEK_START_DATE_TIME) ?: return
|
||||||
currentWeekTS = (DateTime.parse(dateTimeString) ?: DateTime()).seconds()
|
currentWeekTS = (DateTime.parse(dateTimeString) ?: DateTime()).seconds()
|
||||||
thisWeekTS = DateTime.parse(requireContext().getDatesWeekDateTime(DateTime())).seconds()
|
thisWeekTS = DateTime.parse(requireContext().getFirstDayOfWeek(DateTime())).seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
|
Loading…
Reference in New Issue