Skip to content

Commit

Permalink
新增 支持荣耀定制版网易云音乐数据库文件的自动获取。
Browse files Browse the repository at this point in the history
新增 如果安装了多个相同歌单来源的App(如:官方版、华为版、小米版等),可以选择需要使用的是哪一个。
新增 部分文案及其对应的翻译。
优化 使用Root权限自动获取文件的相关代码,便于以后加入其他的厂商定制版App。
优化 为错误对话框的更改内容与显示的顺序。
优化 更新SaltUI版本到0.1.0-dev45.
修复 某些对话框中,若未选择合法值,点击“确定”,会导致App强制关闭的问题。

Added support for automatically obtaining the database file of the Honor customized version of NetEase Cloud Music.
Added the ability to choose which one to use if multiple apps from the same playlist source are installed (such as: official version, Huawei version, Xiaomi version, etc.).
Added some text and their corresponding translations.
Optimized the relevant code for automatically obtaining files with Root permissions, making it easier to add other vendor-customized apps in the future.
Optimized the change of content and display order for error dialog boxes.
Updated the SaltUI version to 0.1.0-dev45.
Fixed the issue where clicking “OK” in some dialog boxes without selecting a valid value would cause the app to force close.
  • Loading branch information
Winnie0408 committed Jan 22, 2024
1 parent d9ebb78 commit e498095
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "com.hwinzniej.musichelper"
minSdk = 26
targetSdk = 34
versionCode = 5
versionName = "0.9.9.4"
versionCode = 6
versionName = "0.9.9.5"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -82,7 +82,7 @@ dependencies {
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.0-rc01")

//SaltUI
implementation("com.github.Moriafly:SaltUI:0.1.0-dev42")
implementation("com.github.Moriafly:SaltUI:0.1.0-dev45")

//JAudioTagger
implementation("org.bitbucket.ijabz:jaudiotagger:7b004a1")
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.MusicHelper">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -26,6 +25,14 @@
</activity>
</application>

<queries>
<package android:name="com.netease.cloudmusic" />
<package android:name="com.tencent.qqmusic" />
<package android:name="com.kugou.android" />
<package android:name="cn.kuwo.player" />
<package android:name="com.hihonor.cloudmusic" />
</queries>

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down
97 changes: 76 additions & 21 deletions app/src/main/java/com/hwinzniej/musichelper/activity/ConvertPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ConvertPage(
var playlistName = mutableStateListOf<String>()
var playlistEnabled = mutableStateListOf<Int>()
var playlistSum = mutableStateListOf<Int>()
var showSelectSourceDialog = mutableStateOf(false)
var multiSource = mutableStateListOf<Array<String>>()

/**
* 请求存储权限
Expand Down Expand Up @@ -240,7 +242,6 @@ class ConvertPage(
null
).close()
} catch (e: Exception) {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
Expand All @@ -249,6 +250,7 @@ class ConvertPage(
R.string.read_failed
)
}: ${e.message}"
showErrorDialog.value = true
haveError = true
} finally {
db?.close()
Expand All @@ -259,7 +261,6 @@ class ConvertPage(
try {
val musicCount = db.musicDao().getMusicCount()
if (musicCount == 0) {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
Expand All @@ -268,10 +269,10 @@ class ConvertPage(
R.string.read_failed
)
}: ${context.getString(R.string.use_scan_fun_first)}"
showErrorDialog.value = true
haveError = true
}
} catch (e: Exception) {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
Expand All @@ -280,6 +281,7 @@ class ConvertPage(
R.string.read_failed
)
}: ${context.getString(R.string.use_scan_fun_first)}"
showErrorDialog.value = true
haveError = true
} finally {
loadingProgressSema.release()
Expand All @@ -288,40 +290,92 @@ class ConvertPage(
}
}

fun checkAppStatusWithRoot() {
val appExists =
Tools().execShellCmdWithRoot("pm list packages | grep '${sourceApp.pakageName}'")
if (appExists.contains(sourceApp.pakageName)) {
fun getSelectedMultiSource(selected: Int) {
lifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
val dirPath = context.getExternalFilesDir(null)?.absolutePath + "/userDatabase"
val dir = File(dirPath)
if (!dir.exists())
dir.mkdirs()

val copy = Tools().execShellCmdWithRoot(
"cp -f /data/data/${sourceApp.pakageName}/databases/${
val copyResult = Tools().execShellCmdWithRoot(
"cp -f '/data/data/${multiSource[selected][0]}/databases/${
sourceApp.databaseName
} ${dir.absolutePath}/${sourceApp.sourceEng}_temp.db"
}' '${dir.absolutePath}/${sourceApp.sourceEng}_temp.db'"
)

if (copy == "") {
if (copyResult == "") {
databaseFilePath.value = "${dir.absolutePath}/${sourceApp.sourceEng}_temp.db"
showDialogProgressBar.value = false
showSelectSourceDialog.value = false
loadingProgressSema.release()
} else {
showErrorDialog.value = true
showDialogProgressBar.value = false
showSelectSourceDialog.value = false
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
"${errorDialogContent.value}\n- ${context.getString(R.string.database_file)} ${
context.getString(
R.string.read_failed
)
}: $copy"
}: $copyResult"
showErrorDialog.value = true
haveError = true
loadingProgressSema.release()
return
return@launch
}
}
}

fun checkAppStatusWithRoot() {
val appExists =
Tools().execShellCmdWithRoot("pm list packages | grep -E '${sourceApp.pakageName}'")
if (appExists.isNotEmpty()) {
if (appExists.indexOf("package:") == appExists.lastIndexOf("package:")) {
val dirPath = context.getExternalFilesDir(null)?.absolutePath + "/userDatabase"
val dir = File(dirPath)
if (!dir.exists())
dir.mkdirs()

val copyResult = Tools().execShellCmdWithRoot(
"cp -f '/data/data/${appExists.split(":")[1]}/databases/${
sourceApp.databaseName
}' '${dir.absolutePath}/${sourceApp.sourceEng}_temp.db'"
)

if (copyResult == "") {
databaseFilePath.value = "${dir.absolutePath}/${sourceApp.sourceEng}_temp.db"
loadingProgressSema.release()
} else {
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
"${errorDialogContent.value}\n- ${context.getString(R.string.database_file)} ${
context.getString(
R.string.read_failed
)
}: $copyResult"
showErrorDialog.value = true
haveError = true
loadingProgressSema.release()
return
}
} else {
multiSource.clear()
val pm = context.packageManager
val sourceAppsPackageName = appExists.split("package:").filter { it.isNotEmpty() }
sourceAppsPackageName.forEach {
multiSource.add(
arrayOf(
it,
pm.getPackageInfo(
it,
PackageManager.GET_META_DATA
).applicationInfo.loadLabel(pm).toString()
)
)
}
showSelectSourceDialog.value = true
}
} else {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
Expand All @@ -332,6 +386,7 @@ class ConvertPage(
}: ${
context.getString(R.string.app_not_installed).replace("#", sourceAppText.value)
}"
showErrorDialog.value = true
haveError = true
loadingProgressSema.release()
}
Expand All @@ -341,7 +396,6 @@ class ConvertPage(
lifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
when (selectedSourceApp.intValue) {
0 -> {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
Expand All @@ -354,6 +408,7 @@ class ConvertPage(
R.string.please_select_source_app
)
}"
showErrorDialog.value = true
loadingProgressSema.release()
haveError = true
return@launch
Expand All @@ -380,7 +435,6 @@ class ConvertPage(
null
).close()
} catch (e: Exception) {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
Expand All @@ -389,6 +443,7 @@ class ConvertPage(
R.string.read_failed
)
}: ${e.message}"
showErrorDialog.value = true
haveError = true
} finally {
db?.close()
Expand All @@ -397,7 +452,6 @@ class ConvertPage(
}
}
} else {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error_while_getting_data_dialog_title)
errorDialogContent.value =
Expand All @@ -410,6 +464,7 @@ class ConvertPage(
R.string.please_select_source_app
)
}"
showErrorDialog.value = true
haveError = true
loadingProgressSema.release()
}
Expand Down Expand Up @@ -474,11 +529,11 @@ class ConvertPage(

fun checkSongListSelection() {
if (playlistEnabled.all { it == 0 }) {
showErrorDialog.value = true
errorDialogTitle.value =
context.getString(R.string.error)
errorDialogContent.value =
context.getString(R.string.please_select_at_least_one_playlist)
showErrorDialog.value = true
return
}
for (i in playlistEnabled.indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SourceApp {
songInfoSongArtist = "artists"
songInfoSongAlbum = "album_name"
pakageName =
"com.netease.cloudmusic" //TODO 适配荣耀定制版网易云音乐 com.hihonor.cloudmusic 数据库结构相同
"com.netease.cloudmusic|com.hihonor.cloudmusic"
}

"KugouMusic" -> {
Expand Down
Loading

0 comments on commit e498095

Please sign in to comment.