<commit_before>package com.example.dennis.proxertv.ui.player

import android.net.Uri
import android.os.Bundle
import android.support.v17.leanback.app.PlaybackOverlayFragment
import android.support.v17.leanback.widget.*
import android.support.v17.leanback.widget.PlaybackControlsRow.PlayPauseAction
import com.example.dennis.proxertv.R
import com.example.dennis.proxertv.model.Stream
import com.example.dennis.proxertv.ui.util.StreamPresenter
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import rx.subscriptions.CompositeSubscription

class PlayerOverlayFragment : PlaybackOverlayFragment(), VideoPlayer.StatusListener, OnItemViewClickedListener {
    private var videoPlayer: VideoPlayer? = null
    private var seekLength = 10000 // 10 seconds, overridden once the video length is known
    private val subscriptions = CompositeSubscription()

    private lateinit var rowsAdapter: ArrayObjectAdapter
    private lateinit var actionsRow: PlaybackControlsRow
    private lateinit var actionsAdapter: ArrayObjectAdapter
    private lateinit var streamRowAdapter: ArrayObjectAdapter
    private lateinit var playPauseAction: PlayPauseAction

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        backgroundType = PlaybackOverlayFragment.BG_LIGHT
        setupActions()
    }

    override fun onDestroy() {
        super.onDestroy()
        subscriptions.clear()
    }

    fun connectToPlayer(videoPlayer: VideoPlayer, streamObservable: Observable<Stream>) {
        this.videoPlayer = videoPlayer
        videoPlayer.setStatusListener(this)

        subscriptions.add(streamObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe({ stream ->
                    if (streamRowAdapter.size() == 0) {
                        setStream(stream)
                    }
                    streamRowAdapter.add(stream)
                }, { it.printStackTrace() }, {}))
    }

    private fun setupActions() {
        val controlsRowPresenter = PlaybackControlsRowPresenter()
        val presenterSelector = ClassPresenterSelector()
        presenterSelector.addClassPresenter(PlaybackControlsRow::class.java, controlsRowPresenter)
        presenterSelector.addClassPresenter(ListRow::class.java, ListRowPresenter())

        rowsAdapter = ArrayObjectAdapter(presenterSelector)

        // first row (playback controls)
        actionsRow = PlaybackControlsRow()
        actionsAdapter = ArrayObjectAdapter(ControlButtonPresenterSelector())

        actionsRow.primaryActionsAdapter = actionsAdapter

        playPauseAction = PlaybackControlsRow.PlayPauseAction(activity)
        val rewindAction = PlaybackControlsRow.RewindAction(activity)
        val fastForwardAction = PlaybackControlsRow.FastForwardAction(activity)

        actionsAdapter.add(rewindAction)
        actionsAdapter.add(playPauseAction)
        actionsAdapter.add(fastForwardAction)
<commit_msg>Return from player activity if there are no supported streams<commit_after>package com.example.dennis.proxertv.ui.player

import android.net.Uri
import android.os.Bundle
import android.support.v17.leanback.app.PlaybackOverlayFragment
import android.support.v17.leanback.widget.*
import android.support.v17.leanback.widget.PlaybackControlsRow.PlayPauseAction
import android.widget.Toast
import com.example.dennis.proxertv.R
import com.example.dennis.proxertv.model.Stream
import com.example.dennis.proxertv.ui.util.StreamPresenter
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import rx.subscriptions.CompositeSubscription

class PlayerOverlayFragment : PlaybackOverlayFragment(), VideoPlayer.StatusListener, OnItemViewClickedListener {
    private var videoPlayer: VideoPlayer? = null
    private var seekLength = 10000 // 10 seconds, overridden once the video length is known
    private val subscriptions = CompositeSubscription()

    private lateinit var rowsAdapter: ArrayObjectAdapter
    private lateinit var actionsRow: PlaybackControlsRow
    private lateinit var actionsAdapter: ArrayObjectAdapter
    private lateinit var streamRowAdapter: ArrayObjectAdapter
    private lateinit var playPauseAction: PlayPauseAction

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        backgroundType = PlaybackOverlayFragment.BG_LIGHT
        setupActions()
    }

    override fun onDestroy() {
        super.onDestroy()
        subscriptions.clear()
    }

    fun connectToPlayer(videoPlayer: VideoPlayer, streamObservable: Observable<Stream>) {
        this.videoPlayer = videoPlayer
        videoPlayer.setStatusListener(this)

        subscriptions.add(streamObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe({ stream ->
                    if (streamRowAdapter.size() == 0) {
                        setStream(stream)
                    }
                    streamRowAdapter.add(stream)
                }, { it.printStackTrace(); checkValidStreamsFound() }, { checkValidStreamsFound() }))
    }

    private fun checkValidStreamsFound() {
        if (streamRowAdapter.size() == 0) {
            Toast.makeText(activity, "no supported streams found", Toast.LENGTH_LONG).show()
            activity.finish()
        }
    }

    private fun setupActions() {
        val controlsRowPresenter = PlaybackControlsRowPresenter()
        val presenterSelector = ClassPresenterSelector()
        presenterSelector.addClassPresenter(PlaybackControlsRow::class.java, controlsRowPresenter)
        presenterSelector.addClassPresenter(ListRow::class.java, ListRowPresenter())

        rowsAdapter = ArrayObjectAdapter(presenterSelector)

        // first row (playback controls)
        actionsRow = PlaybackControlsRow()
        actionsAdapter = ArrayObjectAdapter(ControlButtonPresenterSelector())

        actionsRow.primaryActionsAdapter = actionsAdapter

        playPauseAction = PlaybackControlsRow.PlayPauseAction(activity)
        val rewindAction = PlaybackControlsRow.RewindAction(activity)
        val fastForwardAction = PlaybackControlsRow.FastForwardAction(activity)

        actionsAdapter.add(rewindAction)
        actionsAdapter.add(playPauseAction)
        actionsAdapter.add(fastForwardAction)

{'fraction_non_alphanumeric': 0.07378458652493357, 'fraction_numerical': 0.004533375019540409, 'mean_word_length': 3.7357512953367875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4558614', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1607, 'n_words': 314}