mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Added visuals to the app pinning
This commit is contained in:
parent
6a789fad6d
commit
85a5717140
12 changed files with 73 additions and 10 deletions
|
|
@ -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<TextView>(R.id.pin).setCompoundDrawablesWithIntrinsicBounds(null, topDrawable, null, null)
|
||||
|
||||
val pinLabel = when (isPinned) {
|
||||
true -> "Unpin"
|
||||
false -> "Pin"
|
||||
}
|
||||
|
||||
actionMenu.findViewById<TextView>(R.id.pin).text = pinLabel
|
||||
|
||||
actionMenu.findViewById<TextView>(R.id.pin).setOnClickListener {
|
||||
pinApp(appActivity, workProfile)
|
||||
animations.fadeViewOut(actionMenu)
|
||||
|
|
|
|||
|
|
@ -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<AppMenuAdapter.AppViewHolder>() {
|
||||
|
||||
|
|
@ -111,8 +111,17 @@ class AppMenuAdapter(
|
|||
holder.editView.visibility = View.INVISIBLE
|
||||
val app = apps[position]
|
||||
|
||||
// Set initial drawables
|
||||
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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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<Pair<String, Int?>> {
|
||||
val pinnedApps = mutableListOf<Pair<String, Int?>>()
|
||||
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()))
|
||||
|
|
|
|||
|
|
@ -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<Triple<LauncherActivityInfo, UserHandle, Int>> {
|
||||
!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(),
|
||||
|
|
|
|||
9
app/src/main/res/drawable/keep_15px.xml
Normal file
9
app/src/main/res/drawable/keep_15px.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="15dp"
|
||||
android:height="15dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="m640,480 l80,80v80L520,640v240l-40,40 -40,-40v-240L240,640v-80l80,-80v-280h-40v-80h400v80h-40v280ZM354,560h252l-46,-46v-314L400,200v314l-46,46ZM480,560Z" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/keep_24px.xml
Normal file
9
app/src/main/res/drawable/keep_24px.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#D3F3F3F3"
|
||||
android:pathData="m640,480 l80,80v80L520,640v240l-40,40 -40,-40v-240L240,640v-80l80,-80v-280h-40v-80h400v80h-40v280ZM354,560h252l-46,-46v-314L400,200v314l-46,46ZM480,560Z" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/keep_filled_15px.xml
Normal file
9
app/src/main/res/drawable/keep_filled_15px.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="15dp"
|
||||
android:height="15dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="m640,480 l80,80v80L520,640v240l-40,40 -40,-40v-240L240,640v-80l80,-80v-280h-40v-80h400v80h-40v280Z" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/keep_off_24px.xml
Normal file
9
app/src/main/res/drawable/keep_off_24px.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#D3F3F3F3"
|
||||
android:pathData="M680,120v80h-40v327l-80,-80v-247L400,200v87l-87,-87 -33,-33v-47h400ZM480,920l-40,-40v-240L240,640v-80l80,-80v-46L56,168l56,-56 736,736 -58,56 -264,-264h-6v240l-40,40ZM354,560h92l-44,-44 -2,-2 -46,46ZM480,367ZM402,516Z" />
|
||||
</vector>
|
||||
|
|
@ -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" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/info"
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
<string name="empty_rename">Name darf nicht leer sein</string>
|
||||
|
||||
<!--Action Menu Items-->
|
||||
<string name="pin">Pin</string>
|
||||
<string name="info">Info</string>
|
||||
<string name="uninstall">Deinstallieren</string>
|
||||
<string name="rename">Umbenennen</string>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
<string name="launch_error">Sovelluksen avaaminen epäonnistui</string>
|
||||
|
||||
<!--Action Menu Items-->
|
||||
<string name="pin">Pin</string>
|
||||
<string name="empty_rename">Nimi ei voi olla tyhjä</string>
|
||||
<string name="info">Tiedot</string>
|
||||
<string name="uninstall">Poista</string>
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
<string name="empty_rename">Name cannot be empty</string>
|
||||
|
||||
<!--Action Menu Items-->
|
||||
<string name="pin">Pin</string>
|
||||
<string name="info">Info</string>
|
||||
<string name="uninstall">Uninstall</string>
|
||||
<string name="rename">Rename</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue