mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
commit
6e25546170
@ -202,6 +202,8 @@ class MainActivity : AppCompatActivity() {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
playlistId = playlistId.replace("list=", "")
|
||||
}
|
||||
|
||||
loadPlaylist(playlistId)
|
||||
|
@ -31,7 +31,7 @@ class UpdateAvailableDialog(
|
||||
}
|
||||
}
|
||||
|
||||
class NoUpdateAvailableDialog() : DialogFragment() {
|
||||
class NoUpdateAvailableDialog : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
|
@ -249,7 +249,7 @@ class PlayerFragment : Fragment() {
|
||||
|
||||
playbackSpeed = PreferenceHelper.getString(
|
||||
PreferenceKeys.PLAYBACK_SPEED,
|
||||
"1F"
|
||||
"1"
|
||||
)!!
|
||||
|
||||
fullscreenOrientationPref = PreferenceHelper.getString(
|
||||
@ -480,6 +480,7 @@ class PlayerFragment : Fragment() {
|
||||
val playbackSpeedValues =
|
||||
context?.resources?.getStringArray(R.array.playbackSpeedValues)!!
|
||||
exoPlayer.setPlaybackSpeed(playbackSpeed.toFloat())
|
||||
Log.e(TAG, playbackSpeed)
|
||||
val speedIndex = playbackSpeedValues.indexOf(playbackSpeed)
|
||||
playerBinding.speedText.text = playbackSpeeds[speedIndex]
|
||||
|
||||
@ -1124,12 +1125,6 @@ class PlayerFragment : Fragment() {
|
||||
private val hideForwardButtonRunnable = Runnable { binding.forwardBTN.visibility = View.GONE }
|
||||
private val hideRewindButtonRunnable = Runnable { binding.rewindBTN.visibility = View.GONE }
|
||||
|
||||
private fun disableDoubleTapToSeek() {
|
||||
// disable fast forward and rewind by double tapping
|
||||
binding.forwardFL.visibility = View.GONE
|
||||
binding.rewindFL.visibility = View.GONE
|
||||
}
|
||||
|
||||
// enable seek bar preview
|
||||
private fun enableSeekbarPreview() {
|
||||
playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener {
|
||||
@ -1456,6 +1451,7 @@ class PlayerFragment : Fragment() {
|
||||
|
||||
// lock the player
|
||||
private fun lockPlayer(isLocked: Boolean) {
|
||||
// isLocked is the current (old) state of the player lock
|
||||
val visibility = if (isLocked) View.VISIBLE else View.GONE
|
||||
|
||||
playerBinding.exoTopBarRight.visibility = visibility
|
||||
@ -1474,7 +1470,15 @@ class PlayerFragment : Fragment() {
|
||||
) View.VISIBLE else View.GONE
|
||||
|
||||
// disable double tap to seek when the player is locked
|
||||
if (isLocked) enableDoubleTapToSeek() else disableDoubleTapToSeek()
|
||||
if (isLocked) {
|
||||
// enable fast forward and rewind by double tapping
|
||||
binding.forwardFL.visibility = View.VISIBLE
|
||||
binding.rewindFL.visibility = View.VISIBLE
|
||||
} else {
|
||||
// disable fast forward and rewind by double tapping
|
||||
binding.forwardFL.visibility = View.GONE
|
||||
binding.rewindFL.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSubscribed(button: MaterialButton, channel_id: String) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
// data class for the update info, required to return the data
|
||||
data class UpdateInfo(
|
||||
data class VersionInfo(
|
||||
val updateUrl: String,
|
||||
val tagName: String
|
||||
)
|
@ -8,9 +8,15 @@ import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.github.libretube.BuildConfig
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.activities.SettingsActivity
|
||||
import com.github.libretube.dialogs.RequireRestartDialog
|
||||
import com.github.libretube.dialogs.UpdateAvailableDialog
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.github.libretube.util.checkUpdate
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MainSettings : PreferenceFragmentCompat() {
|
||||
val TAG = "SettingsFragment"
|
||||
@ -78,9 +84,35 @@ class MainSettings : PreferenceFragmentCompat() {
|
||||
}
|
||||
|
||||
val update = findPreference<Preference>("update")
|
||||
update?.title = getString(R.string.version, BuildConfig.VERSION_NAME)
|
||||
|
||||
// set the version of the update preference
|
||||
val versionString = if (BuildConfig.DEBUG) "${BuildConfig.VERSION_NAME} Debug"
|
||||
else getString(R.string.version, BuildConfig.VERSION_NAME)
|
||||
update?.title = versionString
|
||||
|
||||
update?.setOnPreferenceClickListener {
|
||||
checkUpdate(childFragmentManager)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
// check for update
|
||||
val versionInfo = checkUpdate()
|
||||
if (versionInfo?.tagName != "" && BuildConfig.VERSION_NAME != versionInfo?.tagName) {
|
||||
// show the UpdateAvailableDialog if there's an update available
|
||||
val updateAvailableDialog = UpdateAvailableDialog(
|
||||
versionInfo!!.tagName,
|
||||
versionInfo.updateUrl
|
||||
)
|
||||
updateAvailableDialog.show(childFragmentManager, "UpdateAvailableDialog")
|
||||
} else {
|
||||
// otherwise show the no update available snackBar
|
||||
val settingsActivity = activity as SettingsActivity
|
||||
val snackBar = Snackbar
|
||||
.make(
|
||||
settingsActivity.binding.root,
|
||||
R.string.app_uptodate,
|
||||
Snackbar.LENGTH_SHORT
|
||||
)
|
||||
snackBar.show()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.github.libretube.BuildConfig
|
||||
import com.github.libretube.GITHUB_API_URL
|
||||
import com.github.libretube.dialogs.NoUpdateAvailableDialog
|
||||
import com.github.libretube.dialogs.UpdateAvailableDialog
|
||||
import com.github.libretube.obj.UpdateInfo
|
||||
import com.github.libretube.obj.VersionInfo
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.BufferedReader
|
||||
@ -14,34 +10,25 @@ import java.io.InputStreamReader
|
||||
import java.net.URL
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
||||
fun checkUpdate(childFragmentManager: FragmentManager) {
|
||||
var updateInfo: UpdateInfo? = UpdateInfo("", "")
|
||||
fun checkUpdate(): VersionInfo? {
|
||||
var versionInfo: VersionInfo? = VersionInfo("", "")
|
||||
// run http request as thread to make it async
|
||||
val thread = Thread {
|
||||
// otherwise crashes without internet
|
||||
try {
|
||||
updateInfo = getUpdateInfo()
|
||||
versionInfo = getUpdateInfo()
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
thread.start()
|
||||
// wait for the thread to finish
|
||||
thread.join()
|
||||
// show the UpdateAvailableDialog if there's an update available
|
||||
if (updateInfo?.tagName != "" && BuildConfig.VERSION_NAME != updateInfo?.tagName) {
|
||||
val updateAvailableDialog = UpdateAvailableDialog(
|
||||
updateInfo?.tagName!!,
|
||||
updateInfo?.updateUrl!!
|
||||
)
|
||||
updateAvailableDialog.show(childFragmentManager, "UpdateAvailableDialog")
|
||||
} else {
|
||||
// otherwise show the no update available dialog
|
||||
val noUpdateAvailableDialog = NoUpdateAvailableDialog()
|
||||
noUpdateAvailableDialog.show(childFragmentManager, "NoUpdateAvailableDialog")
|
||||
}
|
||||
|
||||
// return the information about the latest version
|
||||
return versionInfo
|
||||
}
|
||||
|
||||
fun getUpdateInfo(): UpdateInfo? {
|
||||
fun getUpdateInfo(): VersionInfo? {
|
||||
val latest = URL(GITHUB_API_URL)
|
||||
val json = StringBuilder()
|
||||
val urlConnection: HttpsURLConnection?
|
||||
@ -59,14 +46,15 @@ fun getUpdateInfo(): UpdateInfo? {
|
||||
) {
|
||||
val updateUrl = jsonRoot.getString("html_url")
|
||||
val jsonAssets: JSONArray = jsonRoot.getJSONArray("assets")
|
||||
|
||||
for (i in 0 until jsonAssets.length()) {
|
||||
val jsonAsset = jsonAssets.getJSONObject(i)
|
||||
if (jsonAsset.has("name")) {
|
||||
val name = jsonAsset.getString("name")
|
||||
if (name.endsWith(".apk")) {
|
||||
val tagName = jsonRoot.getString("name")
|
||||
Log.i("", "Latest version: $tagName")
|
||||
return UpdateInfo(updateUrl, tagName)
|
||||
Log.i("VersionInfo", "Latest version: $tagName")
|
||||
return VersionInfo(updateUrl, tagName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -638,14 +638,14 @@
|
||||
<item>4x</item>
|
||||
</string-array>
|
||||
<string-array name="playbackSpeedValues">
|
||||
<item>0.25F</item>
|
||||
<item>0.5F</item>
|
||||
<item>0.75F</item>
|
||||
<item>1F</item>
|
||||
<item>1.25F</item>
|
||||
<item>1.5F</item>
|
||||
<item>2F</item>
|
||||
<item>4F</item>
|
||||
<item>0.25</item>
|
||||
<item>0.5</item>
|
||||
<item>0.75</item>
|
||||
<item>1</item>
|
||||
<item>1.25</item>
|
||||
<item>1.5</item>
|
||||
<item>2</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="downloadLocation">
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
<ListPreference
|
||||
android:icon="@drawable/ic_speed"
|
||||
app:defaultValue="1F"
|
||||
app:defaultValue="1"
|
||||
app:entries="@array/playbackSpeed"
|
||||
app:entryValues="@array/playbackSpeedValues"
|
||||
app:key="playback_speed"
|
||||
|
Loading…
Reference in New Issue
Block a user