Removed app menu closing restriction, made about page image open app info and organized code into smaller packages

This commit is contained in:
ottoptj 2024-08-12 10:31:34 +03:00
commit 4cb52fe719
26 changed files with 108 additions and 50 deletions

View file

@ -25,7 +25,7 @@
android:theme="@style/Theme.YamLauncher"
tools:targetApi="34">
<activity
android:name=".SettingsActivity"
android:name=".settings.SettingsActivity"
android:theme="@style/SettingsTheme"
android:exported="false" />
<activity
@ -46,7 +46,7 @@
</intent-filter>
</activity>
<service
android:name=".ScreenLockService"
android:name=".tasks.ScreenLockService"
android:exported="false"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>

View file

@ -18,6 +18,8 @@ import android.widget.TextView
import androidx.appcompat.widget.AppCompatButton
import androidx.lifecycle.lifecycleScope
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import eu.ottop.yamlauncher.utils.Animations
import kotlinx.coroutines.launch
class AppActionMenu {
@ -33,7 +35,7 @@ class AppActionMenu {
userHandle: UserHandle,
workProfile: Int,
launcherApps: LauncherApps,
mainActivity: LauncherActivityInfo?
appActivity: LauncherActivityInfo?
){
val animations = Animations(activity)
val sharedPreferenceManager = SharedPreferenceManager(activity)
@ -41,9 +43,9 @@ class AppActionMenu {
actionMenu.findViewById<TextView>(R.id.info).setOnClickListener {
// Launch app info in phone settings
if (mainActivity != null) {
if (appActivity != null) {
launcherApps.startAppDetailsActivity(
mainActivity.componentName,
appActivity.componentName,
userHandle,
null,
null
@ -72,7 +74,7 @@ class AppActionMenu {
val editText = editLayout.findViewById<EditText>(R.id.appNameEdit)
val resetButton = editLayout.findViewById<AppCompatButton>(R.id.reset)
val app = Triple(mainActivity!!, userHandle, workProfile)
val app = Triple(appActivity!!, userHandle, workProfile)
searchView.visibility = View.INVISIBLE
editText.requestFocus()

View file

@ -17,6 +17,9 @@ import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import eu.ottop.yamlauncher.utils.AppUtils
import eu.ottop.yamlauncher.utils.UIUtils
class AppMenuAdapter(

View file

@ -33,6 +33,18 @@ import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
import eu.ottop.yamlauncher.settings.SettingsActivity
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import eu.ottop.yamlauncher.tasks.BatteryReceiver
import eu.ottop.yamlauncher.tasks.ScreenLockService
import eu.ottop.yamlauncher.utils.Animations
import eu.ottop.yamlauncher.utils.AppMenuEdgeFactory
import eu.ottop.yamlauncher.utils.AppMenuLinearLayoutManager
import eu.ottop.yamlauncher.utils.AppUtils
import eu.ottop.yamlauncher.utils.GestureUtils
import eu.ottop.yamlauncher.utils.StringUtils
import eu.ottop.yamlauncher.utils.UIUtils
import eu.ottop.yamlauncher.utils.WeatherSystem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -74,8 +86,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private lateinit var preferences: SharedPreferences
private var isBatteryReceiverRegistered = false
private var isJobActive = true
var canExit = true
var isJobActive = true
private val swipeThreshold = 100
private val swipeVelocityThreshold = 100
@ -525,14 +536,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
binding.appView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
if (bottom - top > oldBottom - oldTop) {
// Allow the app menu to be closed after the keyboard is closed
canExit = true
// If keyboard is closed, remove cursor from the search bar
searchView.clearFocus()
}
else if (bottom - top < oldBottom - oldTop) {
// The app menu can't be closed with the keyboard open
canExit = false
}
}
searchView.addTextChangedListener(object :
@ -666,7 +673,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
) {
textView.visibility = View.INVISIBLE
animations.fadeViewIn(actionMenuLayout)
val mainActivity =
val appActivity =
launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle)
.firstOrNull()
appActionMenu.setActionListeners(
@ -680,7 +687,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
userHandle,
userProfile,
launcherApps,
mainActivity
appActivity
)
}

View file

@ -1,10 +1,16 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.fragment.app.Fragment
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.StringUtils
class AboutFragment : Fragment() {
@ -27,7 +33,12 @@ class AboutFragment : Fragment() {
stringUtils.setLink(requireActivity().findViewById(R.id.stripeLink), getString(R.string.stripe_link))
stringUtils.setLink(requireActivity().findViewById(R.id.liberaLink), getString(R.string.libera_link))
stringUtils.setLink(requireActivity().findViewById(R.id.weatherLink), getString(R.string.weather_link))
requireActivity().findViewById<ImageView>(R.id.iconView).setOnClickListener {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.parse("package:${requireContext().packageName}")
}
startActivity(intent)
}
}
}

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.annotation.SuppressLint
import android.content.Context
@ -11,6 +11,8 @@ import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.RecyclerView
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.UIUtils
class GestureAppsAdapter(
private val context: Context,
@ -50,10 +52,12 @@ class GestureAppsAdapter(
val app = apps[position]
if (app.third != 0) {
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null,null,null)
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources,
R.drawable.ic_work_app, null),null,null,null)
}
else {
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(holder.textView)

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.app.AlertDialog
import android.content.Context
@ -15,9 +15,15 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.utils.AppMenuEdgeFactory
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.AppUtils
import eu.ottop.yamlauncher.utils.StringUtils
import eu.ottop.yamlauncher.utils.UIUtils
import kotlinx.coroutines.launch
class GestureAppsFragment(private val direction: String) : Fragment(), GestureAppsAdapter.OnItemClickListener {
class GestureAppsFragment(private val direction: String) : Fragment(),
GestureAppsAdapter.OnItemClickListener {
private var adapter: GestureAppsAdapter? = null
private lateinit var sharedPreferenceManager: SharedPreferenceManager

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.annotation.SuppressLint
import android.content.Context
@ -11,6 +11,8 @@ import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.RecyclerView
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.UIUtils
class HiddenAppsAdapter(
private val context: Context,
@ -51,10 +53,12 @@ class HiddenAppsAdapter(
val app = apps[position]
if (app.third != 0) {
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null,null,null)
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources,
R.drawable.ic_work_app, null),null,null,null)
}
else {
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(holder.textView)

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.app.AlertDialog
import android.content.Context
@ -16,6 +16,11 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.utils.AppMenuEdgeFactory
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.AppUtils
import eu.ottop.yamlauncher.utils.StringUtils
import eu.ottop.yamlauncher.utils.UIUtils
import kotlinx.coroutines.launch
class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.app.AlertDialog
import android.content.Context
@ -13,6 +13,11 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.utils.AppMenuEdgeFactory
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.WeatherSystem
import eu.ottop.yamlauncher.utils.StringUtils
import eu.ottop.yamlauncher.utils.UIUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.annotation.SuppressLint
import android.content.Context
@ -8,6 +8,8 @@ import android.view.ViewGroup
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.UIUtils
class LocationListAdapter(
private val context: Context,

View file

@ -1,7 +1,8 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding
class SettingsActivity : AppCompatActivity() {

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.content.Intent
import android.os.Bundle
@ -7,6 +7,7 @@ import android.widget.Toast
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import eu.ottop.yamlauncher.R
class SettingsFragment : PreferenceFragmentCompat() {

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.settings
import android.content.Context
import android.graphics.Color

View file

@ -1,10 +1,11 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.tasks
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
import eu.ottop.yamlauncher.MainActivity
class BatteryReceiver(private val activity: MainActivity) : BroadcastReceiver() {

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.tasks
import android.accessibilityservice.AccessibilityService
import android.content.Intent

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
@ -9,7 +9,7 @@ import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.View
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
class Animations (context: Context) {

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import android.app.Activity
import android.widget.EdgeEffect

View file

@ -1,7 +1,8 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import eu.ottop.yamlauncher.MainActivity
class AppMenuLinearLayoutManager(private val activity: MainActivity) : LinearLayoutManager(activity) {
@ -18,7 +19,7 @@ class AppMenuLinearLayoutManager(private val activity: MainActivity) : LinearLay
val overscroll: Int = dy - scrollRange
// If the user scrolls up when already on top, go back to home. Only if the keyboard isn't open, though
if (overscroll < 0 && (firstVisibleItemPosition == 0 || firstVisibleItemPosition < 0) && scrollStarted && activity.canExit) {
if (overscroll < 0 && (firstVisibleItemPosition == 0 || firstVisibleItemPosition < 0) && scrollStarted) {
activity.backToHome()
}

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import android.content.Context
import android.content.pm.ApplicationInfo
@ -6,6 +6,7 @@ import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps
import android.os.UserHandle
import android.widget.Toast
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import android.accessibilityservice.AccessibilityService
import android.accessibilityservice.AccessibilityServiceInfo
@ -11,6 +11,7 @@ import android.content.pm.ServiceInfo
import android.provider.Settings
import android.view.accessibility.AccessibilityManager
import androidx.appcompat.app.AppCompatActivity.ACCESSIBILITY_SERVICE
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
class GestureUtils(private val context: Context) {

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import android.text.Html
import android.text.method.LinkMovementMethod

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import android.content.Context
import android.graphics.BlendMode
@ -17,6 +17,7 @@ import android.widget.TextClock
import android.widget.TextView
import androidx.core.view.children
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
class UIUtils(context: Context) {

View file

@ -1,4 +1,4 @@
package eu.ottop.yamlauncher
package eu.ottop.yamlauncher.utils
import android.Manifest
import android.content.Context
@ -7,6 +7,8 @@ import android.location.Location
import android.location.LocationManager
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import eu.ottop.yamlauncher.MainActivity
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View file

@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SettingsActivity">
tools:context=".settings.SettingsActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/settingsLayout"

View file

@ -5,10 +5,10 @@
android:id="@+id/aboutLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AboutFragment">
tools:context=".settings.AboutFragment">
<ImageView
android:id="@+id/imageView"
android:id="@+id/iconView"
android:layout_width="0dp"
android:layout_height="200dp"
android:contentDescription="@string/app_icon"
@ -25,9 +25,9 @@
android:textAlignment="center"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="@+id/iconView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
app:layout_constraintTop_toBottomOf="@+id/iconView" />
<TextView
android:id="@+id/creditText"