Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bengelhaupt committed Jul 18, 2021
1 parent 6cb500f commit 8b04b13
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ abstract class BaseDownloadTest : BaseTest() {
@Rule
@JvmField
var permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ abstract class DownloadHandlerTest<T : DownloadHandler<I, R>,

// wait for download to start
waitWhile({
status?.state?.equals(DownloadStatus.State.DELETED) != false ||
(status?.state?.equals(DownloadStatus.State.PENDING) != true &&
status?.state?.equals(DownloadStatus.State.RUNNING) != true)
status?.state?.equals(DownloadStatus.State.DELETED) != false || (
status?.state?.equals(DownloadStatus.State.PENDING) != true &&
status?.state?.equals(DownloadStatus.State.RUNNING) != true
)
})

// test status after start
Expand Down Expand Up @@ -179,7 +180,7 @@ abstract class DownloadHandlerTest<T : DownloadHandler<I, R>,

var downloaded = false
downloadHandler.listen(downloadHandler.identify(successfulTestRequest)) {
if(it.state == DownloadStatus.State.DOWNLOADED){
if (it.state == DownloadStatus.State.DOWNLOADED) {
downloaded = true
}
}
Expand All @@ -195,7 +196,7 @@ abstract class DownloadHandlerTest<T : DownloadHandler<I, R>,
// wait for result
waitWhile({ nextCount == null }, 1000)

assertEquals(count!! + 1, nextCount);
assertEquals(count!! + 1, nextCount)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ abstract class AbstractHlsVideoDownloadHandlerTest : DownloadHandlerTest<HlsVide

override val successfulTestRequest
get() = HlsVideoDownloadRequest(
"https://open.hpi.de/playlists/93a84211-e40a-416a-b224-4d3ecdbb12f9.m3u8?embed_subtitles_for_video=d7e056da-756f-4437-b64a-16970a33d5ef",
"https://open.hpi.de/playlists/93a84211-e40a-416a-b224-4d3ecdbb12f9.m3u8?" +
"embed_subtitles_for_video=d7e056da-756f-4437-b64a-16970a33d5ef",
VideoSettingsHelper.VideoQuality.LOW.qualityFraction,
context.preferredStorage,
"Video 1",
true,
DownloadCategory.Other
)
override val successfulTestRequest2 = HlsVideoDownloadRequest(
"https://open.hpi.de/playlists/04012fde-be48-47b6-a742-0edc69a9c2a9.m3u8?embed_subtitles_for_video=d7e056da-756f-4437-b64a-16970a33d5ef",
"https://open.hpi.de/playlists/04012fde-be48-47b6-a742-0edc69a9c2a9.m3u8?" +
"embed_subtitles_for_video=d7e056da-756f-4437-b64a-16970a33d5ef",
VideoSettingsHelper.VideoQuality.BEST.qualityFraction,
context.preferredStorage,
"Video 2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ abstract class AbstractHlsVideoDownloadItemTest : DownloadItemTest<HlsVideoDownl

override val testDownloadItem
get() = HlsVideoDownloadItem(
"https://open.hpi.de/playlists/93a84211-e40a-416a-b224-4d3ecdbb12f9.m3u8?embed_subtitles_for_video=d7e056da-756f-4437-b64a-16970a33d5ef",
"https://open.hpi.de/playlists/93a84211-e40a-416a-b224-4d3ecdbb12f9.m3u8?" +
"embed_subtitles_for_video=d7e056da-756f-4437-b64a-16970a33d5ef",
DownloadCategory.Other,
VideoSettingsHelper.VideoQuality.HIGH.qualityFraction,
emptyMap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class DownloadViewHelper(
DownloadStatus.State.DOWNLOADED -> showEndState()
DownloadStatus.State.DELETED -> {
showStartState()
if(status.error != null){
if (status.error != null) {
activity.showToast(R.string.error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ open class VideoStreamPlayerFragment : BaseFragment() {
}
VideoSettingsHelper.PlaybackMode.LOW -> {
playerView.setHLSVideoUri(Uri.parse(videoStream.hlsUrl))
playerView.setDesiredQuality(VideoSettingsHelper.VideoQuality.LOW.qualityFraction)
playerView.setDesiredQuality(
VideoSettingsHelper.VideoQuality.LOW.qualityFraction
)
}
VideoSettingsHelper.PlaybackMode.MEDIUM -> {
playerView.setHLSVideoUri(Uri.parse(videoStream.hlsUrl))
Expand All @@ -612,11 +614,15 @@ open class VideoStreamPlayerFragment : BaseFragment() {
}
VideoSettingsHelper.PlaybackMode.HIGH -> {
playerView.setHLSVideoUri(Uri.parse(videoStream.hlsUrl))
playerView.setDesiredQuality(VideoSettingsHelper.VideoQuality.HIGH.qualityFraction)
playerView.setDesiredQuality(
VideoSettingsHelper.VideoQuality.HIGH.qualityFraction
)
}
VideoSettingsHelper.PlaybackMode.BEST -> {
playerView.setHLSVideoUri(Uri.parse(videoStream.hlsUrl))
playerView.setDesiredQuality(VideoSettingsHelper.VideoQuality.BEST.qualityFraction)
playerView.setDesiredQuality(
VideoSettingsHelper.VideoQuality.BEST.qualityFraction
)
}
VideoSettingsHelper.PlaybackMode.LEGACY_HD -> {
playerView.setProgressiveVideoUri(Uri.parse(videoStream.hdUrl))
Expand Down Expand Up @@ -842,12 +848,7 @@ open class VideoStreamPlayerFragment : BaseFragment() {
if (setVideo(videoSettingsHelper.currentMode)) {
updateSubtitles()
updatePlaybackSpeed()
if (isOfflineVideo) {
// ToDo
/*playerView.uri?.let {
playerView.setPreviewUri(it)
}*/
} else if (context.isOnline) {
if (!isOfflineVideo && context.isOnline) {
if (videoStream.sdUrl != null) {
playerView.setPreviewUri(Uri.parse(videoStream.sdUrl))
} else if (videoStream.hdUrl != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,11 @@ object HlsVideoDownloadHandler :
}
val closestBitrate = closestFormat?.bitrate

val estimatedSize = (closestFormat?.averageBitrate
?.takeUnless { it == Format.NO_VALUE }
?: closestBitrate)
val estimatedSize = (
closestFormat?.averageBitrate
?.takeUnless { it == Format.NO_VALUE }
?: closestBitrate
)
?.times(manifest.mediaPlaylist.durationUs)
?.div(8000000) // to bytes and seconds

Expand Down Expand Up @@ -274,15 +276,17 @@ object HlsVideoDownloadHandler :
if (request.storage == context.internalStorage) {
Log.i(
TAG,
"Starting downloading to internal storage: ${request.url} aka $identifier"
"Starting downloading to internal storage: " +
"${request.url} aka $identifier"
)
HlsVideoDownloadInternalStorageForegroundService::class.java
} else if (request.storage == context.sdcardStorage &&
getSdcardStorageCache(context) != null
) {
Log.i(
TAG,
"Starting downloading to sdcard storage: ${request.url} aka $identifier"
"Starting downloading to sdcard storage: " +
"${request.url} aka $identifier"
)
HlsVideoDownloadSdcardStorageForegroundService::class.java
} else {
Expand Down Expand Up @@ -409,7 +413,8 @@ object HlsVideoDownloadHandler :
private fun getDownloadStatus(download: Download?): DownloadStatus {
if (download == null) {
Log.w(
TAG, "getDownloadStatus(): Download not found, default status is generated: " +
TAG,
"getDownloadStatus(): Download not found, default status is generated: " +
"${download?.request?.id}"
)
return DownloadStatus(null, null, DownloadStatus.State.DELETED, null)
Expand All @@ -423,7 +428,9 @@ object HlsVideoDownloadHandler :
?: download.bytesDownloaded * 100 / download.percentDownloaded
}.toLong()
val state = when (download.state) {
Download.STATE_QUEUED, Download.STATE_RESTARTING, Download.STATE_REMOVING -> DownloadStatus.State.PENDING
Download.STATE_QUEUED,
Download.STATE_RESTARTING,
Download.STATE_REMOVING -> DownloadStatus.State.PENDING
Download.STATE_DOWNLOADING -> DownloadStatus.State.RUNNING
Download.STATE_COMPLETED -> DownloadStatus.State.DOWNLOADED
else -> DownloadStatus.State.DELETED
Expand All @@ -434,8 +441,9 @@ object HlsVideoDownloadHandler :
} else null

Log.d(
TAG, "getDownloadStatus(): Generated download status [${state.name}]" +
"${downloaded}/${totalSize} B (error: ${error}) for ${download.request.id}"
TAG,
"getDownloadStatus(): Generated download status [${state.name}]" +
"$downloaded/$totalSize B (error: ${error}) for ${download.request.id}"
)
return DownloadStatus(totalSize, downloaded, state, error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ open class HlsVideoDownloadItem(
)
}

private fun getMediaSource(storage: Storage): Pair<HlsMediaSource, Map<String, SingleSampleMediaSource>>? {
private fun getMediaSource(storage: Storage)
: Pair<HlsMediaSource, Map<String, SingleSampleMediaSource>>? {
return getIndexEntry(storage)?.let { indexEntry ->
HlsMediaSource.Factory(
CacheDataSource.Factory()
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/de/xikolo/models/Video.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ open class Video : RealmObject() {
val streamToPlay: VideoStream?
get() {
return if (singleStream != null && (
singleStream?.hlsUrl != null || singleStream?.hdUrl != null ||
singleStream?.hlsUrl != null ||
singleStream?.hdUrl != null ||
singleStream?.sdUrl != null
)
) {
singleStream
} else if (lecturerStream != null && (
lecturerStream?.hlsUrl != null || lecturerStream?.hdUrl != null ||
lecturerStream?.hlsUrl != null ||
lecturerStream?.hdUrl != null ||
lecturerStream?.sdUrl != null
)
) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/de/xikolo/views/ExoPlayerVideoView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ open class ExoPlayerVideoView : PlayerView {
false
}
}
} finally {
mediaMetadataRetriever?.release()
}
}
previewPrepareThread.start()
Expand Down

0 comments on commit 8b04b13

Please sign in to comment.