Skip to content

Commit

Permalink
Use ParameterProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarr21 committed Jun 26, 2021
1 parent afcfac1 commit bb29129
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdkVersion(23)
targetSdkVersion(30)
versionCode = 2
versionName = "0.0.2"
versionName = "0.0.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
Expand Down Expand Up @@ -72,6 +72,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.5.0")
implementation("androidx.datastore:datastore-preferences:1.0.0-alpha01")
implementation("androidx.hilt:hilt-navigation-compose:1.0.0-alpha03")
implementation("com.google.dagger:hilt-android:$hiltVersion")
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
implementation("androidx.lifecycle:lifecycle-runtime:2.3.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
Expand All @@ -86,7 +87,6 @@ dependencies {
implementation("com.google.accompanist:accompanist-swiperefresh:0.11.1")
implementation("com.google.accompanist:accompanist-systemuicontroller:0.11.1")
implementation("com.google.android.material:material:1.3.0")
implementation("com.google.dagger:hilt-android:$hiltVersion")
implementation("com.jakewharton:process-phoenix:2.0.0")
implementation("com.jakewharton.timber:timber:4.7.1")
implementation("io.coil-kt:coil:1.2.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.MaterialTheme
Expand All @@ -22,6 +20,8 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.imageloading.ImageLoadState
Expand Down Expand Up @@ -77,17 +77,16 @@ fun AppItem(
}
}

private class AppProvider : PreviewParameterProvider<App> {
override val values = listOf("Name", "Application Name", "Really Long Application Name")
.map { previewApp.copy(name = it) }
.asSequence()
}

@Preview(widthDp = 150)
@Composable
fun AppItemPreview() {
fun AppItemPreview(@PreviewParameter(AppProvider::class) app: App) {
AppTheme(darkTheme = true) {
Column {
listOf("Name", "Application Name", "Really Long Application Name")
.forEach {
AppItem(previewApp.copy(name = it))
Spacer(modifier = Modifier.height(16.dp))
}
AppItem(previewApp.copy(name = "Calm"), query = "AA")
}
AppItem(app)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package io.github.jbarr21.appdialer.ui.main.dialer

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material.MaterialTheme
Expand All @@ -18,6 +15,8 @@ import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import io.github.jbarr21.appdialer.data.DialerButton
import io.github.jbarr21.appdialer.ui.AppTheme
Expand Down Expand Up @@ -54,19 +53,18 @@ fun DialerItem(
)
}

private class ButtonProvider : PreviewParameterProvider<DialerButton> {
override val values = listOf(
4 to "GHI",
5 to "JKL",
-1 to "CLEAR*"
).map { (digit, letters) -> DialerButton(digit = digit, letters = letters) }.asSequence()
}

@Preview
@Composable
fun DialerItemPreview() {
fun DialerItemPreview(@PreviewParameter(ButtonProvider::class) button: DialerButton) {
AppTheme(darkTheme = true) {
Column {
listOf(
4 to "GHI",
5 to "JKL",
-1 to "CLEAR*"
).forEach { (digit, letters) ->
DialerItem(DialerButton(digit = digit, letters = letters))
Spacer(modifier = Modifier.height(16.dp))
}
}
DialerItem(button)
}
}

0 comments on commit bb29129

Please sign in to comment.