mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Unified rest of preference management into SharedPreferenceManager
This commit is contained in:
parent
240bf4463b
commit
830c45cb63
14 changed files with 182 additions and 169 deletions
|
|
@ -18,8 +18,6 @@ import android.widget.TextView
|
||||||
import androidx.appcompat.widget.AppCompatButton
|
import androidx.appcompat.widget.AppCompatButton
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class AppActionMenu {
|
class AppActionMenu {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import android.content.pm.LauncherActivityInfo
|
||||||
import android.content.pm.LauncherApps
|
import android.content.pm.LauncherApps
|
||||||
import android.graphics.BlendMode
|
import android.graphics.BlendMode
|
||||||
import android.graphics.BlendModeColorFilter
|
import android.graphics.BlendModeColorFilter
|
||||||
import android.graphics.Color
|
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
@ -16,7 +15,6 @@ import android.widget.FrameLayout
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
|
|
||||||
|
|
@ -35,9 +33,8 @@ class AppMenuAdapter(
|
||||||
var shortcutTextView: TextView? = null
|
var shortcutTextView: TextView? = null
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||||
private var preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
private val uiUtils = UIUtils(context)
|
private val uiUtils = UIUtils(context)
|
||||||
private val appUtils = AppUtils(context)
|
private val appUtils = AppUtils(context, launcherApps)
|
||||||
|
|
||||||
interface OnItemClickListener {
|
interface OnItemClickListener {
|
||||||
fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle)
|
fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle)
|
||||||
|
|
@ -115,23 +112,22 @@ class AppMenuAdapter(
|
||||||
if (app.second.second != 0) {
|
if (app.second.second != 0) {
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null, ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null, ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null)
|
||||||
holder.textView.compoundDrawables[0].colorFilter =
|
holder.textView.compoundDrawables[0].colorFilter =
|
||||||
BlendModeColorFilter(Color.parseColor(preferences?.getString("textColor", "#FFF3F3F3")), BlendMode.SRC_ATOP)
|
BlendModeColorFilter(sharedPreferenceManager.getTextColor(), BlendMode.SRC_ATOP)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null,ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null,ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null)
|
||||||
}
|
}
|
||||||
|
|
||||||
uiUtils.setAppAlignment(context, preferences, holder.textView, holder.editText)
|
uiUtils.setAppAlignment(holder.textView, holder.editText)
|
||||||
|
|
||||||
uiUtils.setAppSize(preferences, holder.textView, holder.editText)
|
uiUtils.setAppSize(holder.textView, holder.editText)
|
||||||
|
|
||||||
val appInfo = appUtils.getAppInfo(
|
val appInfo = appUtils.getAppInfo(
|
||||||
launcherApps,
|
|
||||||
app.first.applicationInfo.packageName,
|
app.first.applicationInfo.packageName,
|
||||||
app.second.second
|
app.second.second
|
||||||
)
|
)
|
||||||
|
|
||||||
holder.textView.setTextColor(Color.parseColor(preferences?.getString("textColor", "#FFF3F3F3")))
|
holder.textView.setTextColor(sharedPreferenceManager.getTextColor())
|
||||||
val appLabel: CharSequence = appInfo?.loadLabel(context.packageManager) ?: "Removing..."
|
val appLabel: CharSequence = appInfo?.loadLabel(context.packageManager) ?: "Removing..."
|
||||||
|
|
||||||
if (appInfo != null) {
|
if (appInfo != null) {
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ import androidx.appcompat.app.AppCompatActivity
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class AppUtils(private val context: Context) {
|
class AppUtils(private val context: Context, private val launcherApps: LauncherApps) {
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||||
|
|
||||||
suspend fun getInstalledApps(launcherApps: LauncherApps): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
suspend fun getInstalledApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||||
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
var sortedApps = listOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
var sortedApps = listOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
|
|
@ -44,7 +44,6 @@ class AppUtils(private val context: Context) {
|
||||||
|
|
||||||
fun getHiddenApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
fun getHiddenApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||||
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
val launcherApps = context.getSystemService(AppCompatActivity.LAUNCHER_APPS_SERVICE) as LauncherApps
|
|
||||||
for (i in launcherApps.profiles.indices) {
|
for (i in launcherApps.profiles.indices) {
|
||||||
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
|
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
|
||||||
if (sharedPreferenceManager.isAppHidden(app.applicationInfo.packageName, i)) {
|
if (sharedPreferenceManager.isAppHidden(app.applicationInfo.packageName, i)) {
|
||||||
|
|
@ -62,7 +61,6 @@ class AppUtils(private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAppInfo(
|
fun getAppInfo(
|
||||||
launcherApps: LauncherApps,
|
|
||||||
packageName: String,
|
packageName: String,
|
||||||
profile: Int
|
profile: Int
|
||||||
): ApplicationInfo? {
|
): ApplicationInfo? {
|
||||||
|
|
@ -73,7 +71,7 @@ class AppUtils(private val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchApp(launcherApps: LauncherApps, appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
fun launchApp(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
||||||
val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull()
|
val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull()
|
||||||
if (mainActivity != null) {
|
if (mainActivity != null) {
|
||||||
launcherApps.startMainActivity(mainActivity.componentName, userHandle, null, null)
|
launcherApps.startMainActivity(mainActivity.componentName, userHandle, null, null)
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.os.BatteryManager
|
import android.os.BatteryManager
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class BatteryReceiver(private val activity: MainActivity) : BroadcastReceiver() {
|
class BatteryReceiver(private val activity: MainActivity) : BroadcastReceiver() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
class GestureAppsAdapter(
|
class GestureAppsAdapter(
|
||||||
|
|
@ -21,7 +20,6 @@ class GestureAppsAdapter(
|
||||||
RecyclerView.Adapter<GestureAppsAdapter.AppViewHolder>() {
|
RecyclerView.Adapter<GestureAppsAdapter.AppViewHolder>() {
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||||
private var preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
private val uiUtils = UIUtils(context)
|
private val uiUtils = UIUtils(context)
|
||||||
|
|
||||||
interface OnItemClickListener {
|
interface OnItemClickListener {
|
||||||
|
|
@ -58,9 +56,9 @@ class GestureAppsAdapter(
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null,null,null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null,null,null)
|
||||||
}
|
}
|
||||||
|
|
||||||
uiUtils.setAppAlignment(context, preferences, holder.textView)
|
uiUtils.setAppAlignment(holder.textView)
|
||||||
|
|
||||||
uiUtils.setAppSize(preferences, holder.textView)
|
uiUtils.setAppSize(holder.textView)
|
||||||
|
|
||||||
val appInfo = app.first.activityInfo.applicationInfo
|
val appInfo = app.first.activityInfo.applicationInfo
|
||||||
holder.textView.text = sharedPreferenceManager.getAppName(
|
holder.textView.text = sharedPreferenceManager.getAppName(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package eu.ottop.yamlauncher
|
||||||
|
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.content.pm.LauncherActivityInfo
|
import android.content.pm.LauncherActivityInfo
|
||||||
import android.content.pm.LauncherApps
|
import android.content.pm.LauncherApps
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
|
@ -41,25 +40,26 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
appUtils = AppUtils(requireContext())
|
launcherApps = requireContext().getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||||
|
|
||||||
|
appUtils = AppUtils(requireContext(), launcherApps)
|
||||||
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
|
|
||||||
launcherApps = requireContext().getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
|
||||||
|
|
||||||
adapter = GestureAppsAdapter(
|
adapter = GestureAppsAdapter(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
appUtils.getInstalledApps(launcherApps).toMutableList(),
|
appUtils.getInstalledApps().toMutableList(),
|
||||||
this@GestureAppsFragment
|
this@GestureAppsFragment
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val recyclerView = view.findViewById<RecyclerView>(R.id.gesture_app_recycler)
|
val recyclerView = view.findViewById<RecyclerView>(R.id.gesture_app_recycler)
|
||||||
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
||||||
val uiUtils = UIUtils(requireContext())
|
val uiUtils = UIUtils(requireContext())
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
|
||||||
|
|
||||||
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
|
|
@ -68,9 +68,9 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
||||||
|
|
||||||
val searchView = view.findViewById<TextInputEditText>(R.id.gestureAppSearch)
|
val searchView = view.findViewById<TextInputEditText>(R.id.gestureAppSearch)
|
||||||
|
|
||||||
uiUtils.setMenuTitleAlignment(preferences, view.findViewById(R.id.gesture_menutitle))
|
uiUtils.setMenuTitleAlignment(view.findViewById(R.id.gesture_menutitle))
|
||||||
uiUtils.setSearchAlignment(preferences, searchView)
|
uiUtils.setSearchAlignment(searchView)
|
||||||
uiUtils.setSearchSize(preferences, searchView)
|
uiUtils.setSearchSize(searchView)
|
||||||
|
|
||||||
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
||||||
|
|
||||||
val cleanQuery = stringUtils.cleanString(query)
|
val cleanQuery = stringUtils.cleanString(query)
|
||||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
val updatedApps = appUtils.getInstalledApps(launcherApps)
|
val updatedApps = appUtils.getInstalledApps()
|
||||||
|
|
||||||
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
class HiddenAppsAdapter(
|
class HiddenAppsAdapter(
|
||||||
|
|
@ -21,8 +20,6 @@ class HiddenAppsAdapter(
|
||||||
RecyclerView.Adapter<HiddenAppsAdapter.AppViewHolder>() {
|
RecyclerView.Adapter<HiddenAppsAdapter.AppViewHolder>() {
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||||
private var preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
|
|
||||||
private val uiUtils = UIUtils(context)
|
private val uiUtils = UIUtils(context)
|
||||||
|
|
||||||
interface OnItemClickListener {
|
interface OnItemClickListener {
|
||||||
|
|
@ -60,9 +57,9 @@ class HiddenAppsAdapter(
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null,null,null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null,null,null)
|
||||||
}
|
}
|
||||||
|
|
||||||
uiUtils.setAppAlignment(context, preferences, holder.textView)
|
uiUtils.setAppAlignment(holder.textView)
|
||||||
|
|
||||||
uiUtils.setAppSize(preferences, holder.textView)
|
uiUtils.setAppSize(holder.textView)
|
||||||
|
|
||||||
val appInfo = app.first.activityInfo.applicationInfo
|
val appInfo = app.first.activityInfo.applicationInfo
|
||||||
holder.textView.text = sharedPreferenceManager.getAppName(
|
holder.textView.text = sharedPreferenceManager.getAppName(
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package eu.ottop.yamlauncher
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.LauncherActivityInfo
|
import android.content.pm.LauncherActivityInfo
|
||||||
|
import android.content.pm.LauncherApps
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
|
|
@ -17,11 +18,13 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
|
|
||||||
class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
||||||
private lateinit var appUtils: AppUtils
|
|
||||||
private lateinit var sharedPreferenceManager: SharedPreferenceManager
|
private lateinit var sharedPreferenceManager: SharedPreferenceManager
|
||||||
private var adapter: HiddenAppsAdapter? = null
|
private var adapter: HiddenAppsAdapter? = null
|
||||||
private var stringUtils = StringUtils()
|
private var stringUtils = StringUtils()
|
||||||
private lateinit var uiUtils: UIUtils
|
private lateinit var uiUtils: UIUtils
|
||||||
|
private lateinit var appUtils: AppUtils
|
||||||
|
private lateinit var launcherApps: LauncherApps
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
|
@ -33,13 +36,13 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
launcherApps = requireContext().getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||||
uiUtils = UIUtils(requireContext())
|
uiUtils = UIUtils(requireContext())
|
||||||
appUtils = AppUtils(requireContext())
|
appUtils = AppUtils(requireContext(), launcherApps)
|
||||||
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
||||||
|
|
||||||
val recyclerView = view.findViewById<RecyclerView>(R.id.hidden_app_recycler)
|
val recyclerView = view.findViewById<RecyclerView>(R.id.hidden_app_recycler)
|
||||||
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
|
||||||
|
|
||||||
adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps().toMutableList(), this)
|
adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps().toMutableList(), this)
|
||||||
|
|
||||||
|
|
@ -51,9 +54,9 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
||||||
|
|
||||||
val searchView = view.findViewById<TextInputEditText>(R.id.hiddenAppSearch)
|
val searchView = view.findViewById<TextInputEditText>(R.id.hiddenAppSearch)
|
||||||
|
|
||||||
uiUtils.setMenuTitleAlignment(preferences, view.findViewById(R.id.hidden_menutitle))
|
uiUtils.setMenuTitleAlignment(view.findViewById(R.id.hidden_menutitle))
|
||||||
uiUtils.setSearchAlignment(preferences, searchView)
|
uiUtils.setSearchAlignment(searchView)
|
||||||
uiUtils.setSearchSize(preferences, searchView)
|
uiUtils.setSearchSize(searchView)
|
||||||
|
|
||||||
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||||
|
|
||||||
|
|
@ -78,7 +81,7 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("autoKeyboard", false)) {
|
if (sharedPreferenceManager.isAutoKeyboardEnabled()) {
|
||||||
val imm =
|
val imm =
|
||||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
searchView.requestFocus()
|
searchView.requestFocus()
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,6 @@ class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener {
|
||||||
|
|
||||||
var locationList = mutableListOf<Map<String, String>>()
|
var locationList = mutableListOf<Map<String, String>>()
|
||||||
|
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
|
||||||
|
|
||||||
stringUtils.setLink(requireActivity().findViewById(R.id.locationLink), getString(R.string.location_link))
|
stringUtils.setLink(requireActivity().findViewById(R.id.locationLink), getString(R.string.location_link))
|
||||||
|
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
|
@ -56,9 +54,9 @@ class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener {
|
||||||
adapter = LocationListAdapter(requireContext(), locationList, this)
|
adapter = LocationListAdapter(requireContext(), locationList, this)
|
||||||
val recyclerView = view.findViewById<RecyclerView>(R.id.locationrecycler)
|
val recyclerView = view.findViewById<RecyclerView>(R.id.locationrecycler)
|
||||||
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
||||||
uiUtils.setMenuTitleAlignment(preferences, view.findViewById(R.id.location_menutitle))
|
uiUtils.setMenuTitleAlignment(view.findViewById(R.id.location_menutitle))
|
||||||
uiUtils.setSearchAlignment(preferences, searchView)
|
uiUtils.setSearchAlignment(searchView)
|
||||||
uiUtils.setSearchSize(preferences, searchView)
|
uiUtils.setSearchSize(searchView)
|
||||||
|
|
||||||
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
|
|
@ -97,7 +95,7 @@ class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("autoKeyboard", false)) {
|
if (sharedPreferenceManager.isAutoKeyboardEnabled()) {
|
||||||
val imm =
|
val imm =
|
||||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
searchView.requestFocus()
|
searchView.requestFocus()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
class LocationListAdapter(
|
class LocationListAdapter(
|
||||||
|
|
@ -17,7 +16,6 @@ class LocationListAdapter(
|
||||||
) :
|
) :
|
||||||
RecyclerView.Adapter<LocationListAdapter.AppViewHolder>() {
|
RecyclerView.Adapter<LocationListAdapter.AppViewHolder>() {
|
||||||
|
|
||||||
private var preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
private val uiUtils = UIUtils(context)
|
private val uiUtils = UIUtils(context)
|
||||||
|
|
||||||
interface OnItemClickListener {
|
interface OnItemClickListener {
|
||||||
|
|
@ -51,9 +49,9 @@ class LocationListAdapter(
|
||||||
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
||||||
val app = apps[position]
|
val app = apps[position]
|
||||||
|
|
||||||
uiUtils.setAppAlignment(context, preferences, holder.textView, null ,holder.regionText)
|
uiUtils.setAppAlignment(holder.textView, null, holder.regionText)
|
||||||
|
|
||||||
uiUtils.setAppSize(preferences, holder.textView, null, holder.regionText)
|
uiUtils.setAppSize(holder.textView, null, holder.regionText)
|
||||||
|
|
||||||
holder.textView.text = app["name"]
|
holder.textView.text = app["name"]
|
||||||
holder.regionText.text = context.getString(R.string.region_text, app["region"], app["country"])
|
holder.regionText.text = context.getString(R.string.region_text, app["region"], app["country"])
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMainVariables() {
|
private fun setMainVariables() {
|
||||||
|
launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||||
|
|
||||||
weatherSystem = WeatherSystem(this@MainActivity)
|
weatherSystem = WeatherSystem(this@MainActivity)
|
||||||
appUtils = AppUtils(this@MainActivity)
|
appUtils = AppUtils(this@MainActivity, launcherApps)
|
||||||
uiUtils = UIUtils(this@MainActivity)
|
uiUtils = UIUtils(this@MainActivity)
|
||||||
gestureUtils = GestureUtils(this@MainActivity)
|
gestureUtils = GestureUtils(this@MainActivity)
|
||||||
sharedPreferenceManager = SharedPreferenceManager(this@MainActivity)
|
sharedPreferenceManager = SharedPreferenceManager(this@MainActivity)
|
||||||
|
|
@ -141,8 +143,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
searchView = findViewById(R.id.searchView)
|
searchView = findViewById(R.id.searchView)
|
||||||
|
|
||||||
launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
|
||||||
|
|
||||||
preferences = PreferenceManager.getDefaultSharedPreferences(this)
|
preferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,14 +152,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
uiUtils.setSearchColors(searchView)
|
uiUtils.setSearchColors(searchView)
|
||||||
|
|
||||||
uiUtils.setClockAlignment(clock, dateText)
|
uiUtils.setClockAlignment(clock, dateText)
|
||||||
uiUtils.setSearchAlignment(preferences, searchView)
|
uiUtils.setSearchAlignment(searchView)
|
||||||
|
|
||||||
uiUtils.setClockSize(preferences, clock)
|
uiUtils.setClockSize(clock)
|
||||||
uiUtils.setDateSize(preferences, dateText)
|
uiUtils.setDateSize(dateText)
|
||||||
uiUtils.setShortcutSize(preferences, binding.homeView)
|
uiUtils.setShortcutSize(binding.homeView)
|
||||||
uiUtils.setSearchSize(preferences, searchView)
|
uiUtils.setSearchSize(searchView)
|
||||||
|
|
||||||
uiUtils.setStatusBar(window, preferences)
|
uiUtils.setStatusBar(window)
|
||||||
|
|
||||||
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
||||||
rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right")
|
rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right")
|
||||||
|
|
@ -172,7 +172,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
val textView = findViewById<TextView>(shortcuts[i])
|
val textView = findViewById<TextView>(shortcuts[i])
|
||||||
|
|
||||||
val shortcutNo = preferences.getString("shortcutNo", "4")?.toInt()
|
val shortcutNo = sharedPreferenceManager.getShortcutNumber()
|
||||||
|
|
||||||
if (i >= shortcutNo!!) {
|
if (i >= shortcutNo!!) {
|
||||||
textView.visibility = View.GONE
|
textView.visibility = View.GONE
|
||||||
|
|
@ -189,7 +189,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
setShortcutSetup(textView, savedView)
|
setShortcutSetup(textView, savedView)
|
||||||
}
|
}
|
||||||
|
|
||||||
uiUtils.setShortcutAlignment(preferences, binding.homeView)
|
uiUtils.setShortcutAlignment(binding.homeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -213,7 +213,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
textView.setOnLongClickListener {
|
textView.setOnLongClickListener {
|
||||||
uiUtils.setMenuTitleAlignment(preferences, binding.menutitle)
|
uiUtils.setMenuTitleAlignment(binding.menutitle)
|
||||||
binding.menutitle.visibility = View.VISIBLE
|
binding.menutitle.visibility = View.VISIBLE
|
||||||
|
|
||||||
adapter?.shortcutTextView = textView
|
adapter?.shortcutTextView = textView
|
||||||
|
|
@ -226,7 +226,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
private fun toAppMenu() {
|
private fun toAppMenu() {
|
||||||
animations.showApps(binding)
|
animations.showApps(binding)
|
||||||
animations.backgroundIn(this@MainActivity)
|
animations.backgroundIn(this@MainActivity)
|
||||||
if (preferences.getBoolean("autoKeyboard", false)) {
|
if (sharedPreferenceManager.isAutoKeyboardEnabled()) {
|
||||||
val imm =
|
val imm =
|
||||||
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
searchView.requestFocus()
|
searchView.requestFocus()
|
||||||
|
|
@ -260,7 +260,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
private fun setHomeListeners() {
|
private fun setHomeListeners() {
|
||||||
registerBatteryReceiver()
|
registerBatteryReceiver()
|
||||||
|
|
||||||
if (!preferences.getBoolean("battery_enabled", false)) {
|
if (!sharedPreferenceManager.isBatteryEnabled()) {
|
||||||
unregisterBatteryReceiver()
|
unregisterBatteryReceiver()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,31 +310,31 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
"shortcutAlignment" -> {
|
"shortcutAlignment" -> {
|
||||||
uiUtils.setShortcutAlignment(preferences, binding.homeView)
|
uiUtils.setShortcutAlignment(binding.homeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
"searchAlignment" -> {
|
"searchAlignment" -> {
|
||||||
uiUtils.setSearchAlignment(preferences, searchView)
|
uiUtils.setSearchAlignment(searchView)
|
||||||
}
|
}
|
||||||
|
|
||||||
"clockSize" -> {
|
"clockSize" -> {
|
||||||
uiUtils.setClockSize(preferences, clock)
|
uiUtils.setClockSize(clock)
|
||||||
}
|
}
|
||||||
|
|
||||||
"dateSize" -> {
|
"dateSize" -> {
|
||||||
uiUtils.setDateSize(preferences, dateText)
|
uiUtils.setDateSize(dateText)
|
||||||
}
|
}
|
||||||
|
|
||||||
"shortcutSize" -> {
|
"shortcutSize" -> {
|
||||||
uiUtils.setShortcutSize(preferences, binding.homeView)
|
uiUtils.setShortcutSize(binding.homeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
"searchSize" -> {
|
"searchSize" -> {
|
||||||
uiUtils.setSearchSize(preferences, searchView)
|
uiUtils.setSearchSize(searchView)
|
||||||
}
|
}
|
||||||
|
|
||||||
"barVisibility" -> {
|
"barVisibility" -> {
|
||||||
uiUtils.setStatusBar(window, preferences)
|
uiUtils.setStatusBar(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
"leftSwipeApp" -> {
|
"leftSwipeApp" -> {
|
||||||
|
|
@ -346,7 +346,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
"battery_enabled" -> {
|
"battery_enabled" -> {
|
||||||
if (preferences.getBoolean(key, false)) {
|
if (sharedPreferenceManager.isBatteryEnabled()) {
|
||||||
registerBatteryReceiver()
|
registerBatteryReceiver()
|
||||||
} else {
|
} else {
|
||||||
unregisterBatteryReceiver()
|
unregisterBatteryReceiver()
|
||||||
|
|
@ -405,7 +405,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
suspend fun refreshAppMenu() {
|
suspend fun refreshAppMenu() {
|
||||||
try {
|
try {
|
||||||
if (isJobActive) {
|
if (isJobActive) {
|
||||||
val updatedApps = appUtils.getInstalledApps(launcherApps)
|
val updatedApps = appUtils.getInstalledApps()
|
||||||
if (!listsEqual(installedApps, updatedApps)) {
|
if (!listsEqual(installedApps, updatedApps)) {
|
||||||
|
|
||||||
updateMenu(updatedApps)
|
updateMenu(updatedApps)
|
||||||
|
|
@ -438,8 +438,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
private suspend fun updateWeather() {
|
private suspend fun updateWeather() {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (preferences.getBoolean("weather_enabled", false)) {
|
if (sharedPreferenceManager.isWeatherEnabled()) {
|
||||||
if (preferences.getBoolean("gps_location", false)) {
|
if (sharedPreferenceManager.isWeatherGPS()) {
|
||||||
weatherSystem.setGpsLocation(this@MainActivity)
|
weatherSystem.setGpsLocation(this@MainActivity)
|
||||||
} else {
|
} else {
|
||||||
updateWeatherText()
|
updateWeatherText()
|
||||||
|
|
@ -462,7 +462,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
private fun setupApps() {
|
private fun setupApps() {
|
||||||
lifecycleScope.launch(Dispatchers.Default) {
|
lifecycleScope.launch(Dispatchers.Default) {
|
||||||
installedApps = appUtils.getInstalledApps(launcherApps)
|
installedApps = appUtils.getInstalledApps()
|
||||||
val newApps = installedApps.toMutableList()
|
val newApps = installedApps.toMutableList()
|
||||||
|
|
||||||
setupRecyclerView(newApps)
|
setupRecyclerView(newApps)
|
||||||
|
|
@ -526,7 +526,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
val cleanQuery = stringUtils.cleanString(query)
|
val cleanQuery = stringUtils.cleanString(query)
|
||||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
val updatedApps = appUtils.getInstalledApps(launcherApps)
|
val updatedApps = appUtils.getInstalledApps()
|
||||||
|
|
||||||
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||||
}
|
}
|
||||||
|
|
@ -598,7 +598,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
||||||
appUtils.launchApp(launcherApps, appInfo, userHandle)
|
appUtils.launchApp(appInfo, userHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onShortcut(
|
override fun onShortcut(
|
||||||
|
|
@ -615,38 +615,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
shortcutView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
shortcutView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (preferences.getString("shortcutAlignment", "left")) {
|
|
||||||
"left" -> {
|
|
||||||
shortcutView.setCompoundDrawablesWithIntrinsicBounds(
|
|
||||||
textView.compoundDrawables.filterNotNull().first(), null, null, null
|
|
||||||
)
|
|
||||||
shortcutView.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
|
||||||
}
|
|
||||||
|
|
||||||
"center" -> {
|
|
||||||
shortcutView.setCompoundDrawablesWithIntrinsicBounds(
|
|
||||||
shortcutView.compoundDrawables.filterNotNull().first(),
|
|
||||||
null,
|
|
||||||
shortcutView.compoundDrawables.filterNotNull().first(),
|
|
||||||
null
|
|
||||||
)
|
|
||||||
shortcutView.gravity = Gravity.CENTER
|
|
||||||
}
|
|
||||||
|
|
||||||
"right" -> {
|
|
||||||
shortcutView.setCompoundDrawablesWithIntrinsicBounds(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
shortcutView.compoundDrawables.filterNotNull().first(),
|
|
||||||
null
|
|
||||||
)
|
|
||||||
shortcutView.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shortcutView.text = textView.text.toString()
|
shortcutView.text = textView.text.toString()
|
||||||
shortcutView.setOnClickListener {
|
shortcutView.setOnClickListener {
|
||||||
appUtils.launchApp(launcherApps, appInfo, userHandle)
|
appUtils.launchApp(appInfo, userHandle)
|
||||||
}
|
}
|
||||||
sharedPreferenceManager.setShortcut(
|
sharedPreferenceManager.setShortcut(
|
||||||
shortcutView,
|
shortcutView,
|
||||||
|
|
@ -714,7 +685,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swipe left
|
// Swipe left
|
||||||
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("leftSwipe", true)){
|
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("left")){
|
||||||
|
|
||||||
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
|
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
|
||||||
launcherApps.startMainActivity(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!], null, null)
|
launcherApps.startMainActivity(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!], null, null)
|
||||||
|
|
@ -725,7 +696,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
|
|
||||||
// Swipe right
|
// Swipe right
|
||||||
else if (deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("rightSwipe", true)) {
|
else if (deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("right")) {
|
||||||
if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) {
|
if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) {
|
||||||
launcherApps.startMainActivity(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!], null, null)
|
launcherApps.startMainActivity(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!], null, null)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -742,7 +713,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||||
if (preferences.getBoolean("doubleTap", false)) {
|
if (sharedPreferenceManager.isDoubleTapEnabled()) {
|
||||||
if (gestureUtils.isAccessibilityServiceEnabled(
|
if (gestureUtils.isAccessibilityServiceEnabled(
|
||||||
ScreenLockService::class.java
|
ScreenLockService::class.java
|
||||||
)
|
)
|
||||||
|
|
@ -772,5 +743,4 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -11,84 +11,74 @@ class SharedPreferenceManager (context: Context) {
|
||||||
|
|
||||||
fun setShortcut(textView: TextView, packageName: String, profile: Int) {
|
fun setShortcut(textView: TextView, packageName: String, profile: Int) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
val key = "shortcut${textView.id}"
|
editor.putString("shortcut${textView.id}", "$packageName§splitter§$profile§splitter§${textView.text}")
|
||||||
editor.putString(key, "$packageName§splitter§$profile§splitter§${textView.text}")
|
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getShortcut(textView: TextView): List<String>? {
|
fun getShortcut(textView: TextView): List<String>? {
|
||||||
val key = "shortcut${textView.id}"
|
val value = preferences.getString("shortcut${textView.id}", "e§splitter§e")
|
||||||
val value = preferences.getString(key, "e§splitter§e")
|
|
||||||
return value?.split("§splitter§")
|
return value?.split("§splitter§")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getShortcutNumber(): Int? {
|
||||||
|
return preferences.getString("shortcutNo", "4")?.toInt()
|
||||||
|
}
|
||||||
|
|
||||||
fun setAppHidden(packageName: String, profile: Int, hidden: Boolean) {
|
fun setAppHidden(packageName: String, profile: Int, hidden: Boolean) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
val key = "hidden$packageName-$profile"
|
editor.putBoolean("hidden$packageName-$profile", hidden)
|
||||||
editor.putBoolean(key, hidden)
|
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isAppHidden(packageName: String, profile: Int): Boolean {
|
fun isAppHidden(packageName: String, profile: Int): Boolean {
|
||||||
val key = "hidden$packageName-$profile"
|
return preferences.getBoolean("hidden$packageName-$profile", false) // Default to false (visible)
|
||||||
return preferences.getBoolean(key, false) // Default to false (visible)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAppVisible(packageName: String, profile: Int) {
|
fun setAppVisible(packageName: String, profile: Int) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
val key = "hidden$packageName-$profile"
|
editor.remove("hidden$packageName-$profile")
|
||||||
editor.remove(key)
|
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAppName(packageName: String, profile: Int, newName: String) {
|
fun setAppName(packageName: String, profile: Int, newName: String) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
val key = "name$packageName-$profile"
|
editor.putString("name$packageName-$profile", newName)
|
||||||
editor.putString(key, newName)
|
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAppName(packageName: String, profile: Int, appName: CharSequence): CharSequence? {
|
fun getAppName(packageName: String, profile: Int, appName: CharSequence): CharSequence? {
|
||||||
val key = "name$packageName-$profile"
|
return preferences.getString("name$packageName-$profile", appName.toString())
|
||||||
return preferences.getString(key, appName.toString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resetAppName(packageName: String, profile: Int) {
|
fun resetAppName(packageName: String, profile: Int) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
val key = "name$packageName-$profile"
|
editor.remove("name$packageName-$profile")
|
||||||
editor.remove(key)
|
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setWeatherLocation(location: String, region: String?) {
|
fun setWeatherLocation(location: String, region: String?) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
val key = "location"
|
editor.putString("location", location)
|
||||||
val regionKey = "location_region"
|
editor.putString("location_region", region)
|
||||||
editor.putString(key, location)
|
|
||||||
editor.putString(regionKey, region)
|
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWeatherLocation(): String? {
|
fun getWeatherLocation(): String? {
|
||||||
val key = "location"
|
return preferences.getString("location", "")
|
||||||
return preferences.getString(key, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWeatherRegion(): String? {
|
fun getWeatherRegion(): String? {
|
||||||
val key = "location_region"
|
return preferences.getString("location_region", "")
|
||||||
return preferences.getString(key, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setGestures(direction: String, appName: String?) {
|
fun setGestures(direction: String, appName: String?) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
val nameKey = "${direction}SwipeApp"
|
editor.putString("${direction}SwipeApp", appName)
|
||||||
editor.putString(nameKey, appName)
|
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGestureName(direction: String) : String? {
|
fun getGestureName(direction: String) : String? {
|
||||||
val key = "${direction}SwipeApp"
|
val name = preferences.getString("${direction}SwipeApp", "")?.split("§splitter§")
|
||||||
val name = preferences.getString(key, "")?.split("§splitter§")
|
|
||||||
return name?.get(0)
|
return name?.get(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,6 +86,14 @@ class SharedPreferenceManager (context: Context) {
|
||||||
return preferences.getString("${direction}SwipeApp", "")?.split("§splitter§")
|
return preferences.getString("${direction}SwipeApp", "")?.split("§splitter§")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isGestureEnabled(direction: String) : Boolean {
|
||||||
|
return preferences.getBoolean("${direction}Swipe", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isDoubleTapEnabled(): Boolean {
|
||||||
|
return preferences.getBoolean("doubleTap", false)
|
||||||
|
}
|
||||||
|
|
||||||
fun getBgColor(): Int {
|
fun getBgColor(): Int {
|
||||||
return Color.parseColor(preferences.getString("bgColor", "#00000000"))
|
return Color.parseColor(preferences.getString("bgColor", "#00000000"))
|
||||||
}
|
}
|
||||||
|
|
@ -108,4 +106,59 @@ class SharedPreferenceManager (context: Context) {
|
||||||
return preferences.getString("clockAlignment", "left")
|
return preferences.getString("clockAlignment", "left")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getShortcutAlignment(): String? {
|
||||||
|
return preferences.getString("shortcutAlignment", "left")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAppAlignment(): String? {
|
||||||
|
return preferences.getString("appMenuAlignment", "left")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSearchAlignment(): String? {
|
||||||
|
return preferences.getString("searchAlignment", "left")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getClockSize(): String? {
|
||||||
|
return preferences.getString("clockSize","medium")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getDateSize(): String? {
|
||||||
|
return preferences.getString("dateSize", "medium")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getShortcutSize(): String? {
|
||||||
|
return preferences.getString("shortcutSize", "medium")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAppSize(): String? {
|
||||||
|
return preferences.getString("appMenuSize", "medium")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSearchSize(): String? {
|
||||||
|
return preferences.getString("searchSize", "medium")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isBarVisible(): Boolean {
|
||||||
|
return preferences.getBoolean("barVisibility", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAutoKeyboardEnabled(): Boolean {
|
||||||
|
return preferences.getBoolean("autoKeyboard", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTempUnits(): String? {
|
||||||
|
return preferences.getString("tempUnits", "celsius")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isWeatherEnabled(): Boolean {
|
||||||
|
return preferences.getBoolean("weather_enabled", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isWeatherGPS(): Boolean {
|
||||||
|
return preferences.getBoolean("gps_location", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isBatteryEnabled(): Boolean {
|
||||||
|
return preferences.getBoolean("battery_enabled", false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.ottop.yamlauncher
|
package eu.ottop.yamlauncher
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.graphics.BlendMode
|
import android.graphics.BlendMode
|
||||||
import android.graphics.BlendModeColorFilter
|
import android.graphics.BlendModeColorFilter
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
|
@ -20,7 +19,7 @@ import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
|
|
||||||
class UIUtils(context: Context) {
|
class UIUtils(private val context: Context) {
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||||
|
|
||||||
|
|
@ -95,13 +94,13 @@ class UIUtils(context: Context) {
|
||||||
setTextAlignment(dateText, alignment)
|
setTextAlignment(dateText, alignment)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setShortcutAlignment(preferences: SharedPreferences, shortcuts: LinearLayout) {
|
fun setShortcutAlignment(shortcuts: LinearLayout) {
|
||||||
shortcuts.children.forEach {
|
shortcuts.children.forEach {
|
||||||
|
|
||||||
if (it is TextView) {
|
if (it is TextView) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
when (preferences.getString("shortcutAlignment", "left")) {
|
when (sharedPreferenceManager.getShortcutAlignment()) {
|
||||||
"left" -> {
|
"left" -> {
|
||||||
it.setCompoundDrawablesWithIntrinsicBounds(
|
it.setCompoundDrawablesWithIntrinsicBounds(
|
||||||
it.compoundDrawables.filterNotNull().first(), null, null, null
|
it.compoundDrawables.filterNotNull().first(), null, null, null
|
||||||
|
|
@ -134,8 +133,12 @@ class UIUtils(context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAppAlignment(activity: Context, preferences: SharedPreferences, textView: TextView, editText: TextInputEditText? = null, regionText: TextView? = null) {
|
fun setAppAlignment(
|
||||||
val alignment = preferences.getString("appMenuAlignment", "left")
|
textView: TextView,
|
||||||
|
editText: TextInputEditText? = null,
|
||||||
|
regionText: TextView? = null
|
||||||
|
) {
|
||||||
|
val alignment = sharedPreferenceManager.getAppAlignment()
|
||||||
setTextGravity(textView, alignment)
|
setTextGravity(textView, alignment)
|
||||||
|
|
||||||
if (regionText != null) {
|
if (regionText != null) {
|
||||||
|
|
@ -146,7 +149,7 @@ class UIUtils(context: Context) {
|
||||||
|
|
||||||
when (alignment) {
|
when (alignment) {
|
||||||
"left" -> {
|
"left" -> {
|
||||||
textView.setCompoundDrawablesWithIntrinsicBounds(textView.compoundDrawables.filterNotNull().first(),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null), null)
|
textView.setCompoundDrawablesWithIntrinsicBounds(textView.compoundDrawables.filterNotNull().first(),null, ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null), null)
|
||||||
editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -156,19 +159,19 @@ class UIUtils(context: Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
"right" -> {
|
"right" -> {
|
||||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null, textView.compoundDrawables.filterNotNull().first(), null)
|
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null, textView.compoundDrawables.filterNotNull().first(), null)
|
||||||
editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setSearchAlignment(preferences: SharedPreferences, searchView: TextInputEditText) {
|
fun setSearchAlignment(searchView: TextInputEditText) {
|
||||||
setTextAlignment(searchView, preferences.getString("searchAlignment", "left"))
|
setTextAlignment(searchView, sharedPreferenceManager.getSearchAlignment())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setMenuTitleAlignment(preferences: SharedPreferences, menuTitle: TextView) {
|
fun setMenuTitleAlignment(menuTitle: TextView) {
|
||||||
setTextGravity(menuTitle, preferences.getString("appMenuAlignment", "left"))
|
setTextGravity(menuTitle, sharedPreferenceManager.getAppAlignment())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,15 +199,15 @@ class UIUtils(context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setClockSize(preferences: SharedPreferences, clock: TextClock) {
|
fun setClockSize(clock: TextClock) {
|
||||||
setTextSize(clock, preferences.getString("clockSize","medium"), 48F, 58F, 68F)
|
setTextSize(clock, sharedPreferenceManager.getClockSize(), 48F, 58F, 68F)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setDateSize(preferences: SharedPreferences, dateText: TextClock) {
|
fun setDateSize(dateText: TextClock) {
|
||||||
setTextSize(dateText, preferences.getString("dateSize", "medium"), 17F, 20F, 23F)
|
setTextSize(dateText, sharedPreferenceManager.getDateSize(), 17F, 20F, 23F)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setShortcutSize(preferences: SharedPreferences, shortcuts: LinearLayout) {
|
fun setShortcutSize(shortcuts: LinearLayout) {
|
||||||
|
|
||||||
val viewTreeObserver = shortcuts.viewTreeObserver
|
val viewTreeObserver = shortcuts.viewTreeObserver
|
||||||
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
|
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
|
|
@ -213,7 +216,7 @@ class UIUtils(context: Context) {
|
||||||
shortcuts.children.forEach {
|
shortcuts.children.forEach {
|
||||||
if (it is TextView) {
|
if (it is TextView) {
|
||||||
|
|
||||||
when (preferences.getString("shortcutSize", "medium")) {
|
when (sharedPreferenceManager.getShortcutSize()) {
|
||||||
"small" -> {
|
"small" -> {
|
||||||
it.setPadding(
|
it.setPadding(
|
||||||
it.paddingLeft,
|
it.paddingLeft,
|
||||||
|
|
@ -249,8 +252,12 @@ class UIUtils(context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAppSize(preferences: SharedPreferences, textView: TextView, editText: TextInputEditText? = null, regionText: TextView? = null) {
|
fun setAppSize(
|
||||||
val size = preferences.getString("appMenuSize", "medium")
|
textView: TextView,
|
||||||
|
editText: TextInputEditText? = null,
|
||||||
|
regionText: TextView? = null
|
||||||
|
) {
|
||||||
|
val size = sharedPreferenceManager.getAppSize()
|
||||||
setTextSize(textView, size, 24F, 26F, 28F)
|
setTextSize(textView, size, 24F, 26F, 28F)
|
||||||
if (editText != null) {
|
if (editText != null) {
|
||||||
setTextSize(editText, size, 24F, 26F, 28F)
|
setTextSize(editText, size, 24F, 26F, 28F)
|
||||||
|
|
@ -260,8 +267,8 @@ class UIUtils(context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setSearchSize(preferences: SharedPreferences, searchView: TextInputEditText) {
|
fun setSearchSize(searchView: TextInputEditText) {
|
||||||
setTextSize(searchView, preferences.getString("searchSize", "medium"), 21F, 23F, 25F)
|
setTextSize(searchView, sharedPreferenceManager.getSearchSize(), 21F, 23F, 25F)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setTextSize(view: TextView, size: String?, s: Float, m: Float, l: Float) {
|
private fun setTextSize(view: TextView, size: String?, s: Float, m: Float, l: Float) {
|
||||||
|
|
@ -276,11 +283,11 @@ class UIUtils(context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setStatusBar(window: Window, preferences: SharedPreferences) {
|
fun setStatusBar(window: Window) {
|
||||||
val windowInsetsController = window.insetsController
|
val windowInsetsController = window.insetsController
|
||||||
|
|
||||||
windowInsetsController?.let {
|
windowInsetsController?.let {
|
||||||
if (preferences.getBoolean("barVisibility", false)) {
|
if (sharedPreferenceManager.isBarVisible()) {
|
||||||
it.show(WindowInsets.Type.statusBars())
|
it.show(WindowInsets.Type.statusBars())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,7 @@ class WeatherSystem(private val context: Context) {
|
||||||
|
|
||||||
fun getTemp() : String {
|
fun getTemp() : String {
|
||||||
|
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
val tempUnits = sharedPreferenceManager.getTempUnits()
|
||||||
val tempUnits = preferences.getString("tempUnits", "celsius")
|
|
||||||
var currentWeather = ""
|
var currentWeather = ""
|
||||||
|
|
||||||
val location = sharedPreferenceManager.getWeatherLocation()
|
val location = sharedPreferenceManager.getWeatherLocation()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue