Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Oct 24, 2024
1 parent 2f11363 commit 0c05cff
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.biometric.BiometricPrompt
import androidx.compose.foundation.layout.Box
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -100,7 +99,6 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.dsl.module
import timber.log.Timber


@Composable
fun Rescue() {
AppTheme {
Expand All @@ -109,7 +107,6 @@ fun Rescue() {
}
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
class MainActivityX : BaseActivity() {

private val mScope: CoroutineScope = MainScope()
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/machiav3lli/backup/dbs/ODatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ abstract class ODatabase : RoomDatabase() {

val databaseModule = module {
single { ODatabase.getInstance(androidContext()) }
factory { get<ODatabase>().getScheduleDao() }
factory { get<ODatabase>().getBlocklistDao() }
factory { get<ODatabase>().getAppExtrasDao() }
factory { get<ODatabase>().getBackupDao() }
factory { get<ODatabase>().getAppInfoDao() }
factory { get<ODatabase>().getSpecialInfoDao() }
single { get<ODatabase>().getScheduleDao() }
single { get<ODatabase>().getBlocklistDao() }
single { get<ODatabase>().getAppExtrasDao() }
single { get<ODatabase>().getBackupDao() }
single { get<ODatabase>().getAppInfoDao() }
single { get<ODatabase>().getSpecialInfoDao() }
}
2 changes: 1 addition & 1 deletion src/main/java/com/machiav3lli/backup/items/StorageFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ open class StorageFile {
if (pref_shadowRootFile.value && allowShadowing) {
try {
val last =
//uri.lastPathSegment // docs say: last segment of the decoded(!) path, not the encoded one
//uri.lastPathSegment // docs say: last segment of the decoded(!) path, not the encoded one
// so make it explicit:
URLDecoder.decode(uri.encodedPath?.split("/")?.last() ?: "", "UTF-8")
Timber.i("SAF: last=$last uri=$uri")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class InternalRegexPlugin(file: File) : TextPlugin(file) {
Regex("T-h-I-s--S-h-O-u-L-d--N-e-V-e-R--m-A-t-C-h")
}

fun replaceVars(text: String, replacements: Map<String, String> = mapOf()) : String {
fun replaceVars(text: String, replacements: Map<String, String> = mapOf()): String {
var result = text
replacements.forEach { replacement ->
result = result.replace(replacement.key, replacement.value)
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/com/machiav3lli/backup/plugins/SpecialFilesPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class SpecialFilesPlugin(file: File) : TextPlugin(file) {
.map { replaceVars(it, userId) }

init {
tracePlugin { (listOf("${this.javaClass.simpleName} $name <- ${file.name}") + getFiles("<userId>")).joinToString("\n ") }
tracePlugin {
(listOf("${this.javaClass.simpleName} $name <- ${file.name}") + getFiles("<userId>")).joinToString(
"\n "
)
}
}

companion object : PluginCompanion {
Expand All @@ -25,7 +29,7 @@ class SpecialFilesPlugin(file: File) : TextPlugin(file) {
override fun register() = registerType(name(), Companion, listOf("special_files"))
override fun create(file: File): Plugin? = SpecialFilesPlugin(file)

fun specialInfos(userId: String) : List<SpecialInfo> {
fun specialInfos(userId: String): List<SpecialInfo> {

ensureScanned()

Expand All @@ -45,19 +49,19 @@ class SpecialFilesPlugin(file: File) : TextPlugin(file) {
}

@SuppressLint("SdCardPath")
fun replaceVars(text: String, userId: String) : String {
fun replaceVars(text: String, userId: String): String {
val replacements = mapOf(
"userId" to userId.toString(),
"miscData" to "/data/misc",
"systemData" to "/data/system",
"systemUserData" to "/data/system/users/$userId",
"systemCeUserData" to "/data/system_ce/$userId",
"vendorDeUserData" to "/data/vendor_de/$userId",
"userData" to "/data/user/$userId",
"userDeData" to "/data/user_de/$userId",
"extUserData" to "/storage/emulated/$userId/Android/data",
"extUserMedia" to "/storage/emulated/$userId/Android/media",
"extUserObb" to "/storage/emulated/$userId/Android/obb",
"userId" to userId.toString(),
"miscData" to "/data/misc",
"systemData" to "/data/system",
"systemUserData" to "/data/system/users/$userId",
"systemCeUserData" to "/data/system_ce/$userId",
"vendorDeUserData" to "/data/vendor_de/$userId",
"userData" to "/data/user/$userId",
"userDeData" to "/data/user_de/$userId",
"extUserData" to "/storage/emulated/$userId/Android/data",
"extUserMedia" to "/storage/emulated/$userId/Android/media",
"extUserObb" to "/storage/emulated/$userId/Android/obb",
)
var result = text
replacements.forEach { replacement ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CommandReceiver : //TODO hg42 how to maintain security?
OABX.addInfoLogText("$command $batchName")
OABX.work.cancel(batchName)
}

ACTION_SCHEDULE -> {
intent.getStringExtra("name")?.let { name ->
OABX.addInfoLogText("$command $name")
Expand All @@ -47,6 +48,7 @@ class CommandReceiver : //TODO hg42 how to maintain security?
}.start()
}
}

ACTION_RESCHEDULE -> {
intent.getStringExtra("name")?.let { name ->
val now = SystemUtils.now
Expand All @@ -70,9 +72,11 @@ class CommandReceiver : //TODO hg42 how to maintain security?
}.start()
}
}

ACTION_CRASH -> {
throw Exception("this is a crash via command intent")
}

null -> {}
else -> {
OABX.addInfoLogText("Command: command '$command'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PackageUnInstalledReceiver : BroadcastReceiver() {
when (intent.action.orEmpty()) {
Intent.ACTION_PACKAGE_ADDED,
Intent.ACTION_PACKAGE_REPLACED,
-> {
-> {
context.packageManager.getPackageInfo(
packageName,
PackageManager.GET_PERMISSIONS
Expand All @@ -58,7 +58,7 @@ class PackageUnInstalledReceiver : BroadcastReceiver() {
}

Intent.ACTION_PACKAGE_REMOVED,
-> {
-> {
GlobalScope.launch(Dispatchers.IO) {
val backups = db.getBackupDao().get(packageName)
if (backups.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ open class ScheduleService : Service() {
WorkInfo.State.SUCCEEDED,
WorkInfo.State.FAILED,
WorkInfo.State.CANCELLED,
-> {
-> {
finished += 1
val succeeded =
value.outputData.getBoolean(
Expand Down Expand Up @@ -252,6 +252,7 @@ open class ScheduleService : Service() {
intent
)
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
Expand Down Expand Up @@ -98,7 +97,6 @@ import coil.request.ImageRequest
import coil.size.Size
import com.machiav3lli.backup.ENABLED_FILTER_DISABLED
import com.machiav3lli.backup.ICON_SIZE_LARGE
import com.machiav3lli.backup.ICON_SIZE_MEDIUM
import com.machiav3lli.backup.ICON_SIZE_SMALL
import com.machiav3lli.backup.LATEST_FILTER_NEW
import com.machiav3lli.backup.LAUNCHABLE_FILTER_NOT
Expand Down Expand Up @@ -531,7 +529,7 @@ fun RefreshButton(
@Composable
fun RefreshButtonPreview() {
OABX.fakeContext = LocalContext.current.applicationContext

val level by remember { OABX.busyLevel }
val factor = 1.0 / max(1, level)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.yield
import java.io.File



@Composable
fun SimpleButton(
text: String,
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/machiav3lli/backup/ui/navigation/Item.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ sealed class NavItem(
NavItem(
R.string.home,
when {
isNeo -> Phosphor.Infinity
isNeo -> Phosphor.Infinity
isDebug -> Phosphor.Bug
isHg42 -> Phosphor.Detective
else -> Phosphor.House
isHg42 -> Phosphor.Detective
else -> Phosphor.House
},
"home",
{ HomePage() }
Expand Down Expand Up @@ -88,18 +88,18 @@ sealed class NavItem(
})

data object ServicePrefs :
NavItem(R.string.prefs_service_short, Phosphor.SlidersHorizontal, "prefs_service",{
NavItem(R.string.prefs_service_short, Phosphor.SlidersHorizontal, "prefs_service", {
ServicePrefsPage()
})

data object AdvancedPrefs :
NavItem(R.string.prefs_advanced_short, Phosphor.Flask, "prefs_advanced",{
NavItem(R.string.prefs_advanced_short, Phosphor.Flask, "prefs_advanced", {
AdvancedPrefsPage()
})

data object ToolsPrefs : NavItem(R.string.prefs_tools_short, Phosphor.Wrench, "prefs_tools", {
ToolsPrefsPage()
})
ToolsPrefsPage()
})

data object Terminal :
NavItem(R.string.prefs_tools_terminal, Phosphor.Bug, "prefs_tools/terminal")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/machiav3lli/backup/utils/UIUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ val secondaryColor
fun Context.restartApp(data: String? = null) {
Timber.w(
"restarting application${
data?.let { " at $data" } ?: { "" }
data?.let { " at $data" } ?: { "" }
}"
)
val context = this.applicationContext
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/com/machiav3lli/backup/viewmodels/HomeViewModel.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package com.machiav3lli.backup.viewmodels

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.machiav3lli.backup.OABX
import com.machiav3lli.backup.dbs.dao.ScheduleDao
Expand Down Expand Up @@ -101,16 +99,4 @@ class ScheduleViewModel(
scheduleDB.deleteById(id)
}
}

class Factory(
private val id: Long, private val scheduleDB: ScheduleDao,
) : ViewModelProvider.Factory {
@Suppress("unchecked_cast")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(ScheduleViewModel::class.java)) {
return ScheduleViewModel(id, scheduleDB) as T
}
throw IllegalArgumentException("Unknown ViewModel class")
}
}
}

0 comments on commit 0c05cff

Please sign in to comment.