Skip to content

Commit

Permalink
Update sample codes
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Jan 25, 2023
1 parent 46c16fb commit bd4c2b0
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 14 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@
![downloads](https://user-images.githubusercontent.com/24237865/101273131-2187a980-37d6-11eb-9000-e1cd10f87b0d.png)

### Gradle
Add the codes below to your **root** `build.gradle` file:
```gradle
allprojects {
repositories {
mavenCentral()
}
}
```
Next, add the dependency below to your module's build.gradle file:
Add the dependency below to your module's `build.gradle` file:
```gradle
dependencies {
implementation "com.github.skydoves:whatif:1.1.1"
Expand Down
42 changes: 37 additions & 5 deletions app/src/main/kotlin/com/skydoves/whatifdemo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,52 @@ package com.skydoves.whatifdemo

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.skydoves.whatif.whatIf
import com.skydoves.whatif.whatIfMap
import com.skydoves.whatif.whatIfNotNull
import com.skydoves.whatifdemo.databinding.ActivityMainBinding
import com.skydoves.whatifdemo.theme.WhatIfTheme
import com.skydoves.whatifdemo.theme.background

class MainActivity : AppCompatActivity() {
class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
whatIfExamples()

setContent {
WhatIfTheme {
var isBlueColor by remember { mutableStateOf(false) }

Box(modifier = Modifier.fillMaxSize()) {
Box(
modifier = Modifier
.align(Alignment.Center)
.clickable { isBlueColor = !isBlueColor }
.whatIfMap(isBlueColor, { it.background(Color.Blue) }, { it.background(Color.Cyan) })
.whatIfMap(isBlueColor, { it.size(120.dp) }, { it.size(240.dp) })
)
}
}
}
}

private fun whatIfExamples() {
val nullableBoolean: Boolean? = true
var nullableString: String? = null

Expand Down
27 changes: 27 additions & 0 deletions app/src/main/kotlin/com/skydoves/whatifdemo/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Designed and developed by 2019-2023 skydoves (Jaewoong Eum)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.skydoves.whatifdemo.theme

import androidx.compose.ui.graphics.Color

val purple200 = Color(0xFF651FFF)
val purple500 = Color(0xFF6200EA)
val background = Color(0xFF2B292B)
val background800 = Color(0xFF424242)
val background900 = Color(0xFF212121)
val white87 = Color(0Xddffffff)
val shimmerHighLight = Color(0xA3C2C2C2)
80 changes: 80 additions & 0 deletions app/src/main/kotlin/com/skydoves/whatifdemo/theme/Type.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Designed and developed by 2019-2023 skydoves (Jaewoong Eum)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.skydoves.whatifdemo.theme

import androidx.compose.material.Typography
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp

// set of dark material typography styles to start with.
val DarkTypography = Typography(
h1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
color = Color.White,
fontSize = 28.sp
),
h2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
color = Color.White,
fontSize = 21.sp
),
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
color = Color.White,
fontSize = 14.sp
),
body2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
color = white87,
fontSize = 14.sp
)
)

// set of light material typography styles to start with.
val LightTypography = Typography(
h1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
color = background900,
fontSize = 28.sp
),
h2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
color = background900,
fontSize = 21.sp
),
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
color = background800,
fontSize = 14.sp
),
body2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
color = background800,
fontSize = 14.sp
)
)
67 changes: 67 additions & 0 deletions app/src/main/kotlin/com/skydoves/whatifdemo/theme/WhatIfTheme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Designed and developed by 2019-2023 skydoves (Jaewoong Eum)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.skydoves.whatifdemo.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

private val DarkColorPalette = darkColors(
onBackground = background800,
primary = purple200,
primaryVariant = purple500,
secondary = purple500,
onPrimary = Color.White,
onSecondary = Color.White
)

private val LightColorPalette = lightColors(
onBackground = Color.White,
surface = Color.White,
primary = purple200,
primaryVariant = purple500,
secondary = purple500,
onPrimary = Color.White,
onSecondary = Color.White
)

@Composable
fun WhatIfTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}

val typography = if (darkTheme) {
DarkTypography
} else {
LightTypography
}

MaterialTheme(
colors = colors,
typography = typography,
content = content
)
}

0 comments on commit bd4c2b0

Please sign in to comment.