Skip to content

Commit

Permalink
Show feed load error, improve ErrorInfoDisplay
Browse files Browse the repository at this point in the history
When getHomeFeed fails to parse the feed JSON, repeat the feed request and include its content in the returned result
Display feed load error in UI
Add JSON data display to ErrorInfoDisplay
Add Paste.ee upload button to ErrorInfoDisplay
Block main NowPlaying scrolling from the overlay menu
Respect OverlayMenu.closeOnTap
Improve ErrorReportActivity layout
  • Loading branch information
toasterofbread committed Jul 13, 2023
1 parent bd8fa26 commit c8ef09f
Show file tree
Hide file tree
Showing 25 changed files with 798 additions and 422 deletions.
35 changes: 22 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
kotlin.code.style=official
android.nonTransitiveRClass=true
android.enableR8.fullMode=true
kotlin.mpp.enableCInteropCommonization=true

# Android
android.useAndroidX=true
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Wed Jul 12 23:12:00 BST 2023
agp.version=7.4.2
android.compileSdk=33
android.targetSdk=33
android.enableR8.fullMode=true
android.minSdk=27

# Versions
android.nonTransitiveRClass=true
android.targetSdk=33
android.useAndroidX=true
compose.version=1.4.1
kotlin.code.style=official
kotlin.mpp.enableCInteropCommonization=true
kotlin.version=1.8.20
agp.version=7.4.2
compose.version=1.4.1
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" -Dfile.encoding\=UTF-8
3 changes: 2 additions & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ plugins {
val KEY_NAMES = mapOf(
"DISCORD_BOT_TOKEN" to "String",
"DISCORD_CUSTOM_IMAGES_CHANNEL_CATEGORY" to "Long",
"DISCORD_CUSTOM_IMAGES_CHANNEL_NAME_PREFIX" to "String"
"DISCORD_CUSTOM_IMAGES_CHANNEL_NAME_PREFIX" to "String",
"PASTE_EE_TOKEN" to "String"
)
val DEBUG_KEY_NAMES = listOf("YTM_CHANNEL_ID", "YTM_COOKIE", "YTM_HEADERS", "DISCORD_ACCOUNT_TOKEN", "DISCORD_ERROR_REPORT_WEBHOOK")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ContentCopy
import androidx.compose.material.icons.outlined.Share
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.beust.klaxon.Klaxon
import com.toasterofbread.spmp.platform.PlatformContext
import com.toasterofbread.spmp.ui.theme.ApplicationTheme
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.utils.thenIf
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -53,12 +57,17 @@ class ErrorReportActivity : ComponentActivity() {
setContent {
ApplicationTheme(context) {
Surface(modifier = Modifier.fillMaxSize()) {
var width by remember { mutableStateOf(0) }

Column(
Modifier
.fillMaxSize()
.padding(10.dp)) {
var stack_wrap_enabled by remember { mutableStateOf(false) }
.padding(10.dp)
.onSizeChanged {
width = it.width
}
) {
var wrap_text by remember { mutableStateOf(false) }

Row(
Modifier
Expand All @@ -67,20 +76,10 @@ class ErrorReportActivity : ComponentActivity() {
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(Modifier.weight(1f)) {
Text("An error occurred", fontSize = 22.sp)
Text(message)
}

Spacer(Modifier.requiredWidth(10.dp))

Row(verticalAlignment = Alignment.CenterVertically) {
Column(horizontalAlignment = Alignment.End) {
Text("Text wrap")
Switch(checked = stack_wrap_enabled, onCheckedChange = { stack_wrap_enabled = it })
}
Column {
Text(getString("error_message_generic"), fontSize = 22.sp)

Column {
Row {
IconButton(onClick = { startActivity(share_intent) }) {
Icon(Icons.Outlined.Share, null)
}
Expand All @@ -102,7 +101,7 @@ class ErrorReportActivity : ComponentActivity() {
val client = OkHttpClient()
val klaxon = Klaxon()

for (chunk in listOf("--------------\nMESSAGE: $message\n\nSTACKTRACE:") + stack_trace.chunked(2000)) {
for (chunk in listOf("---\nMESSAGE: $message\n\nSTACKTRACE:") + stack_trace.chunked(2000)) {
val body = klaxon.toJsonString(mapOf(
"content" to chunk,
"username" to message.take(78) + if (message.length > 78) ".." else "",
Expand All @@ -122,6 +121,8 @@ class ErrorReportActivity : ComponentActivity() {
}

response.close()

delay(500)
}
}
}) {
Expand All @@ -130,27 +131,42 @@ class ErrorReportActivity : ComponentActivity() {
}
}
}

Spacer(Modifier.requiredWidth(10.dp))

Column(horizontalAlignment = Alignment.End) {
Text(getString("wrap_text_switch_label"))
Switch(checked = wrap_text, onCheckedChange = { wrap_text = it })
}
}

Spacer(Modifier.height(10.dp))

Column(
Modifier
.verticalScroll(rememberScrollState())
.then(
if (stack_wrap_enabled) Modifier else Modifier.horizontalScroll(
rememberScrollState()
)
)
) {
SelectionContainer {
Text(stack_trace, softWrap = stack_wrap_enabled, fontSize = 15.sp)
// Scroll modifiers don't work here, no idea why
LazyRow {
item {
LazyColumn(
Modifier.thenIf(wrap_text) {
width(with(LocalDensity.current) { width.toDp() })
},
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
item {
SelectionContainer {
Text(message, softWrap = wrap_text, fontSize = 20.sp)
}
}
item {
SelectionContainer {
Text(stack_trace, softWrap = wrap_text, fontSize = 15.sp)
}
}
}
}
}
}

}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.toasterofbread.spmp.model.mediaitem.MediaItemThumbnailProvider
import com.toasterofbread.spmp.model.mediaitem.Song
import com.toasterofbread.spmp.platform.*
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.spmp.resources.getStringTODO
import kotlinx.coroutines.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.Semaphore
Expand Down Expand Up @@ -193,7 +194,7 @@ class PlayerService : MediaPlayerService() {
assert(b in 0 until song_count)

val offset_b = b + (if (b > a) -1 else 1)

undoableAction {
moveSong(a, b)
moveSong(offset_b, a)
Expand Down Expand Up @@ -242,18 +243,18 @@ class PlayerService : MediaPlayerService() {
}

fun addMultipleToQueue(songs: List<Song>, index: Int = 0, skip_first: Boolean = false, save: Boolean = true, is_active_queue: Boolean = false, skip_existing: Boolean = false) {
val to_add: List<Song> =
val to_add: List<Song> =
if (!skip_existing) {
songs
}
else {
songs.toMutableList().apply {
iterateSongs { _, song ->
removeAll { it == song }
}
}
}
}

if (to_add.isEmpty()) {
return
}
Expand Down Expand Up @@ -522,12 +523,10 @@ class PlayerService : MediaPlayerService() {
return
}

check(song.artist?.title != null)

discord_status_update_job = coroutine_scope.launch {
fun formatText(text: String): String {
return text
.replace("\$artist", song.artist!!.title!!)
.replace("\$artist", song.artist?.title ?: getStringTODO("Unknown"))
.replace("\$song", song.title!!)
}

Expand All @@ -547,7 +546,7 @@ class PlayerService : MediaPlayerService() {
}.getOrThrow()
}
}
catch (e: IOException) {
catch (e: Throwable) {
return@launch
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import org.schabi.newpipe.extractor.downloader.Response as NewPipeResponse
const val DEFAULT_CONNECT_TIMEOUT = 3000
val PLAIN_HEADERS = listOf("accept-language", "user-agent", "accept-encoding", "content-encoding", "origin")

class JsonParseException(val json_obj: JsonObject, message: String? = null, cause: Throwable? = null): RuntimeException(message, cause)

fun <T> Result.Companion.failure(response: Response, is_gzip: Boolean = true): Result<T> {
var body: String
if (is_gzip) {
Expand Down
Loading

0 comments on commit c8ef09f

Please sign in to comment.