Skip to content

Commit

Permalink
Improved the code and project
Browse files Browse the repository at this point in the history
  • Loading branch information
D4rK7355608 committed Jun 29, 2024
1 parent 7a1f7bc commit d7c89b1
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 124 deletions.
26 changes: 13 additions & 13 deletions app/src/main/kotlin/com/d4rk/cleaner/MainComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.d4rk.cleaner.ads.FullBannerAdsComposable
import com.d4rk.cleaner.data.datastore.DataStore
import com.d4rk.cleaner.data.navigation.NavigationItem
import com.d4rk.cleaner.data.navigation.Screen
import com.d4rk.cleaner.ui.components.navigation.NavigationDrawerItem
import com.d4rk.cleaner.ui.components.navigation.BottomNavigationScreen
import com.d4rk.cleaner.ui.appmanager.AppManagerComposable
import com.d4rk.cleaner.ui.help.HelpActivity
import com.d4rk.cleaner.ui.home.HomeComposable
Expand All @@ -62,30 +62,30 @@ import kotlinx.coroutines.launch
@Composable
fun MainComposable() {
val bottomBarItems = listOf(
Screen.Home, Screen.AppManager, Screen.MemoryManager
BottomNavigationScreen.Home, BottomNavigationScreen.AppManager, BottomNavigationScreen.MemoryManager
)
val drawerItems = listOf(
NavigationItem(
NavigationDrawerItem(
title = R.string.whitelist, selectedIcon = Icons.AutoMirrored.Outlined.ListAlt
),

NavigationItem(
NavigationDrawerItem(
title = R.string.image_optimizer, selectedIcon = Icons.Outlined.Image
),

NavigationItem(
NavigationDrawerItem(
title = R.string.settings,
selectedIcon = Icons.Outlined.Settings,
),
NavigationItem(
NavigationDrawerItem(
title = R.string.help_and_feedback,
selectedIcon = Icons.AutoMirrored.Outlined.HelpOutline,
),
NavigationItem(
NavigationDrawerItem(
title = R.string.updates,
selectedIcon = Icons.AutoMirrored.Outlined.EventNote,
),
NavigationItem(
NavigationDrawerItem(
title = R.string.share, selectedIcon = Icons.Outlined.Share
),
)
Expand Down Expand Up @@ -212,18 +212,18 @@ fun MainComposable() {
}
}
}) { innerPadding ->
NavHost(navController, startDestination = Screen.Home.route) {
composable(Screen.Home.route) {
NavHost(navController, startDestination = BottomNavigationScreen.Home.route) {
composable(BottomNavigationScreen.Home.route) {
Box(modifier = Modifier.padding(innerPadding)) {
HomeComposable()
}
}
composable(Screen.AppManager.route) {
composable(BottomNavigationScreen.AppManager.route) {
Box(modifier = Modifier.padding(innerPadding)) {
AppManagerComposable()
}
}
composable(Screen.MemoryManager.route) {
composable(BottomNavigationScreen.MemoryManager.route) {
Box(modifier = Modifier.padding(innerPadding)) {
MemoryManagerComposable()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.d4rk.cleaner.constants.ui.bottombar

object BottomBarRoutes {
const val HOME = "home"
const val APP_MANAGER = "app_manager"
const val MEMORY_MANAGER = "memory_manager"
}

This file was deleted.

28 changes: 0 additions & 28 deletions app/src/main/kotlin/com/d4rk/cleaner/data/navigation/Screen.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.d4rk.cleaner.ui.components.button

enum class ButtonState { Pressed , Idle }
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.d4rk.cleaner.ui.components.navigation

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.rounded.AppRegistration
import androidx.compose.material.icons.rounded.Storage
import androidx.compose.material.icons.sharp.AppRegistration
import androidx.compose.material.icons.sharp.Storage
import androidx.compose.ui.graphics.vector.ImageVector
import com.d4rk.cleaner.R
import com.d4rk.cleaner.constants.ui.bottombar.BottomBarRoutes

sealed class BottomNavigationScreen(
val route: String,
val icon: ImageVector,
val selectedIcon: ImageVector,
val title: Int
) {
data object Home : BottomNavigationScreen(
BottomBarRoutes.HOME,
Icons.Outlined.Home,
Icons.Filled.Home,
R.string.home
)

data object AppManager : BottomNavigationScreen(
BottomBarRoutes.APP_MANAGER,
Icons.Sharp.AppRegistration,
Icons.Rounded.AppRegistration,
R.string.app_manager
)

data object MemoryManager : BottomNavigationScreen(
BottomBarRoutes.MEMORY_MANAGER,
Icons.Sharp.Storage,
Icons.Rounded.Storage,
R.string.memory_manager
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.d4rk.cleaner.data.navigation
package com.d4rk.cleaner.ui.components.navigation

import androidx.compose.ui.graphics.vector.ImageVector

data class NavigationItem(
data class NavigationDrawerItem(
val title: Int, val selectedIcon: ImageVector, val badgeCount: Int? = null
)
54 changes: 1 addition & 53 deletions app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import android.content.Context
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand All @@ -33,7 +30,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
Expand All @@ -48,15 +44,14 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.asFlow
import androidx.lifecycle.viewmodel.compose.viewModel
import com.d4rk.cleaner.R
import com.d4rk.cleaner.ui.startup.StartupActivity
import com.d4rk.cleaner.utils.CircularDeterminateIndicator
import com.d4rk.cleaner.utils.Utils
import com.d4rk.cleaner.utils.bounceClick
import com.google.common.io.Files.getFileExtension
Expand Down Expand Up @@ -178,53 +173,6 @@ fun HomeComposable() {
}
}

/**
* Composable function representing a circular determinate progress indicator with storage information.
*
* This composable displays a circular progress indicator representing a determinate progress value.
* It also shows storage usage information (used/total) in gigabytes (GB).
*
* @param progress The progress value as a float, representing the completion percentage of the progress indicator.
* @param storageUsed The amount of storage used, formatted as a string (e.g., "2.5 GB").
* @param storageTotal The total amount of storage, formatted as a string (e.g., "10 GB").
* @param modifier The modifier for styling and layout customization.
*/
@Composable
fun CircularDeterminateIndicator(
progress: Float, storageUsed: String, storageTotal: String, modifier: Modifier = Modifier
) {
val animatedProgress by animateFloatAsState(
targetValue = progress,
animationSpec = tween(durationMillis = 1000, easing = LinearOutSlowInEasing),
label = ""
)

Box(
contentAlignment = Alignment.Center, modifier = modifier.size(240.dp)
) {
CircularProgressIndicator(
progress = { 1f },
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.primaryContainer,
strokeWidth = 6.dp,
)
CircularProgressIndicator(
progress = { animatedProgress },
modifier = Modifier
.animateContentSize()
.fillMaxSize(),
color = MaterialTheme.colorScheme.primary,
strokeWidth = 6.dp,
strokeCap = StrokeCap.Round,
)
Text(
text = "$storageUsed/$storageTotal GB \n Used",
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge
)
}
}

/**
* Composable function representing the analyze screen displaying a list of files to clean.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.lerp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.d4rk.cleaner.data.model.RamInfo
import com.d4rk.cleaner.data.model.StorageInfo
import com.d4rk.cleaner.ui.memory.model.RamInfo
import com.d4rk.cleaner.ui.memory.model.StorageInfo
import com.d4rk.cleaner.utils.StorageProgressBar
import kotlin.math.absoluteValue

val StorageIcons = mapOf(
Expand Down Expand Up @@ -257,22 +258,6 @@ fun RamInfoCard(ramInfo: RamInfo) {
}
}

@Composable
fun StorageProgressBar(storageInfo: StorageInfo) {
val progress =
(storageInfo.usedStorage.toFloat() / storageInfo.totalStorage.toFloat()).coerceIn(
0f,
1f
)
LinearProgressIndicator(
progress = { progress },
modifier = Modifier
.fillMaxWidth()
.height(8.dp),
color = MaterialTheme.colorScheme.primary,
)
}

@Composable
fun DotsIndicator(
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import android.os.StatFs
import android.os.storage.StorageManager
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.d4rk.cleaner.data.model.InternalStorageInfo
import com.d4rk.cleaner.data.model.RamInfo
import com.d4rk.cleaner.data.model.StorageInfo
import com.d4rk.cleaner.ui.memory.model.InternalStorageInfo
import com.d4rk.cleaner.ui.memory.model.RamInfo
import com.d4rk.cleaner.ui.memory.model.StorageInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cleaner.data.model
package com.d4rk.cleaner.ui.memory.model

data class InternalStorageInfo(
val totalStorage: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cleaner.data.model
package com.d4rk.cleaner.ui.memory.model

data class RamInfo(
val totalRam: Long = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cleaner.data.model
package com.d4rk.cleaner.ui.memory.model

data class StorageInfo(
val totalStorage: Long = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import com.d4rk.cleaner.data.model.ButtonState
import com.d4rk.cleaner.ui.components.button.ButtonState

@SuppressLint("ReturnFromAwaitPointerEventScope")
@Composable
Expand Down
Loading

0 comments on commit d7c89b1

Please sign in to comment.