Feat: Added app font color to headers of the page.

Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
HeCodes2Much
2024-05-27 14:54:12 +01:00
parent 162d8a0386
commit b7ff0d8b1a
7 changed files with 71 additions and 15 deletions

View File

@@ -3,6 +3,9 @@ package com.github.droidworksstudio.launcher.ui.drawer
import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.Log
import android.view.LayoutInflater
import android.view.View
@@ -98,6 +101,16 @@ class DrawFragment : Fragment(),
private fun observeDrawerApps() {
viewModel.compareInstalledAppInfo()
val searchAppsHint = getString(R.string.search)
val coloredHint = SpannableString(searchAppsHint)
coloredHint.setSpan(
ForegroundColorSpan(preferenceHelper.appColor),
0,
searchAppsHint.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
binding.searchViewText.queryHint = coloredHint
@Suppress("DEPRECATION")
viewLifecycleOwner.lifecycleScope.launchWhenCreated {
viewModel.drawApps.collect {

View File

@@ -7,12 +7,14 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.github.droidworksstudio.launcher.data.entities.AppInfo
import com.github.droidworksstudio.launcher.databinding.ItemFavoriteBinding
import com.github.droidworksstudio.launcher.helper.PreferenceHelper
import com.github.droidworksstudio.launcher.listener.OnItemClickedListener
import com.github.droidworksstudio.launcher.listener.OnItemMoveListener
class FavoriteAdapter(
private val onAppClickedListener:
OnItemClickedListener.OnAppsClickedListener,
private val preferenceHelperProvider: PreferenceHelper
) : ListAdapter<AppInfo, RecyclerView.ViewHolder>(DiffCallback()),
OnItemMoveListener.OnItemActionListener {
@@ -27,7 +29,13 @@ class FavoriteAdapter(
parent,
false
)
return FavoriteViewHolder(binding, onAppClickedListener, touchHelper)
val preferenceHelper = preferenceHelperProvider
return FavoriteViewHolder(
binding,
onAppClickedListener,
preferenceHelper,
touchHelper
)
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {

View File

@@ -58,7 +58,7 @@ class FavoriteFragment : Fragment(),
@Inject
lateinit var appHelper: AppHelper
private val favoriteAdapter: FavoriteAdapter by lazy { FavoriteAdapter(this) }
private val favoriteAdapter: FavoriteAdapter by lazy { FavoriteAdapter(this, preferenceHelper) }
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
@@ -107,6 +107,8 @@ class FavoriteFragment : Fragment(),
}
private fun observeFavorite() {
binding.topTextView.setTextColor(preferenceHelper.appColor)
viewModel.compareInstalledAppInfo()
viewLifecycleOwner.lifecycleScope.launch {
viewModel.favoriteApps.collect {
@@ -180,7 +182,7 @@ class FavoriteFragment : Fragment(),
@SuppressLint("ClickableViewAccessibility")
private fun observeSwipeTouchListener() {
binding.touchArea.setOnTouchListener(getSwipeGestureListener(context))
binding.fragmentContainer.setOnTouchListener(getSwipeGestureListener(context))
binding.favoriteAdapter.setOnTouchListener(getSwipeGestureListener(context))
}

View File

@@ -1,18 +1,26 @@
package com.github.droidworksstudio.launcher.ui.favorite
import android.annotation.SuppressLint
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Build
import android.util.Log
import android.view.MotionEvent
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.github.droidworksstudio.launcher.data.entities.AppInfo
import com.github.droidworksstudio.launcher.databinding.ItemFavoriteBinding
import com.github.droidworksstudio.launcher.helper.PreferenceHelper
import com.github.droidworksstudio.launcher.listener.OnItemClickedListener
@SuppressLint("ClickableViewAccessibility")
class FavoriteViewHolder(
private val binding: ItemFavoriteBinding,
private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener,
private val preferenceHelper: PreferenceHelper,
private val touchHelper: ItemTouchHelper,
) :
RecyclerView.ViewHolder(binding.root) {
@@ -27,10 +35,42 @@ class FavoriteViewHolder(
}
fun bind(appInfo: AppInfo) {
binding.apply {
// Get the current LayoutParams of appFavoriteName
val layoutParams = appFavoriteName.layoutParams as LinearLayoutCompat.LayoutParams
// Set the margins
layoutParams.topMargin = preferenceHelper.homeAppPadding.toInt()
layoutParams.bottomMargin = preferenceHelper.homeAppPadding.toInt()
appFavoriteName.layoutParams = layoutParams
appFavoriteName.text = appInfo.appName
//appFavoriteDragIcon.visibility = View.GONE
appFavoriteName.setTextColor(preferenceHelper.appColor)
appFavoriteName.textSize = preferenceHelper.appTextSize
Log.d("Tag", "Draw Adapter: ${appInfo.appName}")
// Create a BlendModeColorFilter with the specified color and blend mode
val blendModeColorFilter = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
BlendModeColorFilter(
preferenceHelper.appColor,
BlendMode.SRC_IN
)
} else {
PorterDuffColorFilter(
preferenceHelper.appColor,
PorterDuff.Mode.SRC_IN
)
}
// Get the current drawable set as the background
val drawable = appFavoriteDragIcon.background.mutate()
// Apply a color filter to change its color
drawable.colorFilter = blendModeColorFilter
// Set the modified drawable back as the background
appFavoriteDragIcon.background = drawable
}
itemView.setOnClickListener {

View File

@@ -7,13 +7,6 @@
android:id="@+id/favorite_view"
tools:context=".ui.favorite.FavoriteFragment">
<FrameLayout
android:id="@+id/touchArea"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
@@ -38,7 +31,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/favoriteAdapter"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="92dp"

View File

@@ -91,7 +91,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/appListAdapter"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.appcompat.widget.LinearLayoutCompat>

View File

@@ -14,7 +14,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appFavorite_name"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="10dp"
android:layout_weight="1"
@@ -23,7 +23,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded"
style="@style/TextDefaultStyle"/>
style="@style/TextDefaultStyle" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/appFavorite_drag_icon"