Start the weekly view with the current date

This commit is contained in:
0x8664b2
2021-10-06 02:29:03 -07:00
parent 155da25db6
commit feb70ef96d
5 changed files with 51 additions and 9 deletions

View File

@@ -81,6 +81,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private var mStoredUse24HourFormat = false
private var mStoredDimPastEvents = true
private var mStoredHighlightWeekends = false
private var mStoredStartWeeklyViewWithCurrentDate = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -122,7 +123,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
if (!config.wasUpgradedFromFreeShown && isPackageInstalled("com.simplemobiletools.calendar")) {
ConfirmationDialog(this, "", R.string.upgraded_from_free, R.string.ok, 0, false) {}
ConfirmationDialog(this, "", R.string.upgraded_from_free, R.string.ok, 0) {}
config.wasUpgradedFromFreeShown = true
}
}
@@ -143,7 +144,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
if (config.storedView == WEEKLY_VIEW) {
if (mStoredIsSundayFirst != config.isSundayFirst || mStoredUse24HourFormat != config.use24HourFormat || mStoredMidnightSpan != config.showMidnightSpanningEventsAtTop) {
if (mStoredIsSundayFirst != config.isSundayFirst || mStoredUse24HourFormat != config.use24HourFormat
|| mStoredMidnightSpan != config.showMidnightSpanningEventsAtTop || mStoredStartWeeklyViewWithCurrentDate != config.startWeeklyViewWithCurrentDate) {
updateViewPager()
}
}
@@ -258,6 +260,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
mStoredDimPastEvents = dimPastEvents
mStoredHighlightWeekends = highlightWeekends
mStoredMidnightSpan = showMidnightSpanningEventsAtTop
mStoredStartWeeklyViewWithCurrentDate = startWeeklyViewWithCurrentDate
}
mStoredAdjustedPrimaryColor = getAdjustedPrimaryColor()
mStoredDayCode = Formatter.getTodayCode()
@@ -816,15 +819,19 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
private fun getThisWeekDateTime(): String {
val currentOffsetHours = TimeZone.getDefault().rawOffset / 1000 / 60 / 60
return if(! config.startWeeklyViewWithCurrentDate) {
val currentOffsetHours = TimeZone.getDefault().rawOffset / 1000 / 60 / 60
// not great, not terrible
val useHours = if (currentOffsetHours >= 10) 8 else 12
var thisweek = DateTime().withZone(DateTimeZone.UTC).withDayOfWeek(1).withHourOfDay(useHours).minusDays(if (config.isSundayFirst) 1 else 0)
if (DateTime().minusDays(7).seconds() > thisweek.seconds()) {
thisweek = thisweek.plusDays(7)
// not great, not terrible
val useHours = if (currentOffsetHours >= 10) 8 else 12
var thisweek = DateTime().withZone(DateTimeZone.UTC).withDayOfWeek(1).withHourOfDay(useHours).minusDays(if (config.isSundayFirst) 1 else 0)
if (DateTime().minusDays(7).seconds() > thisweek.seconds()) {
thisweek = thisweek.plusDays(7)
}
thisweek.toString()
} else {
DateTime().withZone(DateTimeZone.UTC).toString()
}
return thisweek.toString()
}
private fun getFragmentsHolder() = when (config.storedView) {

View File

@@ -58,6 +58,7 @@ class SettingsActivity : SimpleActivity() {
setupWeeklyStart()
setupMidnightSpanEvents()
setupAllowCustomiseDayCount()
setupStartWeeklyViewWithCurrentDate()
setupVibrate()
setupReminderSound()
setupReminderAudioStream()
@@ -358,6 +359,13 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupStartWeeklyViewWithCurrentDate() {
settings_start_weekly_view_with_current_date.isChecked = config.startWeeklyViewWithCurrentDate
settings_start_weekly_view_with_current_date.setOnClickListener {
config.startWeeklyViewWithCurrentDate = settings_start_weekly_view_with_current_date.isChecked
}
}
private fun setupWeekNumbers() {
settings_week_numbers.isChecked = config.showWeekNumbers
settings_week_numbers_holder.setOnClickListener {

View File

@@ -23,6 +23,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(START_WEEKLY_AT, 7)
set(startWeeklyAt) = prefs.edit().putInt(START_WEEKLY_AT, startWeeklyAt).apply()
var startWeeklyViewWithCurrentDate: Boolean
get() = prefs.getBoolean(START_WEEKLY_VIEW_WITH_CURRENT_DATE, false)
set(startWeeklyViewWithCurrentDate) = prefs.edit().putBoolean(START_WEEKLY_VIEW_WITH_CURRENT_DATE, startWeeklyViewWithCurrentDate).apply()
var showMidnightSpanningEventsAtTop: Boolean
get() = prefs.getBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, true)
set(midnightSpanning) = prefs.edit().putBoolean(SHOW_MIDNIGHT_SPANNING_EVENTS_AT_TOP, midnightSpanning).apply()

View File

@@ -45,6 +45,7 @@ const val YEAR = 31536000
// Shared Preferences
const val WEEK_NUMBERS = "week_numbers"
const val START_WEEKLY_AT = "start_weekly_at"
const val START_WEEKLY_VIEW_WITH_CURRENT_DATE = "start_weekly_with_current_date"
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 VIBRATE = "vibrate"

View File

@@ -744,6 +744,28 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_start_weekly_view_with_current_date_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/normal_margin"
android:paddingBottom="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_start_weekly_view_with_current_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingStart="@dimen/medium_margin"
android:text="Start weekly view with current date" />
</RelativeLayout>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/monthly_view_label"
android:layout_width="wrap_content"