Skip to content

Commit

Permalink
migrate demo app to Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
connyduck committed Mar 11, 2024
1 parent c09edcb commit 1a47bb1
Show file tree
Hide file tree
Showing 32 changed files with 413 additions and 1,043 deletions.
18 changes: 10 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ dependencies {
implementation(project(":sparkbutton"))
implementation(project(":sparkbutton-compose"))

implementation(libs.material)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.cardview)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)

implementation(libs.androidx.compose.foundation)

androidTestImplementation(libs.espresso.core)
androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.rules)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/Theme.SparkButton">
<activity
android:name="at.connyduck.sparkbutton.sample.DemoActivity"
android:exported="true">
Expand Down
141 changes: 93 additions & 48 deletions app/src/main/java/at/connyduck/sparkbutton/sample/ComposeDemo.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
/* Copyright 2024 Conny Duck
*
* 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 at.connyduck.sparkbutton.sample

import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -16,64 +32,93 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import at.connyduck.sparkbutton.compose.SparkButton

@Composable
fun ComposeDemo() {
Column(Modifier.fillMaxWidth()) {
var checked1 by remember { mutableStateOf(false) }
Column(
Modifier.fillMaxWidth()
) {
DemoRow(R.string.heart_standard_description) {
var checked1 by remember { mutableStateOf(false) }

SparkButton(
checked = checked1,
onCheckedChange = {
checked1 = it
},
animationSpeed = 0.1f,
modifier =
Modifier
.padding(64.dp)
.size(128.dp)
.align(Alignment.CenterHorizontally)
) {
if (checked1) {
Image(painterResource(R.drawable.ic_heart_on), null)
} else {
Image(painterResource(R.drawable.ic_heart_off), null)
SparkButton(
checked = checked1,
onCheckedChange = {
checked1 = it
},
modifier = Modifier
.padding(16.dp)
.size(32.dp)
) {
if (checked1) {
Image(painterResource(R.drawable.ic_heart_on), stringResource(R.string.unlike))
} else {
Image(painterResource(R.drawable.ic_heart_off), stringResource(R.string.like))
}
}
}

Spacer(modifier = Modifier.height(16.dp))

SparkButton(
checked = true,
onCheckedChange = {},
enabled = false,
modifier =
Modifier
.padding(32.dp)
.size(32.dp)
.align(Alignment.CenterHorizontally)
) {
Image(painterResource(R.drawable.ic_heart_on), null)
DemoRow(R.string.heart_disabled_description) {
SparkButton(
checked = true,
onCheckedChange = {},
enabled = false,
modifier = Modifier
.padding(16.dp)
.size(32.dp)
) {
Image(painterResource(R.drawable.ic_heart_on), null)
}
}

Spacer(modifier = Modifier.height(16.dp))

var checked2 by remember { mutableStateOf(true) }
DemoRow(R.string.thumbs_description) {
var checked2 by remember { mutableStateOf(true) }

SparkButton(
checked = checked2,
onCheckedChange = { checked2 = it },
modifier =
Modifier
.padding(32.dp)
.size(80.dp)
.align(Alignment.CenterHorizontally),
primaryColor = colorResource(id = R.color.facebook_primary_color),
secondaryColor = colorResource(id = R.color.facebook_secondary_color),
) {
Image(painter = painterResource(R.drawable.ic_thumb), contentDescription = "")
SparkButton(
checked = true,
onCheckedChange = { checked2 = it },
modifier = Modifier
.padding(32.dp)
.size(64.dp)
.align(Alignment.CenterHorizontally),
primaryColor = colorResource(id = R.color.thumb_primary_color),
secondaryColor = colorResource(id = R.color.thumb_secondary_color),
animationSpeed = 0.5f
) {
Image(painter = painterResource(R.drawable.ic_thumb), contentDescription = stringResource(R.string.thumbs_up))
}
}
}
}

@Composable
fun DemoRow(
@StringRes text: Int,
content: @Composable () -> Unit
) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 32.dp, vertical = 16.dp)
) {
Text(
text = stringResource(id = text),
fontSize = 16.sp,
modifier = Modifier.weight(1f)
)
content()
}
}

@Preview
@Composable
fun ComposeDemoPreview() {
ComposeDemo()
}
Loading

0 comments on commit 1a47bb1

Please sign in to comment.