adding some helpers related to week days handling

This commit is contained in:
tibbi 2018-03-04 12:22:38 +01:00
parent 1a0b2fd7fa
commit 25aaf4544c
3 changed files with 33 additions and 0 deletions

View file

@ -353,3 +353,17 @@ fun Context.isPackageInstalled(pkgName: String): Boolean {
false
}
}
// format day bits to strings like "Mon, Tue, Wed"
fun Context.getSelectedDaysString(bitMask: Int): String {
val dayBits = arrayListOf(MONDAY_BIT, TUESDAY_BIT, WEDNESDAY_BIT, THURSDAY_BIT, FRIDAY_BIT, SATURDAY_BIT, SUNDAY_BIT)
val weekDays = resources.getStringArray(R.array.week_days)
var days = ""
dayBits.forEachIndexed { index, bit ->
if (bitMask and bit != 0) {
days += "${weekDays[index].substringTo(3)}, "
}
}
return days.trim().trimEnd(',')
}

View file

@ -217,6 +217,14 @@ fun String.getPublicUri(context: Context) = context.getDocumentFile(this)?.uri ?
fun String.getOTGPublicPath(context: Context) = "${context.baseConfig.OTGBasePath}%3A${substring(OTG_PATH.length).replace("/", "%2F")}"
fun String.substringTo(cnt: Int): String {
return if (isEmpty()) {
""
} else {
substring(0, Math.min(length, cnt))
}
}
fun String.getMimeType(): String {
val typesMap = HashMap<String, String>().apply {
put("323", "text/h323")

View file

@ -121,6 +121,17 @@ const val CONFLICT_SKIP = 1
const val CONFLICT_OVERWRITE = 2
const val CONFLICT_MERGE = 3
const val MONDAY_BIT = 1
const val TUESDAY_BIT = 2
const val WEDNESDAY_BIT = 4
const val THURSDAY_BIT = 8
const val FRIDAY_BIT = 16
const val SATURDAY_BIT = 32
const val SUNDAY_BIT = 64
const val EVERY_DAY_BIT = MONDAY_BIT or TUESDAY_BIT or WEDNESDAY_BIT or THURSDAY_BIT or FRIDAY_BIT or SATURDAY_BIT or SUNDAY_BIT
const val WEEK_DAYS_BIT = MONDAY_BIT or TUESDAY_BIT or WEDNESDAY_BIT or THURSDAY_BIT or FRIDAY_BIT
const val WEEKENDS_BIT = SATURDAY_BIT or SUNDAY_BIT
fun getDateFormats() = arrayListOf(
"yyyy-MM-dd",
"yyyyMMdd",