Skip to content

Commit

Permalink
新增 应用启动时初始页的自定义。
Browse files Browse the repository at this point in the history
新增 转换页,转换模式项、来源应用项、目标应用项,可以保存上次的选择。
新增 部分文案及其对应的翻译。
优化 同步更新新使用的项目依赖项的License到项目文件中。
优化 通过DataStore管理的变量的使用。
优化 文件权限的管理。
优化 部分ItemValue的文本区域的宽度比例。
优化 部分图标的样式。
优化 本地到本地的歌单转换完成后,自动清除已选歌单文件的名称。
修复 将Poweramp的歌单转换为Salt Player格式后,无法在Salt Player中使用歌单文件导入的问题。
修复 在进行本地到本地的歌单转换中,若未选择歌单文件,点击开始后,应用会闪退的问题。

Added: Customization of the initial page when the application starts.
Added: On the conversion page, the conversion mode item, source application item, and target application item can save the last selection.
Added: Some copywriting and their corresponding translations.
Optimized: Synchronized update of the License of the newly used project dependencies to the project files.
Optimized: The use of variables managed by DataStore.
Optimized: File permission management.
Optimized: The width ratio of the text area of some ItemValue.
Optimized: The style of some icons.
Optimized: After the playlist conversion from local to local is completed, the name of the selected playlist file is automatically cleared.
Fixed: After converting the Poweramp playlist to Salt Player format, the playlist file cannot be imported in Salt Player.
Fixed: When performing local to local playlist conversion, if no playlist file is selected, the application will crash after clicking start.
  • Loading branch information
Winnie0408 committed May 10, 2024
1 parent 0c18b86 commit fccc2c3
Show file tree
Hide file tree
Showing 19 changed files with 1,617 additions and 368 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
minSdk = 26
// targetSdk = 28
targetSdk = 34
versionCode = 55
versionName = "1.4.0"
versionCode = 56
versionName = "1.4.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
494 changes: 494 additions & 0 deletions app/src/main/assets/licenses.html

Large diffs are not rendered by default.

494 changes: 494 additions & 0 deletions app/src/main/assets/licenses_dark.html

Large diffs are not rendered by default.

560 changes: 289 additions & 271 deletions app/src/main/java/com/hwinzniej/musichelper/MainActivity.kt

Large diffs are not rendered by default.

36 changes: 20 additions & 16 deletions app/src/main/java/com/hwinzniej/musichelper/activity/ConvertPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class ConvertPage(
var lunaCookie = mutableStateOf("")
var showLunaVerifyDialog = mutableStateOf(false)
var lunaVerifyRelated = mutableStateMapOf<String, String>()
val convertMode = mutableIntStateOf(1)
val selectedSourceLocalApp = mutableIntStateOf(2)
val selectedTargetApp = mutableIntStateOf(0)

/**
* 请求存储权限
Expand Down Expand Up @@ -224,11 +227,11 @@ class ConvertPage(
}
}

fun selectPlaylistFile(selectedSourceLocalApp: Int) {
fun selectPlaylistFile() {
try {
openPlaylistFileLauncher.launch(
arrayOf(
when (selectedSourceLocalApp) {
when (selectedSourceLocalApp.intValue) {
0 -> "text/plain"
1 -> "audio/x-mpegurl"
2 -> "audio/x-mpegurl"
Expand Down Expand Up @@ -501,13 +504,13 @@ class ConvertPage(
Tools().execShellCmd(
"find '/data/data/${appExists.split(":")[1]}/cache/NetCacheLoader' -type f -exec cp {} '${
tempPath
}/lunaJsonDir' \\; && chmod -R 777 '${tempPath}/lunaJsonDir'"
}/lunaJsonDir' \\; && chmod -R +r '${tempPath}/lunaJsonDir'"
)
} else {
Tools().execShellCmd(
"cp -f '/data/data/${appExists.split(":")[1]}/databases/${
sourceApp.databaseName
}' '${dir.absolutePath}/${sourceApp.sourceEng}_temp.db' && chmod 777 '${dir.absolutePath}/${sourceApp.sourceEng}_temp.db'"
}' '${dir.absolutePath}/${sourceApp.sourceEng}_temp.db' && chmod +r '${dir.absolutePath}/${sourceApp.sourceEng}_temp.db'"
)
}

Expand Down Expand Up @@ -2918,14 +2921,17 @@ class ConvertPage(
}
}

fun launchLocalPlayer(targetApp: Int) {
fun launchLocalPlayer() {
val targetAppList = listOf(
arrayOf("com.salt.music", "com.salt.music.ui.MainActivity"),
arrayOf("remix.myplayer", "remix.myplayer.ui.activity.MainActivity"),
arrayOf("com.maxmpz.audioplayer", "com.maxmpz.audioplayer.MainActivity"),
)
val intent = Intent(Intent.ACTION_MAIN).apply {
setClassName(targetAppList[targetApp][0], targetAppList[targetApp][1])
setClassName(
targetAppList[selectedTargetApp.intValue][0],
targetAppList[selectedTargetApp.intValue][1]
)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
Expand All @@ -2934,7 +2940,7 @@ class ConvertPage(
Toast.makeText(
context,
context.getString(R.string.other_app_not_installed).replace(
"#", when (targetApp) {
"#", when (selectedTargetApp.intValue) {
0 -> "Salt Player"
1 -> "APlayer"
2 -> "Poweramp"
Expand Down Expand Up @@ -3229,10 +3235,7 @@ class ConvertPage(
return result
}

fun convertLocalPlaylist(
sourceApp: Int,
targetApp: Int,
): String {
fun convertLocalPlaylist(): String {
val targetFile = File(
"${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)}/${
context.getString(
Expand All @@ -3247,7 +3250,7 @@ class ConvertPage(
sourcePlaylistFileName.value.lastIndexOf(".")
)
}.${
when (targetApp) {
when (selectedTargetApp.intValue) {
0 -> "txt"
1 -> "m3u"
2 -> "m3u8"
Expand All @@ -3260,7 +3263,7 @@ class ConvertPage(
if (targetFile.parentFile?.exists() == false)
targetFile.parentFile?.mkdirs()
val sourceFile = File(sourcePlaylistFilePath)
when (sourceApp) {
when (selectedSourceApp.intValue) {
0 -> { //来源:Salt Player
sourceFile.copyTo(targetFile, true)
return targetFile.absolutePath.replace("/storage/emulated/0/", "")
Expand All @@ -3272,10 +3275,11 @@ class ConvertPage(
}

2 -> { //来源:Poweramp
val extRegex = "#.*((\\r\\n)|\\r|\\n)".toRegex()
var powerampPlaylist = sourceFile.readText()
powerampPlaylist = extRegex.replace(powerampPlaylist, "")
powerampPlaylist = powerampPlaylist.replace("primary/", "/storage/emulated/0/")
powerampPlaylist = powerampPlaylist
.replace("#.*((\\r\\n)|\\r|\\n)".toRegex(), "")
.replace("(\\r\\n)|\\r".toRegex(), "\n")
.replace("primary/", "/storage/emulated/0/")
val fileWriter = FileWriter(targetFile, true)
fileWriter.write(powerampPlaylist)
fileWriter.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.net.Uri
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.datastore.core.DataStore
Expand All @@ -27,14 +28,15 @@ class SettingsPage(
val openUmExecutableFileLauncher: ActivityResultLauncher<Array<String>>,
val dataStore: DataStore<Preferences>,
) {
var enableAutoCheckUpdate = mutableStateOf(true)
var encryptServer = mutableStateOf("")
var serverPing = mutableStateMapOf(
val enableAutoCheckUpdate = mutableStateOf(true)
val encryptServer = mutableStateOf("")
val serverPing = mutableStateMapOf(
0 to context.getString(R.string.pinging),
1 to context.getString(R.string.pinging),
2 to context.getString(R.string.pinging)
)
var showDialogProgressBar = mutableStateOf(false)
val showDialogProgressBar = mutableStateOf(false)
val initialPage = mutableIntStateOf(0)

fun checkServerPing() {
lifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ object DataStoreConstants {
val LUNA_DEVICE_ID = stringPreferencesKey("luna_device_id")
val LUNA_INSTALL_ID = stringPreferencesKey("luna_install_id")
val LUNA_COOKIE = stringPreferencesKey("luna_cookie")
val CONVERT_MODE = intPreferencesKey("convert_mode")
val SELECTED_TARGET_APP = intPreferencesKey("selected_target_app")
val SELECTED_SOURCE_APP = intPreferencesKey("selected_source_app")
val INITIAL_PAGE = intPreferencesKey("initial_page")
}
31 changes: 16 additions & 15 deletions app/src/main/java/com/hwinzniej/musichelper/ui/AboutPageUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ fun AboutPageUi(


BackHandler(enabled = settingsPageState.currentPage == 1) {
if (showLoadingProgressBar) {
Toast.makeText(
context,
context.getString(R.string.wait_operate_end),
Toast.LENGTH_SHORT
).show()
return@BackHandler
}
coroutineScope.launch {
settingsPageState.animateScrollToPage(
0, animationSpec = spring(2f)
Expand Down Expand Up @@ -384,7 +392,7 @@ fun AboutPageUi(
Item(
onClick = {
yesDialogCustomContent = {
val currentTheme = SaltTheme.colors.text.red
val isDarkTheme = SaltTheme.colors.text.red
Column(
modifier = Modifier
.heightIn(
Expand All @@ -393,20 +401,13 @@ fun AboutPageUi(
)
) {
AndroidView(factory = { WebView(context) }) { webView ->
val licensesHtml = if (currentTheme < 0.5f) {
context.assets.open("licenses.html")
.use { inputStream ->
inputStream.bufferedReader().use {
it.readText()
}
}
} else {
context.assets.open("licenses_dark.html")
.use { inputStream ->
inputStream.bufferedReader().use {
it.readText()
}
}
val licensesHtml = context.assets.open(
if (isDarkTheme < 0.5f) "licenses.html"
else "licenses_dark.html"
).use { inputStream ->
inputStream.bufferedReader().use {
it.readText()
}
}
webView.setBackgroundColor(0)
webView.settings.javaScriptEnabled = false
Expand Down
Loading

0 comments on commit fccc2c3

Please sign in to comment.