Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions commons/src/main/kotlin/org/fossify/commons/extensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.fossify.commons.helpers.*
import org.fossify.commons.helpers.MyContentProvider.PERMISSION_WRITE_GLOBAL_SETTINGS
import org.fossify.commons.models.AlarmSound
import org.fossify.commons.models.BlockedNumber
import org.joda.time.DateTimeConstants
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
Expand Down Expand Up @@ -1259,3 +1260,18 @@ fun Context.openFullScreenIntentSettings(appId: String) {
startActivity(intent)
}
}

fun Context.getDayOfWeekString(dayOfWeek: Int): String {
val dayOfWeekResId = when (dayOfWeek) {
DateTimeConstants.MONDAY -> org.fossify.commons.R.string.monday
DateTimeConstants.TUESDAY -> org.fossify.commons.R.string.tuesday
DateTimeConstants.WEDNESDAY -> org.fossify.commons.R.string.wednesday
DateTimeConstants.THURSDAY -> org.fossify.commons.R.string.thursday
DateTimeConstants.FRIDAY -> org.fossify.commons.R.string.friday
DateTimeConstants.SATURDAY -> org.fossify.commons.R.string.saturday
DateTimeConstants.SUNDAY -> org.fossify.commons.R.string.sunday
else -> throw IllegalArgumentException("Invalid day: $dayOfWeek")
}

return getString(dayOfWeekResId)
}
12 changes: 12 additions & 0 deletions commons/src/main/kotlin/org/fossify/commons/extensions/List.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.fossify.commons.extensions

import java.util.Collections

fun List<String>.getMimeType(): String {
val mimeGroups = HashSet<String>(size)
val subtypes = HashSet<String>(size)
Expand All @@ -19,3 +21,13 @@ fun List<String>.getMimeType(): String {
else -> "*/*"
}
}

fun <T> List<T>.rotate(distance: Int): List<T> {
return toMutableList().apply {
Collections.rotate(this, distance)
}
}

fun <T> List<T>.rotateRight(distance: Int) = rotate(distance)

fun <T> List<T>.rotateLeft(distance: Int) = rotate(-distance)
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,14 @@ open class BaseConfig(val context: Context) {
get() = prefs.getLong(PASSWORD_COUNTDOWN_START_MS, 0L)
set(passwordCountdownStartMs) = prefs.edit().putLong(PASSWORD_COUNTDOWN_START_MS, passwordCountdownStartMs).apply()

// Returns the first day of week, indexing follows ISO 8601: Mon=1, ..., Sun=7
var firstDayOfWeek: Int
get() {
val defaultFirstDayOfWeek = Calendar.getInstance(Locale.getDefault()).firstDayOfWeek
return prefs.getInt(FIRST_DAY_OF_WEEK, getISODayOfWeekFromJava(defaultFirstDayOfWeek))
}
set(firstDayOfWeek) = prefs.edit().putInt(FIRST_DAY_OF_WEEK, firstDayOfWeek).apply()

// Accessibility
var showCheckmarksOnSwitches: Boolean
get() = prefs.getBoolean(SHOW_CHECKMARKS_ON_SWITCHES, false)
Expand Down
22 changes: 22 additions & 0 deletions commons/src/main/kotlin/org/fossify/commons/helpers/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.fossify.commons.R
import org.fossify.commons.extensions.normalizeString
import org.fossify.commons.models.contacts.LocalContact
import org.fossify.commons.overloads.times
import org.joda.time.DateTimeConstants

const val EXTERNAL_STORAGE_PROVIDER_AUTHORITY = "com.android.externalstorage.documents"
const val EXTRA_SHOW_ADVANCED = "android.content.extra.SHOW_ADVANCED"
Expand Down Expand Up @@ -197,6 +198,7 @@ const val PASSWORD_COUNTDOWN_START_MS = "password_count_down_start_ms"
const val LAST_UNLOCK_TIMESTAMP_MS = "last_unlock_timestamp_ms"
const val UNLOCK_TIMEOUT_DURATION_MS = "unlock_timeout_duration_ms"
const val SHOW_CHECKMARKS_ON_SWITCHES = "show_checkmarks_on_switches"
const val FIRST_DAY_OF_WEEK = "first_day_of_week"

const val MAX_PASSWORD_RETRY_COUNT = 3
const val DEFAULT_PASSWORD_COUNTDOWN = 5
Expand Down Expand Up @@ -720,3 +722,23 @@ fun getProperText(text: String, shouldNormalize: Boolean) =
shouldNormalize -> text.normalizeString()
else -> text
}

fun getISODayOfWeekFromJava(javaDayOfWeek: Int): Int {
if (javaDayOfWeek !in 1..7) {
throw IllegalArgumentException("Invalid Java day of week: $javaDayOfWeek")
}

// Java: Sun=1, ..., Sat=7
// ISO: Mon=1, ..., Sun=7
return (javaDayOfWeek + 5) % 7 + 1
}

fun getJavaDayOfWeekFromISO(isoDayOfWeek: Int): Int {
if (isoDayOfWeek !in 1..7) {
throw IllegalArgumentException("Invalid ISO day of week: $isoDayOfWeek")
}

// ISO: Mon=1, ..., Sun=7
// Java: Sun=1, ..., Sat=7
return (isoDayOfWeek % 7) + 1
}
Loading