-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port Personality Provider from Lawnchair Legacy #4848
Open
validcube
wants to merge
9
commits into
LawnchairLauncher:14-dev
Choose a base branch
from
validcube:14-dev
base: 14-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb33d05
Oh sheesh I hope this thing won't impldoe and leak all my smartspace …
validcube 6392ced
Remove Logging + TAG
validcube 6d9d5d3
Remove internal changes
validcube dc48743
Spotless™️ Tape
validcube 35d9524
More Tape
validcube 8d6a024
Apply suggestions from code review
validcube 5244f6c
Merge branch '14-dev' into 14-dev
validcube 85a9ec8
fix build
validcube 6529e4f
Merge branch '14-dev' into 14-dev
validcube File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
lawnchair/src/app/lawnchair/smartspace/provider/PersonalityProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package app.lawnchair.smartspace.provider | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import app.lawnchair.smartspace.model.SmartspaceAction | ||
import app.lawnchair.smartspace.model.SmartspaceScores | ||
import app.lawnchair.smartspace.model.SmartspaceTarget | ||
import app.lawnchair.util.broadcastReceiverFlow | ||
import com.android.launcher3.R | ||
import java.util.Calendar | ||
import kotlin.math.abs | ||
import kotlin.random.Random | ||
import kotlinx.coroutines.flow.map | ||
|
||
class PersonalityProvider(context: Context) : SmartspaceDataSource( | ||
context, | ||
R.string.smartspace_personality_provider, | ||
{ smartspacePersonalityProvider }, | ||
) { | ||
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) | ||
validcube marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
IntentFilter().apply { | ||
addAction(Intent.ACTION_DATE_CHANGED) | ||
addAction(Intent.ACTION_TIME_CHANGED) | ||
addAction(Intent.ACTION_TIMEZONE_CHANGED) | ||
|
||
// Difficulty testing? I know you do, uncomment this. | ||
// addAction(Intent.ACTION_SCREEN_ON) | ||
}, | ||
).map { | ||
val time = Calendar.getInstance() | ||
listOfNotNull(getSmartspaceTarget(time)) | ||
} | ||
|
||
private fun getSmartspaceTarget(time: Calendar): SmartspaceTarget? { | ||
val randomIndex = abs(Random(time.dayOfYear).nextInt()) | ||
|
||
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 = title, | ||
subtitle = subtitle, | ||
), | ||
score = SmartspaceScores.SCORE_PERSONALITY, | ||
featureType = SmartspaceTarget.FeatureType.FEATURE_REMINDER, | ||
) | ||
} | ||
|
||
private fun isMorning(time: Calendar) = time.hourOfDay in 5 until 9 | ||
private fun isEvening(time: Calendar) = time.hourOfDay in 19 until 21 | ||
private fun isNight(time: Calendar) = time.hourOfDay in 22 until 24 || time.hourOfDay in 0 until 4 | ||
|
||
private val Calendar.dayOfYear: Int get() = get(Calendar.DAY_OF_YEAR) | ||
private val Calendar.hourOfDay: Int get() = get(Calendar.HOUR_OF_DAY) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please help this is so robotic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't used old lawnchair, but this just shows greetings, right?
In my app I use ones from crdroid: https://raw.githubusercontent.com/crdroidandroid/android_packages_apps_Launcher3/14.0/res/values/cr_strings.xml (those starting with
quickspace_grt_
). I think bananadroid had some nice ones too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can take greetings from the following
https://github.com/BananaDroid-Revived/android_packages_apps_Launcher3/blob/14/res/values/banana_strings.xml
https://github.com/BootleggersROM/packages_apps_Launcher3/blob/tirimbino/res/values/bootleg_strings.xml
https://github.com/ProjectMatrixx/android_packages_apps_Launcher3/blob/14.0/res/values/cr_strings.xml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a bad idea, but how about a small ML model to provide greetings?