Skip to content

Commit

Permalink
targetSdk updated
Browse files Browse the repository at this point in the history
  • Loading branch information
beradeep committed Sep 27, 2023
1 parent d7f3447 commit 345bcaa
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 64 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.bera.collegesearch"
minSdk 24
targetSdk 34
versionCode 7
versionName "2.0"
versionCode 8
versionName "3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -105,4 +105,7 @@ dependencies {
//Coil
implementation "io.coil-kt:coil-compose:2.4.0"

//Extended Icons
implementation("androidx.compose.material:material-icons-extended:1.5.0")

}
11 changes: 9 additions & 2 deletions app/src/main/java/com/bera/collegesearch/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bera.collegesearch
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -31,15 +32,21 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
connectivityObserver = ConnectivityObserver(applicationContext)
setContent {
CollegeSearchTheme {

val systemDefault = isSystemInDarkTheme()
var isDarkMode by remember { mutableStateOf(systemDefault) }
CollegeSearchTheme(darkTheme = isDarkMode) {

val status by connectivityObserver.observe()
.collectAsState(initial = ConnectivityStatus.Unavailable)
Surface(
modifier = Modifier.fillMaxSize(),
) {
when(status) {
ConnectivityStatus.Available -> Navigation()
ConnectivityStatus.Available -> Navigation(isDarkMode) {
isDarkMode = !isDarkMode
}

else -> {
var showError by remember {
mutableStateOf(false)
Expand Down
100 changes: 100 additions & 0 deletions app/src/main/java/com/bera/collegesearch/components/ThemeSwitcher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.bera.collegesearch.components

import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LightMode
import androidx.compose.material.icons.filled.Nightlight
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

@Composable
fun ThemeSwitcher(
darkTheme: Boolean = false,
size: Dp = 150.dp,
iconSize: Dp = size / 3,
padding: Dp = 10.dp,
borderWidth: Dp = 1.dp,
parentShape: Shape = CircleShape,
toggleShape: Shape = CircleShape,
animationSpec: AnimationSpec<Dp> = tween(durationMillis = 300),
onClick: () -> Unit
) {
val offset by animateDpAsState(
targetValue = if (darkTheme) 0.dp else size,
animationSpec = animationSpec, label = ""
)

Box(modifier = Modifier
.width(size * 2)
.height(size)
.clip(shape = parentShape)
.clickable { onClick() }
.background(MaterialTheme.colorScheme.secondaryContainer)
) {
Box(
modifier = Modifier
.size(size)
.offset(x = offset)
.padding(all = padding)
.clip(shape = toggleShape)
.background(MaterialTheme.colorScheme.primary)
) {}
Row(
modifier = Modifier
.border(
border = BorderStroke(
width = borderWidth,
color = MaterialTheme.colorScheme.primary
),
shape = parentShape
)
) {
Box(
modifier = Modifier.size(size),
contentAlignment = Alignment.Center
) {
Icon(
modifier = Modifier.size(iconSize),
imageVector = Icons.Default.Nightlight,
contentDescription = "Theme Icon",
tint = if (darkTheme) MaterialTheme.colorScheme.secondaryContainer
else MaterialTheme.colorScheme.primary
)
}
Box(
modifier = Modifier.size(size),
contentAlignment = Alignment.Center
) {
Icon(
modifier = Modifier.size(iconSize),
imageVector = Icons.Default.LightMode,
contentDescription = "Theme Icon",
tint = if (darkTheme) MaterialTheme.colorScheme.primary
else MaterialTheme.colorScheme.secondaryContainer
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ import com.bera.collegesearch.screens.home.HomeScreen


@Composable
fun Navigation() {
fun Navigation(isDarkMode: Boolean, onDarkModeToggle: () -> Unit) {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = Routes.HomeScreen.route) {
composable(Routes.HomeScreen.route) {
HomeScreen(navController = navController)
HomeScreen(
navController = navController,
isDarkMode = isDarkMode,
onDarkModeToggle = onDarkModeToggle
)
}
composable(Routes.CollegeScreen.route + "/{category}", listOf(navArgument("category") {
type = NavType.StringType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.bera.collegesearch.models.CutoffItem
import com.bera.collegesearch.repository.CutoffRepository
import com.bera.collegesearch.use_cases.GetCutoffsUseCase
import com.bera.collegesearch.utils.Constants.IIT_STRING
import com.bera.collegesearch.utils.Constants.IIT_STRING_1
Expand Down
Loading

0 comments on commit 345bcaa

Please sign in to comment.