Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ fun Context.getFormattedDate(calendar: Calendar): String {

val dayString = resources.getStringArray(org.fossify.commons.R.array.week_days_short)[dayOfWeek]
val monthString = resources.getStringArray(org.fossify.commons.R.array.months)[month]
return "$dayString, $dayOfMonth $monthString"

return formatDateString(monthString, dayOfMonth, dayString)
}

private fun Context.formatDateString(month: String, day: Int, weekday: String): String {
return getString(R.string.date_format_md, weekday, day, month)
}

fun Context.getEditedTimeZonesMap(): HashMap<Int, String> {
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/kotlin/org/fossify/clock/views/MyTextClock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import android.text.style.RelativeSizeSpan
import android.util.AttributeSet
import android.widget.TextClock
import androidx.annotation.AttrRes
import org.fossify.clock.R
import org.fossify.clock.extensions.config
import org.fossify.clock.extensions.getFormattedDate
import org.fossify.commons.extensions.applyFontToTextView
import java.text.DateFormatSymbols
import java.util.Calendar
import androidx.core.content.withStyledAttributes

private const val AM_PM_SCALE = 0.4f

Expand All @@ -21,6 +25,12 @@ class MyTextClock @JvmOverloads constructor(

init {
if (!isInEditMode) context.applyFontToTextView(this)

attrs?.let {
context.withStyledAttributes(it, R.styleable.MyTextClock, defStyleAttr, 0) {
useLocalizedDateFormat = getBoolean(R.styleable.MyTextClock_useLocalizedDateFormat, false)
}
}
}

private val amPmStrings by lazy {
Expand All @@ -30,18 +40,29 @@ class MyTextClock @JvmOverloads constructor(
}

private var reenter = false
private var useLocalizedDateFormat = false

override fun setText(text: CharSequence?, type: BufferType?) {
if (reenter) {
super.setText(text, type)
return
}

if (useLocalizedDateFormat) {
val formattedDate = context.getFormattedDate(Calendar.getInstance())
super.setText(formattedDate, type)
return
}

if (context.config.use24HourFormat || text.isNullOrEmpty()) {
super.setText(text, type)
return
}

setTextWithAmPmScaled(text, type);
}

private fun setTextWithAmPmScaled(text: CharSequence?, type: BufferType?) {
val full = text.toString()
var amPmPosition = -1
var amPmString: String? = null
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/fragment_clock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/clock_time"
android:format12Hour="EEE, d MMM"
android:format24Hour="EEE, d MMM"
android:gravity="center_horizontal"
android:textSize="@dimen/big_text_size"
app:useLocalizedDateFormat="true"
tools:text="Mon, 1 January" />

<org.fossify.commons.views.MyTextView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="max_reminder_duration">リマインダーの最大再生時間</string>
<string name="time_expired">時間切れ</string>
<string name="clock_and_date">時計と日付</string>
<string name="date_format_md">%3$s%2$d日(%1$s)</string>
<string name="use_text_shadow">文字に影を付ける</string>
<string name="swipe_right_to_dismiss">右にスワイプして終了、または左にスワイプしてスヌーズ。</string>
<string name="sort_by_creation_order">作成順</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<string name="max_reminder_duration">알림 최대 지속시간</string>
<string name="time_expired">시간 만료</string>
<string name="clock_and_date">시계 및 날짜</string>
<string name="date_format_md">%3$s %2$d일 %1$s</string>
<string name="use_text_shadow">텍스트 그림자 사용</string>
<string name="sort_by_creation_order">생성된 순서</string>
<string name="analogue_clock">아날로그 시계</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string name="max_reminder_duration">最长提醒持续时间</string>
<string name="time_expired">时间结束</string>
<string name="clock_and_date">时钟和日期</string>
<string name="date_format_md">%3$s%2$d日 %1$s</string>
<string name="use_text_shadow">使用文字阴影</string>
<string name="swipe_right_to_dismiss">向右滑动可关闭,向左滑动可暂停。</string>
<string name="sort_by_creation_order">创建顺序</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyTextClock">
<attr name="useLocalizedDateFormat" format="boolean" />
</declare-styleable>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string name="max_reminder_duration">Max reminder duration</string>
<string name="time_expired">Time expired</string>
<string name="clock_and_date">Clock and date</string>
<string name="date_format_md">%1$s, %2$d %3$s</string>
<string name="use_text_shadow">Use text shadow</string>
<string name="swipe_right_to_dismiss">Swipe right to Dismiss, or left to Snooze.</string>
<string name="sort_by_creation_order">Creation order</string>
Expand Down
Loading