@@ -30,6 +30,7 @@ import androidx.core.animation.doOnEnd
30
30
import androidx.core.content.ContextCompat
31
31
import androidx.core.content.edit
32
32
import androidx.core.net.toUri
33
+ import androidx.core.view.forEach
33
34
import androidx.fragment.app.Fragment
34
35
import androidx.lifecycle.ViewModelProvider
35
36
import androidx.lifecycle.lifecycleScope
@@ -38,8 +39,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
38
39
import androidx.recyclerview.widget.RecyclerView
39
40
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
40
41
import coil3.load
41
- import com.google.android.material.card.MaterialCardView
42
- import com.google.android.material.textview.MaterialTextView
43
42
import kotlinx.coroutines.Dispatchers
44
43
import kotlinx.coroutines.delay
45
44
import kotlinx.coroutines.launch
@@ -55,6 +54,7 @@ import ru.queuejw.mpl.R
55
54
import ru.queuejw.mpl.content.data.app.App
56
55
import ru.queuejw.mpl.content.data.tile.Tile
57
56
import ru.queuejw.mpl.content.settings.SettingsActivity
57
+ import ru.queuejw.mpl.databinding.AllAppsWindowBinding
58
58
import ru.queuejw.mpl.databinding.AppBinding
59
59
import ru.queuejw.mpl.databinding.LauncherAllAppsScreenBinding
60
60
import ru.queuejw.mpl.helpers.receivers.PackageChangesReceiver
@@ -435,11 +435,11 @@ class AllApps : Fragment() {
435
435
436
436
private fun runAppWithAnimation (app : String , pm : PackageManager ) {
437
437
val first =
438
- (binding.appList.layoutManager as LinearLayoutManager ) .findFirstVisibleItemPosition()
438
+ (binding.appList.layoutManager as LinearLayoutManager ? )? .findFirstVisibleItemPosition()
439
439
val last =
440
- (binding.appList.layoutManager as LinearLayoutManager ) .findLastVisibleItemPosition()
440
+ (binding.appList.layoutManager as LinearLayoutManager ? )? .findLastVisibleItemPosition()
441
441
binding.appList.isScrollEnabled = false
442
- if (appAdapter == null ) {
442
+ if (appAdapter == null || first == null || last == null ) {
443
443
runApp(app, pm)
444
444
return
445
445
}
@@ -501,40 +501,45 @@ class AllApps : Fragment() {
501
501
return contentView.measuredHeight
502
502
}
503
503
504
- private fun showPopupWindow (view : View , app : App ) {
504
+ private fun showPopupWindow (view : View , app : App , position : Int ) {
505
505
binding.appList.isScrollEnabled = false
506
+ if (PREFS .isAAllAppsAnimEnabled) {
507
+ animateApps(position, false )
508
+ }
506
509
(requireActivity() as Main ).configureViewPagerScroll(false )
507
510
val inflater =
508
511
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 )
510
513
popupWindow = PopupWindow (
511
- popupView ,
514
+ windowBinding.root ,
512
515
LinearLayout .LayoutParams .MATCH_PARENT ,
513
516
LinearLayout .LayoutParams .WRAP_CONTENT ,
514
517
true
515
518
)
516
519
popupWindow!! .isFocusable = true
517
520
val popupHeight = getPopupHeight(popupWindow!! )
518
521
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()
523
523
(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()
534
540
}
535
- anim2 .start()
541
+ anim .start()
536
542
}
537
- anim.start()
538
543
popupWindow!! .showAsDropDown(
539
544
view,
540
545
0 ,
@@ -543,10 +548,6 @@ class AllApps : Fragment() {
543
548
)
544
549
isWindowVisible = true
545
550
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
-
550
551
var isAppAlreadyPinned = false
551
552
lifecycleScope.launch(Dispatchers .Default ) {
552
553
mainViewModel.getViewModelTileDao().getTilesList().forEach {
@@ -556,12 +557,12 @@ class AllApps : Fragment() {
556
557
557
558
withContext(Dispatchers .Main ) {
558
559
if (isAppAlreadyPinned) {
559
- pin .apply {
560
+ windowBinding.pinApp .apply {
560
561
isEnabled = false
561
562
alpha = 0.5f
562
563
}
563
564
} else {
564
- pin .apply {
565
+ windowBinding.pinApp .apply {
565
566
isEnabled = true
566
567
alpha = 1f
567
568
setOnClickListener {
@@ -573,12 +574,12 @@ class AllApps : Fragment() {
573
574
}
574
575
}
575
576
}
576
- uninstall .setOnClickListener {
577
+ windowBinding.uninstallApp .setOnClickListener {
577
578
popupWindow?.dismiss()
578
579
startActivity(Intent (Intent .ACTION_DELETE ).setData(" package:${app.appPackage} " .toUri()))
579
580
}
580
581
581
- info .setOnClickListener {
582
+ windowBinding.infoApp .setOnClickListener {
582
583
isAppOpened = true
583
584
startActivity(
584
585
Intent (android.provider.Settings .ACTION_APPLICATION_DETAILS_SETTINGS )
@@ -587,12 +588,35 @@ class AllApps : Fragment() {
587
588
}
588
589
popupWindow?.setOnDismissListener {
589
590
(requireActivity() as Main ).configureViewPagerScroll(true )
591
+ animateApps(position, true )
590
592
binding.appList.isScrollEnabled = true
591
593
isWindowVisible = false
592
594
popupWindow = null
593
595
}
594
596
}
595
597
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
+
596
620
private fun insertNewApp (app : App ) {
597
621
lifecycleScope.launch(Dispatchers .Default ) {
598
622
val list = mainViewModel.getViewModelTileDao().getTilesList()
@@ -640,7 +664,7 @@ class AllApps : Fragment() {
640
664
click()
641
665
}
642
666
itemView.setOnLongClickListener {
643
- showPopupWindow(itemView, list[absoluteAdapterPosition])
667
+ showPopupWindow(itemView, list[absoluteAdapterPosition], absoluteAdapterPosition )
644
668
true
645
669
}
646
670
}
0 commit comments