@@ -9,11 +9,15 @@ import android.graphics.Canvas
9
9
import android.graphics.drawable.BitmapDrawable
10
10
import android.net.Uri
11
11
import android.provider.Settings
12
+ import androidx.compose.animation.core.animateFloat
13
+ import androidx.compose.animation.core.updateTransition
14
+
12
15
import androidx.compose.foundation.ExperimentalFoundationApi
13
16
import androidx.compose.foundation.Image
14
17
import androidx.compose.foundation.layout.Box
15
18
import androidx.compose.foundation.layout.Column
16
19
import androidx.compose.foundation.layout.Row
20
+ import androidx.compose.foundation.layout.fillMaxSize
17
21
import androidx.compose.foundation.layout.fillMaxWidth
18
22
import androidx.compose.foundation.layout.padding
19
23
import androidx.compose.foundation.layout.size
@@ -24,6 +28,7 @@ import androidx.compose.foundation.pager.rememberPagerState
24
28
import androidx.compose.foundation.shape.RoundedCornerShape
25
29
import androidx.compose.material.icons.Icons
26
30
import androidx.compose.material.icons.outlined.MoreVert
31
+ import androidx.compose.material3.CircularProgressIndicator
27
32
import androidx.compose.material3.DropdownMenu
28
33
import androidx.compose.material3.DropdownMenuItem
29
34
import androidx.compose.material3.Icon
@@ -45,6 +50,7 @@ import androidx.compose.runtime.rememberCoroutineScope
45
50
import androidx.compose.runtime.setValue
46
51
import androidx.compose.ui.Alignment
47
52
import androidx.compose.ui.Modifier
53
+ import androidx.compose.ui.draw.alpha
48
54
import androidx.compose.ui.draw.clip
49
55
import androidx.compose.ui.graphics.ImageBitmap
50
56
import androidx.compose.ui.graphics.asImageBitmap
@@ -55,7 +61,7 @@ import androidx.compose.ui.text.style.TextOverflow
55
61
import androidx.compose.ui.unit.dp
56
62
import androidx.lifecycle.viewmodel.compose.viewModel
57
63
import com.d4rk.cleaner.R
58
- import com.d4rk.cleaner.data.model.ui.ApkInfo
64
+ import com.d4rk.cleaner.data.model.ui.appmanager.ui. ApkInfo
59
65
import com.d4rk.cleaner.utils.PermissionsUtils
60
66
import kotlinx.coroutines.launch
61
67
import java.io.File
@@ -73,56 +79,73 @@ fun AppManagerComposable() {
73
79
val tabs = listOf (" Installed Apps" , " System Apps" , " App Install Files" )
74
80
val pagerState = rememberPagerState(pageCount = { tabs.size })
75
81
val coroutineScope = rememberCoroutineScope()
82
+ val isLoading by viewModel.isLoading.collectAsState()
83
+ val transition = updateTransition(targetState = ! isLoading, label = " LoadingTransition" )
84
+
85
+ val contentAlpha by transition.animateFloat(label = " Content Alpha" ) {
86
+ if (it) 1f else 0f
87
+ }
76
88
77
89
LaunchedEffect (context) {
78
90
if (! PermissionsUtils .hasStoragePermissions(context)) {
79
91
PermissionsUtils .requestStoragePermissions(context as Activity )
80
92
}
81
93
}
82
94
83
- Column {
84
- TabRow (
85
- selectedTabIndex = pagerState.currentPage,
86
- indicator = { tabPositions ->
87
- TabRowDefaults .PrimaryIndicator (
88
- modifier = Modifier .tabIndicatorOffset(tabPositions[pagerState.currentPage]),
89
- shape = RoundedCornerShape (
90
- topStart = 3 .dp, topEnd = 3 .dp, bottomEnd = 0 .dp, bottomStart = 0 .dp
91
- ),
92
- )
93
- },
95
+ if (isLoading) {
96
+ Box (
97
+ modifier = Modifier .fillMaxSize(),
98
+ contentAlignment = Alignment .Center
94
99
) {
95
- tabs.forEachIndexed { index, title ->
96
- Tab (
97
- text = {
98
- Text (
99
- text = title,
100
- maxLines = 1 ,
101
- overflow = TextOverflow .Ellipsis ,
102
- color = MaterialTheme .colorScheme.onSurface
103
- )
104
- },
105
- selected = pagerState.currentPage == index,
106
- onClick = {
107
- coroutineScope.launch {
108
- pagerState.animateScrollToPage(index)
100
+ CircularProgressIndicator ()
101
+ }
102
+ } else {
103
+ Column (
104
+ modifier = Modifier .alpha(contentAlpha),
105
+ ) {
106
+ TabRow (
107
+ selectedTabIndex = pagerState.currentPage,
108
+ indicator = { tabPositions ->
109
+ TabRowDefaults .PrimaryIndicator (
110
+ modifier = Modifier .tabIndicatorOffset(tabPositions[pagerState.currentPage]),
111
+ shape = RoundedCornerShape (
112
+ topStart = 3 .dp, topEnd = 3 .dp, bottomEnd = 0 .dp, bottomStart = 0 .dp
113
+ ),
114
+ )
115
+ },
116
+ ) {
117
+ tabs.forEachIndexed { index, title ->
118
+ Tab (
119
+ text = {
120
+ Text (
121
+ text = title,
122
+ maxLines = 1 ,
123
+ overflow = TextOverflow .Ellipsis ,
124
+ color = MaterialTheme .colorScheme.onSurface
125
+ )
126
+ },
127
+ selected = pagerState.currentPage == index,
128
+ onClick = {
129
+ coroutineScope.launch {
130
+ pagerState.animateScrollToPage(index)
131
+ }
109
132
}
110
- }
111
- )
133
+ )
134
+ }
112
135
}
113
- }
114
136
115
- HorizontalPager (
116
- state = pagerState, // Only provide pagerState here
117
- ) { page ->
118
- when (page) {
119
- 0 -> AppsComposable (
120
- apps = viewModel.installedApps.collectAsState().value.filter { it.flags and ApplicationInfo .FLAG_SYSTEM == 0 }
121
- )
122
- 1 -> AppsComposable (
123
- apps = viewModel.installedApps.collectAsState().value.filter { it.flags and ApplicationInfo .FLAG_SYSTEM != 0 }
124
- )
125
- 2 -> ApksComposable (apkFiles = viewModel.apkFiles.collectAsState().value)
137
+ HorizontalPager (
138
+ state = pagerState,
139
+ ) { page ->
140
+ when (page) {
141
+ 0 -> AppsComposable (
142
+ apps = viewModel.installedApps.collectAsState().value.filter { it.flags and ApplicationInfo .FLAG_SYSTEM == 0 }
143
+ )
144
+ 1 -> AppsComposable (
145
+ apps = viewModel.installedApps.collectAsState().value.filter { it.flags and ApplicationInfo .FLAG_SYSTEM != 0 }
146
+ )
147
+ 2 -> ApksComposable (apkFiles = viewModel.apkFiles.collectAsState().value)
148
+ }
126
149
}
127
150
}
128
151
}
0 commit comments