forked from jellyfin/jellyfin-androidtv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for intro-skipper button
- Loading branch information
Showing
8 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Custom App / Build | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'custom-v*' | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v4 | ||
|
||
- name: Set JELLYFIN_VERSION | ||
run: echo "JELLYFIN_VERSION=$(echo ${GITHUB_REF#refs/tags/custom-v} | tr / -)" >> $GITHUB_ENV | ||
|
||
- name: Assemble release file | ||
run: ./gradlew assembleRelease | ||
|
||
- name: Sign APK | ||
id: signApk | ||
uses: r0adkll/sign-android-release@v1 | ||
env: | ||
BUILD_TOOLS_VERSION: "34.0.0" | ||
with: | ||
releaseDirectory: app/build/outputs/apk/release | ||
signingKeyBase64: ${{ secrets.KEYSTORE }} | ||
keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }} | ||
alias: ${{ secrets.KEY_ALIAS }} | ||
keyPassword: ${{ secrets.KEY_PASSWORD }} | ||
|
||
- name: Prepare release archive | ||
run: | | ||
mkdir -p build/jellyfin-publish | ||
mv ${{ steps.signApk.outputs.signedReleaseFile }} build/jellyfin-publish/jellyfin-androidtv-v${{ env.JELLYFIN_VERSION }}-release.apk | ||
- name: Create GitHub Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
name: ${{ github.ref_name }} | ||
files: build/jellyfin-publish/*.apk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/main/java/org/jellyfin/androidtv/ui/playback/segmentskip/SegmentModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.jellyfin.androidtv.ui.playback.segmentskip | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
enum class SegmentType { | ||
INTRO, CREDITS, UNKNOWN | ||
} | ||
|
||
@Serializable | ||
data class SegmentModel ( | ||
var type: SegmentType = SegmentType.UNKNOWN, | ||
@SerialName("IntroStart") | ||
val startTime: Double, | ||
@SerialName("IntroEnd") | ||
val endTime: Double, | ||
@SerialName("ShowSkipPromptAt") | ||
val showAt: Double, | ||
@SerialName("HideSkipPromptAt") | ||
val hideAt: Double, | ||
) |
93 changes: 93 additions & 0 deletions
93
app/src/main/java/org/jellyfin/androidtv/ui/playback/segmentskip/SegmentSkipFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.jellyfin.androidtv.ui.playback.segmentskip | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import androidx.fragment.app.Fragment | ||
import org.jellyfin.androidtv.R | ||
import org.jellyfin.androidtv.ui.playback.PlaybackControllerContainer | ||
import org.jellyfin.sdk.api.client.ApiClient | ||
import org.jellyfin.sdk.api.client.extensions.get | ||
import org.jellyfin.sdk.model.UUID | ||
import org.jellyfin.sdk.model.api.BaseItemDto | ||
import org.koin.android.ext.android.inject | ||
|
||
class SegmentSkipFragment() : Fragment() { | ||
|
||
private val api: ApiClient by inject() | ||
private val playbackControllerContainer: PlaybackControllerContainer by inject() | ||
|
||
private lateinit var button: Button | ||
private var segments: List<SegmentModel>? = null | ||
private var lastSegment: SegmentModel? = null | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return inflater.inflate(R.layout.fragment_segment_skip, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
button = view.findViewById(R.id.skip_segment_button) | ||
button.setOnClickListener { | ||
buttonClicked() | ||
} | ||
} | ||
|
||
private fun buttonClicked() { | ||
lastSegment?.let { segment -> | ||
playbackControllerContainer.playbackController?.seek((segment.endTime * 1000).toLong()) | ||
} | ||
} | ||
|
||
fun handleProgress(currentPosition: Long) { | ||
val currentSegment = getCurrentSegment(currentPosition) ?: lastSegment ?: return | ||
lastSegment = currentSegment | ||
|
||
if (currentPosition >= currentSegment.showAt * 1000 && currentPosition < currentSegment.hideAt * 1000 && | ||
button.visibility != View.VISIBLE | ||
) { | ||
button.visibility = View.VISIBLE | ||
button.requestFocus() | ||
} | ||
|
||
if ((currentPosition < currentSegment.showAt * 1000 || currentPosition >= currentSegment.hideAt * 1000) && | ||
button.visibility == View.VISIBLE | ||
) { | ||
button.visibility = View.GONE | ||
} | ||
} | ||
|
||
suspend fun onStartItem(item: BaseItemDto) { | ||
button.visibility = View.GONE | ||
segments = getSegments(item.id) | ||
} | ||
|
||
private suspend fun getSegments(itemId: UUID): List<SegmentModel> { | ||
val segmentsMap = api.get<Map<String, SegmentModel>>( | ||
pathTemplate = "/Episode/{itemId}/IntroSkipperSegments", | ||
pathParameters = mapOf("itemId" to itemId), | ||
).content | ||
|
||
for ((type, segment) in segmentsMap) { | ||
segment.type = when (type) { | ||
"Introduction" -> SegmentType.INTRO | ||
"Credits" -> SegmentType.CREDITS | ||
else -> SegmentType.UNKNOWN | ||
} | ||
} | ||
|
||
return segmentsMap.values.toList() | ||
} | ||
|
||
private fun getCurrentSegment(currentPosition: Long): SegmentModel? { | ||
return segments?.firstOrNull { | ||
currentPosition >= it.startTime * 1000 && currentPosition < it.endTime * 1000 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.playback.segmentskip.SegmentSkipFragment"> | ||
|
||
<Button | ||
android:id="@+id/skip_segment_button" | ||
style="@style/Button.Default" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="56dp" | ||
android:layout_marginBottom="32.5dp" | ||
android:elevation="0dp" | ||
android:text="Skip" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters