mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
commit
e8b9ecfde2
@ -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,16 +107,15 @@ class ChannelFragment : Fragment() {
|
||||
isSubscribed = true
|
||||
binding.channelSubscribe.text = getString(R.string.unsubscribe)
|
||||
}
|
||||
if (response.subscribed != null) {
|
||||
binding.channelSubscribe.apply {
|
||||
setOnClickListener {
|
||||
text = if (isSubscribed) {
|
||||
unsubscribe()
|
||||
getString(R.string.subscribe)
|
||||
} else {
|
||||
subscribe()
|
||||
getString(R.string.unsubscribe)
|
||||
}
|
||||
|
||||
binding.channelSubscribe.setOnClickListener {
|
||||
if (response.subscribed != null) {
|
||||
binding.channelSubscribe.text = if (isSubscribed) {
|
||||
unsubscribe()
|
||||
getString(R.string.subscribe)
|
||||
} else {
|
||||
subscribe()
|
||||
getString(R.string.unsubscribe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -5,6 +5,6 @@
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,13c0,3.31 -2.69,6 -6,6s-6,-2.69 -6,-6s2.69,-6 6,-6v4l5,-5l-5,-5v4c-4.42,0 -8,3.58 -8,8c0,4.42 3.58,8 8,8c4.42,0 8,-3.58 8,-8H18z" />
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12.322,1.707 L16.615,6 12.322,10.293L12.322,7A0.292,0.292 0,0 0,12.029 6.707c-3.468,0 -6.293,2.825 -6.293,6.293 -0,3.468 2.825,6.293 6.293,6.293 3.368,0 6.107,-2.67 6.264,-6L19.707,13.293C19.55,17.416 16.191,20.707 12.029,20.707 7.767,20.707 4.322,17.262 4.322,13 4.322,8.738 7.767,5.293 12.029,5.293A0.292,0.292 0,0 0,12.322 5Z" />
|
||||
</vector>
|
||||
|
@ -5,6 +5,6 @@
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="m6,13c0,3.31 2.69,6 6,6 3.31,0 6,-2.69 6,-6 0,-3.31 -2.69,-6 -6,-6v4L7,6 12,1v4c4.42,0 8,3.58 8,8 0,4.42 -3.58,8 -8,8 -4.42,0 -8,-3.58 -8,-8z" />
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M11.707,1.707 L7.414,6 11.707,10.293V7A0.292,0.292 0,0 1,12 6.707c3.468,0 6.293,2.825 6.293,6.293 0,3.468 -2.825,6.293 -6.293,6.293 -3.368,0 -6.107,-2.67 -6.264,-6H4.322C4.479,17.416 7.838,20.707 12,20.707 16.262,20.707 19.707,17.262 19.707,13 19.707,8.738 16.262,5.293 12,5.293A0.292,0.292 0,0 1,11.707 5Z" />
|
||||
</vector>
|
||||
|
Loading…
x
Reference in New Issue
Block a user