This commit is contained in:
Tommaso Berlose
2020-05-22 19:18:29 +02:00
parent 94825808f4
commit e58fef66aa
11 changed files with 71 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package com.tommasoberlose.anotherwidget.helpers
import android.content.Context
import android.text.format.DateUtils
import android.util.Log
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.utils.getCapWordString
import java.lang.Exception
@ -17,7 +16,11 @@ object DateHelper {
} catch (e: Exception) {
getDefaultDateText(context, date)
}
if (Preferences.isDateCapitalize) text.getCapWordString() else text
when {
Preferences.isDateUppercase -> text.toUpperCase(Locale.getDefault())
Preferences.isDateCapitalize -> text.getCapWordString()
else -> text
}
} else {
val flags: Int =
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
@ -25,17 +28,20 @@ object DateHelper {
SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time),
DateUtils.formatDateTime(context, date.timeInMillis, flags)
)
if (Preferences.isDateCapitalize) text.getCapWordString() else text
when {
Preferences.isDateUppercase -> text.toUpperCase(Locale.getDefault())
Preferences.isDateCapitalize -> text.getCapWordString()
else -> text
}
}
}
fun getDefaultDateText(context: Context, date: Calendar): String {
val flags: Int =
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
val text = "%s, %s".format(
return "%s, %s".format(
SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time),
DateUtils.formatDateTime(context, date.timeInMillis, flags)
)
return if (Preferences.isDateCapitalize) text.getCapWordString() else text
}
}