Skip to content

Commit

Permalink
feat: hadnles
Browse files Browse the repository at this point in the history
  • Loading branch information
MahmoudMabrok committed Jan 3, 2024
1 parent ed13a1d commit 788e757
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.material3.ExperimentalMaterial3Api
import tools.mo3ta.githubactivity.theme.MobileTheme

class AndroidApp : Application() {
Expand All @@ -20,7 +20,7 @@ class AndroidApp : Application() {
}
}

@ExperimentalComposeApi
@ExperimentalMaterial3Api
class AppActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
13 changes: 0 additions & 13 deletions composeApp/src/commonMain/kotlin/tools/mo3ta/githubactivity/App.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
package tools.mo3ta.githubactivity

import androidx.compose.runtime.Composable
import cafe.adriel.voyager.navigator.Navigator
import tools.mo3ta.githubactivity.screens.config.ConfigScreen
import tools.mo3ta.githubactivity.theme.CommonTheme

@Composable
internal fun AppWithCommonTheme() = CommonTheme {
AppContent()
}

@Composable
internal fun AppContent() = Navigator(ConfigScreen)


internal expect fun openUrl(url: String?)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tools.mo3ta.githubactivity

import androidx.compose.runtime.Composable
import cafe.adriel.voyager.navigator.Navigator
import tools.mo3ta.githubactivity.screens.config.ConfigScreen
import tools.mo3ta.githubactivity.theme.CommonTheme

@Composable
internal fun AppWithCommonTheme() = CommonTheme {
AppContent()
}

@Composable
internal fun AppContent() = Navigator(ConfigScreen)
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ data class UserDetailsScreen(
.verticalScroll(rememberScrollState())
) {
if (uiState.isLoading) {
Loading(
Modifier.fillMaxSize(),
"User Data for ${data.userName}"
)
Loading(Modifier.fillMaxSize(), "User Data for ${data.userName}")
} else {
BasicUserData(
uiState.userData,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package tools.mo3ta.githubactivity.theme

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun MobileTheme(
content: @Composable() () -> Unit
) {
AppTheme(
content = content,
appBar = { TopAppBar(title = { Text("Github Activity") }) })
}


@Composable
fun CommonTheme(content: @Composable() () -> Unit) {
AppTheme(content)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package tools.mo3ta.githubactivity.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.lightColorScheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Shapes
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
Expand Down Expand Up @@ -56,7 +53,7 @@ private val LightColorScheme = lightColorScheme(
surfaceTint = md_theme_light_surfaceTint,
outlineVariant = md_theme_light_outlineVariant,
scrim = md_theme_light_scrim,
)
)

private val DarkColorScheme = darkColorScheme(
primary = md_theme_dark_primary,
Expand Down Expand Up @@ -88,64 +85,53 @@ private val DarkColorScheme = darkColorScheme(
surfaceTint = md_theme_dark_surfaceTint,
outlineVariant = md_theme_dark_outlineVariant,
scrim = md_theme_dark_scrim,
)
)

private val AppShapes = Shapes(
extraSmall = RoundedCornerShape(2.dp),
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(8.dp),
large = RoundedCornerShape(16.dp),
extraLarge = RoundedCornerShape(32.dp)
)
)

private val AppTypography = Typography(
bodyMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 16.sp
)
)

internal val LocalThemeIsDark = compositionLocalOf { mutableStateOf(true) }

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun MobileTheme(
content: @Composable() () -> Unit
) {
AppTheme (content = content , appBar = { TopAppBar(title = { Text("Github Activity") }) })
}
)
)

internal val LocalThemeIsDark =
compositionLocalOf { mutableStateOf(true) }

@Composable
fun CommonTheme( content: @Composable() () -> Unit) {
AppTheme(content)
}
@Composable
internal fun AppTheme(
content: @Composable () -> Unit,
appBar : @Composable () -> Unit = {}
) {
appBar: @Composable () -> Unit = {}
) {
val systemIsDark = isSystemInDarkTheme()
val isDarkState = remember { mutableStateOf(systemIsDark) }
val isDarkState =
remember { mutableStateOf(systemIsDark) }
CompositionLocalProvider(
LocalThemeIsDark provides isDarkState
) {
) {
val isDark by isDarkState
SystemAppearance(!isDark)
MaterialTheme(
colorScheme = if (isDark) DarkColorScheme else LightColorScheme,
typography = AppTypography,
shapes = AppShapes,
content = {
Scaffold (topBar = appBar){
Scaffold(topBar = appBar) {
Surface(Modifier.padding(it)) {
content()
}
}
},

)
)
}
}

Expand Down

0 comments on commit 788e757

Please sign in to comment.