diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7ead180..d430082 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -12,8 +12,8 @@ android { applicationId = "me.kyuubiran.ncmdumper" minSdk = 24 targetSdk = 34 - versionCode = 1 - versionName = "0.1" + versionCode = 2 + versionName = "0.2" buildFeatures { buildConfig = true diff --git a/app/src/main/java/me/kyuubiran/ncmdumper/MainActivity.kt b/app/src/main/java/me/kyuubiran/ncmdumper/MainActivity.kt index e649ef3..0c5afb3 100644 --- a/app/src/main/java/me/kyuubiran/ncmdumper/MainActivity.kt +++ b/app/src/main/java/me/kyuubiran/ncmdumper/MainActivity.kt @@ -10,6 +10,8 @@ import android.provider.Settings import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.material.AlertDialog import androidx.compose.material.Text import androidx.compose.material.TextButton @@ -19,6 +21,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.stringResource import androidx.lifecycle.DefaultLifecycleObserver @@ -33,8 +36,11 @@ import me.kyuubiran.ncmdumper.ui.pages.SettingsPage import me.kyuubiran.ncmdumper.ui.theme.MyTheme class MainActivity : ComponentActivity() { - lateinit var sp: SharedPreferences - private set + + companion object { + lateinit var sp: SharedPreferences + private set + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -45,9 +51,11 @@ class MainActivity : ComponentActivity() { val navController = rememberNavController() MyTheme { RequireAllFileAccessPermissionDialog(this) - NavHost(navController = navController, startDestination = "main_page") { - composable("main_page") { MainPage.View(navController, this@MainActivity) } - composable("settings_page") { SettingsPage.View(navController, this@MainActivity) } + Box(modifier = Modifier.statusBarsPadding()) { + NavHost(navController = navController, startDestination = "main_page") { + composable("main_page") { MainPage.View(navController, this@MainActivity) } + composable("settings_page") { SettingsPage.View(navController, this@MainActivity) } + } } } } diff --git a/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/MainPage.kt b/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/MainPage.kt index 3ffbde8..9addc86 100644 --- a/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/MainPage.kt +++ b/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/MainPage.kt @@ -1,8 +1,6 @@ package me.kyuubiran.ncmdumper.ui.pages -import android.net.Uri import android.os.Environment -import android.util.Dumpable import android.util.Log import androidx.compose.foundation.Image import androidx.compose.foundation.clickable @@ -90,15 +88,10 @@ object MainPage { doSearch(f) } -// init { -// reloadFiles() -// } - @Composable private fun AppBar(controller: NavHostController) { var moreShowed by remember { mutableStateOf(false) } TopAppBar( - modifier = Modifier.statusBarsPadding(), title = { Text(text = stringResource(id = R.string.app_name)) }, actions = { Box( @@ -147,8 +140,8 @@ object MainPage { @OptIn(ExperimentalMaterialApi::class) @Composable - private fun NcmFileList(activity: MainActivity) { - val sp = activity.sp + private fun NcmFileList() { + val sp = MainActivity.sp val refreshScope = rememberCoroutineScope() var refreshing by remember { mutableStateOf(false) } @@ -196,7 +189,7 @@ object MainPage { fun View(controller: NavHostController, activity: MainActivity) { Column { AppBar(controller) - NcmFileList(activity) + NcmFileList() } } } diff --git a/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/SettingsPage.kt b/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/SettingsPage.kt index 27c16e4..6d06901 100644 --- a/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/SettingsPage.kt +++ b/app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/SettingsPage.kt @@ -48,7 +48,6 @@ object SettingsPage { @Composable private fun AppBar(navController: NavHostController) { TopAppBar( - modifier = Modifier.statusBarsPadding(), title = { Row { Image( @@ -67,7 +66,7 @@ object SettingsPage { @Composable private fun Configs(activity: MainActivity) { - val sp = activity.sp + val sp = MainActivity.sp var outputFolder by remember { mutableStateOf(sp.getString("output_path", Dumper.DEFAULT_NETEASE_MUSIC_PATH)!!) } val folderPicker = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { @@ -94,11 +93,13 @@ object SettingsPage { fontSize = 18.sp ) + var searchFullDiskEnabled by remember { mutableStateOf(sp.getBoolean("search_full_disk", false)) } SwitchConfigItem( title = stringResource(id = R.string.title_config_search_full_disk), subtitle = stringResource(id = R.string.subtitle_config_search_full_disk), - isChecked = false, + isChecked = searchFullDiskEnabled, onChanged = { + searchFullDiskEnabled = it sp.edit().putBoolean("search_full_disk", it).apply() } ) @@ -152,13 +153,14 @@ object SettingsPage { private fun BaseConfigItem( title: String, subtitle: String? = null, - onClick: (() -> Unit)? = null, + onClick: (() -> Unit) = {}, rightView: @Composable () -> Unit = { Text(text = ">", fontSize = 20.sp, color = Color.Gray) } ) { - Box(modifier = Modifier - .apply { if (onClick != null) clickable(onClick = onClick) } + Box( + modifier = Modifier + .clickable(onClick = onClick) ) { Row( modifier = Modifier.fillMaxWidth() @@ -195,17 +197,12 @@ private fun SwitchConfigItem( isChecked: Boolean, onChanged: (Boolean) -> Unit = {}, ) { - var checked by remember { mutableStateOf(isChecked) } - BaseConfigItem( title = title, subtitle = subtitle, - onClick = { checked = !checked }, + onClick = { onChanged(!isChecked) }, rightView = { - Switch(checked = checked, onCheckedChange = { - checked = !checked - onChanged(checked) - }) + Switch(checked = isChecked, onCheckedChange = { onChanged(!isChecked) }) } ) } diff --git a/app/src/main/java/me/kyuubiran/ncmdumper/ui/views/NcmFileItem.kt b/app/src/main/java/me/kyuubiran/ncmdumper/ui/views/NcmFileItem.kt index 820408b..e6f4ce4 100644 --- a/app/src/main/java/me/kyuubiran/ncmdumper/ui/views/NcmFileItem.kt +++ b/app/src/main/java/me/kyuubiran/ncmdumper/ui/views/NcmFileItem.kt @@ -1,5 +1,6 @@ package me.kyuubiran.ncmdumper.ui.views +import android.content.Context import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.basicMarquee @@ -26,6 +27,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -34,6 +36,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import me.kyuubiran.ncmdumper.MainActivity import me.kyuubiran.ncmdumper.R import me.kyuubiran.ncmdumper.ui.utils.Dumper.dumpNcmFile import java.io.File @@ -46,6 +49,8 @@ data class NcmFileInfo(val file: File) { @Composable private fun ConfirmDumpDialog(show: Boolean, fileInfo: NcmFileInfo, onDismiss: () -> Unit) { + val sp = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE) + var exportResult by remember { mutableIntStateOf(-1) } var exportingDialogShow by remember { mutableStateOf(false) } var exportResultDialogShow by remember { mutableStateOf(false) } @@ -55,7 +60,8 @@ private fun ConfirmDumpDialog(show: Boolean, fileInfo: NcmFileInfo, onDismiss: ( exportingDialogShow = true withContext(Dispatchers.IO) { val beg = System.currentTimeMillis() - exportResult = dumpNcmFile(fileInfo.filePath, fileInfo.file.parent ?: "") + val output = sp.getString("output_path", fileInfo.file.parent ?: "") ?: "" + exportResult = dumpNcmFile(fileInfo.filePath, output) val end = System.currentTimeMillis() if (end - beg < 500) delay(500 - (end - beg)) }