diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b53a8cd..3a48dd4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -39,15 +39,9 @@ android { } dependencies { - implementation("androidx.core:core-ktx:1.13.1") implementation("androidx.appcompat:appcompat:1.7.0") implementation("com.google.android.material:material:1.12.0") - implementation("androidx.constraintlayout:constraintlayout:2.1.4") - implementation("androidx.navigation:navigation-fragment-ktx:2.7.7") - implementation("androidx.navigation:navigation-ui-ktx:2.7.7") - implementation("com.google.code.gson:gson:2.11.0") implementation("androidx.recyclerview:recyclerview:1.3.2") implementation("androidx.preference:preference-ktx:1.2.1") - implementation ("androidx.activity:activity-ktx:1.9.1") } \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/AboutFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/AboutFragment.kt index 65b897a..fd04f3c 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AboutFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AboutFragment.kt @@ -1,13 +1,10 @@ package eu.ottop.yamlauncher import android.os.Bundle -import android.text.Html -import android.text.method.LinkMovementMethod -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.TextView +import androidx.fragment.app.Fragment class AboutFragment : Fragment() { diff --git a/app/src/main/java/eu/ottop/yamlauncher/Animations.kt b/app/src/main/java/eu/ottop/yamlauncher/Animations.kt index ba1cd6c..4b21271 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/Animations.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/Animations.kt @@ -3,18 +3,15 @@ package eu.ottop.yamlauncher import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.animation.ArgbEvaluator -import android.animation.ObjectAnimator import android.animation.ValueAnimator import android.app.Activity import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.view.View -import android.view.WindowManager -import androidx.core.content.ContextCompat import eu.ottop.yamlauncher.databinding.ActivityMainBinding -class Animations () { +class Animations { fun fadeViewIn(view: View, duration: Long = 100) { view.fadeIn(duration) diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt index 869f080..2994102 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt @@ -16,8 +16,8 @@ import android.widget.EditText import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.widget.AppCompatButton +import androidx.lifecycle.lifecycleScope import eu.ottop.yamlauncher.databinding.ActivityMainBinding -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -105,7 +105,7 @@ class AppActionMenu { workProfile, editText.text.toString() ) - CoroutineScope(Dispatchers.Default).launch { + activity.lifecycleScope.launch(Dispatchers.Default) { activity.applySearch() } @@ -125,7 +125,7 @@ class AppActionMenu { app.second.second ) - CoroutineScope(Dispatchers.Default).launch { + activity.lifecycleScope.launch(Dispatchers.Default) { activity.applySearch() } } @@ -135,7 +135,7 @@ class AppActionMenu { editLayout.visibility = View.GONE textView.visibility = View.GONE actionMenu.visibility = View.GONE - CoroutineScope(Dispatchers.Default).launch { + activity.lifecycleScope.launch { sharedPreferenceManager.setAppHidden(activity, appInfo.packageName, workProfile, true) activity.refreshAppMenu() } diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index 0641c31..dc3cb3c 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -9,22 +9,21 @@ import android.graphics.BlendMode import android.graphics.BlendModeColorFilter import android.graphics.Color import android.os.UserHandle -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.EditText import android.widget.FrameLayout import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.res.ResourcesCompat import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.textfield.TextInputEditText class AppMenuAdapter( private val activity: Context, - var apps: MutableList>>, + private var apps: MutableList>>, private val itemClickListener: OnItemClickListener, private val shortcutListener: OnShortcutListener, private val itemLongClickListener: OnItemLongClickListener, @@ -36,6 +35,8 @@ class AppMenuAdapter( private val sharedPreferenceManager = SharedPreferenceManager() private var preferences = PreferenceManager.getDefaultSharedPreferences(activity) + private val uiUtils = UIUtils() + private val appUtils = AppUtils() interface OnItemClickListener { fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) @@ -62,7 +63,7 @@ class AppMenuAdapter( val textView: TextView = listItem.findViewById(R.id.app_name) val actionMenuLayout: LinearLayout = listItem.findViewById(R.id.action_menu) private val editView: LinearLayout = listItem.findViewById(R.id.rename_view) - val editText: EditText = editView.findViewById(R.id.app_name_edit) + val editText: TextInputEditText = editView.findViewById(R.id.app_name_edit) init { actionMenuLayout.visibility = View.INVISIBLE @@ -119,51 +120,18 @@ class AppMenuAdapter( holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null) } - when (preferences.getString("appMenuAlignment", "left")) { - "left" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null), null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START - } - "center" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER + uiUtils.setAppAlignment(activity, preferences, holder.textView, holder.editText) - } - "right" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null, holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END - } - } + uiUtils.setAppSize(preferences, holder.textView, holder.editText) - when (preferences.getString("appMenuSize", "medium")) { - "small" -> { - holder.textView.textSize = 24F - holder.editText.textSize = 24F - } - - "medium" -> { - holder.textView.textSize = 26F - holder.editText.textSize = 26F - } - - "large" -> { - holder.textView.textSize = 28F - holder.editText.textSize = 28F - } - } - - val appUtils = AppUtils() - var appInfo = appUtils.getAppInfo( + val appInfo = appUtils.getAppInfo( launcherApps, app.first.applicationInfo.packageName, app.second.second ) holder.textView.setTextColor(Color.parseColor(preferences?.getString("textColor", "#FFF3F3F3"))) - var appLabel: CharSequence = "" - appLabel = appInfo?.loadLabel(activity.packageManager) ?: "Removing..." - - println(appLabel) + val appLabel: CharSequence = appInfo?.loadLabel(activity.packageManager) ?: "Removing..." if (appInfo != null) { holder.textView.text = sharedPreferenceManager.getAppName( @@ -192,28 +160,9 @@ class AppMenuAdapter( return apps.size } - fun addApp(position: Int, app: Pair>) { - apps.add(position, app) - } - - fun removeApp(position: Int) { - apps.removeAt(position) - } - - fun updateApp(position: Int, app: Pair>) { - apps[position] = app - } - - fun moveApp(position: Int, newPosition: Int) { - val app = apps.removeAt(position) - apps.add(newPosition, app) - - } - @SuppressLint("NotifyDataSetChanged") fun updateApps(newApps: List>>) { apps = newApps.toMutableList() notifyDataSetChanged() } - } \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt index 24c7420..6fbbb3d 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppUtils.kt @@ -10,7 +10,6 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import java.lang.reflect.InvocationTargetException class AppUtils { diff --git a/app/src/main/java/eu/ottop/yamlauncher/BatteryReceiver.kt b/app/src/main/java/eu/ottop/yamlauncher/BatteryReceiver.kt index dc46d81..bdc1c3c 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/BatteryReceiver.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/BatteryReceiver.kt @@ -5,7 +5,6 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.BatteryManager -import android.widget.TextClock class BatteryReceiver(private val activity: MainActivity) : BroadcastReceiver() { diff --git a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt index 160ff0a..da2df71 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt @@ -2,21 +2,16 @@ package eu.ottop.yamlauncher import android.annotation.SuppressLint import android.content.Context -import android.content.pm.ApplicationInfo import android.content.pm.LauncherActivityInfo import android.os.UserHandle -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.EditText import android.widget.FrameLayout -import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.res.ResourcesCompat import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView -import kotlin.time.Duration.Companion.seconds class GestureAppsAdapter( private val activity: Context, @@ -25,8 +20,9 @@ class GestureAppsAdapter( ) : RecyclerView.Adapter() { - private val sharedPreferenceManager = SharedPreferenceManager() - private var preferences = PreferenceManager.getDefaultSharedPreferences(activity) + private val sharedPreferenceManager = SharedPreferenceManager() + private var preferences = PreferenceManager.getDefaultSharedPreferences(activity) + private val uiUtils = UIUtils() interface OnItemClickListener { fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) @@ -35,14 +31,8 @@ class GestureAppsAdapter( inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private val listItem: FrameLayout = itemView.findViewById(R.id.list_item) val textView: TextView = listItem.findViewById(R.id.app_name) - private val actionMenuLayout: LinearLayout = listItem.findViewById(R.id.action_menu) - private val editView: LinearLayout = listItem.findViewById(R.id.rename_view) - val editText: EditText = editView.findViewById(R.id.app_name_edit) init { - actionMenuLayout.visibility = View.INVISIBLE - editView.visibility = View.INVISIBLE - textView.setOnClickListener { val position = bindingAdapterPosition val app = apps[position].first @@ -68,38 +58,9 @@ class GestureAppsAdapter( holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,null,null) } - when (preferences.getString("appMenuAlignment", "left")) { - "left" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START - } - "center" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER + uiUtils.setAppAlignment(activity, preferences, holder.textView) - } - "right" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END - } - } - - when (preferences.getString("appMenuSize", "medium")) { - "small" -> { - holder.textView.textSize = 24F - holder.editText.textSize = 24F - } - - "medium" -> { - holder.textView.textSize = 26F - holder.editText.textSize = 26F - } - - "large" -> { - holder.textView.textSize = 28F - holder.editText.textSize = 28F - } - } + uiUtils.setAppSize(preferences, holder.textView) val appInfo = app.first.activityInfo.applicationInfo holder.textView.text = sharedPreferenceManager.getAppName(activity, app.first.applicationInfo.packageName,app.second.second, holder.itemView.context.packageManager.getApplicationLabel(appInfo)) diff --git a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt index 71aa9d4..5e0fbd0 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt @@ -9,18 +9,15 @@ import android.os.Bundle import android.os.UserHandle import android.text.Editable import android.text.TextWatcher -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.EditText -import android.widget.Toast -import androidx.core.content.ContextCompat.getSystemService +import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult import androidx.lifecycle.lifecycleScope -import androidx.preference.Preference +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView -import kotlinx.coroutines.CoroutineScope +import com.google.android.material.textfield.TextInputEditText import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -58,13 +55,19 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener { } val recyclerView = view.findViewById(R.id.gesture_app_recycler) val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity()) + val uiUtils = UIUtils() + val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) recyclerView.edgeEffectFactory = appMenuEdgeFactory recyclerView.adapter = adapter recyclerView.scrollToPosition(0) - val searchView = view.findViewById(R.id.gestureAppSearch) + val searchView = view.findViewById(R.id.gestureAppSearch) + + uiUtils.setMenuTitleAlignment(preferences, view.findViewById(R.id.gesture_menutitle)) + uiUtils.setSearchAlignment(preferences, searchView) + uiUtils.setSearchSize(preferences, searchView) recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom -> diff --git a/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt index 4069819..5db15d7 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/GestureUtils.kt @@ -14,6 +14,7 @@ import android.view.accessibility.AccessibilityManager import androidx.appcompat.app.AppCompatActivity.ACCESSIBILITY_SERVICE class GestureUtils { + fun getSwipeInfo(preferences: SharedPreferences, launcherApps: LauncherApps, direction: String): Pair { val app = preferences.getString("${direction}SwipeApp", "")?.split("§splitter§") diff --git a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt index d5d0771..f484435 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt @@ -2,25 +2,20 @@ package eu.ottop.yamlauncher import android.annotation.SuppressLint import android.content.Context -import android.content.pm.ApplicationInfo import android.content.pm.LauncherActivityInfo import android.os.UserHandle -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.EditText import android.widget.FrameLayout -import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.res.ResourcesCompat import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView -import kotlin.time.Duration.Companion.seconds class HiddenAppsAdapter( private val activity: Context, - var apps: MutableList>>, + private var apps: MutableList>>, private val itemClickListener: OnItemClickListener ) : RecyclerView.Adapter() { @@ -28,6 +23,8 @@ class HiddenAppsAdapter( private val sharedPreferenceManager = SharedPreferenceManager() private var preferences = PreferenceManager.getDefaultSharedPreferences(activity) + private val uiUtils = UIUtils() + interface OnItemClickListener { fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) } @@ -35,13 +32,8 @@ class HiddenAppsAdapter( inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private val listItem: FrameLayout = itemView.findViewById(R.id.list_item) val textView: TextView = listItem.findViewById(R.id.app_name) - private val actionMenuLayout: LinearLayout = listItem.findViewById(R.id.action_menu) - private val editView: LinearLayout = listItem.findViewById(R.id.rename_view) - val editText: EditText = editView.findViewById(R.id.app_name_edit) init { - actionMenuLayout.visibility = View.INVISIBLE - editView.visibility = View.INVISIBLE textView.setOnClickListener { val position = bindingAdapterPosition @@ -68,38 +60,9 @@ class HiddenAppsAdapter( holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,null,null) } - when (preferences.getString("appMenuAlignment", "left")) { - "left" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START - } - "center" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER + uiUtils.setAppAlignment(activity, preferences, holder.textView) - } - "right" -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END - } - } - - when (preferences.getString("appMenuSize", "medium")) { - "small" -> { - holder.textView.textSize = 24F - holder.editText.textSize = 24F - } - - "medium" -> { - holder.textView.textSize = 26F - holder.editText.textSize = 26F - } - - "large" -> { - holder.textView.textSize = 28F - holder.editText.textSize = 28F - } - } + uiUtils.setAppSize(preferences, holder.textView) val appInfo = app.first.activityInfo.applicationInfo holder.textView.text = sharedPreferenceManager.getAppName(activity, app.first.applicationInfo.packageName,app.second.second, holder.itemView.context.packageManager.getApplicationLabel(appInfo)) diff --git a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt index ef6693d..54fe0e3 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt @@ -8,42 +8,47 @@ import android.os.Bundle import android.os.UserHandle import android.text.Editable import android.text.TextWatcher -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.inputmethod.InputMethodManager -import android.widget.EditText +import androidx.fragment.app.Fragment import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.textfield.TextInputEditText class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener { private val appUtils = AppUtils() private val sharedPreferenceManager = SharedPreferenceManager() private var adapter: HiddenAppsAdapter? = null private var stringUtils = StringUtils() + private val uiUtils = UIUtils() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_hidden_apps, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps(activity as Activity).toMutableList(), this) + adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps(activity as Activity).toMutableList(), this) val recyclerView = view.findViewById(R.id.hidden_app_recycler) val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity()) + val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) recyclerView.edgeEffectFactory = appMenuEdgeFactory recyclerView.adapter = adapter recyclerView.scrollToPosition(0) - val searchView = view.findViewById(R.id.hiddenAppSearch) + val searchView = view.findViewById(R.id.hiddenAppSearch) + + uiUtils.setMenuTitleAlignment(preferences, view.findViewById(R.id.hidden_menutitle)) + uiUtils.setSearchAlignment(preferences, searchView) + uiUtils.setSearchSize(preferences, searchView) recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom -> @@ -113,7 +118,7 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener { setMessage("Are you sure you want to unhide $appName?") setPositiveButton("Yes") { _, _ -> // Perform action on confirmation - performConfirmedAction(appInfo, appName, profile) + performConfirmedAction(appInfo, profile) } setNegativeButton("Cancel") { _, _ -> @@ -121,15 +126,11 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener { }.create().show() } - private fun performConfirmedAction(appInfo: LauncherActivityInfo, appName: String, profile: Int) { + private fun performConfirmedAction(appInfo: LauncherActivityInfo, profile: Int) { sharedPreferenceManager.setAppVisible(requireContext(), appInfo.applicationInfo.packageName, profile) adapter?.updateApps(appUtils.getHiddenApps(requireActivity())) } - private fun handleCancellation() { - // Handle the cancellation of the dialog - } - override fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) { showConfirmationDialog(appInfo, sharedPreferenceManager.getAppName(requireContext(), appInfo.applicationInfo.packageName,profile, requireContext().packageManager.getApplicationLabel(appInfo.applicationInfo)).toString(), profile) } diff --git a/app/src/main/java/eu/ottop/yamlauncher/LocationFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/LocationFragment.kt index 1b21d32..f3233f8 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/LocationFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/LocationFragment.kt @@ -5,18 +5,15 @@ import android.content.Context import android.os.Bundle import android.text.Editable import android.text.TextWatcher -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.inputmethod.InputMethodManager -import android.widget.EditText -import androidx.fragment.app.setFragmentResult +import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope -import androidx.preference.Preference import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView -import kotlinx.coroutines.CoroutineScope +import com.google.android.material.textfield.TextInputEditText import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -27,6 +24,7 @@ class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener { private val weatherSystem = WeatherSystem() private val sharedPreferenceManager = SharedPreferenceManager() private val stringUtils = StringUtils() + private val uiUtils = UIUtils() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -39,10 +37,12 @@ class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val searchView = view.findViewById(R.id.locationSearch) + val searchView = view.findViewById(R.id.locationSearch) var locationList = mutableListOf>() + val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + stringUtils.setLink(requireActivity().findViewById(R.id.locationLink), getString(R.string.location_link)) lifecycleScope.launch(Dispatchers.IO) { @@ -54,6 +54,9 @@ class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener { adapter = LocationListAdapter(requireContext(), locationList, this) val recyclerView = view.findViewById(R.id.locationrecycler) val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity()) + uiUtils.setMenuTitleAlignment(preferences, view.findViewById(R.id.location_menutitle)) + uiUtils.setSearchAlignment(preferences, searchView) + uiUtils.setSearchSize(preferences, searchView) recyclerView.edgeEffectFactory = appMenuEdgeFactory recyclerView.adapter = adapter diff --git a/app/src/main/java/eu/ottop/yamlauncher/LocationListAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/LocationListAdapter.kt index 2477103..520796a 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/LocationListAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/LocationListAdapter.kt @@ -2,28 +2,23 @@ package eu.ottop.yamlauncher import android.annotation.SuppressLint import android.content.Context -import android.content.pm.LauncherActivityInfo -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.EditText -import android.widget.FrameLayout -import android.widget.LinearLayout import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.content.res.ResourcesCompat import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView class LocationListAdapter( - activity: Context, - var apps: MutableList>, + private val activity: Context, + private var apps: MutableList>, private val itemClickListener: OnItemClickListener ) : RecyclerView.Adapter() { private var preferences = PreferenceManager.getDefaultSharedPreferences(activity) + private val uiUtils = UIUtils() interface OnItemClickListener { fun onItemClick(name: String?, latitude: String?, longitude: String?) @@ -56,42 +51,12 @@ class LocationListAdapter( override fun onBindViewHolder(holder: AppViewHolder, position: Int) { val app = apps[position] - when (preferences.getString("appMenuAlignment", "left")) { - "left" -> { - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START - holder.regionText.gravity = Gravity.CENTER_VERTICAL or Gravity.START - } - "center" -> { - holder.textView.gravity = Gravity.CENTER - holder.regionText.gravity = Gravity.CENTER + uiUtils.setAppAlignment(activity, preferences, holder.textView, null ,holder.regionText) - - } - "right" -> { - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END - holder.regionText.gravity = Gravity.CENTER_VERTICAL or Gravity.END - } - } - - when (preferences.getString("appMenuSize", "medium")) { - "small" -> { - holder.textView.textSize = 24F - holder.regionText.textSize = 14F - } - - "medium" -> { - holder.textView.textSize = 26F - holder.regionText.textSize = 16F - } - - "large" -> { - holder.textView.textSize = 28F - holder.regionText.textSize = 18F - } - } + uiUtils.setAppSize(preferences, holder.textView, null, holder.regionText) holder.textView.text = app["name"] - holder.regionText.text = "${app["region"]}${app["country"]}" + holder.regionText.text = activity.getString(R.string.region_text, app["region"], app["country"]) holder.textView.visibility = View.VISIBLE } diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index f61e79d..3935083 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -44,49 +44,47 @@ import kotlin.math.abs class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener, AppMenuAdapter.OnItemClickListener, AppMenuAdapter.OnShortcutListener, AppMenuAdapter.OnItemLongClickListener { - private lateinit var binding: ActivityMainBinding - private lateinit var gestureDetector: GestureDetector - private lateinit var shortcutGestureDetector: GestureDetector - private lateinit var launcherApps: LauncherApps - private lateinit var installedApps: List>> + private val weatherSystem = WeatherSystem() + private val appUtils = AppUtils() + private val stringUtils = StringUtils() + private val uiUtils = UIUtils() + private val gestureUtils = GestureUtils() + + private var appActionMenu = AppActionMenu() + private val appMenuLinearLayoutManager = AppMenuLinearLayoutManager(this@MainActivity) + private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity) + + private val sharedPreferenceManager = SharedPreferenceManager() + + private val animations = Animations() + + private lateinit var clock: TextClock + private var clockMargin = 0 + private lateinit var dateText: TextClock + private var dateElements = mutableListOf() private lateinit var recyclerView: RecyclerView private lateinit var searchView: TextInputEditText private var adapter: AppMenuAdapter? = null private var batteryReceiver: BatteryReceiver? = null - private var appActionMenu = AppActionMenu() - private val sharedPreferenceManager = SharedPreferenceManager() - private val appUtils = AppUtils() - private val appMenuLinearLayoutManager = AppMenuLinearLayoutManager(this@MainActivity) - private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity) - private val animations = Animations() + private lateinit var binding: ActivityMainBinding + private lateinit var launcherApps: LauncherApps + private lateinit var installedApps: List>> + + private lateinit var preferences: SharedPreferences + + private var isBatteryReceiverRegistered = false + var isJobActive = true private val swipeThreshold = 100 private val swipeVelocityThreshold = 100 - private lateinit var clock: TextClock - private var clockMargin = 0 - - private lateinit var dateText: TextClock - - private lateinit var preferences: SharedPreferences - - private val stringUtils = StringUtils() - - private var dateElements = mutableListOf() - - private val weatherSystem = WeatherSystem() - - private lateinit var uiUtils: UIUtils - private lateinit var gestureUtils: GestureUtils - - private var isBatteryReceiverRegistered = false - private lateinit var leftSwipeActivity: Pair private lateinit var rightSwipeActivity: Pair - var isJobActive = true + private lateinit var gestureDetector: GestureDetector + private lateinit var shortcutGestureDetector: GestureDetector override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -140,8 +138,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps preferences = PreferenceManager.getDefaultSharedPreferences(this) - uiUtils = UIUtils() - gestureUtils = GestureUtils() } private fun setPreferences() { @@ -211,6 +207,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show() } textView.setOnLongClickListener { + uiUtils.setMenuTitleAlignment(preferences, binding.menutitle) + binding.menutitle.visibility = View.VISIBLE + adapter?.shortcutTextView = textView toAppMenu() @@ -305,7 +304,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } "shortcutAlignment" -> { - uiUtils.setShortcutSize(preferences, binding.homeView) + uiUtils.setShortcutAlignment(preferences, binding.homeView) } "searchAlignment" -> { @@ -369,7 +368,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh val handler = Handler(Looper.getMainLooper()) handler.postDelayed({ try { - binding.menutitle.visibility = View.VISIBLE searchView.setText(R.string.empty) } catch (_: UninitializedPropertyAccessException) { @@ -554,7 +552,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } suspend fun applySearch() { - filterItems(searchView.text.toString()) + withContext(Dispatchers.Default) { + filterItems(searchView.text.toString()) + } } @@ -737,7 +737,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh ScreenLockService::class.java ) ) { - println("enabled") val intent = Intent(this@MainActivity, ScreenLockService::class.java) intent.action = "LOCK_SCREEN" startService(intent) diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt index ec590a8..77fc197 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt @@ -1,10 +1,7 @@ package eu.ottop.yamlauncher -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.AdapterView -import androidx.core.content.ContextCompat +import androidx.appcompat.app.AppCompatActivity import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding class SettingsActivity : AppCompatActivity() { diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt index 8ea015d..9f42607 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt @@ -16,8 +16,6 @@ class SettingsFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.root_preferences, rootKey) - val weatherSystem = WeatherSystem() - val gpsLocationPref: SwitchPreference? = findPreference("gps_location") manualLocationPref = findPreference("manual_location") val leftSwipePref = findPreference("leftSwipeApp") diff --git a/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt index dbf7357..ca3782f 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt @@ -1,5 +1,6 @@ package eu.ottop.yamlauncher +import android.content.Context import android.content.SharedPreferences import android.graphics.BlendMode import android.graphics.BlendModeColorFilter @@ -15,10 +16,11 @@ import android.view.WindowInsetsController import android.widget.LinearLayout import android.widget.TextClock import android.widget.TextView +import androidx.core.content.res.ResourcesCompat import androidx.core.view.children import com.google.android.material.textfield.TextInputEditText -class UIUtils() { +class UIUtils { fun setBackground(window: Window, preferences: SharedPreferences) { window.setBackgroundDrawable(ColorDrawable(Color.parseColor("#00000000"))) @@ -64,14 +66,15 @@ class UIUtils() { } fun setSearchColors(preferences: SharedPreferences, searchView: TextInputEditText) { + val color = Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")) val viewTreeObserver = searchView.viewTreeObserver val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { - searchView.setTextColor(Color.parseColor(preferences.getString("textColor", "#FFF3F3F3"))) + searchView.setTextColor(color) searchView.setHintTextColor(setAlpha(Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")), "A9")) searchView.compoundDrawables[0].mutate().colorFilter = - BlendModeColorFilter(Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")), BlendMode.SRC_ATOP) + BlendModeColorFilter(color, BlendMode.SRC_ATOP) if (viewTreeObserver.isAlive) { viewTreeObserver.removeOnGlobalLayoutListener(this) @@ -85,8 +88,9 @@ class UIUtils() { } fun setClockAlignment(preferences: SharedPreferences, clock: TextClock, dateText: TextClock) { - setTextAlignment(clock, preferences.getString("clockAlignment", "left")) - setTextAlignment(dateText, preferences.getString("clockAlignment", "left")) + val alignment = preferences.getString("clockAlignment", "left") + setTextAlignment(clock, alignment) + setTextAlignment(dateText, alignment) } fun setShortcutAlignment(preferences: SharedPreferences, shortcuts: LinearLayout) { @@ -128,10 +132,44 @@ class UIUtils() { } } + fun setAppAlignment(activity: Context, preferences: SharedPreferences, textView: TextView, editText: TextInputEditText? = null, regionText: TextView? = null) { + val alignment = preferences.getString("appMenuAlignment", "left") + setTextGravity(textView, alignment) + + if (regionText != null) { + setTextGravity(textView, alignment) + setTextGravity(regionText, alignment) + return + } + + when (alignment) { + "left" -> { + textView.setCompoundDrawablesWithIntrinsicBounds(textView.compoundDrawables.filterNotNull().first(),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null), null) + editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.START + + } + "center" -> { + textView.setCompoundDrawablesWithIntrinsicBounds(textView.compoundDrawables.filterNotNull().first(),null, textView.compoundDrawables.filterNotNull().first(), null) + editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.END + + } + "right" -> { + textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null, textView.compoundDrawables.filterNotNull().first(), null) + editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.END + } + } + + } + fun setSearchAlignment(preferences: SharedPreferences, searchView: TextInputEditText) { setTextAlignment(searchView, preferences.getString("searchAlignment", "left")) } + fun setMenuTitleAlignment(preferences: SharedPreferences, menuTitle: TextView) { + setTextGravity(menuTitle, preferences.getString("appMenuAlignment", "left")) + + } + private fun setTextAlignment(view: TextView, alignment: String?) { view.textAlignment = when (alignment) { "left" -> View.TEXT_ALIGNMENT_VIEW_START @@ -144,6 +182,18 @@ class UIUtils() { } } + private fun setTextGravity(view: TextView, alignment: String?) { + view.gravity = when (alignment) { + "left" -> Gravity.CENTER_VERTICAL or Gravity.START + + "center" -> Gravity.CENTER + + "right" -> Gravity.CENTER_VERTICAL or Gravity.END + + else -> Gravity.CENTER_VERTICAL or Gravity.START + } + } + fun setClockSize(preferences: SharedPreferences, clock: TextClock) { setTextSize(clock, preferences.getString("clockSize","medium"), 48F, 58F, 68F) } @@ -197,6 +247,17 @@ class UIUtils() { } } + fun setAppSize(preferences: SharedPreferences, textView: TextView, editText: TextInputEditText? = null, regionText: TextView? = null) { + val size = preferences.getString("appMenuSize", "medium") + setTextSize(textView, size, 24F, 26F, 28F) + if (editText != null) { + setTextSize(editText, size, 24F, 26F, 28F) + } + if (regionText != null) { + setTextSize(regionText, size, 14F, 16F, 18F) + } + } + fun setSearchSize(preferences: SharedPreferences, searchView: TextInputEditText) { setTextSize(searchView, preferences.getString("searchSize", "medium"), 21F, 23F, 25F) } @@ -227,5 +288,4 @@ class UIUtils() { } } } - } \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt b/app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt index 16f7c95..fad8f85 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt @@ -1,29 +1,19 @@ package eu.ottop.yamlauncher import android.Manifest -import android.app.Activity import android.content.Context import android.content.pm.PackageManager import android.location.Location -import android.location.LocationListener import android.location.LocationManager -import android.os.Handler -import android.os.Looper -import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.preference.PreferenceManager import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.asExecutor -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.json.JSONObject import java.net.HttpURLConnection import java.net.URL -import kotlin.coroutines.coroutineContext class WeatherSystem { @@ -134,7 +124,7 @@ class WeatherSystem { } - currentWeather = "$weatherType ${currentData.getInt("temperature_2m").toString()}" + currentWeather = "$weatherType ${currentData.getInt("temperature_2m")}" } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6cf8c90..10af334 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,5 +26,6 @@ Open-Meteo.com
(CC BY 4.0)]]>
Open-Meteo.com (CC BY 4.0)]]> Idk this is my service + %1$s%2$s \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index a5e0607..f04142d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,7 @@ pluginManagement { gradlePluginPortal() } } + dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -14,5 +15,4 @@ dependencyResolutionManagement { } rootProject.name = "Yam Launcher" -include(":app") - \ No newline at end of file +include(":app") \ No newline at end of file