Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
tsynik committed May 21, 2024
1 parent 18f696e commit ab1a9fe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
38 changes: 30 additions & 8 deletions app/src/main/java/ru/yourok/torrserve/atv/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ru.yourok.torrserve.server.local.TorrService
import ru.yourok.torrserve.server.models.torrent.Torrent
import ru.yourok.torrserve.ui.activities.play.PlayActivity
import ru.yourok.torrserve.utils.TorrentHelper
import java.util.Locale
import kotlin.concurrent.thread


Expand Down Expand Up @@ -53,26 +54,47 @@ object Utils {
return false
}

fun hasSAFChooser(pm: PackageManager?): Boolean {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
private fun hasSAFChooser(pm: PackageManager?): Boolean {
val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent(Intent.ACTION_OPEN_DOCUMENT)
} else {
return true // VERSION.SDK_INT < KITKAT
}
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "video/*"
return intent.resolveActivity(pm!!) != null
}

val isGoogleTV: Boolean
private val deviceName: String
get() = String.format("%s (%s)", Build.MODEL, Build.PRODUCT)

private val isHuaweiDevice: Boolean
get() {
val manufacturer = Build.MANUFACTURER
val brand = Build.BRAND
return manufacturer.lowercase(Locale.getDefault())
.contains("huawei") || brand.lowercase(
Locale.getDefault()
).contains("huawei")
}

val isAndroidTV: Boolean
get() {
return App.context.packageManager.hasSystemFeature("android.software.leanback") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
return App.context.packageManager.hasSystemFeature("android.software.leanback") &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
!isHuaweiDevice // Huawei Vision S TV on Harmony OS don't have support for content://android.media.tv/channel
}

val isGoogleTV: Boolean // wide posters on home
get() {
return App.context.packageManager.hasSystemFeature("com.google.android.tv") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
}

val isAmazonTV: Boolean
get() {
return App.context.packageManager.hasSystemFeature(FEATURE_FIRE_TV)
}

private val deviceName: String
get() = String.format("%s (%s)", Build.MODEL, Build.PRODUCT)

val isBrokenTCL: Boolean
get() {
val deviceName = deviceName
Expand All @@ -96,7 +118,7 @@ object Utils {

private var lock = Any()
fun updateAtvCards() {
if (isGoogleTV) {
if (isAndroidTV) {
synchronized(lock) {
if (lock == true)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object UpdaterCards {

fun updateCards() {
thread {
if (!Utils.isGoogleTV)
if (!Utils.isAndroidTV)
return@thread

synchronized(lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ru.yourok.torrserve.server.api.Api
class HomeWatch : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
if (action == null || !Utils.isGoogleTV) return
if (action == null || !Utils.isAndroidTV) return

val previewProgramId = intent.getLongExtra(TvContractCompat.EXTRA_PREVIEW_PROGRAM_ID, -1L)
val watchNextInternalId = intent.getLongExtra(TvContractCompat.EXTRA_WATCH_NEXT_PROGRAM_ID, -1L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
setOnPreferenceClickListener {
//showPowerRequest(context)
try {
if (Utils.isGoogleTV) { // open Power Settings
if (Utils.isAndroidTV) { // open Power Settings
if (Accessibility.isPackageInstalled(context, "com.android.settings")) {
intent.`package` = "com.android.settings"
requireActivity().startActivity(intent)
Expand Down

0 comments on commit ab1a9fe

Please sign in to comment.