Returns to home on every resume so that back key also brings the app back home

This commit is contained in:
ottoptj 2024-08-30 14:16:10 +03:00
commit fc418e6a2c
4 changed files with 16 additions and 23 deletions

View file

@ -258,11 +258,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private fun setShortcutListeners(textView: TextView, savedView: List<String>?) {
textView.setOnClickListener {
val mainActivity = launcherApps.getActivityList(savedView?.get(0).toString(), launcherApps.profiles[savedView?.get(1)!!.toInt()]).firstOrNull()
if (mainActivity != null) {
launcherApps.startMainActivity(mainActivity.componentName, launcherApps.profiles[savedView[1].toInt()], null, null)
} else {
Toast.makeText(this, "Cannot launch app", Toast.LENGTH_SHORT).show()
if (savedView != null) {
appUtils.launchApp(savedView[0], launcherApps.profiles[savedView[1].toInt()])
}
}
}
@ -425,11 +422,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
dateText.format24Hour = "${dateElements[1]}${stringUtils.addStartTextIfNotEmpty(dateElements[2], " | ")}${stringUtils.addStartTextIfNotEmpty(dateElements[3], " | ")}"
}
fun backToHome() {
fun backToHome(animSpeed: Long = sharedPreferenceManager.getAnimationSpeed()) {
closeKeyboard()
animations.showHome(binding.homeView, binding.appView)
animations.backgroundOut(this@MainActivity)
val animSpeed = sharedPreferenceManager.getAnimationSpeed()
animations.showHome(binding.homeView, binding.appView, animSpeed)
animations.backgroundOut(this@MainActivity, animSpeed)
// Delay app menu changes so that the user doesn't see them
@ -651,11 +647,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
@SuppressLint("NotifyDataSetChanged")
override fun onResume() {
super.onResume()
backToHome(0)
adapter?.notifyDataSetChanged()
}
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
appUtils.launchApp(appInfo, userHandle)
appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle)
}
override fun onShortcut(
@ -678,7 +675,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
shortcutView.text = textView.text.toString()
shortcutView.setOnClickListener {
appUtils.launchApp(appInfo, userHandle)
appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle)
}
sharedPreferenceManager.setShortcut(
shortcutView,

View file

@ -4,7 +4,6 @@ import android.content.Context
import android.graphics.Color
import android.util.TypedValue
import android.widget.TextView
import androidx.core.graphics.toColor
import androidx.preference.PreferenceManager
import eu.ottop.yamlauncher.R

View file

@ -25,9 +25,9 @@ class Animations (context: Context) {
view.fadeOut()
}
fun showHome(homeView: View, appView: View) {
appView.slideOutToBottom()
homeView.fadeIn()
fun showHome(homeView: View, appView: View, duration: Long) {
appView.slideOutToBottom(duration)
homeView.fadeIn(duration)
}
fun showApps(homeView: View, appView: View) {
@ -58,7 +58,7 @@ class Animations (context: Context) {
}
}
fun backgroundOut(activity: Activity) {
fun backgroundOut(activity: Activity, duration: Long) {
val newColor = sharedPreferenceManager.getBgColor()
// Only animate darkness onto the transparent background
@ -72,7 +72,6 @@ class Animations (context: Context) {
colorDrawable.color = animator.animatedValue as Int
}
val duration = sharedPreferenceManager.getAnimationSpeed()
backgroundColorAnimator.duration = duration
backgroundColorAnimator.start()
@ -97,9 +96,8 @@ class Animations (context: Context) {
}
}
private fun View.slideOutToBottom() {
private fun View.slideOutToBottom(duration: Long) {
if (visibility == View.VISIBLE) {
val duration = sharedPreferenceManager.getAnimationSpeed()
animate()
.translationY(height.toFloat() / 5)
@ -114,12 +112,11 @@ class Animations (context: Context) {
}
}
private fun View.fadeIn() {
private fun View.fadeIn(duration: Long = sharedPreferenceManager.getAnimationSpeed()) {
if (visibility != View.VISIBLE) {
alpha = 0f
translationY = -height.toFloat()/100
visibility = View.VISIBLE
val duration = sharedPreferenceManager.getAnimationSpeed()
animate()
.alpha(1f)

View file

@ -79,8 +79,8 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
}
}
fun launchApp(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull()
fun launchApp(packageName: String, userHandle: UserHandle) {
val mainActivity = launcherApps.getActivityList(packageName, userHandle).firstOrNull()
if (mainActivity != null) {
launcherApps.startMainActivity(mainActivity.componentName, userHandle, null, null)
} else {