mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Add "Start week on" preference
This commit is contained in:
@@ -73,7 +73,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
private var mStoredBackgroundColor = 0
|
private var mStoredBackgroundColor = 0
|
||||||
private var mStoredPrimaryColor = 0
|
private var mStoredPrimaryColor = 0
|
||||||
private var mStoredDayCode = ""
|
private var mStoredDayCode = ""
|
||||||
private var mStoredIsSundayFirst = false
|
private var mStoredFirstDayOfWeek = 0
|
||||||
private var mStoredMidnightSpan = true
|
private var mStoredMidnightSpan = true
|
||||||
private var mStoredUse24HourFormat = false
|
private var mStoredUse24HourFormat = false
|
||||||
private var mStoredDimPastEvents = true
|
private var mStoredDimPastEvents = true
|
||||||
@@ -183,7 +183,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.storedView == WEEKLY_VIEW) {
|
if (config.storedView == WEEKLY_VIEW) {
|
||||||
if (mStoredIsSundayFirst != config.isSundayFirst || mStoredUse24HourFormat != config.use24HourFormat
|
if (mStoredFirstDayOfWeek != config.firstDayOfWeek || mStoredUse24HourFormat != config.use24HourFormat
|
||||||
|| mStoredMidnightSpan != config.showMidnightSpanningEventsAtTop || mStoredStartWeekWithCurrentDay != config.startWeekWithCurrentDay
|
|| mStoredMidnightSpan != config.showMidnightSpanningEventsAtTop || mStoredStartWeekWithCurrentDay != config.startWeekWithCurrentDay
|
||||||
) {
|
) {
|
||||||
updateViewPager()
|
updateViewPager()
|
||||||
@@ -318,7 +318,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
mStoredPrimaryColor = getProperPrimaryColor()
|
mStoredPrimaryColor = getProperPrimaryColor()
|
||||||
mStoredBackgroundColor = getProperBackgroundColor()
|
mStoredBackgroundColor = getProperBackgroundColor()
|
||||||
config.apply {
|
config.apply {
|
||||||
mStoredIsSundayFirst = isSundayFirst
|
mStoredFirstDayOfWeek = firstDayOfWeek
|
||||||
mStoredUse24HourFormat = use24HourFormat
|
mStoredUse24HourFormat = use24HourFormat
|
||||||
mStoredDimPastEvents = dimPastEvents
|
mStoredDimPastEvents = dimPastEvents
|
||||||
mStoredDimCompletedTasks = dimCompletedTasks
|
mStoredDimCompletedTasks = dimCompletedTasks
|
||||||
|
@@ -26,6 +26,7 @@ import com.simplemobiletools.commons.models.AlarmSound
|
|||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeConstants
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -63,7 +64,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
setupManageQuickFilterEventTypes()
|
setupManageQuickFilterEventTypes()
|
||||||
setupHourFormat()
|
setupHourFormat()
|
||||||
setupAllowCreatingTasks()
|
setupAllowCreatingTasks()
|
||||||
setupSundayFirst()
|
setupStartWeekOn()
|
||||||
setupHighlightWeekends()
|
setupHighlightWeekends()
|
||||||
setupHighlightWeekendsColor()
|
setupHighlightWeekendsColor()
|
||||||
setupDeleteAllEvents()
|
setupDeleteAllEvents()
|
||||||
@@ -343,11 +344,24 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSundayFirst() {
|
private fun setupStartWeekOn() {
|
||||||
settings_sunday_first.isChecked = config.isSundayFirst
|
val items = arrayListOf(
|
||||||
settings_sunday_first_holder.setOnClickListener {
|
RadioItem(DateTimeConstants.SUNDAY, getString(R.string.sunday)),
|
||||||
settings_sunday_first.toggle()
|
RadioItem(DateTimeConstants.MONDAY, getString(R.string.monday)),
|
||||||
config.isSundayFirst = settings_sunday_first.isChecked
|
RadioItem(DateTimeConstants.TUESDAY, getString(R.string.tuesday)),
|
||||||
|
RadioItem(DateTimeConstants.WEDNESDAY, getString(R.string.wednesday)),
|
||||||
|
RadioItem(DateTimeConstants.THURSDAY, getString(R.string.thursday)),
|
||||||
|
RadioItem(DateTimeConstants.FRIDAY, getString(R.string.friday)),
|
||||||
|
RadioItem(DateTimeConstants.SATURDAY, getString(R.string.saturday)),
|
||||||
|
)
|
||||||
|
|
||||||
|
settings_start_week_on.text = getDayOfWeekString(config.firstDayOfWeek)
|
||||||
|
settings_start_week_on_holder.setOnClickListener {
|
||||||
|
RadioGroupDialog(this, items, config.firstDayOfWeek) { any ->
|
||||||
|
val firstDayOfWeek = any as Int
|
||||||
|
config.firstDayOfWeek = firstDayOfWeek
|
||||||
|
settings_start_week_on.text = getDayOfWeekString(config.firstDayOfWeek)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -532,6 +532,7 @@ fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Bool
|
|||||||
val currMinutes = calendar.get(Calendar.MINUTE)
|
val currMinutes = calendar.get(Calendar.MINUTE)
|
||||||
dateTime.withMinuteOfHour(currMinutes).seconds()
|
dateTime.withMinuteOfHour(currMinutes).seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_START_TIME_NEXT_FULL_HOUR -> newDateTime.seconds()
|
DEFAULT_START_TIME_NEXT_FULL_HOUR -> newDateTime.seconds()
|
||||||
else -> {
|
else -> {
|
||||||
val hours = defaultStartTime / 60
|
val hours = defaultStartTime / 60
|
||||||
@@ -692,11 +693,13 @@ fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Long>, ac
|
|||||||
eventsHelper.deleteRepeatingEventOccurrence(value, timestamps[index], true)
|
eventsHelper.deleteRepeatingEventOccurrence(value, timestamps[index], true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DELETE_FUTURE_OCCURRENCES -> {
|
DELETE_FUTURE_OCCURRENCES -> {
|
||||||
eventIds.forEachIndexed { index, value ->
|
eventIds.forEachIndexed { index, value ->
|
||||||
eventsHelper.addEventRepeatLimit(value, timestamps[index])
|
eventsHelper.addEventRepeatLimit(value, timestamps[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DELETE_ALL_OCCURRENCES -> {
|
DELETE_ALL_OCCURRENCES -> {
|
||||||
eventsHelper.deleteEvents(eventIds.toMutableList(), true)
|
eventsHelper.deleteEvents(eventIds.toMutableList(), true)
|
||||||
}
|
}
|
||||||
@@ -762,20 +765,38 @@ fun Context.getFirstDayOfWeek(date: DateTime): String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getFirstDayOfWeekDt(date: DateTime): DateTime {
|
fun Context.getFirstDayOfWeekDt(date: DateTime): DateTime {
|
||||||
var startOfWeek = date.withTimeAtStartOfDay()
|
val currentDate = date.withTimeAtStartOfDay()
|
||||||
if (!config.startWeekWithCurrentDay) {
|
if (config.startWeekWithCurrentDay) {
|
||||||
startOfWeek = if (config.isSundayFirst) {
|
return currentDate
|
||||||
// a workaround for Joda-time's Monday-as-first-day-of-the-week
|
} else {
|
||||||
if (startOfWeek.dayOfWeek == DateTimeConstants.SUNDAY) {
|
val firstDayOfWeek = config.firstDayOfWeek
|
||||||
startOfWeek
|
val currentDayOfWeek = currentDate.dayOfWeek
|
||||||
} else {
|
return if (currentDayOfWeek == firstDayOfWeek) {
|
||||||
startOfWeek.minusWeeks(1).withDayOfWeek(DateTimeConstants.SUNDAY)
|
currentDate
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
startOfWeek.withDayOfWeek(DateTimeConstants.MONDAY)
|
// Joda-time's weeks always starts on Monday but user preferred firstDayOfWeek could be any week day
|
||||||
|
if (firstDayOfWeek < currentDayOfWeek) {
|
||||||
|
currentDate.withDayOfWeek(firstDayOfWeek)
|
||||||
|
} else {
|
||||||
|
currentDate.minusWeeks(1).withDayOfWeek(firstDayOfWeek)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return startOfWeek
|
}
|
||||||
|
|
||||||
|
fun Context.getDayOfWeekString(dayOfWeek: Int): String {
|
||||||
|
val dayOfWeekResId = when (dayOfWeek) {
|
||||||
|
DateTimeConstants.MONDAY -> R.string.monday
|
||||||
|
DateTimeConstants.TUESDAY -> R.string.tuesday
|
||||||
|
DateTimeConstants.WEDNESDAY -> R.string.wednesday
|
||||||
|
DateTimeConstants.THURSDAY -> R.string.thursday
|
||||||
|
DateTimeConstants.FRIDAY -> R.string.friday
|
||||||
|
DateTimeConstants.SATURDAY -> R.string.saturday
|
||||||
|
DateTimeConstants.SUNDAY -> R.string.sunday
|
||||||
|
else -> throw IllegalArgumentException("Invalid day: $dayOfWeek")
|
||||||
|
}
|
||||||
|
|
||||||
|
return getString(dayOfWeekResId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.isTaskCompleted(event: Event): Boolean {
|
fun Context.isTaskCompleted(event: Event): Boolean {
|
||||||
|
@@ -29,6 +29,10 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
get() = prefs.getBoolean(START_WEEK_WITH_CURRENT_DAY, false)
|
get() = prefs.getBoolean(START_WEEK_WITH_CURRENT_DAY, false)
|
||||||
set(startWeekWithCurrentDay) = prefs.edit().putBoolean(START_WEEK_WITH_CURRENT_DAY, startWeekWithCurrentDay).apply()
|
set(startWeekWithCurrentDay) = prefs.edit().putBoolean(START_WEEK_WITH_CURRENT_DAY, startWeekWithCurrentDay).apply()
|
||||||
|
|
||||||
|
var firstDayOfWeek: Int
|
||||||
|
get() = prefs.getInt(FIRST_DAY_OF_WEEK, getDefaultFirstDayOfWeekJoda())
|
||||||
|
set(firstDayOfWeek) = prefs.edit().putInt(FIRST_DAY_OF_WEEK, firstDayOfWeek).apply()
|
||||||
|
|
||||||
var showMidnightSpanningEventsAtTop: Boolean
|
var showMidnightSpanningEventsAtTop: Boolean
|
||||||
get() = prefs.getBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, true)
|
get() = prefs.getBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, true)
|
||||||
set(midnightSpanning) = prefs.edit().putBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, midnightSpanning).apply()
|
set(midnightSpanning) = prefs.edit().putBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, midnightSpanning).apply()
|
||||||
|
@@ -4,6 +4,7 @@ import com.simplemobiletools.calendar.pro.activities.EventActivity
|
|||||||
import com.simplemobiletools.calendar.pro.activities.TaskActivity
|
import com.simplemobiletools.calendar.pro.activities.TaskActivity
|
||||||
import com.simplemobiletools.commons.helpers.MONTH_SECONDS
|
import com.simplemobiletools.commons.helpers.MONTH_SECONDS
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeConstants
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
const val STORED_LOCALLY_ONLY = 0
|
const val STORED_LOCALLY_ONLY = 0
|
||||||
@@ -82,6 +83,7 @@ const val EVENT_LIST_PERIOD = "event_list_period"
|
|||||||
const val WEEK_NUMBERS = "week_numbers"
|
const val WEEK_NUMBERS = "week_numbers"
|
||||||
const val START_WEEKLY_AT = "start_weekly_at"
|
const val START_WEEKLY_AT = "start_weekly_at"
|
||||||
const val START_WEEK_WITH_CURRENT_DAY = "start_week_with_current_day"
|
const val START_WEEK_WITH_CURRENT_DAY = "start_week_with_current_day"
|
||||||
|
const val FIRST_DAY_OF_WEEK = "start_week_on"
|
||||||
const val SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP = "show_midnight_spanning_events_at_top"
|
const val SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP = "show_midnight_spanning_events_at_top"
|
||||||
const val ALLOW_CUSTOMIZE_DAY_COUNT = "allow_customise_day_count"
|
const val ALLOW_CUSTOMIZE_DAY_COUNT = "allow_customise_day_count"
|
||||||
const val VIBRATE = "vibrate"
|
const val VIBRATE = "vibrate"
|
||||||
@@ -299,3 +301,17 @@ fun getPreviousAutoBackupTime(): DateTime {
|
|||||||
val nextBackupTime = getNextAutoBackupTime()
|
val nextBackupTime = getNextAutoBackupTime()
|
||||||
return nextBackupTime.minusDays(AUTO_BACKUP_INTERVAL_IN_DAYS)
|
return nextBackupTime.minusDays(AUTO_BACKUP_INTERVAL_IN_DAYS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDefaultFirstDayOfWeekJoda(): Int {
|
||||||
|
val calendar = Calendar.getInstance(Locale.getDefault())
|
||||||
|
return when (calendar.firstDayOfWeek) {
|
||||||
|
Calendar.SUNDAY -> DateTimeConstants.SUNDAY
|
||||||
|
Calendar.MONDAY -> DateTimeConstants.MONDAY
|
||||||
|
Calendar.TUESDAY -> DateTimeConstants.TUESDAY
|
||||||
|
Calendar.WEDNESDAY -> DateTimeConstants.WEDNESDAY
|
||||||
|
Calendar.THURSDAY -> DateTimeConstants.THURSDAY
|
||||||
|
Calendar.FRIDAY -> DateTimeConstants.FRIDAY
|
||||||
|
Calendar.SATURDAY -> DateTimeConstants.SATURDAY
|
||||||
|
else -> DateTimeConstants.SUNDAY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -148,6 +148,29 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/settings_start_week_on_holder"
|
||||||
|
style="@style/SettingsHolderTextViewStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/settings_start_week_on_label"
|
||||||
|
style="@style/SettingsTextLabelStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/start_week_on" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/settings_start_week_on"
|
||||||
|
style="@style/SettingsTextValueStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/settings_start_week_on_label"
|
||||||
|
tools:text="@string/monday" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/settings_hour_format_holder"
|
android:id="@+id/settings_hour_format_holder"
|
||||||
style="@style/SettingsHolderCheckboxStyle"
|
style="@style/SettingsHolderCheckboxStyle"
|
||||||
@@ -163,21 +186,6 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/settings_sunday_first_holder"
|
|
||||||
style="@style/SettingsHolderCheckboxStyle"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
|
||||||
android:id="@+id/settings_sunday_first"
|
|
||||||
style="@style/SettingsCheckboxStyle"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/sunday_first" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/settings_highlight_weekends_holder"
|
android:id="@+id/settings_highlight_weekends_holder"
|
||||||
style="@style/SettingsHolderCheckboxStyle"
|
style="@style/SettingsHolderCheckboxStyle"
|
||||||
|
Reference in New Issue
Block a user