Skip to content

Commit bf7b8c0

Browse files
Replace println with Log and fix permission check
1 parent 3e70b57 commit bf7b8c0

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

app/src/main/kotlin/com/d4rk/cleaner/app/clean/analyze/ui/AnalyzeScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.d4rk.cleaner.app.clean.analyze.ui
22

3+
import android.util.Log
34
import android.view.View
45
import androidx.compose.animation.ExperimentalAnimationApi
56
import androidx.compose.animation.animateContentSize
@@ -37,6 +38,8 @@ import com.d4rk.cleaner.app.clean.scanner.ui.ScannerViewModel
3738
import com.d4rk.cleaner.app.clean.scanner.ui.components.TwoRowButtons
3839
import kotlinx.coroutines.CoroutineScope
3940

41+
private const val TAG = "AnalyzeScreen"
42+
4043
@OptIn(ExperimentalAnimationApi::class)
4144
@Composable
4245
fun AnalyzeScreen(
@@ -62,7 +65,7 @@ fun AnalyzeScreen(
6265
.weight(weight = 1f)
6366
.fillMaxWidth(),
6467
) {
65-
println(message = "The state of the screen is ${data.analyzeState.state}")
68+
Log.d(TAG, "The state of the screen is ${data.analyzeState.state}")
6669
when (data.analyzeState.state) {
6770

6871
CleaningState.Analyzing -> {

app/src/main/kotlin/com/d4rk/cleaner/app/clean/contacts/domain/usecases/GetDuplicateContactsUseCase.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.d4rk.cleaner.app.clean.contacts.domain.usecases
22

3+
import android.util.Log
34
import com.d4rk.android.libs.apptoolkit.core.domain.model.network.DataState
45
import com.d4rk.cleaner.app.clean.contacts.data.ContactsRepository
56
import com.d4rk.cleaner.app.clean.contacts.domain.data.model.RawContactInfo
@@ -8,13 +9,15 @@ import com.d4rk.cleaner.core.utils.extensions.toError
89
import kotlinx.coroutines.flow.Flow
910
import kotlinx.coroutines.flow.flow
1011

12+
private const val TAG = "GetDuplicateContactsUseCase"
13+
1114
class GetDuplicateContactsUseCase(private val repository: ContactsRepository) {
1215
operator fun invoke(): Flow<DataState<List<List<RawContactInfo>>, Errors>> = flow {
1316
emit(DataState.Loading())
1417
runCatching { repository.findDuplicates() }
1518
.onSuccess { emit(DataState.Success(it)) }
1619
.onFailure {
17-
println(it)
20+
Log.e(TAG, "Error fetching duplicate contacts", it)
1821
emit(DataState.Error(error = it.toError()))
1922
}
2023
}

app/src/main/kotlin/com/d4rk/cleaner/app/clean/contacts/ui/ContactsCleanerViewModel.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.d4rk.cleaner.app.clean.contacts.ui
22

3+
import android.util.Log
34
import com.d4rk.android.libs.apptoolkit.core.di.DispatcherProvider
45
import com.d4rk.android.libs.apptoolkit.core.domain.model.network.DataState
56
import com.d4rk.android.libs.apptoolkit.core.domain.model.ui.ScreenState
@@ -29,6 +30,10 @@ class ContactsCleanerViewModel(
2930
initialState = UiStateScreen(data = UiContactsCleanerModel())
3031
) {
3132

33+
companion object {
34+
private const val TAG = "ContactsCleanerViewModel"
35+
}
36+
3237
init {
3338
onEvent(ContactsCleanerEvent.LoadDuplicates)
3439
}
@@ -59,11 +64,9 @@ class ContactsCleanerViewModel(
5964
getDuplicatesUseCase().collectLatest { result ->
6065
_uiState.update { current ->
6166

62-
println("result: $result")
63-
64-
65-
println("error: ${(result as? DataState.Error)?.error}")
66-
println("message error: ${current.errors}")
67+
Log.d(TAG, "result: $result")
68+
Log.d(TAG, "error: ${(result as? DataState.Error)?.error}")
69+
Log.d(TAG, "message error: ${current.errors}")
6770

6871

6972
when (result) {

app/src/main/kotlin/com/d4rk/cleaner/app/clean/largefiles/ui/LargeFilesScreen.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.d4rk.cleaner.app.clean.largefiles.ui
22

33
import android.view.View
4+
import android.util.Log
45
import androidx.compose.foundation.layout.fillMaxSize
56
import androidx.compose.foundation.layout.padding
67
import androidx.compose.material.icons.Icons
@@ -30,6 +31,7 @@ import com.d4rk.cleaner.app.clean.scanner.domain.data.model.ui.CleaningState
3031
import org.koin.compose.viewmodel.koinViewModel
3132
import java.io.File
3233

34+
private const val TAG = "LargeFilesScreen"
3335
@OptIn(ExperimentalMaterial3Api::class)
3436
@Composable
3537
fun LargeFilesScreen(activity: LargeFilesActivity) {
@@ -47,15 +49,15 @@ fun LargeFilesScreen(activity: LargeFilesActivity) {
4749
CleaningAnimationScreen()
4850
} else {
4951
LoadingScreen()
50-
println("LoadingScreen")
52+
Log.d(TAG, "LoadingScreen")
5153
}
5254
},
5355
onEmpty = {
54-
println("onEmpty")
56+
Log.d(TAG, "onEmpty")
5557
NoDataScreen(textMessage = R.string.no_large_files, icon = Icons.Outlined.Folder)
5658
},
5759
onSuccess = { data: UiLargeFilesModel ->
58-
println("onSuccess")
60+
Log.d(TAG, "onSuccess")
5961
ConstraintLayout(
6062
modifier = Modifier
6163
.padding(padding)

app/src/main/kotlin/com/d4rk/cleaner/app/clean/scanner/work/FileCleanupWorker.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import android.app.NotificationManager
66
import android.content.Context
77
import android.os.Build
88
import android.util.Log
9-
import androidx.core.app.ActivityCompat
109
import androidx.core.app.NotificationCompat
1110
import androidx.core.app.NotificationManagerCompat
11+
import androidx.core.content.ContextCompat
1212
import androidx.work.CoroutineWorker
1313
import androidx.work.Data
1414
import androidx.work.WorkerParameters
@@ -50,11 +50,11 @@ class FileCleanupWorker(
5050
}
5151
val action = inputData.getString(KEY_ACTION) ?: ACTION_DELETE
5252
val paths = rawPaths.toList()
53-
println("FileCleanupWorker ---> Received paths: $paths")
53+
Log.d(TAG, "Received paths: $paths")
5454
val files = mutableListOf<File>()
5555
var hasNonProtectedPath = false
5656
for (path in paths) {
57-
println("FileCleanupWorker ---> Checking path: $path")
57+
Log.d(TAG, "Checking path: $path")
5858
val file = File(path)
5959
if (file.isProtectedAndroidDir()) {
6060
Log.i(TAG, "Skipping protected path: ${file.absolutePath}")
@@ -64,11 +64,11 @@ class FileCleanupWorker(
6464
val exists = file.exists()
6565
val isFile = file.isFile
6666
val isDirectory = file.isDirectory
67-
println("FileCleanupWorker ---> File exists: $exists isFile: $isFile isDirectory: $isDirectory")
67+
Log.d(TAG, "File exists: $exists isFile: $isFile isDirectory: $isDirectory")
6868
if (exists) {
69-
println("FileCleanupWorker ---> canRead: ${file.canRead()} canWrite: ${file.canWrite()}")
69+
Log.d(TAG, "canRead: ${file.canRead()} canWrite: ${file.canWrite()}")
7070
if (isDirectory) {
71-
println("FileCleanupWorker ---> directory children: ${file.listFiles()?.size ?: 0}")
71+
Log.d(TAG, "directory children: ${file.listFiles()?.size ?: 0}")
7272
}
7373
files += file
7474
}
@@ -114,7 +114,7 @@ class FileCleanupWorker(
114114
setProgress(workDataOf(KEY_PROGRESS_CURRENT to processed, KEY_PROGRESS_TOTAL to total))
115115

116116
val hasPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
117-
ActivityCompat.checkSelfPermission(
117+
ContextCompat.checkSelfPermission(
118118
applicationContext,
119119
Manifest.permission.POST_NOTIFICATIONS,
120120
) == android.content.pm.PackageManager.PERMISSION_GRANTED
@@ -145,20 +145,20 @@ class FileCleanupWorker(
145145
return Result.failure()
146146
}
147147

148-
println("FileCleanupWorker ---> Attempting to $action: ${file.absolutePath}")
148+
Log.d(TAG, "Attempting to $action: ${file.absolutePath}")
149149
when (val res = performAction(action, listOf(file))) {
150150
is DataState.Error -> {
151151
failedPaths += file.absolutePath
152152
val reason = when (val err = res.error) {
153153
is Errors.Custom -> err.message
154154
else -> err.toString()
155155
}
156-
println("FileCleanupWorker ---> ERROR deleting ${file.absolutePath} → reason = $reason")
156+
Log.e(TAG, "Error deleting ${file.absolutePath} → reason = $reason")
157157
Log.w(TAG, "Failed to process ${file.absolutePath}: $reason")
158158
}
159159
else -> {
160160
successCount++
161-
println("FileCleanupWorker ---> Deleted: ${file.absolutePath} → result = success")
161+
Log.i(TAG, "Deleted: ${file.absolutePath} → result = success")
162162
}
163163
}
164164
processed++
@@ -193,7 +193,7 @@ class FileCleanupWorker(
193193
builder.setProgress(0, 0, false)
194194

195195
val failedCount = failedPaths.size
196-
println("FileCleanupWorker ---> Deleted $successCount, failed $failedCount")
196+
Log.i(TAG, "Deleted $successCount, failed $failedCount")
197197
val resultData = Data.Builder().apply {
198198
if (failedPaths.isNotEmpty()) {
199199
putStringArray(KEY_FAILED_PATHS, failedPaths.toTypedArray())

0 commit comments

Comments
 (0)