Skip to content

Commit

Permalink
feat: about screen
Browse files Browse the repository at this point in the history
*inspired* by mihon/aniyomi
  • Loading branch information
abdallahmehiz committed Aug 24, 2024
1 parent e824c65 commit 32750db
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 22 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.kotlin.compose.compiler)
alias(libs.plugins.room)
alias(libs.plugins.detekt)
alias(libs.plugins.about.libraries)
}

android {
Expand Down Expand Up @@ -121,6 +122,8 @@ dependencies {
implementation(libs.bundles.koin)
implementation(libs.bundles.voyager)
implementation(libs.compose.prefs)
implementation(libs.bundles.about.libs)
implementation(libs.simple.icons)

implementation(libs.room.runtime)
ksp(libs.room.compiler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ class CrashActivity : ComponentActivity() {
return logcat.toString()
}

private fun collectDeviceInfo(): String {
return """
App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.GIT_SHA}/${BuildConfig.BUILD_TIME})
Android version: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})
Device brand: ${Build.BRAND}
Device manufacturer: ${Build.MANUFACTURER}
Device model: ${Build.MODEL} (${Build.DEVICE})
MPV version: ${Utils.VERSIONS.mpv}
ffmpeg version: ${Utils.VERSIONS.ffmpeg}
libplacebo version: ${Utils.VERSIONS.libPlacebo}
""".trimIndent()
}

private fun concatLogs(
deviceInfo: String,
crashLogs: String,
Expand All @@ -120,7 +107,7 @@ class CrashActivity : ComponentActivity() {

private suspend fun dumpLogs(
exceptionString: String,
logcat: String
logcat: String,
) {
withContext(NonCancellable) {
val file = File(applicationContext.cacheDir, "mpvKt_logs.txt")
Expand Down Expand Up @@ -179,8 +166,8 @@ class CrashActivity : ComponentActivity() {
clipboardManager.setPrimaryClip(
ClipData.newPlainText(
null,
concatLogs(collectDeviceInfo(), exceptionString, logcat)
)
concatLogs(collectDeviceInfo(), exceptionString, logcat),
),
)
},
) {
Expand Down Expand Up @@ -239,7 +226,7 @@ class CrashActivity : ComponentActivity() {
@Composable
fun LogsContainer(
logs: String,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
) {
LazyRow(
modifier = modifier
Expand All @@ -259,3 +246,16 @@ class CrashActivity : ComponentActivity() {
}
}
}

fun collectDeviceInfo(): String {
return """
App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.GIT_SHA}/${BuildConfig.BUILD_TIME})
Android version: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})
Device brand: ${Build.BRAND}
Device manufacturer: ${Build.MANUFACTURER}
Device model: ${Build.MODEL} (${Build.DEVICE})
MPV version: ${Utils.VERSIONS.mpv}
ffmpeg version: ${Utils.VERSIONS.ffmpeg}
libplacebo version: ${Utils.VERSIONS.libPlacebo}
""".trimIndent()
}
8 changes: 8 additions & 0 deletions app/src/main/java/live/mehiz/mpvkt/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -33,6 +34,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.navigator.LocalNavigator
Expand All @@ -59,6 +61,12 @@ object HomeScreen : Screen() {
Icon(Icons.Default.Settings, null)
}
},
navigationIcon = {
Image(
painter = painterResource(id = R.drawable.ic_launcher_foreground),
contentDescription = "app_logo",
)
},
)
},
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,10 @@ class PlayerActivity : AppCompatActivity() {
internal fun onObserverEvent(property: String, value: String) {
when (property) {
"speed" -> viewModel.playbackSpeed.update { value.toFloat() }
"hwdec-current" -> Decoder.entries.find { it.value == value }?.let { viewModel.updateDecoder(it) }
"aid" -> trackId(value)?.let { viewModel.selectAudio(it) }
"sid" -> trackId(value)?.let { viewModel.setSubtitle(it, viewModel.selectedSubtitles.value.second) }
"secondary-sid" -> trackId(value)?.let { viewModel.setSubtitle(viewModel.selectedSubtitles.value.first, it) }
"hwdec", "hwdec-current" -> viewModel.getDecoder()
}
}

Expand Down Expand Up @@ -674,6 +674,7 @@ class PlayerActivity : AppCompatActivity() {
"sid" to MPVLib.mpvFormat.MPV_FORMAT_STRING,
"secondary-sid" to MPVLib.mpvFormat.MPV_FORMAT_STRING,
"aid" to MPVLib.mpvFormat.MPV_FORMAT_STRING,
"hwdec-current" to MPVLib.mpvFormat.MPV_FORMAT_STRING
"hwdec-current" to MPVLib.mpvFormat.MPV_FORMAT_STRING,
"hwdec" to MPVLib.mpvFormat.MPV_FORMAT_STRING
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class PlayerViewModel(
}
}

fun cancelTimer() {
timerJob?.cancel()
fun getDecoder() {
_currentDecoder.update { getDecoderFromValue(activity.player.hwdecActive) }
}

fun cycleDecoders() {
Expand Down
157 changes: 157 additions & 0 deletions app/src/main/java/live/mehiz/mpvkt/ui/preferences/AboutScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package live.mehiz.mpvkt.ui.preferences

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
import compose.icons.SimpleIcons
import compose.icons.simpleicons.Github
import live.mehiz.mpvkt.BuildConfig
import live.mehiz.mpvkt.R
import live.mehiz.mpvkt.presentation.Screen
import live.mehiz.mpvkt.presentation.crash.collectDeviceInfo
import live.mehiz.mpvkt.ui.theme.spacing
import me.zhanghai.compose.preference.Preference
import me.zhanghai.compose.preference.ProvidePreferenceLocals
import java.util.Locale

object AboutScreen : Screen() {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
override fun Content() {
val context = LocalContext.current
val navigator = LocalNavigator.currentOrThrow
Scaffold(
topBar = {
TopAppBar(
title = { Text(text = stringResource(id = R.string.pref_about_title)) },
navigationIcon = {
IconButton(onClick = { navigator.pop() }) {
Icon(imageVector = Icons.AutoMirrored.Default.ArrowBack, contentDescription = null)
}
},
)
},
) { paddingValues ->
Column(
modifier = Modifier
.padding(paddingValues)
.verticalScroll(rememberScrollState()),
) {
Column(
Modifier
.fillMaxWidth()
.padding(bottom = MaterialTheme.spacing.large),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Image(
painterResource(id = R.drawable.ic_launcher_foreground),
null,
modifier = Modifier.size(160.dp),
)
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.headlineSmall,
)
}
HorizontalDivider()
ProvidePreferenceLocals {
Preference(
title = { Text(text = "App version") },
summary = {
Text(
text = BuildConfig.BUILD_TYPE.replaceFirstChar {
if (it.isLowerCase()) {
it.titlecase(Locale.ROOT)
} else {
it.toString()
}
} + " " + BuildConfig.VERSION_NAME + " " + "(${BuildConfig.BUILD_TIME})",
)
},
onClick = {
val clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboardManager.setPrimaryClip(ClipData.newPlainText("app_version_data", collectDeviceInfo()))
},
)
Preference(
title = { Text(text = stringResource(id = R.string.pref_about_oss_libraries)) },
onClick = { navigator.push(LibrariesScreen) },
)
}
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
) {
IconButton(
onClick = {
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.github_repo_url))),
)
},
) {
Icon(imageVector = SimpleIcons.Github, contentDescription = null)
}
}
}
}
}
}

object LibrariesScreen : Screen() {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
override fun Content() {
val navigator = LocalNavigator.currentOrThrow
Scaffold(
topBar = {
TopAppBar(
title = {
Text(text = "Open source libraries")
},
navigationIcon = {
IconButton(
onClick = {
navigator.pop()
},
) {
Icon(imageVector = Icons.AutoMirrored.Default.ArrowBack, contentDescription = null)
}
},
)
},
) { paddingValues ->
LibrariesContainer(modifier = Modifier.padding(paddingValues))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
import androidx.compose.material.icons.outlined.Audiotrack
import androidx.compose.material.icons.outlined.Code
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.Memory
import androidx.compose.material.icons.outlined.Palette
import androidx.compose.material.icons.outlined.PlayCircle
Expand Down Expand Up @@ -53,39 +54,52 @@ object PreferencesScreen : Screen() {
preference(
key = "appearance",
title = { Text(text = stringResource(id = R.string.pref_appearance_title)) },
summary = { Text(text = stringResource(id = R.string.pref_appearance_summary)) },
icon = { Icon(Icons.Outlined.Palette, null) },
onClick = { navigator.push(AppearancePreferencesScreen) },
)
preference(
key = "player",
title = { Text(text = stringResource(id = R.string.pref_player)) },
summary = { Text(text = stringResource(id = R.string.pref_player_summary)) },
icon = { Icon(Icons.Outlined.PlayCircle, null) },
onClick = { navigator.push(PlayerPreferencesScreen) },
)
preference(
key = "decoder",
title = { Text(text = stringResource(id = R.string.pref_decoder)) },
summary = { Text(text = stringResource(id = R.string.pref_decoder_summary)) },
icon = { Icon(Icons.Outlined.Memory, null) },
onClick = { navigator.push(DecoderPreferencesScreen) },
)
preference(
key = "subtitles",
title = { Text(text = stringResource(id = R.string.pref_subtitles)) },
summary = { Text(text = stringResource(id = R.string.pref_subtitles_summary)) },
icon = { Icon(Icons.Outlined.Subtitles, null) },
onClick = { navigator.push(SubtitlesPreferencesScreen) },
)
preference(
key = "audio",
title = { Text(text = stringResource(id = R.string.pref_audio)) },
summary = { Text(text = stringResource(id = R.string.pref_audio_summary)) },
icon = { Icon(Icons.Outlined.Audiotrack, null) },
onClick = { navigator.push(AudioPreferencesScreen) },
)
preference(
key = "advanced",
title = { Text(text = stringResource(R.string.pref_advanced)) },
summary = { Text(text = stringResource(id = R.string.pref_advanced_summary)) },
icon = { Icon(Icons.Outlined.Code, null) },
onClick = { navigator.push(AdvancedPreferencesScreen) }
)
preference(
key = "about",
title = { Text(text = stringResource(id = R.string.pref_about_title)) },
summary = { Text(text = stringResource(id = R.string.pref_about_summary)) },
icon = { Icon(Icons.Outlined.Info, null) },
onClick = { navigator.push(AboutScreen) },
)
}
}
}
Expand Down
Loading

0 comments on commit 32750db

Please sign in to comment.