Skip to content

Commit

Permalink
Fix settings clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
KyuubiRan committed Jan 2, 2024
1 parent 9808a28 commit 4f396b4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/java/me/kyuubiran/ncmdumper/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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) }
}
}
}
}
Expand Down
13 changes: 3 additions & 10 deletions app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/MainPage.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -196,7 +189,7 @@ object MainPage {
fun View(controller: NavHostController, activity: MainActivity) {
Column {
AppBar(controller)
NcmFileList(activity)
NcmFileList()
}
}
}
Expand Down
23 changes: 10 additions & 13 deletions app/src/main/java/me/kyuubiran/ncmdumper/ui/pages/SettingsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ object SettingsPage {
@Composable
private fun AppBar(navController: NavHostController) {
TopAppBar(
modifier = Modifier.statusBarsPadding(),
title = {
Row {
Image(
Expand All @@ -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()) {
Expand All @@ -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()
}
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) })
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) }
Expand All @@ -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))
}
Expand Down

0 comments on commit 4f396b4

Please sign in to comment.