-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
app/src/main/java/com/jerboa/ui/components/settings/crashes/CrashesActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package com.jerboa.ui.components.settings.crashes | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.compose.foundation.clickable | ||
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.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.ContentCopy | ||
import androidx.compose.material.icons.outlined.Delete | ||
import androidx.compose.material3.Divider | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.SnackbarDuration | ||
import androidx.compose.material3.SnackbarHost | ||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateListOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.toMutableStateList | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.navigation.NavController | ||
import androidx.navigation.compose.rememberNavController | ||
import com.crazylegend.crashyreporter.CrashyReporter | ||
import com.jerboa.R | ||
import com.jerboa.copyToClipboard | ||
import com.jerboa.showSnackbar | ||
import com.jerboa.ui.components.common.SimpleTopAppBar | ||
import com.jerboa.ui.theme.MEDIUM_PADDING | ||
import com.jerboa.ui.theme.SMALL_PADDING | ||
|
||
@Composable | ||
fun CrashesActivity( | ||
navController: NavController, | ||
) { | ||
Log.d("jerboa", "Got to Crashes activity") | ||
|
||
val ctx = LocalContext.current | ||
|
||
val crashes = CrashyReporter.getLogsAsStrings()?.toMutableStateList() ?: run { mutableStateListOf() } | ||
|
||
Crashes(ctx = ctx, navController = navController, crashes = crashes) | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun Crashes(ctx: Context, navController: NavController, crashes: MutableList<String>) { | ||
val scope = rememberCoroutineScope() | ||
|
||
val snackbarHostState = remember { SnackbarHostState() } | ||
val deleteMessage = stringResource(R.string.crashes_all_deleted) | ||
|
||
Scaffold( | ||
snackbarHost = { SnackbarHost(snackbarHostState) }, | ||
topBar = { | ||
SimpleTopAppBar( | ||
text = stringResource(R.string.crashes), | ||
navController = navController, | ||
actions = { | ||
IconButton( | ||
onClick = { | ||
CrashyReporter.purgeLogs() | ||
crashes.clear() | ||
showSnackbar( | ||
scope, | ||
snackbarHostState, | ||
deleteMessage, | ||
null, | ||
true, | ||
SnackbarDuration.Short, | ||
) | ||
}, | ||
) { | ||
Icon( | ||
Icons.Outlined.Delete, | ||
contentDescription = stringResource(R.string.crashes_delete), | ||
) | ||
} | ||
}, | ||
) | ||
}, | ||
content = { padding -> | ||
Column( | ||
modifier = Modifier | ||
.verticalScroll(rememberScrollState()) | ||
.padding(padding), | ||
) { | ||
crashes.forEachIndexed { index, crash -> | ||
CrashItem(ctx = ctx, crash = crash) | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
fun CrashItem(ctx: Context, crash: String) { | ||
var expanded by remember { mutableStateOf(false) } | ||
val textModifier = Modifier.clickable(onClick = { expanded = !expanded }) | ||
|
||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(MEDIUM_PADDING), | ||
) { | ||
Column( | ||
modifier = Modifier.padding(MEDIUM_PADDING), | ||
) { | ||
IconButton(onClick = { | ||
copyToClipboard(ctx, crash, "crash") | ||
}) { | ||
Icon( | ||
Icons.Outlined.ContentCopy, | ||
contentDescription = stringResource(R.string.crashes_copy_text), | ||
) | ||
} | ||
} | ||
if (expanded) { | ||
Text( | ||
text = crash, | ||
modifier = textModifier, | ||
) | ||
} else { | ||
Text( | ||
text = crash, | ||
maxLines = 4, | ||
overflow = TextOverflow.Ellipsis, | ||
modifier = textModifier, | ||
) | ||
} | ||
} | ||
Divider(modifier = Modifier.padding(bottom = SMALL_PADDING)) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun CrashesPreview() { | ||
Crashes( | ||
ctx = LocalContext.current, | ||
navController = rememberNavController(), | ||
crashes = mutableListOf( | ||
"A really bad one\nlots\nof\ntrace\nlines\nhere", | ||
"NullPointerException!", | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters