React to changing profile availability

This commit is contained in:
MM20
2024-07-07 14:29:42 +02:00
parent 84f3d9f825
commit 5a28eb584e
29 changed files with 424 additions and 77 deletions
@@ -0,0 +1,54 @@
package de.mm20.launcher2.profiles
import android.content.Context
import android.os.Process
import android.os.UserHandle
import de.mm20.launcher2.ktx.getSerialNumber
data class Profile(
val type: Profile.Type,
val userHandle: UserHandle,
val serial: Long,
) {
override fun equals(other: Any?): Boolean {
if (other is Profile) {
return userHandle == other.userHandle
}
return super.equals(other)
}
override fun hashCode(): Int {
return userHandle.hashCode()
}
enum class Type {
/**
* The default profile.
*/
Personal,
/**
* The work profile.
*/
Work,
/**
* The private space profile (Android 15+)
*/
Private,
}
data class State(
val locked: Boolean = false,
val hidden: Boolean = false,
)
companion object {
fun fromContext(context: Context): Profile {
val userHandle = Process.myUserHandle()
val serial = userHandle.getSerialNumber(context)
return Profile(Profile.Type.Personal, userHandle, serial)
}
}
}
@@ -9,6 +9,7 @@ import de.mm20.launcher2.base.R
import de.mm20.launcher2.icons.ColorLayer
import de.mm20.launcher2.icons.StaticLauncherIcon
import de.mm20.launcher2.icons.TintedIconLayer
import de.mm20.launcher2.profiles.Profile
interface AppShortcut : SavableSearchable {
@@ -39,6 +40,4 @@ interface AppShortcut : SavableSearchable {
val isUnavailable: Boolean
get() = false
val profile: AppProfile
}
@@ -10,11 +10,7 @@ import de.mm20.launcher2.base.R
import de.mm20.launcher2.icons.ColorLayer
import de.mm20.launcher2.icons.StaticLauncherIcon
import de.mm20.launcher2.icons.TintedIconLayer
enum class AppProfile {
Personal,
Work,
}
import de.mm20.launcher2.profiles.Profile
interface Application: SavableSearchable {
override val preferDetailsOverLaunch: Boolean
@@ -23,7 +19,6 @@ interface Application: SavableSearchable {
val componentName: ComponentName
val isSystemApp: Boolean
val isSuspended: Boolean
val profile: AppProfile
val user: UserHandle
val versionName: String?