Skip to content

Commit

Permalink
Play downloaded videos when available
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Oct 1, 2017
1 parent f954441 commit 8f994dc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
applicationId 'com.stevenschoen.putionew'
minSdkVersion 19
targetSdkVersion 26
versionCode 123
versionName '4.2 beta 4'
versionCode 124
versionName '4.2 beta 5'
multiDexEnabled true
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PutioApplication : MultiDexApplication() {

interface CastCallbacks {
fun load(file: PutioFile, url: String, utils: PutioUtils)
fun isCasting(): Boolean
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ abstract class BaseCastActivity : AppCompatActivity(), PutioApplication.CastCall
}

override fun load(file: PutioFile, url: String, utils: PutioUtils) {
if (CastOptionsProvider.isCastSdkAvailable(this) &&
castContext != null && castSession != null && castSession!!.remoteMediaClient != null && castSession!!.isConnected) {
if (isCasting()) {
fun play(subtitles: List<PutioSubtitle>? = null) {
val metaData = MediaMetadata(
if (file.isVideo)
Expand Down Expand Up @@ -106,6 +105,12 @@ abstract class BaseCastActivity : AppCompatActivity(), PutioApplication.CastCall
utils.getStreamUrlAndPlay(this, file, url)
}
}

override fun isCasting(): Boolean {
return CastOptionsProvider.isCastSdkAvailable(this) && castContext != null
&& castSession != null && castSession!!.remoteMediaClient != null
&& castSession!!.isConnected
}
}

val Context.isCastSdkAvailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class FileDetailsFragment : RxFragment() {
screenshotTitleScrimView.visibility = View.GONE
}

var lastDownloadStatus: FileDownload.Status? = null

val accessedView: TextView = findViewById(R.id.filedetails_accessed)
if (file.isAccessed) {
val accessed = PutioUtils.parseIsoTime(activity, file.firstAccessedAt)
Expand Down Expand Up @@ -211,7 +213,7 @@ class FileDetailsFragment : RxFragment() {
playMorePopup.show()
}
val playOriginalItem = playMorePopup.menu.add(R.string.stream_original).setOnMenuItemClickListener {
play(false)
play(false, lastDownloadStatus == FileDownload.Status.Downloaded)
true
}

Expand Down Expand Up @@ -256,7 +258,6 @@ class FileDetailsFragment : RxFragment() {
true
}

var lastDownloadStatus: FileDownload.Status? = null
val fileDownload = fileDownloads.getByFileId(file.id)
.bindToLifecycle(this)
.observeOn(AndroidSchedulers.mainThread())
Expand Down Expand Up @@ -296,7 +297,7 @@ class FileDetailsFragment : RxFragment() {
when (newMp4Status.status!!) {
PutioMp4Status.Status.AlreadyMp4 -> {
playActionView.text = getString(playMp4String)
playActionView.setOnClickListener { play(false) }
playActionView.setOnClickListener { play(false, downloadDone) }
setActionDrawable(playActionView, R.drawable.ic_filedetails_play)
playProgressBarView.visibility = View.INVISIBLE
playMoreView.visibility = View.GONE
Expand Down Expand Up @@ -331,7 +332,7 @@ class FileDetailsFragment : RxFragment() {
}
PutioMp4Status.Status.Completed -> {
playActionView.text = getString(playMp4String)
playActionView.setOnClickListener { play(true) }
playActionView.setOnClickListener { play(true, downloadDone && downloadedMp4) }
setActionDrawable(playActionView, R.drawable.ic_filedetails_play)
playProgressBarView.visibility = View.INVISIBLE
playMoreView.visibility = View.VISIBLE
Expand Down Expand Up @@ -413,9 +414,13 @@ class FileDetailsFragment : RxFragment() {
}
}

private fun play(mp4: Boolean) {
val url = file.getStreamUrl(putioApp.putioUtils!!, mp4)
castCallbacks?.load(file, url, putioApp.putioUtils!!)
private fun play(mp4: Boolean, downloaded: Boolean) {
if (downloaded && castCallbacks?.isCasting() != true) {
open()
} else {
val url = file.getStreamUrl(putioApp.putioUtils!!, mp4)
castCallbacks?.load(file, url, putioApp.putioUtils!!)
}
}

private fun download(mp4: Boolean = false) {
Expand Down

0 comments on commit 8f994dc

Please sign in to comment.