フォロー限定投稿にフォロー外から返信しようとした際のエラー表示を改善

This commit is contained in:
tateisu 2023-07-11 09:09:43 +09:00
parent 8dc33e1b70
commit 6ac8545b58
4 changed files with 37 additions and 20 deletions

View File

@ -607,7 +607,19 @@ class PostImpl(
status != null -> status != null ->
PostResult.Normal(account, status) PostResult.Normal(account, status)
else -> error(result.error ?: "(result.error is null)") else -> {
val e = result.error
error(
when {
e.isNullOrBlank() -> "(missing result.error)"
e.contains("HTTP 404") ->
"$e\n${activity.getString(R.string.post_404_desc)}"
else -> e
}
)
}
} }
} }
} }

View File

@ -1289,4 +1289,5 @@
<string name="use_webp_format_if_server_accepts">可能ならWebPフォーマットを使う</string> <string name="use_webp_format_if_server_accepts">可能ならWebPフォーマットを使う</string>
<string name="detail">詳細</string> <string name="detail">詳細</string>
<string name="emoji_detail">絵文字の詳細</string> <string name="emoji_detail">絵文字の詳細</string>
</resources> <string name="post_404_desc">(もしくは、フォロー限定投稿にフォロー外から返信しようとしました)</string>
</resources>

View File

@ -1300,4 +1300,5 @@
<string name="use_webp_format_if_server_accepts">Use WebP format if server accepts.</string> <string name="use_webp_format_if_server_accepts">Use WebP format if server accepts.</string>
<string name="detail">Detail</string> <string name="detail">Detail</string>
<string name="emoji_detail">Emoji detail</string> <string name="emoji_detail">Emoji detail</string>
<string name="post_404_desc">(Or, you reply to follower-only post from other account)</string>
</resources> </resources>

View File

@ -108,7 +108,7 @@ internal fun showToastImpl(
context: Context, context: Context,
bLong: Boolean, bLong: Boolean,
message: String, message: String,
forceToast:Boolean = false, forceToast: Boolean = false,
): Boolean { ): Boolean {
runOnMainLooper { runOnMainLooper {
if (!forceToast && (message.length >= 32 || message.count { it == '\n' } > 1)) { if (!forceToast && (message.length >= 32 || message.count { it == '\n' } > 1)) {
@ -154,8 +154,8 @@ internal fun showToastImpl(
fun Context.showToast( fun Context.showToast(
bLong: Boolean, bLong: Boolean,
caption: String?, caption: String?,
forceToast:Boolean = false, forceToast: Boolean = false,
): Boolean = showToastImpl(this, bLong, caption ?: "(null)" ,forceToast = forceToast) ): Boolean = showToastImpl(this, bLong, caption ?: "(null)", forceToast = forceToast)
fun Context.showToast(ex: Throwable, caption: String? = null): Boolean = fun Context.showToast(ex: Throwable, caption: String? = null): Boolean =
showToastImpl(this, true, ex.withCaption(caption)) showToastImpl(this, true, ex.withCaption(caption))
@ -188,23 +188,26 @@ fun AppCompatActivity.showError(ex: Throwable, caption: String? = null) {
if (ex is CancellationException) return if (ex is CancellationException) return
try { try {
AlertDialog.Builder(this) val text = listOf(
.setTitle("error") caption,
.setMessage( when (ex) {
listOf( is IllegalStateException -> null
caption, else -> ex.javaClass.simpleName
when (ex) { },
is IllegalStateException -> null ex.message,
else -> ex.javaClass.simpleName )
}, .filter { !it.isNullOrBlank() }
ex.message, .joinToString("\n")
) if (text.isNotEmpty()) {
.filter { !it.isNullOrBlank() } AlertDialog.Builder(this)
.joinToString("\n") .setMessage(text)
) .setPositiveButton(android.R.string.ok, null)
.show()
return
}
} catch (ignored: Throwable) { } catch (ignored: Throwable) {
showToast(ex, caption)
} }
showToast(ex, caption)
} }
fun Context.errorString(@StringRes stringId: Int, vararg args: Any?): Nothing = fun Context.errorString(@StringRes stringId: Int, vararg args: Any?): Nothing =