mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
minor fixes
This commit is contained in:
parent
072f31a1e8
commit
ddac0ebfd3
@ -62,7 +62,7 @@ class ChannelAdapter(
|
||||
root.setOnLongClickListener {
|
||||
val videoId = trending.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class PlaylistAdapter(
|
||||
root.setOnLongClickListener {
|
||||
val videoId = streamItem.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ class SearchAdapter(
|
||||
root.setOnLongClickListener {
|
||||
val videoId = item.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
searchChannelImage.setOnClickListener {
|
||||
|
@ -90,7 +90,7 @@ class SubscriptionAdapter(
|
||||
root.setOnLongClickListener {
|
||||
val videoId = trending.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class TrendingAdapter(
|
||||
root.setOnLongClickListener {
|
||||
val videoId = trending.url!!.replace("/watch?v=", "")
|
||||
VideoOptionsDialog(videoId, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class WatchHistoryAdapter(
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsDialog(video.videoId!!, root.context)
|
||||
.show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,12 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.services.UpdateService
|
||||
import com.github.libretube.update.UpdateInfo
|
||||
import com.github.libretube.util.PermissionHelper
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class UpdateDialog(
|
||||
@ -28,6 +30,7 @@ class UpdateDialog(
|
||||
val downloadUrl = getDownloadUrl(updateInfo)
|
||||
Log.i("downloadUrl", downloadUrl.toString())
|
||||
if (downloadUrl != null) {
|
||||
PermissionHelper.requestReadWrite(activity as AppCompatActivity)
|
||||
val intent = Intent(context, UpdateService::class.java)
|
||||
intent.putExtra("downloadUrl", downloadUrl)
|
||||
context?.startService(intent)
|
||||
@ -44,8 +47,8 @@ class UpdateDialog(
|
||||
private fun getDownloadUrl(updateInfo: UpdateInfo): String? {
|
||||
val supportedArchitectures = Build.SUPPORTED_ABIS
|
||||
supportedArchitectures.forEach { arch ->
|
||||
updateInfo.assets.forEach {
|
||||
if (it.browser_download_url.contains(arch)) return it.browser_download_url
|
||||
updateInfo.assets.forEach { asset ->
|
||||
if (asset.name.contains(arch)) return asset.browser_download_url
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
@ -17,6 +17,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
* Needs the [videoId] to load the content from the right video.
|
||||
*/
|
||||
class VideoOptionsDialog(private val videoId: String, context: Context) : DialogFragment() {
|
||||
private val TAG = "VideoOptionsDialog"
|
||||
|
||||
/**
|
||||
* List that stores the different menu options. In the future could be add more options here.
|
||||
*/
|
||||
@ -71,8 +73,4 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "VideoOptionsDialog"
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.github.libretube.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@ -62,6 +62,10 @@ class ChannelFragment : Fragment() {
|
||||
fetchChannel()
|
||||
if (PreferenceHelper.getToken() != "") {
|
||||
isSubscribed()
|
||||
} else {
|
||||
binding.channelSubscribe.setOnClickListener {
|
||||
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
refreshChannel()
|
||||
@ -85,7 +89,6 @@ class ChannelFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun isSubscribed() {
|
||||
@SuppressLint("ResourceAsColor")
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
@ -104,10 +107,10 @@ class ChannelFragment : Fragment() {
|
||||
isSubscribed = true
|
||||
binding.channelSubscribe.text = getString(R.string.unsubscribe)
|
||||
}
|
||||
|
||||
binding.channelSubscribe.setOnClickListener {
|
||||
if (response.subscribed != null) {
|
||||
binding.channelSubscribe.apply {
|
||||
setOnClickListener {
|
||||
text = if (isSubscribed) {
|
||||
binding.channelSubscribe.text = if (isSubscribed) {
|
||||
unsubscribe()
|
||||
getString(R.string.subscribe)
|
||||
} else {
|
||||
@ -119,7 +122,6 @@ class ChannelFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.NotificationManager
|
||||
import android.app.PictureInPictureParams
|
||||
import android.content.Context
|
||||
@ -1526,7 +1525,6 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun isSubscribed(button: MaterialButton, channel_id: String) {
|
||||
@SuppressLint("ResourceAsColor")
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
|
@ -93,7 +93,7 @@ class MainSettings : PreferenceFragmentCompat() {
|
||||
update?.setOnPreferenceClickListener {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
// check for update
|
||||
val updateInfo = UpdateChecker.checkUpdate()
|
||||
val updateInfo = UpdateChecker.getLatestReleaseInfo()
|
||||
if (updateInfo?.name != "" && BuildConfig.VERSION_NAME != updateInfo?.name) {
|
||||
// show the UpdateAvailableDialog if there's an update available
|
||||
val updateAvailableDialog = UpdateDialog(updateInfo!!)
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.github.libretube.update
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class Asset(
|
||||
val browser_download_url: String,
|
||||
val content_type: String,
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.github.libretube.update
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class Author(
|
||||
val avatar_url: String,
|
||||
val events_url: String,
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.github.libretube.update
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class Reactions(
|
||||
val confused: Int,
|
||||
val eyes: Int,
|
||||
|
@ -2,13 +2,10 @@ package com.github.libretube.update
|
||||
|
||||
import com.github.libretube.GITHUB_API_URL
|
||||
import com.google.gson.Gson
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.net.URL
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
||||
object UpdateChecker {
|
||||
fun checkUpdate(): UpdateInfo? {
|
||||
fun getLatestReleaseInfo(): UpdateInfo? {
|
||||
var versionInfo: UpdateInfo? = null
|
||||
// run http request as thread to make it async
|
||||
val thread = Thread {
|
||||
@ -26,19 +23,13 @@ object UpdateChecker {
|
||||
return versionInfo
|
||||
}
|
||||
|
||||
fun getUpdateInfo(): UpdateInfo? {
|
||||
val latest = URL(GITHUB_API_URL)
|
||||
val json = StringBuilder()
|
||||
val urlConnection: HttpsURLConnection?
|
||||
urlConnection = latest.openConnection() as HttpsURLConnection
|
||||
|
||||
// read json
|
||||
val br = BufferedReader(InputStreamReader(urlConnection.inputStream))
|
||||
var line: String?
|
||||
while (br.readLine().also { line = it } != null) json.append(line)
|
||||
private fun getUpdateInfo(): UpdateInfo? {
|
||||
// get the github API response
|
||||
val latestVersionApiUrl = URL(GITHUB_API_URL)
|
||||
val json = latestVersionApiUrl.readText()
|
||||
|
||||
// Parse and return the json data
|
||||
val gson = Gson()
|
||||
return gson.fromJson(json.toString(), UpdateInfo::class.java)
|
||||
return gson.fromJson(json, UpdateInfo::class.java)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.github.libretube.update
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class UpdateInfo(
|
||||
val assets: List<Asset>,
|
||||
val assets_url: String,
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.github.libretube.update
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class Uploader(
|
||||
val avatar_url: String,
|
||||
val events_url: String,
|
||||
|
Loading…
x
Reference in New Issue
Block a user