Merge pull request #815 from Bnyro/master

minor fixes
This commit is contained in:
Bnyro 2022-07-18 14:25:51 +02:00 committed by GitHub
commit 6e25546170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 44 deletions

View File

@ -202,6 +202,8 @@ class MainActivity : AppCompatActivity() {
break break
} }
} }
} else {
playlistId = playlistId.replace("list=", "")
} }
loadPlaylist(playlistId) loadPlaylist(playlistId)

View File

@ -31,7 +31,7 @@ class UpdateAvailableDialog(
} }
} }
class NoUpdateAvailableDialog() : DialogFragment() { class NoUpdateAvailableDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let { return activity?.let {

View File

@ -249,7 +249,7 @@ class PlayerFragment : Fragment() {
playbackSpeed = PreferenceHelper.getString( playbackSpeed = PreferenceHelper.getString(
PreferenceKeys.PLAYBACK_SPEED, PreferenceKeys.PLAYBACK_SPEED,
"1F" "1"
)!! )!!
fullscreenOrientationPref = PreferenceHelper.getString( fullscreenOrientationPref = PreferenceHelper.getString(
@ -480,6 +480,7 @@ class PlayerFragment : Fragment() {
val playbackSpeedValues = val playbackSpeedValues =
context?.resources?.getStringArray(R.array.playbackSpeedValues)!! context?.resources?.getStringArray(R.array.playbackSpeedValues)!!
exoPlayer.setPlaybackSpeed(playbackSpeed.toFloat()) exoPlayer.setPlaybackSpeed(playbackSpeed.toFloat())
Log.e(TAG, playbackSpeed)
val speedIndex = playbackSpeedValues.indexOf(playbackSpeed) val speedIndex = playbackSpeedValues.indexOf(playbackSpeed)
playerBinding.speedText.text = playbackSpeeds[speedIndex] playerBinding.speedText.text = playbackSpeeds[speedIndex]
@ -1124,12 +1125,6 @@ class PlayerFragment : Fragment() {
private val hideForwardButtonRunnable = Runnable { binding.forwardBTN.visibility = View.GONE } private val hideForwardButtonRunnable = Runnable { binding.forwardBTN.visibility = View.GONE }
private val hideRewindButtonRunnable = Runnable { binding.rewindBTN.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 // enable seek bar preview
private fun enableSeekbarPreview() { private fun enableSeekbarPreview() {
playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener { playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener {
@ -1456,6 +1451,7 @@ class PlayerFragment : Fragment() {
// lock the player // lock the player
private fun lockPlayer(isLocked: Boolean) { private fun lockPlayer(isLocked: Boolean) {
// isLocked is the current (old) state of the player lock
val visibility = if (isLocked) View.VISIBLE else View.GONE val visibility = if (isLocked) View.VISIBLE else View.GONE
playerBinding.exoTopBarRight.visibility = visibility playerBinding.exoTopBarRight.visibility = visibility
@ -1474,7 +1470,15 @@ class PlayerFragment : Fragment() {
) View.VISIBLE else View.GONE ) View.VISIBLE else View.GONE
// disable double tap to seek when the player is locked // 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) { private fun isSubscribed(button: MaterialButton, channel_id: String) {

View File

@ -1,7 +1,7 @@
package com.github.libretube.obj package com.github.libretube.obj
// data class for the update info, required to return the data // data class for the update info, required to return the data
data class UpdateInfo( data class VersionInfo(
val updateUrl: String, val updateUrl: String,
val tagName: String val tagName: String
) )

View File

@ -8,9 +8,15 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.BuildConfig import com.github.libretube.BuildConfig
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity
import com.github.libretube.dialogs.RequireRestartDialog import com.github.libretube.dialogs.RequireRestartDialog
import com.github.libretube.dialogs.UpdateAvailableDialog
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
import com.github.libretube.util.checkUpdate 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() { class MainSettings : PreferenceFragmentCompat() {
val TAG = "SettingsFragment" val TAG = "SettingsFragment"
@ -78,9 +84,35 @@ class MainSettings : PreferenceFragmentCompat() {
} }
val update = findPreference<Preference>("update") 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 { 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 true
} }

View File

@ -1,12 +1,8 @@
package com.github.libretube.util package com.github.libretube.util
import android.util.Log 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.GITHUB_API_URL
import com.github.libretube.dialogs.NoUpdateAvailableDialog import com.github.libretube.obj.VersionInfo
import com.github.libretube.dialogs.UpdateAvailableDialog
import com.github.libretube.obj.UpdateInfo
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import java.io.BufferedReader import java.io.BufferedReader
@ -14,34 +10,25 @@ import java.io.InputStreamReader
import java.net.URL import java.net.URL
import javax.net.ssl.HttpsURLConnection import javax.net.ssl.HttpsURLConnection
fun checkUpdate(childFragmentManager: FragmentManager) { fun checkUpdate(): VersionInfo? {
var updateInfo: UpdateInfo? = UpdateInfo("", "") var versionInfo: VersionInfo? = VersionInfo("", "")
// run http request as thread to make it async // run http request as thread to make it async
val thread = Thread { val thread = Thread {
// otherwise crashes without internet // otherwise crashes without internet
try { try {
updateInfo = getUpdateInfo() versionInfo = getUpdateInfo()
} catch (e: Exception) { } catch (e: Exception) {
} }
} }
thread.start() thread.start()
// wait for the thread to finish // wait for the thread to finish
thread.join() thread.join()
// show the UpdateAvailableDialog if there's an update available
if (updateInfo?.tagName != "" && BuildConfig.VERSION_NAME != updateInfo?.tagName) { // return the information about the latest version
val updateAvailableDialog = UpdateAvailableDialog( return versionInfo
updateInfo?.tagName!!,
updateInfo?.updateUrl!!
)
updateAvailableDialog.show(childFragmentManager, "UpdateAvailableDialog")
} else {
// otherwise show the no update available dialog
val noUpdateAvailableDialog = NoUpdateAvailableDialog()
noUpdateAvailableDialog.show(childFragmentManager, "NoUpdateAvailableDialog")
}
} }
fun getUpdateInfo(): UpdateInfo? { fun getUpdateInfo(): VersionInfo? {
val latest = URL(GITHUB_API_URL) val latest = URL(GITHUB_API_URL)
val json = StringBuilder() val json = StringBuilder()
val urlConnection: HttpsURLConnection? val urlConnection: HttpsURLConnection?
@ -59,14 +46,15 @@ fun getUpdateInfo(): UpdateInfo? {
) { ) {
val updateUrl = jsonRoot.getString("html_url") val updateUrl = jsonRoot.getString("html_url")
val jsonAssets: JSONArray = jsonRoot.getJSONArray("assets") val jsonAssets: JSONArray = jsonRoot.getJSONArray("assets")
for (i in 0 until jsonAssets.length()) { for (i in 0 until jsonAssets.length()) {
val jsonAsset = jsonAssets.getJSONObject(i) val jsonAsset = jsonAssets.getJSONObject(i)
if (jsonAsset.has("name")) { if (jsonAsset.has("name")) {
val name = jsonAsset.getString("name") val name = jsonAsset.getString("name")
if (name.endsWith(".apk")) { if (name.endsWith(".apk")) {
val tagName = jsonRoot.getString("name") val tagName = jsonRoot.getString("name")
Log.i("", "Latest version: $tagName") Log.i("VersionInfo", "Latest version: $tagName")
return UpdateInfo(updateUrl, tagName) return VersionInfo(updateUrl, tagName)
} }
} }
} }

View File

@ -638,14 +638,14 @@
<item>4x</item> <item>4x</item>
</string-array> </string-array>
<string-array name="playbackSpeedValues"> <string-array name="playbackSpeedValues">
<item>0.25F</item> <item>0.25</item>
<item>0.5F</item> <item>0.5</item>
<item>0.75F</item> <item>0.75</item>
<item>1F</item> <item>1</item>
<item>1.25F</item> <item>1.25</item>
<item>1.5F</item> <item>1.5</item>
<item>2F</item> <item>2</item>
<item>4F</item> <item>4</item>
</string-array> </string-array>
<string-array name="downloadLocation"> <string-array name="downloadLocation">

View File

@ -28,7 +28,7 @@
<ListPreference <ListPreference
android:icon="@drawable/ic_speed" android:icon="@drawable/ic_speed"
app:defaultValue="1F" app:defaultValue="1"
app:entries="@array/playbackSpeed" app:entries="@array/playbackSpeed"
app:entryValues="@array/playbackSpeedValues" app:entryValues="@array/playbackSpeedValues"
app:key="playback_speed" app:key="playback_speed"