Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
validcube authored Sep 21, 2024
1 parent 35d9524 commit 8d6a024
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
30 changes: 30 additions & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,18 +349,48 @@
<item>Good morning!</item>
<item>Have a great day!</item>
<item>It’s a beautiful day outside!</item>
<item>Rise and shine!</item>
<item>Top of the morning to you!</item>
<item>Ready to start the day?</item>
</string-array>
<string-array name="smartspace_personality_greetings_morning_subtitles">
<item>Wishing you a pleasant start to your day.</item>
<item>May your day be filled with joy and success.</item>
<item>Don\'t forget to enjoy the sunshine and fresh air.</item>
<item>Time to wake up and make things happen!</item>
<item>A cheerful greeting for a cheerful morning.</item>
<item>Let\'s make today amazing!</item>
</string-array>
<string-array name="smartspace_personality_greetings_evening">
<item>What’s up?</item>
<item>Good evening!</item>
<item>How did your day go?</item>
<item>How was your day?</item>
<item>Evening! How are you?</item>
<item>Hope you had a good day!</item>
</string-array>
<string-array name="smartspace_personality_greetings_evening_subtitles">
<item>Just checking in to see how your evening is going.</item>
<item>Curious to hear about your day\'s adventures.</item>
<item>Hoping your day was productive and fulfilling.</item>
<item>A friendly greeting for a wonderful evening.</item>
<item>Time to unwind and enjoy the rest of your day.</item>
</string-array>
<string-array name="smartspace_personality_greetings_night">
<item>Sleep well!</item>
<item>See you tomorrow!</item>
<item>Good night!</item>
<item>Don’t stay up too late!</item>
<item>Night night!</item>
<item>Sweet dreams!</item>
</string-array>
<string-array name="smartspace_personality_greetings_night_subtitles">
<item>May you have a restful sleep.</item>
<item>Looking forward to seeing you again tomorrow.</item>
<item>Wishing you a peaceful and pleasant night.</item>
<item>Remember to sleep for your health.</item>
<item>A cozy goodnight message for a sweet slumber.</item>
<item>May your dreams be filled with wonder and joy.</item>
</string-array>

<!-- Data and time format settings -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class PersonalityProvider(context: Context) : SmartspaceDataSource(
private val morningStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_morning)
private val eveningStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_evening)
private val nightStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_night)
private val morningSubtitleStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_night_subtitles)
private val eveningSubtitleStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_evening_subtitles)
private val nightSubtitleStrings = context.resources.getStringArray(R.array.smartspace_personality_greetings_night_subtitles)

override val internalTargets = broadcastReceiverFlow(
context,
Expand All @@ -40,20 +43,28 @@ class PersonalityProvider(context: Context) : SmartspaceDataSource(
private fun getSmartspaceTarget(time: Calendar): SmartspaceTarget? {
val randomIndex = abs(Random(time.dayOfYear).nextInt())

val greeting = when {
val title = when {
isMorning(time) -> morningStrings[randomIndex % morningStrings.size]
isEvening(time) -> eveningStrings[randomIndex % eveningStrings.size]
isNight(time) -> nightStrings[randomIndex % nightStrings.size]
else -> return null
}

val subtitle = when {
isMorning(time) -> morningSubtitleStrings[randomIndex % morningSubtitleStrings.size]
isEvening(time) -> eveningSubtitleStrings[randomIndex % eveningSubtitleStrings.size]
isNight(time) -> nightSubtitleStrings[randomIndex % nightSubtitleStrings.size]
else -> return null
}

/* TODO: We really need target's expiration time which isn't supported on new Smartspace
* ImplRef: LawnchairSmartspaceController.kt @ 10-dev */
return SmartspaceTarget(
id = "personalityGreeting",
headerAction = SmartspaceAction(
id = "personalityGreetingAction",
title = greeting,
title = title,
subtitle = subtitle,
),
score = SmartspaceScores.SCORE_PERSONALITY,
featureType = SmartspaceTarget.FeatureType.FEATURE_REMINDER,
Expand Down

0 comments on commit 8d6a024

Please sign in to comment.