Skip to content

Commit f2a8284

Browse files
Feature: Added day-of-year indicator [77/365] next to date like 'Wed, Mar 18 [77/365]' (#1024)
1 parent dd1e411 commit f2a8284

6 files changed

Lines changed: 49 additions & 3 deletions

File tree

app/src/main/java/com/github/codeworkscreativehub/mlauncher/MainViewModel.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
8383
val launcherDefault = MutableLiveData<Boolean>()
8484

8585
val showDate = MutableLiveData(prefs.showDate)
86+
val showDayOfYear = MutableLiveData(prefs.showDayOfYear)
8687
val showClock = MutableLiveData(prefs.showClock)
8788
val showAlarm = MutableLiveData(prefs.showAlarm)
8889
val showDailyWord = MutableLiveData(prefs.showDailyWord)
@@ -186,6 +187,10 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
186187
showDate.value = visibility
187188
}
188189

190+
fun setShowDayOfYear(visibility: Boolean) {
191+
showDayOfYear.value = visibility
192+
}
193+
189194
fun setShowClock(visibility: Boolean) {
190195
showClock.value = visibility
191196
}

app/src/main/java/com/github/codeworkscreativehub/mlauncher/data/Prefs.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ class Prefs(val context: Context) {
384384
var showDate: Boolean
385385
get() = getSetting(SHOW_DATE, true)
386386
set(value) = prefsNormal.edit { putBoolean(SHOW_DATE, value) }
387+
388+
var showDayOfYear: Boolean
389+
get() = getSetting(SHOW_DAY_OF_YEAR, false)
390+
set(value) = prefsNormal.edit { putBoolean(SHOW_DAY_OF_YEAR, value) }
387391

388392
var showClock: Boolean
389393
get() = getSetting(SHOW_CLOCK, true)

app/src/main/java/com/github/codeworkscreativehub/mlauncher/data/PrefsKeys.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ internal const val SHOW_WEATHER = "SHOW_WEATHER"
5252
internal const val GPS_LOCATION = "GPS_LOCATION"
5353
internal const val SHOW_AZSIDEBAR = "SHOW_AZSIDEBAR"
5454
internal const val SHOW_DATE = "SHOW_DATE"
55+
internal const val SHOW_DAY_OF_YEAR = "SHOW_DAY_OF_YEAR"
5556
internal const val HOME_LOCKED = "HOME_LOCKED"
5657
internal const val SETTINGS_LOCKED = "SETTINGS_LOCKED"
5758
internal const val HIDE_SEARCH_VIEW = "HIDE_SEARCH_VIEW"

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/HomeFragment.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import com.github.codeworkscreativehub.mlauncher.ui.components.DialogManager
9292
import com.github.codeworkscreativehub.mlauncher.ui.widgets.WidgetActivity
9393
import kotlinx.coroutines.Dispatchers
9494
import kotlinx.coroutines.launch
95+
import java.util.Calendar
9596

9697
class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListener {
9798

@@ -109,6 +110,13 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
109110
private var _binding: FragmentHomeBinding? = null
110111
private val binding get() = _binding!!
111112

113+
private fun getDayOfYearText(): String {
114+
val cal = Calendar.getInstance()
115+
val day = cal.get(Calendar.DAY_OF_YEAR)
116+
val max = cal.getActualMaximum(Calendar.DAY_OF_YEAR)
117+
return "[$day/$max]"
118+
}
119+
112120
override fun onCreateView(
113121
inflater: LayoutInflater,
114122
container: ViewGroup?,
@@ -310,9 +318,21 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
310318
clock.format24Hour = timePattern
311319

312320
// Date format
313-
val datePattern = DateFormat.getBestDateTimePattern(locale, "EEEddMMM")
314-
date.format12Hour = datePattern
315-
date.format24Hour = datePattern
321+
// val datePattern = DateFormat.getBestDateTimePattern(locale, "EEEddMMM")
322+
// date.format12Hour = datePattern
323+
// date.format24Hour = datePattern
324+
325+
val basePattern = DateFormat.getBestDateTimePattern(locale, "EEEddMMM")
326+
327+
val finalPattern = if (prefs.showDayOfYear) {
328+
"$basePattern ${getDayOfYearText()}"
329+
} else {
330+
basePattern
331+
}
332+
333+
date.format12Hour = finalPattern
334+
date.format24Hour = finalPattern
335+
316336

317337
alarm.text = getNextAlarm(requireContext(), prefs)
318338
dailyWord.text = wordOfTheDay(prefs)
@@ -492,6 +512,9 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
492512
showDate.observe(viewLifecycleOwner) {
493513
binding.date.isVisible = it
494514
}
515+
showDayOfYear.observe(viewLifecycleOwner) {
516+
updateTimeAndInfo()
517+
}
495518
showClock.observe(viewLifecycleOwner) {
496519
binding.clock.isVisible = it
497520
}

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/SettingsFragment.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class SettingsFragment : BaseFragment() {
211211
var toggledHomePager by remember { mutableStateOf(prefs.homePager) }
212212

213213
var toggledShowDate by remember { mutableStateOf(prefs.showDate) }
214+
var toggledShowDayOfYear by remember { mutableStateOf(prefs.showDayOfYear) }
214215
var toggledShowClock by remember { mutableStateOf(prefs.showClock) }
215216
var toggledShowClockFormat by remember { mutableStateOf(prefs.showClockFormat) }
216217
var toggledShowAlarm by remember { mutableStateOf(prefs.showAlarm) }
@@ -1012,6 +1013,17 @@ class SettingsFragment : BaseFragment() {
10121013
}
10131014
)
10141015

1016+
SettingsSwitch(
1017+
text = getLocalizedString(R.string.show_day_of_year),
1018+
fontSize = titleFontSize,
1019+
defaultState = toggledShowDayOfYear,
1020+
onCheckedChange = {
1021+
toggledShowDayOfYear = !prefs.showDayOfYear
1022+
prefs.showDayOfYear = toggledShowDayOfYear
1023+
viewModel.setShowDayOfYear(prefs.showDayOfYear)
1024+
}
1025+
)
1026+
10151027
SettingsSwitch(
10161028
text = getLocalizedString(R.string.show_clock),
10171029
fontSize = titleFontSize,

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<string name="show_clock">Show Clock</string>
103103
<string name="show_clock_format">Show Format (AM/PM)</string>
104104
<string name="show_date">Show Date</string>
105+
<string name="show_day_of_year">Show Day Of Year</string>
105106
<string name="show_alarm">Show Alarm</string>
106107
<string name="show_daily_word">Show Daily Word</string>
107108
<string name="show_battery">Show Battery</string>

0 commit comments

Comments
 (0)