Skip to content

Commit

Permalink
Fix opening downloaded non-MP4 videos, fix analytics logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Oct 1, 2017
1 parent 29c0d86 commit 4c4373e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 75 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
applicationId 'com.stevenschoen.putionew'
minSdkVersion 19
targetSdkVersion 26
versionCode 125
versionCode 126
versionName '4.2'
multiDexEnabled true
}
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
<activity
android:name=".LoginActivity"
android:theme="@style/Theme.Putio.Login"/>
<activity
android:name=".files.FileFinishedActivity"
android:label="@string/downloadfinishedopentitle"
android:theme="@style/Putio.Dialog"/>
<activity
android:name=".transfers.add.AddTransferActivity"
android:excludeFromRecents="true"
Expand Down
35 changes: 18 additions & 17 deletions app/src/main/java/com/stevenschoen/putionew/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,51 @@ class Analytics(context: Context) {

fun logViewedFile(file: PutioFile) {
makeFileBundle(file)
.log(FirebaseAnalytics.Event.VIEW_ITEM)
.logEvent(FirebaseAnalytics.Event.VIEW_ITEM)
}

fun logBrowsedToFolder(folder: PutioFile) {
makeFolderBundle(folder)
.log(Event.VIEW_FOLDER)
.logEvent(Event.VIEW_FOLDER)
}

fun logSearched(query: String) {
Bundle().putString(FirebaseAnalytics.Param.SEARCH_TERM, query)
.log(FirebaseAnalytics.Event.SEARCH)
Bundle().apply {
putString(FirebaseAnalytics.Param.SEARCH_TERM, query)
}.logEvent(FirebaseAnalytics.Event.SEARCH)
}

fun logStartedFileDownload(file: PutioFile) {
makeFileBundle(file)
.log(Event.DOWNLOAD_ITEM)
.logEvent(Event.DOWNLOAD_ITEM)
}

fun logStartedVideoDownload(video: PutioFile, mp4: Boolean) {
makeFileBundle(video)
.putBoolean(Param.MP4_SELECTED, mp4)
.log(Event.DOWNLOAD_ITEM)
makeFileBundle(video).apply {
putBoolean(Param.MP4_SELECTED, mp4)
}.logEvent(Event.DOWNLOAD_ITEM)
}

fun logDownloadFinished(file: PutioFile) {
makeFileBundle(file)
.log(Event.FINISH_DOWNLOAD)
.logEvent(Event.FINISH_DOWNLOAD)
}

fun logOpenedDownloadedFile(file: PutioFile) {
makeFileBundle(file)
.log(Event.OPEN_DOWNLOADED_FILE)
.logEvent(Event.OPEN_DOWNLOADED_FILE)
}

fun logOpenedDownloadedVideo(video: PutioFile, mp4: Boolean) {
makeFileBundle(video)
.putBoolean(Param.MP4_SELECTED, mp4)
.log(Event.OPEN_DOWNLOADED_VIDEO)
makeFileBundle(video).apply {
putBoolean(Param.MP4_SELECTED, mp4)
}.logEvent(Event.OPEN_DOWNLOADED_VIDEO)
}

fun logStreamedVideo(video: PutioFile, mp4: Boolean) {
makeFileBundle(video)
.putBoolean(Param.MP4_SELECTED, mp4)
.log(Event.STREAM_VIDEO)
makeFileBundle(video).apply {
putBoolean(Param.MP4_SELECTED, mp4)
}.logEvent(Event.STREAM_VIDEO)
}

private fun makeFileBundle(file: PutioFile) = Bundle().apply { addBasicFileInfo(file) }
Expand All @@ -88,7 +89,7 @@ class Analytics(context: Context) {
putString(FirebaseAnalytics.Param.ITEM_NAME, file.name)
}

private fun Bundle.log(event: String) = putioApp.firebaseAnalytics.logEvent(event, this)
private fun Bundle.logEvent(event: String) = putioApp.firebaseAnalytics.logEvent(event, this)
}

val Context.analytics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class DownloadFinishedService : JobIntentService() {
status = FileDownload.Status.Downloaded
uri = downloadManager.getUriForDownloadedFile(downloadId).toString()
})

putioApp.fileDownloadDatabase.fileDownloadsDao()
.getByDownloadId(downloadId)
.map { it.fileId }
.flatMapSingle(putioApp.putioUtils!!.restInterface::file)
.map { it.file }
.subscribe(analytics::logDownloadFinished)
}
}

putioApp.fileDownloadDatabase.fileDownloadsDao()
.getByDownloadId(downloadId)
.map { it.fileId }
.flatMapSingle(putioApp.putioUtils!!.restInterface::file)
.map { it.file }
.subscribe(analytics::logDownloadFinished)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ 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 @@ -213,7 +211,17 @@ class FileDetailsFragment : RxFragment() {
playMorePopup.show()
}
val playOriginalItem = playMorePopup.menu.add(R.string.stream_original).setOnMenuItemClickListener {
play(false, lastDownloadStatus == FileDownload.Status.Downloaded)
Single.fromCallable {
fileDownloads.getByFileIdSynchronous(file.id)!!
}.subscribeOn(Schedulers.io())
.bindToLifecycle(this@FileDetailsFragment)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ fileDownload ->
play(false, fileDownload.status == FileDownload.Status.Downloaded
&& fileDownload.downloadedMp4 != true)
}, { error ->
PutioUtils.getRxJavaThrowable(error).printStackTrace()
})
true
}

Expand Down Expand Up @@ -266,6 +274,7 @@ class FileDetailsFragment : RxFragment() {
null, FileDownload.Status.NotDownloaded, null, null))
val downloadStatus = fileDownload
.map { it.status }
var lastDownloadStatus: FileDownload.Status? = null
var lastMp4PercentDone = 0

data class DownloadAndMp4Status(
Expand Down

This file was deleted.

0 comments on commit 4c4373e

Please sign in to comment.