Skip to content

Commit

Permalink
Add icon pack support in favorite apps shortcut (#113)
Browse files Browse the repository at this point in the history
* Add icon pack support in favorite apps shortcut
* minor improvements

---------

Co-authored-by: fs-sifat <125657944+fs-sifat@users.noreply.github.com>
Co-authored-by: Md Rasel Hossain <77199897+iamrasel@users.noreply.github.com>
  • Loading branch information
fs-sifat and iamrasel authored Mar 12, 2024
1 parent 4fd4a79 commit 02eed07
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/src/main/kotlin/rasel/lunar/launcher/helpers/UniUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ import androidx.core.view.isVisible
import com.google.android.material.imageview.ShapeableImageView
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
import rasel.lunar.launcher.R
import rasel.lunar.launcher.apps.IconPackManager.Companion.getDrawableIconForPackage
import rasel.lunar.launcher.helpers.Constants.Companion.ACCESSIBILITY_SERVICE_LOCK_SCREEN
import rasel.lunar.launcher.helpers.Constants.Companion.AUTHENTICATOR_TYPE
import rasel.lunar.launcher.helpers.Constants.Companion.DEFAULT_ICON_SIZE
import rasel.lunar.launcher.helpers.Constants.Companion.KEY_APPS_LAYOUT
import rasel.lunar.launcher.helpers.Constants.Companion.KEY_APP_NO_
import rasel.lunar.launcher.helpers.Constants.Companion.KEY_ICON_SIZE
import rasel.lunar.launcher.helpers.Constants.Companion.MAX_FAVORITE_APPS
Expand Down Expand Up @@ -192,6 +194,7 @@ internal class UniUtils {
/* favorite apps */
private fun populateFavApps(context: Context, linearLayoutCompat: LinearLayoutCompat) {
val prefsFavApps = context.getSharedPreferences(PREFS_FAVORITE_APPS, 0)
val useIconPack = context.getSharedPreferences(PREFS_SETTINGS, 0).getInt(KEY_APPS_LAYOUT, 0) != 0
if (linearLayoutCompat.isVisible || prefsFavApps.all.toString().length < 3) {
linearLayoutCompat.visibility = View.GONE
} else {
Expand All @@ -208,12 +211,18 @@ internal class UniUtils {
layoutParams = LinearLayoutCompat.LayoutParams(
(iconSize * resources.displayMetrics.density).toInt(),
(iconSize * resources.displayMetrics.density).toInt(), 1F)
}.let {
it.setImageDrawable(context.packageManager.getApplicationIcon(packageName))
it.setOnClickListener {
}.let { sImageView ->
context.packageManager.getApplicationIcon(packageName).let { defaultIcon ->
sImageView.setImageDrawable(
if (context.getSharedPreferences(PREFS_SETTINGS, 0).getInt(KEY_APPS_LAYOUT, 0) != 0)
getDrawableIconForPackage(packageName, defaultIcon)
else defaultIcon
)
}
sImageView.setOnClickListener {
context.startActivity(context.packageManager.getLaunchIntentForPackage(packageName))
}
linearLayoutCompat.addView(it)
linearLayoutCompat.addView(sImageView)
}
} catch (nameNotFoundException: PackageManager.NameNotFoundException) {
context.getSharedPreferences(PREFS_FAVORITE_APPS, 0)
Expand Down

0 comments on commit 02eed07

Please sign in to comment.