Skip to content

Commit 5a034b2

Browse files
committed
animation improvements
1 parent d238b35 commit 5a034b2

File tree

1 file changed

+57
-33
lines changed
  • app/src/main/java/ru/queuejw/mpl/content

1 file changed

+57
-33
lines changed

app/src/main/java/ru/queuejw/mpl/content/AllApps.kt

+57-33
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.core.animation.doOnEnd
3030
import androidx.core.content.ContextCompat
3131
import androidx.core.content.edit
3232
import androidx.core.net.toUri
33+
import androidx.core.view.forEach
3334
import androidx.fragment.app.Fragment
3435
import androidx.lifecycle.ViewModelProvider
3536
import androidx.lifecycle.lifecycleScope
@@ -38,8 +39,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
3839
import androidx.recyclerview.widget.RecyclerView
3940
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
4041
import coil3.load
41-
import com.google.android.material.card.MaterialCardView
42-
import com.google.android.material.textview.MaterialTextView
4342
import kotlinx.coroutines.Dispatchers
4443
import kotlinx.coroutines.delay
4544
import kotlinx.coroutines.launch
@@ -55,6 +54,7 @@ import ru.queuejw.mpl.R
5554
import ru.queuejw.mpl.content.data.app.App
5655
import ru.queuejw.mpl.content.data.tile.Tile
5756
import ru.queuejw.mpl.content.settings.SettingsActivity
57+
import ru.queuejw.mpl.databinding.AllAppsWindowBinding
5858
import ru.queuejw.mpl.databinding.AppBinding
5959
import ru.queuejw.mpl.databinding.LauncherAllAppsScreenBinding
6060
import ru.queuejw.mpl.helpers.receivers.PackageChangesReceiver
@@ -435,11 +435,11 @@ class AllApps : Fragment() {
435435

436436
private fun runAppWithAnimation(app: String, pm: PackageManager) {
437437
val first =
438-
(binding.appList.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
438+
(binding.appList.layoutManager as LinearLayoutManager?)?.findFirstVisibleItemPosition()
439439
val last =
440-
(binding.appList.layoutManager as LinearLayoutManager).findLastVisibleItemPosition()
440+
(binding.appList.layoutManager as LinearLayoutManager?)?.findLastVisibleItemPosition()
441441
binding.appList.isScrollEnabled = false
442-
if (appAdapter == null) {
442+
if (appAdapter == null || first == null || last == null) {
443443
runApp(app, pm)
444444
return
445445
}
@@ -501,40 +501,45 @@ class AllApps : Fragment() {
501501
return contentView.measuredHeight
502502
}
503503

504-
private fun showPopupWindow(view: View, app: App) {
504+
private fun showPopupWindow(view: View, app: App, position: Int) {
505505
binding.appList.isScrollEnabled = false
506+
if (PREFS.isAAllAppsAnimEnabled) {
507+
animateApps(position, false)
508+
}
506509
(requireActivity() as Main).configureViewPagerScroll(false)
507510
val inflater =
508511
view.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
509-
val popupView = inflater.inflate(R.layout.all_apps_window, binding.appList, false)
512+
val windowBinding = AllAppsWindowBinding.inflate(inflater)
510513
popupWindow = PopupWindow(
511-
popupView,
514+
windowBinding.root,
512515
LinearLayout.LayoutParams.MATCH_PARENT,
513516
LinearLayout.LayoutParams.WRAP_CONTENT,
514517
true
515518
)
516519
popupWindow!!.isFocusable = true
517520
val popupHeight = getPopupHeight(popupWindow!!)
518521
val top = isPopupInTop(view, popupHeight)
519-
popupView.pivotY = if (top) 0f else popupHeight.toFloat()
520-
val pinLabel = popupView.findViewById<MaterialTextView>(R.id.pin_app_label)
521-
val infoLabel = popupView.findViewById<MaterialTextView>(R.id.app_info_label)
522-
val uninstallLabel = popupView.findViewById<MaterialTextView>(R.id.uninstall_label)
522+
windowBinding.root.pivotY = if (top) 0f else popupHeight.toFloat()
523523
(if (PREFS.customLightFontPath != null) customLightFont else customFont)?.let {
524-
pinLabel.typeface = it
525-
infoLabel.typeface = it
526-
uninstallLabel.typeface = it
527-
}
528-
val anim = ObjectAnimator.ofFloat(popupView, "scaleY", 0f, 0.01f).setDuration(1)
529-
val anim2 = ObjectAnimator.ofFloat(popupView, "scaleX", 0f, 1f).setDuration(200)
530-
val anim3 = ObjectAnimator.ofFloat(popupView, "scaleY", 0.01f, 1f).setDuration(400)
531-
anim.doOnEnd {
532-
anim2.doOnEnd {
533-
anim3.start()
524+
windowBinding.pinAppLabel.typeface = it
525+
windowBinding.appInfoLabel.typeface = it
526+
windowBinding.uninstallLabel.typeface = it
527+
}
528+
if (PREFS.isAAllAppsAnimEnabled) {
529+
val anim =
530+
ObjectAnimator.ofFloat(windowBinding.root, "scaleY", 0f, 0.01f).setDuration(1)
531+
val anim2 =
532+
ObjectAnimator.ofFloat(windowBinding.root, "scaleX", 0f, 1f).setDuration(200)
533+
val anim3 =
534+
ObjectAnimator.ofFloat(windowBinding.root, "scaleY", 0.01f, 1f).setDuration(400)
535+
anim.doOnEnd {
536+
anim2.doOnEnd {
537+
anim3.start()
538+
}
539+
anim2.start()
534540
}
535-
anim2.start()
541+
anim.start()
536542
}
537-
anim.start()
538543
popupWindow!!.showAsDropDown(
539544
view,
540545
0,
@@ -543,10 +548,6 @@ class AllApps : Fragment() {
543548
)
544549
isWindowVisible = true
545550

546-
val pin = popupView.findViewById<MaterialCardView>(R.id.pin_app)
547-
val info = popupView.findViewById<MaterialCardView>(R.id.infoApp)
548-
val uninstall = popupView.findViewById<MaterialCardView>(R.id.uninstallApp)
549-
550551
var isAppAlreadyPinned = false
551552
lifecycleScope.launch(Dispatchers.Default) {
552553
mainViewModel.getViewModelTileDao().getTilesList().forEach {
@@ -556,12 +557,12 @@ class AllApps : Fragment() {
556557

557558
withContext(Dispatchers.Main) {
558559
if (isAppAlreadyPinned) {
559-
pin.apply {
560+
windowBinding.pinApp.apply {
560561
isEnabled = false
561562
alpha = 0.5f
562563
}
563564
} else {
564-
pin.apply {
565+
windowBinding.pinApp.apply {
565566
isEnabled = true
566567
alpha = 1f
567568
setOnClickListener {
@@ -573,12 +574,12 @@ class AllApps : Fragment() {
573574
}
574575
}
575576
}
576-
uninstall.setOnClickListener {
577+
windowBinding.uninstallApp.setOnClickListener {
577578
popupWindow?.dismiss()
578579
startActivity(Intent(Intent.ACTION_DELETE).setData("package:${app.appPackage}".toUri()))
579580
}
580581

581-
info.setOnClickListener {
582+
windowBinding.infoApp.setOnClickListener {
582583
isAppOpened = true
583584
startActivity(
584585
Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
@@ -587,12 +588,35 @@ class AllApps : Fragment() {
587588
}
588589
popupWindow?.setOnDismissListener {
589590
(requireActivity() as Main).configureViewPagerScroll(true)
591+
animateApps(position, true)
590592
binding.appList.isScrollEnabled = true
591593
isWindowVisible = false
592594
popupWindow = null
593595
}
594596
}
595597

598+
private fun animateApps(selectedAppPos: Int, restoreAnimations: Boolean) {
599+
val first =
600+
(binding.appList.layoutManager as LinearLayoutManager?)?.findFirstVisibleItemPosition()
601+
val last =
602+
(binding.appList.layoutManager as LinearLayoutManager?)?.findLastVisibleItemPosition()
603+
if(first == null || last == null) {
604+
return
605+
}
606+
lifecycleScope.launch {
607+
for (i in last downTo first) {
608+
val view =
609+
binding.appList.findViewHolderForAdapterPosition(i)?.itemView ?: continue
610+
if (!restoreAnimations) {
611+
if (i == selectedAppPos) continue
612+
view.animate().alpha(0.7f).scaleY(0.96f).scaleX(0.96f).setDuration(500).start()
613+
} else {
614+
view.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(500).start()
615+
}
616+
}
617+
}
618+
}
619+
596620
private fun insertNewApp(app: App) {
597621
lifecycleScope.launch(Dispatchers.Default) {
598622
val list = mainViewModel.getViewModelTileDao().getTilesList()
@@ -640,7 +664,7 @@ class AllApps : Fragment() {
640664
click()
641665
}
642666
itemView.setOnLongClickListener {
643-
showPopupWindow(itemView, list[absoluteAdapterPosition])
667+
showPopupWindow(itemView, list[absoluteAdapterPosition], absoluteAdapterPosition)
644668
true
645669
}
646670
}

0 commit comments

Comments
 (0)