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

Add an Open in browser button on error panel #9180

Merged
merged 6 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ class ErrorInfo(

fun throwableListToStringList(throwableList: List<Throwable>) =
throwableList.map { it.stackTraceToString() }.toTypedArray()

private fun getInfoServiceName(info: Info?) =
if (info == null) SERVICE_NONE else ServiceHelper.getNameOfServiceById(info.serviceId)

AudricV marked this conversation as resolved.
Show resolved Hide resolved
@StringRes
private fun getMessageStringId(
throwable: Throwable?,
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package org.schabi.newpipe.error

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.annotation.Nullable
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat.startActivity
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.jakewharton.rxbinding4.view.clicks
Expand Down Expand Up @@ -52,6 +54,8 @@ class ErrorPanelHelper(
errorPanelRoot.findViewById(R.id.error_action_button)
private val errorRetryButton: Button =
errorPanelRoot.findViewById(R.id.error_retry_button)
private val errorOpenbrowserButton: Button =
errorPanelRoot.findViewById(R.id.error_openinbrowser)
AudricV marked this conversation as resolved.
Show resolved Hide resolved

private var errorDisposable: Disposable? = null

Expand All @@ -69,19 +73,17 @@ class ErrorPanelHelper(
errorServiceExplanationTextView.isVisible = false
errorActionButton.isVisible = false
errorRetryButton.isVisible = false
errorOpenbrowserButton.isVisible = false
AudricV marked this conversation as resolved.
Show resolved Hide resolved
}

fun showError(errorInfo: ErrorInfo) {

AudricV marked this conversation as resolved.
Show resolved Hide resolved
if (errorInfo.throwable != null && errorInfo.throwable!!.isInterruptedCaused) {
if (DEBUG) {
Log.w(TAG, "onError() isInterruptedCaused! = [$errorInfo.throwable]")
}
return
}

ensureDefaultVisibility()

AudricV marked this conversation as resolved.
Show resolved Hide resolved
if (errorInfo.throwable is ReCaptchaException) {
errorTextView.setText(R.string.recaptcha_request_toast)

Expand All @@ -99,6 +101,7 @@ class ErrorPanelHelper(
}

errorRetryButton.isVisible = true
errorOpenbrowserButton.isVisible = true
} else if (errorInfo.throwable is AccountTerminatedException) {
errorTextView.setText(R.string.account_terminated)

Expand Down Expand Up @@ -127,6 +130,12 @@ class ErrorPanelHelper(
) {
// show retry button only for content which is not unavailable or unsupported
errorRetryButton.isVisible = true
errorOpenbrowserButton.isVisible = true
errorOpenbrowserButton.setOnClickListener {
val uriUrl = Uri.parse(errorInfo.request)
val intent = Intent(Intent.ACTION_VIEW, uriUrl)
context.startActivity(intent)
AudricV marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/error_panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@
android:visibility="gone"
tools:visibility="visible" />

<Button
android:id="@+id/error_openinbrowser"
AudricV marked this conversation as resolved.
Show resolved Hide resolved
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
Stypox marked this conversation as resolved.
Show resolved Hide resolved
android:layout_marginBottom="8dp"
AudricV marked this conversation as resolved.
Show resolved Hide resolved
android:text="@string/error_openinbrowser"
AudricV marked this conversation as resolved.
Show resolved Hide resolved
android:textAlignment="center"
android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="16sp"
android:theme="@style/ServiceColoredButton"
android:visibility="gone"
tools:visibility="visible" />

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<string name="error_report_open_github_notice">Please check whether an issue discussing your crash already exists. When creating duplicate tickets, you take time from us which we could spend with fixing the actual bug.</string>
<string name="error_snackbar_message">Sorry, something went wrong.</string>
<string name="error_snackbar_action">Report</string>
<string name="error_openinbrowser">Open in Browser</string>
AudricV marked this conversation as resolved.
Show resolved Hide resolved
<string name="what_device_headline">Info:</string>
<string name="what_happened_headline">What happened:</string>
<string name="info_labels">What:\\nRequest:\\nContent Language:\\nContent Country:\\nApp Language:\\nService:\\nGMT Time:\\nPackage:\\nVersion:\\nOS version:</string>
Expand Down