修复一键定位列表滚动问题,修复搜索歌单点击播放播放图标闪烁问题,增加 timber 日志本地文件存储,release 版不显示 log
This commit is contained in:
parent
b75be79755
commit
3df4c4d31b
@ -4,12 +4,15 @@ import android.app.Application
|
||||
import com.arthenica.ffmpegkit.FFmpegKitConfig
|
||||
import com.arthenica.ffmpegkit.Level
|
||||
import com.arthenica.ffmpegkit.LogRedirectionStrategy
|
||||
import com.audio.vibe.common.logging.DiagnosticFileTree
|
||||
import java.util.logging.Level as JavaLogLevel
|
||||
import java.util.logging.Logger
|
||||
import timber.log.Timber
|
||||
|
||||
class AudioVibeApp : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
plantLoggingTrees()
|
||||
Logger.getLogger("org.jaudiotagger").apply {
|
||||
level = JavaLogLevel.OFF
|
||||
useParentHandlers = false
|
||||
@ -17,4 +20,12 @@ class AudioVibeApp : Application() {
|
||||
FFmpegKitConfig.setLogLevel(Level.AV_LOG_QUIET)
|
||||
FFmpegKitConfig.setLogRedirectionStrategy(LogRedirectionStrategy.NEVER_PRINT_LOGS)
|
||||
}
|
||||
|
||||
private fun plantLoggingTrees() {
|
||||
if (Timber.treeCount > 0) return
|
||||
if (BuildConfig.DEBUG) {
|
||||
Timber.plant(Timber.DebugTree())
|
||||
}
|
||||
Timber.plant(DiagnosticFileTree(this))
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import com.audio.vibe.BuildConfig
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@ -35,14 +34,10 @@ import com.audio.vibe.ui.settings.SettingsScreen
|
||||
import com.audio.vibe.ui.theme.AudioVibeTheme
|
||||
import com.audio.vibe.ui.voicechanger.VoiceChangerScreen
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (BuildConfig.DEBUG && Timber.treeCount == 0) {
|
||||
Timber.plant(Timber.DebugTree())
|
||||
}
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
AudioVibeTheme {
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
package com.audio.vibe.common.logging
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
import timber.log.Timber
|
||||
|
||||
object DiagnosticLogStore {
|
||||
private const val LOG_DIR = "diagnostics"
|
||||
private const val CURRENT_LOG = "app-log-current.txt"
|
||||
private const val PREVIOUS_LOG = "app-log-previous.txt"
|
||||
private const val MAX_LOG_BYTES = 256 * 1024L
|
||||
|
||||
fun currentLogFile(context: Context): File {
|
||||
return File(context.filesDir, LOG_DIR).resolve(CURRENT_LOG)
|
||||
}
|
||||
|
||||
fun previousLogFile(context: Context): File {
|
||||
return File(context.filesDir, LOG_DIR).resolve(PREVIOUS_LOG)
|
||||
}
|
||||
|
||||
fun logFiles(context: Context): List<File> {
|
||||
return listOf(previousLogFile(context), currentLogFile(context)).filter { it.exists() }
|
||||
}
|
||||
|
||||
internal fun logDirectory(context: Context): File {
|
||||
return File(context.filesDir, LOG_DIR).apply { mkdirs() }
|
||||
}
|
||||
|
||||
internal fun rotateIfNeeded(context: Context) {
|
||||
val current = currentLogFile(context)
|
||||
if (!current.exists() || current.length() < MAX_LOG_BYTES) return
|
||||
val previous = previousLogFile(context)
|
||||
if (previous.exists()) {
|
||||
previous.delete()
|
||||
}
|
||||
current.renameTo(previous)
|
||||
}
|
||||
}
|
||||
|
||||
class DiagnosticFileTree(context: Context) : Timber.Tree() {
|
||||
private val appContext = context.applicationContext
|
||||
private val executor = Executors.newSingleThreadExecutor { runnable ->
|
||||
Thread(runnable, "AudioVibeDiagnosticLog").apply { isDaemon = true }
|
||||
}
|
||||
private val timestampFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US)
|
||||
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
executor.execute {
|
||||
DiagnosticLogStore.logDirectory(appContext)
|
||||
DiagnosticLogStore.rotateIfNeeded(appContext)
|
||||
DiagnosticLogStore.currentLogFile(appContext).appendText(
|
||||
buildString {
|
||||
append(timestampFormat.format(Date()))
|
||||
append(' ')
|
||||
append(priority.toLogLabel())
|
||||
append('/')
|
||||
append(tag ?: "AudioVibe")
|
||||
append(": ")
|
||||
append(message.take(MAX_MESSAGE_CHARS))
|
||||
if (t != null) {
|
||||
append('\n')
|
||||
append(Log.getStackTraceString(t).take(MAX_STACKTRACE_CHARS))
|
||||
}
|
||||
append('\n')
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.toLogLabel(): String {
|
||||
return when (this) {
|
||||
Log.VERBOSE -> "V"
|
||||
Log.DEBUG -> "D"
|
||||
Log.INFO -> "I"
|
||||
Log.WARN -> "W"
|
||||
Log.ERROR -> "E"
|
||||
Log.ASSERT -> "A"
|
||||
else -> this.toString()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val MAX_MESSAGE_CHARS = 2_000
|
||||
const val MAX_STACKTRACE_CHARS = 8_000
|
||||
}
|
||||
}
|
||||
@ -692,7 +692,7 @@ class AudioPlaybackController(context: Context) {
|
||||
if (generation == playbackGeneration) {
|
||||
queueItems = resolvedItems
|
||||
if (currentTrack?.id == queueIds.getOrNull(currentIndex)) {
|
||||
publishState()
|
||||
publishState(isPlayingOverride = _state.value.isPlaying)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@ -201,6 +202,7 @@ private fun MusicManagerContent(
|
||||
}
|
||||
val miniPlayerState = uiState.miniPlayerState
|
||||
val listBottomPadding = if (miniPlayerState.isVisible) 64.dp else 0.dp
|
||||
val trackListState = rememberLazyListState()
|
||||
LaunchedEffect(miniPlayerState.errorMessage) {
|
||||
miniPlayerState.errorMessage?.takeIf { it.isNotBlank() }?.let { message ->
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||
@ -233,6 +235,7 @@ private fun MusicManagerContent(
|
||||
onEvent = onEvent,
|
||||
onPlayTrack = onPlayTrack,
|
||||
toEditor = toEditor,
|
||||
listState = trackListState,
|
||||
bottomPadding = listBottomPadding
|
||||
)
|
||||
|
||||
@ -250,6 +253,7 @@ private fun MusicManagerContent(
|
||||
onEvent = onEvent,
|
||||
onPlayTrack = onPlayTrack,
|
||||
toEditor = toEditor,
|
||||
listState = trackListState,
|
||||
bottomPadding = listBottomPadding
|
||||
)
|
||||
}
|
||||
@ -297,6 +301,7 @@ private fun LibrarySearchAndList(
|
||||
onEvent: (MusicManagerEvent) -> Unit,
|
||||
onPlayTrack: (Long) -> Unit,
|
||||
toEditor: () -> Unit,
|
||||
listState: LazyListState,
|
||||
bottomPadding: Dp = 0.dp
|
||||
) {
|
||||
val strings = LocalAppStrings.current
|
||||
@ -315,6 +320,7 @@ private fun LibrarySearchAndList(
|
||||
locateTrackIndex = locateTrackIndex,
|
||||
onPlay = onPlayTrack,
|
||||
toEditor = toEditor,
|
||||
listState = listState,
|
||||
bottomPadding = bottomPadding
|
||||
)
|
||||
}
|
||||
@ -332,6 +338,7 @@ private fun ScanningLibrary(
|
||||
onEvent: (MusicManagerEvent) -> Unit,
|
||||
onPlayTrack: (Long) -> Unit,
|
||||
toEditor: () -> Unit,
|
||||
listState: LazyListState,
|
||||
bottomPadding: Dp = 0.dp
|
||||
) {
|
||||
val visibleStats = stats ?: MusicLibraryStats.Empty
|
||||
@ -347,6 +354,7 @@ private fun ScanningLibrary(
|
||||
onEvent = onEvent,
|
||||
onPlayTrack = onPlayTrack,
|
||||
toEditor = toEditor,
|
||||
listState = listState,
|
||||
bottomPadding = bottomPadding
|
||||
)
|
||||
}
|
||||
@ -553,9 +561,9 @@ private fun TrackList(
|
||||
locateTrackIndex: Int?,
|
||||
onPlay: (Long) -> Unit,
|
||||
toEditor: () -> Unit,
|
||||
listState: LazyListState,
|
||||
bottomPadding: Dp = 0.dp
|
||||
) {
|
||||
val listState = rememberLazyListState()
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val currentTrackVisible by remember(currentTrackId, tracks.itemCount) {
|
||||
derivedStateOf {
|
||||
@ -602,7 +610,7 @@ private fun TrackList(
|
||||
LocateCurrentTrackButton(
|
||||
onClick = {
|
||||
coroutineScope.launch {
|
||||
listState.animateScrollToItem(locateTrackIndex)
|
||||
listState.scrollToItem(locateTrackIndex)
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
|
||||
@ -124,7 +124,7 @@ fun PlayerQueueSheet(
|
||||
LocateCurrentTrackButton(
|
||||
onClick = {
|
||||
coroutineScope.launch {
|
||||
listState.animateScrollToItem(currentIndex)
|
||||
listState.scrollToItem(currentIndex)
|
||||
}
|
||||
},
|
||||
containerColor = QueueSheetColors.Action,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user