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

Replace PlaybackForwardingActivity with PlaybackRewriteFragment #3559

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,5 @@
android:theme="@style/Theme.Jellyfin.Preferences" />

<activity android:name=".ui.playback.ExternalPlayerActivity" />

<!-- Playback Rewrite - Temporary -->
<activity android:name=".ui.playback.rewrite.PlaybackForwardingActivity" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ val playbackModule = module {
val preferences = get<UserPreferences>()
val useRewrite = preferences[UserPreferences.playbackRewriteVideoEnabled] && BuildConfig.DEVELOPMENT

if (useRewrite) RewritePlaybackLauncher()
if (useRewrite) RewritePlaybackLauncher(get())
else GarbagePlaybackLauncher(get())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.jellyfin.androidtv.ui.playback

import android.content.Context
import android.content.Intent
import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.preference.constant.PreferredVideoPlayer
import org.jellyfin.androidtv.ui.navigation.Destination
import org.jellyfin.androidtv.ui.navigation.Destinations
import org.jellyfin.androidtv.ui.navigation.activityDestination
import org.jellyfin.androidtv.ui.playback.rewrite.PlaybackForwardingActivity
import org.jellyfin.androidtv.ui.navigation.NavigationRepository
import org.jellyfin.androidtv.ui.navigation.fragmentDestination
import org.jellyfin.androidtv.ui.playback.rewrite.PlaybackRewriteFragment
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.BaseItemKind
import org.jellyfin.sdk.model.constant.MediaType

interface PlaybackLauncher {
fun useExternalPlayer(itemType: BaseItemKind?): Boolean
Expand Down Expand Up @@ -42,17 +43,20 @@ class GarbagePlaybackLauncher(
override fun interceptPlayRequest(context: Context, item: BaseItemDto?): Boolean = false
}

class RewritePlaybackLauncher : PlaybackLauncher {
class RewritePlaybackLauncher(
private val navigationRepository: NavigationRepository,
) : PlaybackLauncher {
override fun useExternalPlayer(itemType: BaseItemKind?) = false
override fun getPlaybackDestination(itemType: BaseItemKind?, position: Int) =
activityDestination<PlaybackForwardingActivity>()
fragmentDestination<PlaybackRewriteFragment>()

override fun interceptPlayRequest(context: Context, item: BaseItemDto?): Boolean {
if (item == null) return false
if (item.mediaType == MediaType.Audio) return false

val intent = Intent(context, PlaybackForwardingActivity::class.java)
intent.putExtra(PlaybackForwardingActivity.EXTRA_ITEM_ID, item.id.toString())
context.startActivity(intent)
navigationRepository.navigate(fragmentDestination<PlaybackRewriteFragment>(
PlaybackRewriteFragment.EXTRA_ITEM_ID to item.id.toString()
))

return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.jellyfin.androidtv.ui.playback.rewrite

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
Expand All @@ -22,7 +25,11 @@ import org.koin.android.ext.android.inject
import timber.log.Timber
import java.util.UUID

class PlaybackForwardingActivity : ComponentActivity() {
/**
* Temporary fragment used for testing the playback rewrite. This will eventually be replaced with a
* proper player user interface.
*/
class PlaybackRewriteFragment : Fragment() {
companion object {
const val EXTRA_ITEM_ID: String = "item_id"
}
Expand All @@ -39,11 +46,10 @@ class PlaybackForwardingActivity : ComponentActivity() {

if (itemId == null) {
Toast.makeText(
this,
requireContext(),
"Could not find item to play (itemId=null)",
Toast.LENGTH_LONG
).show()
finishAfterTransition()
return
}

Expand All @@ -54,7 +60,7 @@ class PlaybackForwardingActivity : ComponentActivity() {

// Log info
Toast.makeText(
this@PlaybackForwardingActivity,
requireContext(),
"Found item of type ${item.type} - ${item.name} (${item.id}",
Toast.LENGTH_LONG
).show()
Expand All @@ -72,15 +78,16 @@ class PlaybackForwardingActivity : ComponentActivity() {
})
}
}
}

// TODO: Dirty hack to display surface
val view = PlayerSurfaceView(this)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = PlayerSurfaceView(requireContext())
view.playbackManager = playbackManager
setContentView(view)
return view
}

private fun findItemId(): UUID? {
val extra = intent.getStringExtra(EXTRA_ITEM_ID)?.toUUIDOrNull()
val extra = requireArguments().getString(EXTRA_ITEM_ID)?.toUUIDOrNull()

var first: BaseItemDto? = null
var best: BaseItemDto? = null
Expand Down