Skip to content

Commit

Permalink
chore: handle deprecations (#175)
Browse files Browse the repository at this point in the history
Authored-by: mslalith <mslalith.opensource@gmail.com>
  • Loading branch information
mslalith committed Apr 30, 2023
1 parent 0e01e57 commit 408d22e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
Expand Up @@ -3,6 +3,7 @@ package dev.mslalith.focuslauncher.core.launcherapps.manager.iconpack.impl
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import dagger.hilt.android.qualifiers.ApplicationContext
import dev.mslalith.focuslauncher.core.launcherapps.manager.iconpack.IconPackManager
import dev.mslalith.focuslauncher.core.launcherapps.manager.iconcache.IconCacheManager
Expand All @@ -27,15 +28,24 @@ internal class IconPackManagerImpl @Inject constructor(
private val _iconPackLoadedTriggerFlow = MutableStateFlow(value = false)
override val iconPackLoadedTriggerFlow: Flow<Boolean> = _iconPackLoadedTriggerFlow

@Suppress("DEPRECATION")
override fun fetchInstalledIconPacks() {
val packageManager = context.packageManager
val themes = packageManager.queryIntentActivities(Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA)
val themes = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.queryIntentActivities(Intent("org.adw.launcher.THEMES"), PackageManager.ResolveInfoFlags.of(PackageManager.GET_META_DATA.toLong()))
} else {
@Suppress("DEPRECATION")
packageManager.queryIntentActivities(Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA)
}

_iconPacksFlow.value = themes.mapNotNull {
val iconPackageName = it.activityInfo.packageName
try {
val applicationInfo = packageManager.getApplicationInfo(iconPackageName, PackageManager.GET_META_DATA)
val applicationInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getApplicationInfo(iconPackageName, PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()))
} else {
@Suppress("DEPRECATION")
packageManager.getApplicationInfo(iconPackageName, PackageManager.GET_META_DATA)
}
val iconLabel = packageManager.getApplicationLabel(applicationInfo).toString()
IconPack(
label = iconLabel,
Expand Down
Expand Up @@ -39,6 +39,7 @@ internal class IconPackXmlParser(
fun drawableFor(componentName: String): Drawable? {
val set = iconPackToDrawablesMap[componentName]
if (set.isNullOrEmpty()) return null
@Suppress("DEPRECATION")
return iconPackResources?.getDrawable(set.first().drawableId)
}

Expand Down
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -22,7 +21,6 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchField(
modifier: Modifier = Modifier,
Expand All @@ -46,7 +44,7 @@ fun SearchField(
autoCorrect = false,
imeAction = ImeAction.Search
),
colors = TextFieldDefaults.textFieldColors(
colors = TextFieldDefaults.colors(
focusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent
Expand Down
Expand Up @@ -2,7 +2,6 @@ package dev.mslalith.focuslauncher.core.ui

import androidx.annotation.DrawableRes
import androidx.compose.foundation.clickable
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
Expand All @@ -13,7 +12,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SelectableIconItem(
modifier: Modifier = Modifier,
Expand Down
Expand Up @@ -15,6 +15,7 @@ internal fun Context.isDefaultLauncher(): Boolean = if (Build.VERSION.SDK_INT >=

private fun Context.isAppDefaultLauncher(): Boolean {
val intent = Intent(Intent.ACTION_MAIN).apply { addCategory(Intent.CATEGORY_HOME) }
@Suppress("DEPRECATION")
val resolveInfo = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
return resolveInfo?.let { it.activityInfo.packageName == packageName } ?: false
}
Expand Up @@ -55,11 +55,11 @@ internal fun AppInfo(

private fun Context.appIcon(): ImageBitmap = packageManager.getApplicationIcon(packageName).toBitmap().asImageBitmap()

@Suppress("DEPRECATION")
private fun Context.versionName(): String {
val versionName = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0)).versionName
} else {
@Suppress("DEPRECATION")
packageManager.getPackageInfo(packageName, 0).versionName
}
return if (versionName.isNullOrEmpty()) "-" else "v".plus(versionName)
Expand Down

0 comments on commit 408d22e

Please sign in to comment.