Skip to content

Commit

Permalink
feat(settings/about): add option to copy debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog committed Jul 21, 2024
1 parent b729ebe commit d26e4a8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Book
import androidx.compose.material.icons.filled.CopyAll
import androidx.compose.material.icons.filled.Description
import androidx.compose.material.icons.filled.Face
import androidx.compose.material.icons.filled.Update
import androidx.compose.material.icons.outlined.CopyAll
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
Expand All @@ -35,11 +37,13 @@ import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap
Expand Down Expand Up @@ -69,6 +73,7 @@ fun AboutPage(
) {
val context = LocalContext.current
val uriHandler = LocalUriHandler.current
val clipboardManager = LocalClipboardManager.current
val scope = rememberCoroutineScope()
val appIcon = remember {
context.packageManager.getApplicationIcon(context.packageName).toBitmap().asImageBitmap()
Expand Down Expand Up @@ -163,7 +168,7 @@ fun AboutPage(
FormSection(
title = stringResource(R.string.settings_about_credits),
topDivider = true,
bottomDivider = false
bottomDivider = true
) {
LaunchedEffect(Unit) {
SettingsConstant.credits.forEach {
Expand Down Expand Up @@ -213,6 +218,23 @@ fun AboutPage(
onClick = onNavigateLibsRequest
)
}

FormSection(
title = stringResource(R.string.settings_about_other),
bottomDivider = false
) {
ButtonRow(
title = stringResource(R.string.settings_about_other_copyDebugInfo),
description = stringResource(R.string.settings_about_other_copyDebugInfo_description),
painter = rememberVectorPainter(Icons.Outlined.CopyAll)
) {
clipboardManager.setText(AnnotatedString(mainViewModel.debugInfo))
settingsViewModel.topToastState.showToast(
text = R.string.settings_about_other_copyDebugInfo_copied,
icon = Icons.Default.CopyAll
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.aliernfrog.pftool.ui.viewmodel
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.material.icons.Icons
Expand All @@ -21,6 +22,7 @@ import androidx.core.os.LocaleListCompat
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.aliernfrog.pftool.R
import com.aliernfrog.pftool.SettingsConstant
import com.aliernfrog.pftool.TAG
import com.aliernfrog.pftool.data.Language
import com.aliernfrog.pftool.data.ReleaseInfo
Expand All @@ -36,6 +38,7 @@ import com.aliernfrog.pftool.util.extension.cacheFile
import com.aliernfrog.pftool.util.extension.getAvailableLanguage
import com.aliernfrog.pftool.util.extension.showErrorToast
import com.aliernfrog.pftool.util.extension.toLanguage
import com.aliernfrog.pftool.util.manager.ContextUtils
import com.aliernfrog.pftool.util.manager.PreferenceManager
import com.aliernfrog.pftool.util.staticutil.GeneralUtil
import com.aliernfrog.toptoast.enum.TopToastColor
Expand All @@ -55,7 +58,8 @@ class MainViewModel(
context: Context,
val prefs: PreferenceManager,
val topToastState: TopToastState,
val progressState: ProgressState
val progressState: ProgressState,
private val contextUtils: ContextUtils
) : ViewModel() {
lateinit var scope: CoroutineScope
val updateSheetState = SheetState(skipPartiallyExpanded = false, Density(context))
Expand Down Expand Up @@ -90,6 +94,16 @@ class MainViewModel(
var updateAvailable by mutableStateOf(false)
private set

val debugInfo: String
get() = arrayOf(
"PF Tool $applicationVersionName ($applicationVersionCode)",
"Android API ${Build.VERSION.SDK_INT}",
"Storage access type ${prefs.storageAccessType}",
SettingsConstant.experimentalPrefOptions.joinToString("\n") {
"${contextUtils.getString(it.labelResourceId)}: ${it.getValue(prefs)}"
}
).joinToString("\n")

init {
if (!supportsPerAppLanguagePreferences && prefs.language.isNotBlank()) runBlocking {
appLanguage = GeneralUtil.getLanguageFromCode(prefs.language)?.getAvailableLanguage()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
<string name="settings_about_credits_crowdin">Crowdin members</string>
<string name="settings_about_credits_translations">Translations</string>
<string name="settings_about_credits_inspiration">Inspiration</string>
<string name="settings_about_other">Other</string>
<string name="settings_about_other_copyDebugInfo">Copy debug information</string>
<string name="settings_about_other_copyDebugInfo_description">Includes information useful for debugging. Including this in bug reports is recommended</string>
<string name="settings_about_other_copyDebugInfo_copied">Copied debug information</string>
<string name="settings_experimental">Experimental settings</string>
<string name="settings_experimental_enabled">Experimental settings enabled!</string>
<string name="settings_experimental_description">Not intended for normal usage, might break the app when misused</string>
Expand Down

0 comments on commit d26e4a8

Please sign in to comment.