File tree Expand file tree Collapse file tree
main/java/com/theoplayer/android/ui
test/java/com/theoplayer/android/ui/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,23 +71,3 @@ fun rememberTrackLabel(
7171): String = remember(key1 = track.id, key2 = track.uid) {
7272 constructLabel(track) ? : resources.getString(R .string.theoplayer_ui_track_unknown)
7373}
74-
75- /* *
76- * Memoize the most recent call.
77- */
78- internal inline fun <P , R > memoizeLast (crossinline transform : (P ) -> R ): (P ) -> R {
79- return object : (P ) -> R {
80- private var lastCall: Pair <P , R >? = null
81-
82- override fun invoke (input : P ): R {
83- val lastCall = this .lastCall
84- return if (lastCall != null && lastCall.first == input) {
85- lastCall.second
86- } else {
87- transform(input).also { output ->
88- this .lastCall = input to output
89- }
90- }
91- }
92- }
93- }
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import com.theoplayer.android.api.player.track.texttrack.TextTrack
99internal val TextTrack .captionChannelCompat: Int?
1010 get() {
1111 // TextTrack.getCaptionChannel was added in THEOplayer 10.13.0.
12- return if (theoplayerVersion >= version1013) {
12+ return if (THEOplayerGlobalExt .version >= version1013) {
1313 TheoPlayer1013Impl .getTextTrackCaptionChannel(this )
1414 } else null
1515 }
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ internal fun constructLabel(
5252): String? {
5353 val label: String? = if (
5454 (track is TextTrack ) &&
55- theoplayerVersion .major < 11 &&
55+ THEOplayerGlobalExt .version .major < 11 &&
5656 (isLabelCeaFormatted(track.label) || (track.label != null && track.language == track.label))
5757 ) {
5858 // If we are below 11th major release
Original file line number Diff line number Diff line change 11package com.theoplayer.android.ui.util
22
33import com.theoplayer.android.api.THEOplayerGlobal
4- import com.theoplayer.android.ui.memoizeLast
54
65private const val VERSION_DELIMITER = ' .'
76
@@ -55,10 +54,9 @@ internal data class Version(
5554 }
5655}
5756
58- private val getCachedTheoplayerVersion = memoizeLast(Version ::parse)
59-
60- /* *
61- * Returns the major version of THEOplayer.
62- */
63- internal val theoplayerVersion: Version
64- get() = getCachedTheoplayerVersion(THEOplayerGlobal .getVersion())
57+ internal object THEOplayerGlobalExt {
58+ /* *
59+ * Returns the version of THEOplayer, as a [Version].
60+ */
61+ val version: Version by lazy { Version .parse(THEOplayerGlobal .getVersion()) }
62+ }
Original file line number Diff line number Diff line change 11package com.theoplayer.android.ui.util
22
3- import com.theoplayer.android.api.THEOplayerGlobal
43import com.theoplayer.android.api.player.track.Track
54import com.theoplayer.android.api.player.track.texttrack.TextTrack
65import com.theoplayer.android.api.player.track.texttrack.TextTrackType
6+ import io.mockk.clearMocks
77import io.mockk.clearStaticMockk
88import io.mockk.every
99import io.mockk.mockk
10+ import io.mockk.mockkObject
1011import io.mockk.mockkStatic
1112import org.junit.After
1213import org.junit.Assert
@@ -100,8 +101,8 @@ class TrackExtsTest {
100101
101102 @Before
102103 fun setUp () {
103- mockkStatic( THEOplayerGlobal :: class )
104- every { THEOplayerGlobal .getVersion() } returns args.playerVersion
104+ mockkObject( THEOplayerGlobalExt )
105+ every { THEOplayerGlobalExt .version } returns Version .parse( args.playerVersion)
105106
106107 every { track.type } returns TextTrackType .CEA608
107108 every { track.label } returns args.label
@@ -114,7 +115,7 @@ class TrackExtsTest {
114115
115116 @After
116117 fun tearDown () {
117- clearStaticMockk( THEOplayerGlobal :: class )
118+ clearMocks( THEOplayerGlobalExt )
118119 clearStaticMockk(Track ::localizedLanguageName)
119120 }
120121
You can’t perform that action at this time.
0 commit comments