Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
See https://blog.gradle.org/guava for the new plugin.

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
  • Loading branch information
mueller-ma committed Sep 15, 2020
1 parent 1e8b46e commit 7bfbd58
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
5 changes: 5 additions & 0 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ buildscript {
mavenCentral()
google()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.google.gms:google-services:4.3.3"
classpath "com.google.firebase:firebase-crashlytics-gradle:2.3.0"
classpath 'de.mobilej.unmock:UnMockPlugin:0.7.6'
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:$about_libraries_version"
classpath "de.jjohannes.gradle:missing-metadata-guava:0.1"
}
}

Expand All @@ -28,6 +32,7 @@ apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: 'de.mobilej.unmock'
apply plugin: "com.mikepenz.aboutlibraries.plugin"
apply plugin: "de.jjohannes.missing-metadata-guava"
if (!isFoss) {
apply plugin: "com.google.gms.google-services"
apply plugin: "com.google.firebase.crashlytics"
Expand Down
37 changes: 17 additions & 20 deletions mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.core.net.toUri
import androidx.core.view.children
import androidx.core.view.get
import androidx.core.view.isGone
Expand All @@ -55,10 +54,11 @@ import com.flask.colorpicker.ColorPickerView
import com.flask.colorpicker.OnColorChangedListener
import com.flask.colorpicker.OnColorSelectedListener
import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.analytics.AnalyticsListener
import com.google.android.exoplayer2.source.MediaSourceEventListener
import com.google.android.exoplayer2.source.LoadEventInfo
import com.google.android.exoplayer2.source.MediaLoadData
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.upstream.DataSource
Expand Down Expand Up @@ -989,17 +989,13 @@ class WidgetAdapter(
}

override fun onStart() {
if (itemView.context.determineDataUsagePolicy().autoPlayVideos &&
exoPlayer.playbackState != Player.STATE_IDLE
) {
exoPlayer.playWhenReady = true
if (itemView.context.determineDataUsagePolicy().autoPlayVideos) {
exoPlayer.play()
}
}

override fun onStop() {
if (exoPlayer.playbackState != Player.STATE_IDLE) {
exoPlayer.playWhenReady = false
}
exoPlayer.pause()
}

private fun loadVideo(widget: Widget, forceReload: Boolean) {
Expand All @@ -1020,18 +1016,17 @@ class WidgetAdapter(
}
val factory = if (isHls) {
playerView.useController = false
HlsMediaSource.Factory(this).setTag(url)
HlsMediaSource.Factory(this)
} else {
playerView.useController = true
ProgressiveMediaSource.Factory(this).setTag(url)
ProgressiveMediaSource.Factory(this)
}

val mediaSource = url?.let { factory.createMediaSource(it.toUri()) }
val mediaItem = url?.let { MediaItem.fromUri(it) }
val mediaSource = mediaItem?.let { factory.createMediaSource(it) }

if (exoPlayer.currentTag == mediaSource?.tag && !forceReload) {
if (!exoPlayer.isPlaying) {
exoPlayer.playWhenReady = true
}
if (exoPlayer.currentMediaItem == mediaItem && !forceReload) {
exoPlayer.play()
return
}

Expand All @@ -1040,17 +1035,19 @@ class WidgetAdapter(
return
}

exoPlayer.prepare(mediaSource)
exoPlayer.setMediaSource(mediaSource)
exoPlayer.prepare()
exoPlayer.addAnalyticsListener(this)
}

override fun onLoadError(
eventTime: AnalyticsListener.EventTime,
loadEventInfo: MediaSourceEventListener.LoadEventInfo,
mediaLoadData: MediaSourceEventListener.MediaLoadData,
loadEventInfo: LoadEventInfo,
mediaLoadData: MediaLoadData,
error: IOException,
wasCanceled: Boolean
) {
super.onLoadError(eventTime, loadEventInfo, mediaLoadData, error, wasCanceled)
Log.e(TAG, "onLoadError()", error)
handleError()
}
Expand Down

0 comments on commit 7bfbd58

Please sign in to comment.