diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt index 4a0abb5..bf711c4 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt @@ -17,6 +17,7 @@ import android.widget.LinearLayout import android.widget.TextView import android.widget.Toast import androidx.appcompat.widget.AppCompatButton +import androidx.core.content.ContextCompat.getDrawable import androidx.core.view.ViewCompat import androidx.lifecycle.lifecycleScope import eu.ottop.yamlauncher.databinding.ActivityMainBinding @@ -42,6 +43,21 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act true } + val isPinned = sharedPreferenceManager.isAppPinned(appActivity.componentName.flattenToString(), workProfile) + val topDrawable = when (isPinned) { + true -> getDrawable(activity, R.drawable.keep_off_24px) + false -> getDrawable(activity,R.drawable.keep_24px) + } + + actionMenu.findViewById(R.id.pin).setCompoundDrawablesWithIntrinsicBounds(null, topDrawable, null, null) + + val pinLabel = when (isPinned) { + true -> "Unpin" + false -> "Pin" + } + + actionMenu.findViewById(R.id.pin).text = pinLabel + actionMenu.findViewById(R.id.pin).setOnClickListener { pinApp(appActivity, workProfile) animations.fadeViewOut(actionMenu) diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index f35a4f3..0bc4b61 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -30,7 +30,7 @@ class AppMenuAdapter( private val itemClickListener: OnItemClickListener, private val shortcutListener: OnShortcutListener, private val itemLongClickListener: OnItemLongClickListener, - private val launcherApps: LauncherApps + launcherApps: LauncherApps ) : RecyclerView.Adapter() { @@ -111,8 +111,17 @@ class AppMenuAdapter( holder.editView.visibility = View.INVISIBLE val app = apps[position] + if (sharedPreferenceManager.isAppPinned(app.first.componentName.flattenToString(), app.third)) { + if (app.third != 0) { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.keep_filled_15px, null),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null) + } + else { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.keep_15px, null),null,ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null) + } + holder.textView.compoundDrawables[0].colorFilter = BlendModeColorFilter(sharedPreferenceManager.getTextColor(), BlendMode.SRC_ATOP) + } // Set initial drawables - if (app.third != 0) { + else if (app.third != 0) { holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_work_app, null),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null) holder.textView.compoundDrawables[0].colorFilter = BlendModeColorFilter(sharedPreferenceManager.getTextColor(), BlendMode.SRC_ATOP) @@ -171,6 +180,7 @@ class AppMenuAdapter( app.third, ) } + ViewCompat.addAccessibilityAction(holder.textView, activity.getString(R.string.close_app_menu)) { _, _ -> activity.backToHome() true diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt index 312a5a6..e3b14be 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -125,7 +125,7 @@ class SharedPreferenceManager (private val context: Context) { fun setPinnedApp(componentName: String, profile: Int) { val editor = preferences.edit() - println(isAppPinned(componentName, profile)) + val pinnedAppString = when (isAppPinned(componentName, profile)) { true -> { getPinnedAppString()?.replace("§section§$componentName§splitter§$profile", "") @@ -148,9 +148,9 @@ class SharedPreferenceManager (private val context: Context) { private fun getPinnedApps(): List> { val pinnedApps = mutableListOf>() - val pinnedAppsList = getPinnedAppString()?.split("§section§") + val pinnedAppList = getPinnedAppString()?.split("§section§") - pinnedAppsList?.forEach { + pinnedAppList?.forEach { val app = it.split("§splitter§") if (app.size > 1) { pinnedApps.add(Pair(app[0], app[1].toIntOrNull())) diff --git a/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt index 4fcd5c8..325211f 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt @@ -6,8 +6,6 @@ import android.content.pm.ApplicationInfo import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherApps import android.os.UserHandle -import android.widget.Toast -import eu.ottop.yamlauncher.R import eu.ottop.yamlauncher.settings.SharedPreferenceManager import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -35,7 +33,7 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA // Sort apps by name sortedApps = allApps.sortedWith( compareBy> { - !sharedPreferenceManager.isAppPinned(it.first.componentName.flattenToString(), it.third) + !sharedPreferenceManager.isAppPinned(it.first.componentName.flattenToString(), it.third) // This displays the pinned apps for some reason. }.thenBy { sharedPreferenceManager.getAppName( it.first.componentName.flattenToString(), diff --git a/app/src/main/res/drawable/keep_15px.xml b/app/src/main/res/drawable/keep_15px.xml new file mode 100644 index 0000000..681d50d --- /dev/null +++ b/app/src/main/res/drawable/keep_15px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/keep_24px.xml b/app/src/main/res/drawable/keep_24px.xml new file mode 100644 index 0000000..0e11a18 --- /dev/null +++ b/app/src/main/res/drawable/keep_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/keep_filled_15px.xml b/app/src/main/res/drawable/keep_filled_15px.xml new file mode 100644 index 0000000..095a91f --- /dev/null +++ b/app/src/main/res/drawable/keep_filled_15px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/keep_off_24px.xml b/app/src/main/res/drawable/keep_off_24px.xml new file mode 100644 index 0000000..f73f221 --- /dev/null +++ b/app/src/main/res/drawable/keep_off_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/app_item_layout.xml b/app/src/main/res/layout/app_item_layout.xml index ccf0bec..e7df845 100644 --- a/app/src/main/res/layout/app_item_layout.xml +++ b/app/src/main/res/layout/app_item_layout.xml @@ -91,11 +91,11 @@ android:background="@drawable/app_action_background" android:paddingVertical="5dp" android:singleLine="true" - android:text="@string/info" + android:text="@string/pin" android:textAlignment="center" android:textAppearance="@android:style/TextAppearance.DeviceDefault" android:textColor="#E3F3F3F3" - app:drawableTopCompat="@drawable/info_24px" /> + app:drawableTopCompat="@drawable/keep_24px" /> Name darf nicht leer sein + Pin Info Deinstallieren Umbenennen diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index c17b559..f449e00 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -33,6 +33,7 @@ Sovelluksen avaaminen epäonnistui + Pin Nimi ei voi olla tyhjä Tiedot Poista diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8350222..df21a8d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -36,6 +36,7 @@ Name cannot be empty + Pin Info Uninstall Rename