Small fixes

master
Koitharu 2 years ago
parent a0de73a7ed
commit a7138d23ac
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -9,11 +9,12 @@ import android.os.Build
import android.os.StrictMode import android.os.StrictMode
import android.os.strictmode.Violation import android.os.strictmode.Violation
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.app.PendingIntentCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.fragment.app.strictmode.FragmentStrictMode import androidx.fragment.app.strictmode.FragmentStrictMode
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor import kotlinx.coroutines.asExecutor
import org.koitharu.kotatsu.core.ErrorReporterReceiver import org.koitharu.kotatsu.core.util.ShareHelper
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import androidx.fragment.app.strictmode.Violation as FragmentViolation import androidx.fragment.app.strictmode.Violation as FragmentViolation
@ -51,7 +52,15 @@ class StrictModeNotifier(
.setSummaryText(violation.message) .setSummaryText(violation.message)
.bigText(violation.stackTraceToString()), .bigText(violation.stackTraceToString()),
).setShowWhen(true) ).setShowWhen(true)
.setContentIntent(ErrorReporterReceiver.getPendingIntent(context, violation)) .setContentIntent(
PendingIntentCompat.getActivity(
context,
0,
ShareHelper(context).getShareTextIntent(violation.stackTraceToString()),
0,
false,
),
)
.setAutoCancel(true) .setAutoCancel(true)
.setGroup(CHANNEL_ID) .setGroup(CHANNEL_ID)
.build() .build()

@ -53,9 +53,6 @@ class CurlLoggingInterceptor(
private fun String.escape() = replace(escapeRegex) { match -> private fun String.escape() = replace(escapeRegex) { match ->
"\\" + match.value "\\" + match.value
} }
// .replace("\"", "\\\"")
// .replace("[", "\\[")
// .replace("]", "\\]")
private fun log(msg: String) { private fun log(msg: String) {
Log.d("CURL", msg) Log.d("CURL", msg)

@ -1,6 +1,7 @@
package org.koitharu.kotatsu.core.util package org.koitharu.kotatsu.core.util
import android.content.Context import android.content.Context
import android.content.Intent
import android.net.Uri import android.net.Uri
import androidx.core.app.ShareCompat import androidx.core.app.ShareCompat
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
@ -75,11 +76,9 @@ class ShareHelper(private val context: Context) {
.startChooser() .startChooser()
} }
fun shareText(text: String) { fun getShareTextIntent(text: String): Intent = ShareCompat.IntentBuilder(context)
ShareCompat.IntentBuilder(context)
.setText(text) .setText(text)
.setType(TYPE_TEXT) .setType(TYPE_TEXT)
.setChooserTitle(R.string.share) .setChooserTitle(R.string.share)
.startChooser() .createChooserIntent()
}
} }

@ -36,8 +36,11 @@ import org.koitharu.kotatsu.parsers.exception.NotFoundException
import org.koitharu.kotatsu.parsers.exception.ParseException import org.koitharu.kotatsu.parsers.exception.ParseException
import org.koitharu.kotatsu.parsers.exception.TooManyRequestExceptions import org.koitharu.kotatsu.parsers.exception.TooManyRequestExceptions
import org.koitharu.kotatsu.scrobbling.common.domain.ScrobblerAuthRequiredException import org.koitharu.kotatsu.scrobbling.common.domain.ScrobblerAuthRequiredException
import java.net.ConnectException
import java.net.NoRouteToHostException
import java.net.SocketTimeoutException import java.net.SocketTimeoutException
import java.net.UnknownHostException import java.net.UnknownHostException
import java.util.Locale
private const val MSG_NO_SPACE_LEFT = "No space left on device" private const val MSG_NO_SPACE_LEFT = "No space left on device"
private const val IMAGE_FORMAT_NOT_SUPPORTED = "Image format not supported" private const val IMAGE_FORMAT_NOT_SUPPORTED = "Image format not supported"
@ -82,13 +85,20 @@ private fun Throwable.getDisplayMessageOrNull(resources: Resources): String? = w
is ContentUnavailableException -> message is ContentUnavailableException -> message
is ParseException -> shortMessage is ParseException -> shortMessage
is ConnectException,
is UnknownHostException, is UnknownHostException,
is NoRouteToHostException,
is SocketTimeoutException -> resources.getString(R.string.network_error) is SocketTimeoutException -> resources.getString(R.string.network_error)
is ImageDecodeException -> resources.getString( is ImageDecodeException -> {
R.string.error_image_format, val type = format?.substringBefore('/')
format.ifNullOrEmpty { resources.getString(R.string.unknown) }, val formatString = format.ifNullOrEmpty { resources.getString(R.string.unknown).lowercase(Locale.getDefault()) }
) if (type.isNullOrEmpty() || type == "image") {
resources.getString(R.string.error_image_format, formatString)
} else {
resources.getString(R.string.error_not_image, formatString)
}
}
is NoDataReceivedException -> resources.getString(R.string.error_no_data_received) is NoDataReceivedException -> resources.getString(R.string.error_no_data_received)
is IncompatiblePluginException -> { is IncompatiblePluginException -> {
@ -96,6 +106,7 @@ private fun Throwable.getDisplayMessageOrNull(resources: Resources): String? = w
resources.getString(R.string.plugin_incompatible_with_cause, it) resources.getString(R.string.plugin_incompatible_with_cause, it)
} ?: resources.getString(R.string.plugin_incompatible) } ?: resources.getString(R.string.plugin_incompatible)
} }
is WrongPasswordException -> resources.getString(R.string.wrong_password) is WrongPasswordException -> resources.getString(R.string.wrong_password)
is NotFoundException -> resources.getString(R.string.not_found_404) is NotFoundException -> resources.getString(R.string.not_found_404)
is UnsupportedSourceException -> resources.getString(R.string.unsupported_source) is UnsupportedSourceException -> resources.getString(R.string.unsupported_source)
@ -112,6 +123,8 @@ fun Throwable.getDisplayIcon() = when (this) {
is CloudFlareProtectedException -> R.drawable.ic_bot_large is CloudFlareProtectedException -> R.drawable.ic_bot_large
is UnknownHostException, is UnknownHostException,
is SocketTimeoutException, is SocketTimeoutException,
is ConnectException,
is NoRouteToHostException,
is ProtocolException -> R.drawable.ic_plug_large is ProtocolException -> R.drawable.ic_plug_large
is CloudFlareBlockedException -> R.drawable.ic_denied_large is CloudFlareBlockedException -> R.drawable.ic_denied_large
@ -133,6 +146,7 @@ fun Throwable.getCauseUrl(): String? = when (this) {
private fun getHttpDisplayMessage(statusCode: Int, resources: Resources): String? = when (statusCode) { private fun getHttpDisplayMessage(statusCode: Int, resources: Resources): String? = when (statusCode) {
404 -> resources.getString(R.string.not_found_404) 404 -> resources.getString(R.string.not_found_404)
403 -> resources.getString(R.string.access_denied_403)
in 500..599 -> resources.getString(R.string.server_error, statusCode) in 500..599 -> resources.getString(R.string.server_error, statusCode)
else -> null else -> null
} }
@ -165,6 +179,8 @@ fun Throwable.isReportable(): Boolean {
|| this is CloudFlareProtectedException || this is CloudFlareProtectedException
|| this is BadBackupFormatException || this is BadBackupFormatException
|| this is WrongPasswordException || this is WrongPasswordException
|| this is TooManyRequestExceptions
|| this is HttpStatusException
) { ) {
return false return false
} }

@ -79,8 +79,7 @@ class MangaPageFetcher(
} }
} }
private fun Response.toNetworkResponse(): NetworkResponse { private fun Response.toNetworkResponse() = NetworkResponse(
return NetworkResponse(
code = code, code = code,
requestMillis = sentRequestAtMillis, requestMillis = sentRequestAtMillis,
responseMillis = receivedResponseAtMillis, responseMillis = receivedResponseAtMillis,
@ -88,7 +87,6 @@ class MangaPageFetcher(
body = body?.source()?.let(::NetworkResponseBody), body = body?.source()?.let(::NetworkResponseBody),
delegate = this, delegate = this,
) )
}
private fun Headers.toNetworkHeaders(): NetworkHeaders { private fun Headers.toNetworkHeaders(): NetworkHeaders {
val headers = NetworkHeaders.Builder() val headers = NetworkHeaders.Builder()

@ -739,6 +739,7 @@
<string name="user_manual">User manual</string> <string name="user_manual">User manual</string>
<string name="telegram_group">Telegram group</string> <string name="telegram_group">Telegram group</string>
<string name="error_image_format">Unsupported image format: %s</string> <string name="error_image_format">Unsupported image format: %s</string>
<string name="error_not_image">Invalid format: expected image but got %s</string>
<string name="start_download">Start download</string> <string name="start_download">Start download</string>
<string name="save_manga_confirm">Save selected manga? This may consume traffic and disk space</string> <string name="save_manga_confirm">Save selected manga? This may consume traffic and disk space</string>
<string name="save_manga">Save manga</string> <string name="save_manga">Save manga</string>
@ -759,4 +760,5 @@
<string name="portrait">Portrait</string> <string name="portrait">Portrait</string>
<string name="landscape">Landscape</string> <string name="landscape">Landscape</string>
<string name="breadcrumbs_separator" translatable="false"><![CDATA[" > "]]></string> <string name="breadcrumbs_separator" translatable="false"><![CDATA[" > "]]></string>
<string name="access_denied_403">Access denied (403)</string>
</resources> </resources>

Loading…
Cancel
Save