Skip to content

Commit e02cd6b

Browse files
Started porting android specific classes to the android-compat module, Tv theme color scheme
1 parent dbb4f7a commit e02cd6b

File tree

21 files changed

+214
-57
lines changed

21 files changed

+214
-57
lines changed

app/build.gradle.kts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ kotlin {
2727
dependencies {
2828
implementation(projects.core)
2929
implementation(projects.ui)
30-
implementation(projects.data)
3130
implementation(projects.extension.loaders)
31+
32+
// Idk why, but gradle does not want to sync if these projects
33+
// aren't declared here ._.
34+
implementation(projects.data)
3235
}
3336
}
3437

@@ -85,20 +88,7 @@ android {
8588
compose = true
8689
}
8790

88-
flavorDimensions += listOf("platform")
89-
90-
productFlavors {
91-
register("mobile") {
92-
isDefault = true
93-
dimension = "platform"
94-
}
95-
96-
register("tv") {
97-
dimension = "platform"
98-
}
99-
}
100-
101-
@Suppress("UnstableApiUsage")
91+
@Suppress("UnstableApiUsage", "WrongGradleMethod")
10292
androidResources {
10393
generateLocaleConfig = true
10494
localeFilters += rootProject.projectDir.resolve(
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
package com.mrboomdev.awery.core
22

33
import android.annotation.SuppressLint
4+
import android.app.UiModeManager
45
import android.content.Context
6+
import android.content.pm.PackageManager
7+
import android.content.res.Configuration
8+
9+
/**
10+
* Global application context.
11+
*/
12+
var Awery.context: Context
13+
get() = androidContext!!
14+
set(value) { androidContext = value }
515

616
@SuppressLint("StaticFieldLeak")
717
private var androidContext: Context? = null
818

9-
var Awery.context: Context
10-
get() = androidContext!!
11-
set(value) { androidContext = value }
19+
@Suppress("DEPRECATION")
20+
private val isTv by lazy {
21+
with(androidContext!!) {
22+
packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
23+
|| packageManager.hasSystemFeature(PackageManager.FEATURE_TELEVISION)
24+
|| getSystemService(UiModeManager::class.java).currentModeType == Configuration.UI_MODE_TYPE_TELEVISION
25+
|| !packageManager.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)
26+
}
27+
}
28+
29+
actual fun isTv() = isTv
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
package com.mrboomdev.awery.core
22

33
object Awery {
4-
}
4+
/**
5+
* Checks whatever device is an TV or not.
6+
*/
7+
val Awery.TV: Boolean
8+
get() = isTv()
9+
}
10+
11+
internal expect fun isTv(): Boolean
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.mrboomdev.awery.core
2+
3+
actual fun isTv(): Boolean {
4+
return false
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import com.android.build.api.dsl.androidLibrary
2+
3+
plugins {
4+
alias(libs.plugins.kotlin.multiplatform)
5+
alias(libs.plugins.android.library)
6+
}
7+
8+
kotlin {
9+
applyDefaultHierarchyTemplate()
10+
jvm()
11+
12+
androidLibrary {
13+
namespace = "com.mrboomdev.awery.extension.api"
14+
compileSdk = 35
15+
minSdk = 25
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import com.android.build.api.dsl.androidLibrary
2+
3+
plugins {
4+
alias(libs.plugins.kotlin.multiplatform)
5+
alias(libs.plugins.android.library)
6+
}
7+
8+
kotlin {
9+
applyDefaultHierarchyTemplate()
10+
jvm("desktop")
11+
12+
androidLibrary {
13+
namespace = "com.mrboomdev.awery.extension.loaders.androidcompat"
14+
compileSdk = 35
15+
minSdk = 25
16+
}
17+
18+
compilerOptions {
19+
freeCompilerArgs = listOf("-Xexpect-actual-classes")
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
actual typealias Context = android.content.Context
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
expect abstract class Context
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
actual typealias Context = android.content.Context
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package android.content
2+
3+
abstract class Context {}

0 commit comments

Comments
 (0)