Skip to content

Commit

Permalink
Add an Open in browser button on error panel (#9180)
Browse files Browse the repository at this point in the history
* add a open in browser button

* Corrected a few things that needed to be changed

* Remove unneeded changes.

* Remove unneeded changes.

* Add showAndSetOpenInBrowserButtonAction function

* modify some codes
  • Loading branch information
YonghaoDeng authored Oct 27, 2022
1 parent 38579e9 commit a22162f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.schabi.newpipe.ktx.animate
import org.schabi.newpipe.ktx.isInterruptedCaused
import org.schabi.newpipe.ktx.isNetworkRelated
import org.schabi.newpipe.util.ServiceHelper
import org.schabi.newpipe.util.external_communication.ShareUtils
import java.util.concurrent.TimeUnit

class ErrorPanelHelper(
Expand All @@ -52,6 +53,8 @@ class ErrorPanelHelper(
errorPanelRoot.findViewById(R.id.error_action_button)
private val errorRetryButton: Button =
errorPanelRoot.findViewById(R.id.error_retry_button)
private val errorOpenInBrowserButton: Button =
errorPanelRoot.findViewById(R.id.error_open_in_browser)

private var errorDisposable: Disposable? = null

Expand All @@ -69,6 +72,7 @@ class ErrorPanelHelper(
errorServiceExplanationTextView.isVisible = false
errorActionButton.isVisible = false
errorRetryButton.isVisible = false
errorOpenInBrowserButton.isVisible = false
}

fun showError(errorInfo: ErrorInfo) {
Expand Down Expand Up @@ -99,6 +103,7 @@ class ErrorPanelHelper(
}

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

Expand Down Expand Up @@ -128,6 +133,7 @@ class ErrorPanelHelper(
// show retry button only for content which is not unavailable or unsupported
errorRetryButton.isVisible = true
}
showAndSetOpenInBrowserButtonAction(errorInfo)
}

setRootVisible()
Expand All @@ -145,6 +151,15 @@ class ErrorPanelHelper(
errorActionButton.setOnClickListener(listener)
}

fun showAndSetOpenInBrowserButtonAction(
errorInfo: ErrorInfo
) {
errorOpenInBrowserButton.isVisible = true
errorOpenInBrowserButton.setOnClickListener {
ShareUtils.openUrlInBrowser(context, errorInfo.request, true)
}
}

fun showTextError(errorString: String) {
ensureDefaultVisibility()

Expand Down
18 changes: 16 additions & 2 deletions app/src/main/res/layout/error_panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
android:id="@+id/error_message_service_explanation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="4dp"
android:gravity="center"
android:text="@string/general_error"
android:textSize="16sp"
android:textStyle="italic"
Expand Down Expand Up @@ -62,7 +62,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:text="@string/retry"
android:textAlignment="center"
android:textAllCaps="true"
Expand All @@ -72,4 +71,19 @@
android:visibility="gone"
tools:visibility="visible" />

<Button
android:id="@+id/error_open_in_browser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:text="@string/open_in_browser"
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>

0 comments on commit a22162f

Please sign in to comment.