Skip to content

Commit

Permalink
Merge pull request #59 from ZTFtrue/develope
Browse files Browse the repository at this point in the history
Develope
  • Loading branch information
ZTFtrue authored Aug 31, 2024
2 parents 75a3bda + f1c2e06 commit 81b4672
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 182 deletions.
20 changes: 9 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,16 @@ android {
dependencies {

implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.3")
implementation("androidx.activity:activity-compose:1.9.0")
implementation(platform("androidx.compose:compose-bom:2024.06.00"))
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.4")
implementation("androidx.activity:activity-compose:1.9.1")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("androidx.media3:media3-exoplayer:1.3.1")
implementation("androidx.media3:media3-exoplayer:1.4.1")
implementation ("androidx.media:media:1.7.0")

implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3:1.2.1")
implementation("androidx.compose.material3:material3-window-size-class:1.2.1")

Expand All @@ -112,11 +110,11 @@ dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2024.06.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:2024.08.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")

// debugImplementation ("com.squareup.leakcanary:leakcanary-android:2.14")
implementation ("com.github.bumptech.glide:compose:1.0.0-beta01")
// https://mvnrepository.com/artifact/pl.edu.icm/JLargeArrays
// implementation("pl.edu.icm:JLargeArrays:1.6")
Expand All @@ -132,9 +130,9 @@ dependencies {
// implementation("net.jthink:jaudiotagger:3.0.1")

implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.collection:collection-ktx:1.4.1")
implementation("androidx.fragment:fragment-ktx:1.8.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3")
implementation("androidx.collection:collection-ktx:1.4.3")
implementation("androidx.fragment:fragment-ktx:1.8.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")

implementation("androidx.palette:palette-ktx:1.0.0")

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/ztftrue/music/ErrorTipActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.media3.common.util.UnstableApi
import com.ztftrue.music.ui.theme.MusicPitchTheme
import kotlin.system.exitProcess


class ErrorTipActivity : ComponentActivity() {
Expand All @@ -59,12 +60,14 @@ class ErrorTipActivity : ComponentActivity() {
LaunchedEffect(Unit) {
try {
errorMessage = intent.getStringExtra("error") ?: ""
errorMessage=errorMessage+"\n\nVERSION_CODE "+BuildConfig.VERSION_CODE
} catch (e: Exception) {
Log.e("ERROR", e.toString())
}
}
BackHandler(enabled = true) {
finish()
exitProcess(0)
}
Surface(
modifier = Modifier
Expand Down
118 changes: 59 additions & 59 deletions app/src/main/java/com/ztftrue/music/MusicViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -241,72 +241,70 @@ class MusicViewModel : ViewModel() {
""
}
val files = getDb(context).StorageFolderDao().findAllByType(LYRICS_TYPE)
if (files != null) {
outer@ for (storageFolder in files) {
try {
val treeUri = Uri.parse(storageFolder.uri)
if (treeUri != null) {
context.contentResolver.takePersistableUriPermission(
treeUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
val pickedDir = DocumentFile.fromTreeUri(context, treeUri)
val d = pickedDir?.listFiles()
if (d != null) {
for (it in d) {
if (it.isFile && it.canRead()
) {
val fileNameWithSuffix =
it.name?.lowercase() ?: ""
val type =
if (fileNameWithSuffix.endsWith(".lrc")) {
LyricsType.LRC
} else if (fileNameWithSuffix.endsWith(".srt")) {
LyricsType.SRT
} else if (fileNameWithSuffix.endsWith(".vtt")) {
LyricsType.VTT
} else if (fileNameWithSuffix.endsWith(".txt")) {
LyricsType.TEXT
} else {
continue
}
val fileName = try {
fileNameWithSuffix.substring(
0,
fileNameWithSuffix.indexOf(".")
)
} catch (e: Exception) {
""
outer@ for (storageFolder in files) {
try {
val treeUri = Uri.parse(storageFolder.uri)
if (treeUri != null) {
context.contentResolver.takePersistableUriPermission(
treeUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
val pickedDir = DocumentFile.fromTreeUri(context, treeUri)
val d = pickedDir?.listFiles()
if (d != null) {
for (it in d) {
if (it.isFile && it.canRead()
) {
val fileNameWithSuffix =
it.name?.lowercase() ?: ""
val type =
if (fileNameWithSuffix.endsWith(".lrc")) {
LyricsType.LRC
} else if (fileNameWithSuffix.endsWith(".srt")) {
LyricsType.SRT
} else if (fileNameWithSuffix.endsWith(".vtt")) {
LyricsType.VTT
} else if (fileNameWithSuffix.endsWith(".txt")) {
LyricsType.TEXT
} else {
continue
}
if (fileName.trim()
.lowercase() == musicName.trim()
.lowercase()
) {
fileLyrics.addAll(
fileRead(
it.uri,
context,
type
)
val fileName = try {
fileNameWithSuffix.substring(
0,
fileNameWithSuffix.indexOf(".")
)
} catch (e: Exception) {
""
}
if (fileName.trim()
.lowercase() == musicName.trim()
.lowercase()
) {
fileLyrics.addAll(
fileRead(
it.uri,
context,
type
)
break@outer
}
)
break@outer
}
}
}
}
} catch (e: Exception) {
getDb(context).StorageFolderDao().deleteById(storageFolder.id!!)
CoroutineScope(Dispatchers.Main).launch {
Toast.makeText(
context,
"There has error, can't read some lyrics. Most of times, this occur after you reinstall app.",
Toast.LENGTH_SHORT
).show()
}
}

} catch (e: Exception) {
getDb(context).StorageFolderDao().deleteById(storageFolder.id!!)
CoroutineScope(Dispatchers.Main).launch {
Toast.makeText(
context,
"There has error, can't read some lyrics. Most of times, this occur after you reinstall app.",
Toast.LENGTH_SHORT
).show()
}
}

}
}
}
Expand Down Expand Up @@ -375,6 +373,7 @@ class MusicViewModel : ViewModel() {
)
arrayList.add(an)
}
bufferedReader.close()
return arrayList
}

Expand Down Expand Up @@ -421,6 +420,7 @@ class MusicViewModel : ViewModel() {
bm.compress(Bitmap.CompressFormat.JPEG, 100, outStream)
outStream.flush()
outStream.close()
bm.recycle()
result =
R.drawable.songs_thumbnail_cover
} else {
Expand All @@ -441,10 +441,10 @@ class MusicViewModel : ViewModel() {
R.drawable.songs_thumbnail_cover
)
val outStream = FileOutputStream(coverPath)

bm.compress(Bitmap.CompressFormat.JPEG, 100, outStream)
outStream.flush()
outStream.close()
bm.recycle()
return R.drawable.songs_thumbnail_cover
}
return result
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/com/ztftrue/music/PlayMusicWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.support.v4.media.session.PlaybackStateCompat
import android.util.Log
Expand Down Expand Up @@ -110,19 +111,23 @@ class PlayMusicWidget : AppWidgetProvider() {
newOptions: Bundle?
) {
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
val sizes = newOptions?.getParcelableArrayList<SizeF>(
AppWidgetManager.OPTION_APPWIDGET_SIZES
)
val sizes = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
newOptions?.getParcelableArrayList<SizeF>(
AppWidgetManager.OPTION_APPWIDGET_SIZES
)
} else {
TODO("VERSION.SDK_INT < S")
}
// Check that the list of sizes is provided by the launcher.
if (sizes.isNullOrEmpty()) {
return
}

// Get the min and max sizes
val minWidth = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
val minHeight = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)
val maxWidth = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
val maxHeight = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)
val minWidth = newOptions?.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
val minHeight = newOptions?.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)
val maxWidth = newOptions?.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
val maxHeight = newOptions?.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)
// Map the sizes to the RemoteViews that you want.
// val remoteViews = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// RemoteViews(sizes.associateWith(::createRemoteViews))
Expand Down
Loading

0 comments on commit 81b4672

Please sign in to comment.