Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b42a476
Hide DeviceType from IDE auto completion
Luna712 May 26, 2026
edf8249
Update
Luna712 May 26, 2026
36f37cc
Try
Luna712 May 26, 2026
380d18f
Update
Luna712 May 26, 2026
c57d64f
Update
Luna712 May 26, 2026
e258f99
Update
Luna712 May 26, 2026
1b14d38
Try
Luna712 May 26, 2026
3509c08
Rm
Luna712 May 26, 2026
f8c9feb
-
Luna712 May 26, 2026
8ed00e3
-
Luna712 May 26, 2026
b66d381
Update
Luna712 May 26, 2026
8a28fbc
-
Luna712 May 26, 2026
05ea0df
rename
Luna712 May 26, 2026
e5637ed
-
Luna712 May 26, 2026
9e36078
-
Luna712 May 26, 2026
2fec244
-
Luna712 May 26, 2026
e3aaaea
Update
Luna712 May 26, 2026
44810bc
Update
Luna712 May 26, 2026
1f95b3c
Try
Luna712 May 26, 2026
0f065e1
Update
Luna712 May 26, 2026
9f05a17
Update
Luna712 May 26, 2026
a732d13
Update
Luna712 May 26, 2026
4042aba
Update
Luna712 May 26, 2026
5ca7456
Update
Luna712 May 26, 2026
052580c
Update
Luna712 May 26, 2026
0261d36
Update
Luna712 May 26, 2026
dea04ef
Update SettingsFragment.kt
Luna712 May 26, 2026
df0c176
Add import
Luna712 May 26, 2026
3978245
Add
Luna712 May 26, 2026
4f35e95
-
Luna712 May 26, 2026
050daf6
Add comment
Luna712 May 26, 2026
534ddfd
Update
Luna712 May 26, 2026
e40c6e3
Update
Luna712 May 26, 2026
572d47d
Order
Luna712 May 26, 2026
0455d46
Update
Luna712 May 26, 2026
47b8d7c
Typo
Luna712 May 26, 2026
1ca1693
back compat
Luna712 May 26, 2026
6bb4933
-
Luna712 May 26, 2026
94f19dd
Update
Luna712 May 26, 2026
1df9f15
Comment
Luna712 May 26, 2026
b95ac99
Update
Luna712 May 26, 2026
efce523
use DeviceType
Luna712 May 26, 2026
2f19b3f
Update
Luna712 May 26, 2026
a5cbaef
Update
Luna712 May 26, 2026
95e8fae
Update
Luna712 May 26, 2026
f2c43bd
Update
Luna712 May 26, 2026
4c7b848
internal
Luna712 May 26, 2026
63d6b74
try
Luna712 May 26, 2026
2435c4c
Update
Luna712 May 26, 2026
4de647b
Update
Luna712 May 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package com.lagradost.cloudstream3.ui.settings
import android.content.Context
import com.lagradost.cloudstream4.utils.DeviceLayout

// TODO: remove and use DeviceLayout directly.
// this currently just acts as a wrapper to
// avoid changing so much at once.
object Globals {
var beneneCount = 0

const val PHONE: Int = DeviceLayout.PHONE
const val TV: Int = DeviceLayout.TV
const val EMULATOR: Int = DeviceLayout.EMULATOR
const val PHONE: Int = 0b00001
const val TV: Int = 0b00010
const val EMULATOR: Int = 0b00100

fun Context.updateTv() {
DeviceLayout.update()
}

fun isLandscape(): Boolean = DeviceLayout.isLandscape()

fun isLayout(flags: Int): Boolean = DeviceLayout.isLayout(flags)
fun isLayout(flags: Int): Boolean = DeviceLayout.isLayout(DeviceLayout.Layout(flags))
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.lagradost.cloudstream4.preferences.PreferenceDefaults
import com.lagradost.cloudstream4.preferences.PreferenceKeys

internal actual object DeviceInfo {
actual fun getDeviceType(): DeviceType {
val context = getContext() as? Context ?: return DeviceType.PHONE
actual fun getDetectedLayout(): DeviceLayout.Layout {
val context = getContext() as? Context ?: return DeviceLayout.PHONE
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager?
val isTelevisionMode = uiModeManager?.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION
val model = Build.MODEL.lowercase()
Expand All @@ -20,8 +20,8 @@ internal actual object DeviceInfo {
|| Build.MODEL.contains("AFT") // AFT = Fire TV
|| model.contains("firestick")
|| model.contains("fire tv")
|| model.contains("chromecast") -> DeviceType.TV
else -> DeviceType.PHONE
|| model.contains("chromecast") -> DeviceLayout.TV
else -> DeviceLayout.PHONE
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.lagradost.cloudstream4.utils

internal expect object DeviceInfo {
fun getDeviceType(): DeviceType
fun getDetectedLayout(): DeviceLayout.Layout
fun isLandscape(): Boolean
fun getLayoutPreference(): Int
}

enum class DeviceType {
PHONE, TV, EMULATOR, COMPUTER
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.lagradost.cloudstream4.utils

import com.lagradost.cloudstream4.preferences.PreferenceDefaults
import kotlin.jvm.JvmInline

object DeviceLayout {
const val PHONE: Int = 0b00001
const val TV: Int = 0b00010
const val EMULATOR: Int = 0b00100
const val COMPUTER: Int = 0b01000
@JvmInline // This still works but has no affect on non-JVM targets
value class Layout(private val value: Int) {
infix fun or(other: Layout) = Layout(value or other.value)
internal fun and(other: Layout) = (value and other.value) != 0
}

val PHONE = Layout(0b00001)
val TV = Layout(0b00010)
val EMULATOR = Layout(0b00100)
val COMPUTER = Layout(0b01000)

private var layoutId = -1
private var layoutId = Layout(PreferenceDefaults.APP_LAYOUT)
// TODO when fully on Compose
// private val layoutId: Int get() = resolveLayout()

Expand All @@ -19,7 +28,7 @@ object DeviceLayout {
*
* Valid flags are: PHONE, TV, EMULATOR, or COMPUTER
*/
fun isLayout(flags: Int): Boolean = (layoutId and flags) != 0
fun isLayout(flags: Layout): Boolean = layoutId.and(flags)

/** Returns true if the current orientation is landscape. */
fun isLandscape(): Boolean =
Expand All @@ -36,14 +45,9 @@ object DeviceLayout {
layoutId = resolveLayout()
}

private fun resolveLayout(): Int {
private fun resolveLayout(): Layout {
return when (DeviceInfo.getLayoutPreference()) {
-1 -> when (DeviceInfo.getDeviceType()) {
DeviceType.COMPUTER -> COMPUTER
DeviceType.EMULATOR -> EMULATOR
DeviceType.PHONE -> PHONE
DeviceType.TV -> TV
}
PreferenceDefaults.APP_LAYOUT -> DeviceInfo.getDetectedLayout()
0 -> PHONE
1 -> TV
2 -> EMULATOR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.lagradost.cloudstream4.utils

import com.lagradost.cloudstream4.preferences.PreferenceDefaults
import java.awt.Toolkit

internal actual object DeviceInfo {
actual fun getDeviceType(): DeviceType = DeviceType.COMPUTER
actual fun getDetectedLayout(): DeviceLayout.Layout = DeviceLayout.COMPUTER

actual fun isLandscape(): Boolean {
return try {
Expand All @@ -14,5 +15,5 @@ internal actual object DeviceInfo {
}
}

actual fun getLayoutPreference(): Int = -1
actual fun getLayoutPreference(): Int = PreferenceDefaults.APP_LAYOUT
}