Skip to content

Commit

Permalink
Add isDebug method to AppPlatform
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Dec 4, 2024
1 parent dd98943 commit 653b610
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import org.koin.compose.KoinApplication
import xyz.ksharma.krail.core.appinfo.LocalPlatformTypeProvider
import xyz.ksharma.krail.core.appinfo.getPlatform
import xyz.ksharma.krail.core.appinfo.getAppPlatform
import xyz.ksharma.krail.di.koinConfig
import xyz.ksharma.krail.taj.theme.KrailTheme

@Composable
fun KrailApp() {
KoinApplication(application = koinConfig) {
CompositionLocalProvider(LocalPlatformTypeProvider provides getPlatform().type) {
CompositionLocalProvider(LocalPlatformTypeProvider provides getAppPlatform()) {
KrailTheme {
KrailNavHost()
}
Expand Down
4 changes: 4 additions & 0 deletions core/app-info/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ plugins {

android {
namespace = "xyz.ksharma.krail.core.appinfo"

buildFeatures {
buildConfig = true
}
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package xyz.ksharma.krail.core.appinfo

import android.os.Build

class AndroidPlatform : Platform {
class AndroidAppPlatform : AppPlatform {
override val name: String = "Android ${Build.VERSION.SDK_INT}"
override val type: PlatformType = PlatformType.ANDROID
override fun isDebug(): Boolean = BuildConfig.DEBUG
}

actual fun getPlatform(): Platform = AndroidPlatform()
actual fun getAppPlatform(): AppPlatform = AndroidAppPlatform()
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package xyz.ksharma.krail.core.appinfo

interface Platform {
interface AppPlatform {
val name: String
val type: PlatformType

fun isDebug(): Boolean
}

enum class PlatformType {
Expand All @@ -11,4 +13,4 @@ enum class PlatformType {
UNKNOWN,
}

expect fun getPlatform(): Platform
expect fun getAppPlatform(): AppPlatform
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package xyz.ksharma.krail.core.appinfo

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.staticCompositionLocalOf

val LocalPlatformTypeProvider = compositionLocalOf { PlatformType.UNKNOWN }
val LocalPlatformTypeProvider = staticCompositionLocalOf { getAppPlatform() }
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package xyz.ksharma.krail.core.appinfo

import platform.UIKit.UIDevice
import kotlin.experimental.ExperimentalNativeApi

class IOSPlatform : Platform {
class IOSAppPlatform : AppPlatform {
override val name: String =
UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion

override val type: PlatformType = PlatformType.IOS

@OptIn(ExperimentalNativeApi::class)
override fun isDebug(): Boolean = Platform.isDebugBinary
}

actual fun getPlatform(): Platform = IOSPlatform()
actual fun getAppPlatform(): AppPlatform = IOSAppPlatform()

0 comments on commit 653b610

Please sign in to comment.