mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
some bug fixes
This commit is contained in:
parent
7d993fcd5c
commit
587a3ba9ac
@ -14,7 +14,7 @@ import com.github.libretube.obj.WatchPosition
|
||||
SearchHistoryItem::class,
|
||||
CustomInstance::class
|
||||
],
|
||||
version = 5
|
||||
version = 6
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
/**
|
||||
|
@ -26,10 +26,11 @@ class CustomInstanceDialog : DialogFragment() {
|
||||
}
|
||||
|
||||
binding.addInstance.setOnClickListener {
|
||||
val customInstance = CustomInstance()
|
||||
customInstance.name = binding.instanceName.text.toString()
|
||||
customInstance.apiUrl = binding.instanceApiUrl.text.toString()
|
||||
customInstance.frontendUrl = binding.instanceFrontendUrl.text.toString()
|
||||
val customInstance = CustomInstance(
|
||||
name = binding.instanceName.text.toString(),
|
||||
apiUrl = binding.instanceApiUrl.text.toString(),
|
||||
frontendUrl = binding.instanceFrontendUrl.text.toString()
|
||||
)
|
||||
|
||||
if (
|
||||
customInstance.name != "" &&
|
||||
|
@ -5,42 +5,36 @@ import android.view.ViewTreeObserver
|
||||
import android.widget.LinearLayout
|
||||
import com.github.libretube.database.DatabaseHolder
|
||||
import com.github.libretube.extensions.await
|
||||
import com.github.libretube.obj.WatchPosition
|
||||
|
||||
/**
|
||||
* shows the already watched time under the video
|
||||
*/
|
||||
fun View?.setWatchProgressLength(videoId: String, duration: Long) {
|
||||
val view = this!!
|
||||
var positions = listOf<WatchPosition>()
|
||||
var newWidth: Long? = null
|
||||
var progress: Long? = null
|
||||
|
||||
Thread {
|
||||
positions = DatabaseHolder.database.watchPositionDao().getAll()
|
||||
try {
|
||||
progress = DatabaseHolder.database.watchPositionDao().findById(videoId).position
|
||||
} catch (e: Exception) {
|
||||
progress = null
|
||||
}
|
||||
}.await()
|
||||
|
||||
view.getViewTreeObserver()
|
||||
.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
this@setWatchProgressLength.getViewTreeObserver().removeOnGlobalLayoutListener(this)
|
||||
positions.forEach {
|
||||
if (it.videoId == videoId) {
|
||||
val fullWidth = (parent as LinearLayout).width
|
||||
if (duration != 0L) newWidth =
|
||||
(fullWidth * (it.position / (duration))) / 1000
|
||||
return@forEach
|
||||
}
|
||||
}
|
||||
if (newWidth != null) {
|
||||
val lp = view.layoutParams
|
||||
lp.apply {
|
||||
width = newWidth!!.toInt()
|
||||
}
|
||||
view.layoutParams = lp
|
||||
view.visibility = View.VISIBLE
|
||||
} else {
|
||||
if (progress == null) {
|
||||
view.visibility = View.GONE
|
||||
return
|
||||
}
|
||||
val fullWidth = (parent as LinearLayout).width
|
||||
val newWidth = (fullWidth * (progress!! / (duration))) / 1000
|
||||
val lp = view.layoutParams
|
||||
lp.width = newWidth.toInt()
|
||||
view.layoutParams = lp
|
||||
view.visibility = View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ import com.github.libretube.obj.ChapterSegment
|
||||
import com.github.libretube.obj.Segment
|
||||
import com.github.libretube.obj.Segments
|
||||
import com.github.libretube.obj.Streams
|
||||
import com.github.libretube.obj.WatchPosition
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
import com.github.libretube.preferences.PreferenceKeys
|
||||
import com.github.libretube.services.BackgroundMode
|
||||
@ -936,17 +935,14 @@ class PlayerFragment : BaseFragment() {
|
||||
|
||||
private fun seekToWatchPosition() {
|
||||
// seek to saved watch position if available
|
||||
var watchPositions = listOf<WatchPosition>()
|
||||
Thread {
|
||||
watchPositions = DatabaseHolder.database.watchPositionDao().getAll()
|
||||
}.await()
|
||||
var position: Long? = null
|
||||
watchPositions.forEach {
|
||||
if (it.videoId == videoId &&
|
||||
// don't seek to the position if it's the end, autoplay would skip it immediately
|
||||
streams.duration!! - it.position / 1000 > 2
|
||||
) position = it.position
|
||||
}
|
||||
Thread {
|
||||
try {
|
||||
position = DatabaseHolder.database.watchPositionDao().findById(videoId!!).position
|
||||
} catch (e: Exception) {
|
||||
position = null
|
||||
}
|
||||
}.await()
|
||||
// support for time stamped links
|
||||
val timeStamp: Long? = arguments?.getLong("timeStamp")
|
||||
if (timeStamp != null && timeStamp != 0L) {
|
||||
|
@ -6,8 +6,7 @@ import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "customInstance")
|
||||
class CustomInstance(
|
||||
@PrimaryKey(autoGenerate = true) var id: Int = 0,
|
||||
@ColumnInfo var name: String = "",
|
||||
@PrimaryKey var name: String = "",
|
||||
@ColumnInfo var apiUrl: String = "",
|
||||
@ColumnInfo var frontendUrl: String = ""
|
||||
)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.preferences
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
|
Loading…
Reference in New Issue
Block a user