diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 216485d..bc78ead 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -258,11 +258,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh private fun setShortcutListeners(textView: TextView, savedView: List?) { 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, diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt index 1b9a7a3..7f7c348 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -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 diff --git a/app/src/main/java/eu/ottop/yamlauncher/utils/Animations.kt b/app/src/main/java/eu/ottop/yamlauncher/utils/Animations.kt index 1c0ce27..bb07608 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/utils/Animations.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/utils/Animations.kt @@ -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) diff --git a/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt index 41067ee..ba8e5a1 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/utils/AppUtils.kt @@ -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 {