mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 13:50:30 +05:30
Merge pull request #5569 from Isira-Seneviratne/Collection
refactor: Avoid boxing for segment pair
This commit is contained in:
commit
939668d3b8
@ -98,6 +98,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.navigation.ui)
|
implementation(libs.androidx.navigation.ui)
|
||||||
implementation(libs.androidx.preference)
|
implementation(libs.androidx.preference)
|
||||||
implementation(libs.androidx.work.runtime)
|
implementation(libs.androidx.work.runtime)
|
||||||
|
implementation(libs.androidx.collection)
|
||||||
|
|
||||||
/* Android Lifecycle */
|
/* Android Lifecycle */
|
||||||
implementation(libs.lifecycle.viewmodel)
|
implementation(libs.lifecycle.viewmodel)
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.github.libretube.api.obj
|
package com.github.libretube.api.obj
|
||||||
|
|
||||||
|
import androidx.collection.FloatFloatPair
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.Transient
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Segment(
|
data class Segment(
|
||||||
@ -10,11 +12,12 @@ data class Segment(
|
|||||||
val category: String? = null,
|
val category: String? = null,
|
||||||
val description: String? = null,
|
val description: String? = null,
|
||||||
val locked: Int? = null,
|
val locked: Int? = null,
|
||||||
val segment: List<Double> = listOf(),
|
private val segment: List<Float> = listOf(),
|
||||||
val userID: String? = null,
|
val userID: String? = null,
|
||||||
val videoDuration: Double? = null,
|
val videoDuration: Double? = null,
|
||||||
val votes: Int? = null,
|
val votes: Int? = null,
|
||||||
var skipped: Boolean = false
|
var skipped: Boolean = false
|
||||||
) {
|
) {
|
||||||
val segmentStartAndEnd = segment[0] to segment[1]
|
@Transient
|
||||||
|
val segmentStartAndEnd = FloatFloatPair(segment[0], segment[1])
|
||||||
}
|
}
|
||||||
|
@ -550,11 +550,9 @@ object PlayerHelper {
|
|||||||
if ((duration - currentPosition).absoluteValue < 500) continue
|
if ((duration - currentPosition).absoluteValue < 500) continue
|
||||||
|
|
||||||
if (currentPosition in segmentStart until segmentEnd) {
|
if (currentPosition in segmentStart until segmentEnd) {
|
||||||
if (sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC ||
|
val key = sponsorBlockConfig[segment.category]
|
||||||
(
|
if (key == SbSkipOptions.AUTOMATIC ||
|
||||||
sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE &&
|
(key == SbSkipOptions.AUTOMATIC_ONCE && !segment.skipped)
|
||||||
!segment.skipped
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
if (sponsorBlockNotifications) {
|
if (sponsorBlockNotifications) {
|
||||||
runCatching {
|
runCatching {
|
||||||
@ -564,11 +562,8 @@ object PlayerHelper {
|
|||||||
}
|
}
|
||||||
seekTo(segmentEnd)
|
seekTo(segmentEnd)
|
||||||
segment.skipped = true
|
segment.skipped = true
|
||||||
} else if (sponsorBlockConfig[segment.category] == SbSkipOptions.MANUAL ||
|
} else if (key == SbSkipOptions.MANUAL ||
|
||||||
(
|
(key == SbSkipOptions.AUTOMATIC_ONCE && segment.skipped)
|
||||||
sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE &&
|
|
||||||
segment.skipped
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
return segment
|
return segment
|
||||||
}
|
}
|
||||||
|
@ -98,11 +98,10 @@ class VoteForSegmentDialog : DialogFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.segmentsDropdown.items = segments.map {
|
binding.segmentsDropdown.items = segments.map {
|
||||||
"${it.category} (${
|
val (start, end) = it.segmentStartAndEnd
|
||||||
DateUtils.formatElapsedTime(it.segmentStartAndEnd.first.toLong())
|
val (startStr, endStr) = DateUtils.formatElapsedTime(start.toLong()) to
|
||||||
} - ${
|
DateUtils.formatElapsedTime(end.toLong())
|
||||||
DateUtils.formatElapsedTime(it.segmentStartAndEnd.second.toLong())
|
"${it.category} ($startStr - $endStr)"
|
||||||
})"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1142,7 +1142,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
val durationWithoutSegments = duration - segments.sumOf {
|
val durationWithoutSegments = duration - segments.sumOf {
|
||||||
val (start, end) = it.segmentStartAndEnd
|
val (start, end) = it.segmentStartAndEnd
|
||||||
end - start
|
end.toDouble() - start.toDouble()
|
||||||
}.toLong()
|
}.toLong()
|
||||||
val durationString = DateUtils.formatElapsedTime(duration)
|
val durationString = DateUtils.formatElapsedTime(duration)
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class MarkableTimeBar(
|
|||||||
canvas.restore()
|
canvas.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Double.toLength(): Int {
|
private fun Float.toLength(): Int {
|
||||||
return (this * 1000 / player!!.duration * length).toInt()
|
return (this * 1000 / player!!.duration * length).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ benchmarkMacroJunit4 = "1.2.3"
|
|||||||
baselineprofile = "1.2.3"
|
baselineprofile = "1.2.3"
|
||||||
profileinstaller = "1.3.1"
|
profileinstaller = "1.3.1"
|
||||||
paging = "3.2.1"
|
paging = "3.2.1"
|
||||||
|
collection = "1.4.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-activity = { group = "androidx.activity", name = "activity-ktx", version.ref = "activity" }
|
androidx-activity = { group = "androidx.activity", name = "activity-ktx", version.ref = "activity" }
|
||||||
@ -74,6 +75,7 @@ androidx-uiautomator = { group = "androidx.test.uiautomator", name = "uiautomato
|
|||||||
androidx-benchmark-macro-junit4 = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "benchmarkMacroJunit4" }
|
androidx-benchmark-macro-junit4 = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "benchmarkMacroJunit4" }
|
||||||
androidx-profileinstaller = { group = "androidx.profileinstaller", name = "profileinstaller", version.ref = "profileinstaller" }
|
androidx-profileinstaller = { group = "androidx.profileinstaller", name = "profileinstaller", version.ref = "profileinstaller" }
|
||||||
androidx-paging = { group = "androidx.paging", name = "paging-runtime-ktx", version.ref = "paging" }
|
androidx-paging = { group = "androidx.paging", name = "paging-runtime-ktx", version.ref = "paging" }
|
||||||
|
androidx-collection = { group = "androidx.collection", name = "collection", version.ref = "collection" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
androidTest = { id = "com.android.test", version.ref = "gradle" }
|
androidTest = { id = "com.android.test", version.ref = "gradle" }
|
||||||
|
Loading…
Reference in New Issue
Block a user