Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make text in error dialogs selectable/copyable #1418

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions app/src/main/java/eu/darken/sdmse/common/error/ErrorDialog.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
package eu.darken.sdmse.common.error

import android.app.Activity
import android.util.TypedValue
import androidx.navigation.findNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textview.MaterialTextView
import eu.darken.sdmse.common.R
import eu.darken.sdmse.common.files.WriteException
import eu.darken.sdmse.exclusion.ui.editor.path.PathExclusionEditorOptions
import eu.darken.sdmse.exclusion.ui.editor.path.PathExclusionFragmentArgs

fun Throwable.asErrorDialogBuilder(
activity: Activity
context: Activity
): MaterialAlertDialogBuilder {
val context = activity
return MaterialAlertDialogBuilder(context).apply {
val error = this@asErrorDialogBuilder
val localizedError = error.localized(context)

setTitle(localizedError.label.get(context))
setMessage(localizedError.description.get(context))

val messageView = MaterialTextView(context).apply {
text = localizedError.description.get(context)
setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Caption)
setTextIsSelectable(true)

val paddingHorizontal = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 24f, resources.displayMetrics
).toInt()
val paddingVertical = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 8f, resources.displayMetrics
).toInt()
setPadding(
paddingHorizontal,
paddingVertical,
paddingHorizontal,
0,
)
}
setView(messageView)

if (localizedError.fixAction != null) {
setPositiveButton(
localizedError.fixActionLabel?.get(context) ?: context.getString(android.R.string.ok)
) { _, _ ->
localizedError.fixAction!!.invoke(activity)
localizedError.fixAction!!.invoke(context)
}
setNegativeButton(R.string.general_cancel_action) { _, _ ->
}
Expand All @@ -35,13 +55,13 @@ fun Throwable.asErrorDialogBuilder(
when {
localizedError.infoAction != null -> {
setNeutralButton(R.string.general_show_details_action) { _, _ ->
localizedError.infoAction!!.invoke(activity)
localizedError.infoAction!!.invoke(context)
}
}

this@asErrorDialogBuilder is WriteException && path != null -> {
setNeutralButton(eu.darken.sdmse.R.string.exclusion_create_action) { _, _ ->
activity.findNavController(eu.darken.sdmse.R.id.nav_host).navigate(
context.findNavController(eu.darken.sdmse.R.id.nav_host).navigate(
resId = eu.darken.sdmse.R.id.goToPathExclusionEditor,
args = PathExclusionFragmentArgs(
initial = PathExclusionEditorOptions(targetPath = path!!)
Expand Down
Loading