-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lorenzovngl:main' into main
- Loading branch information
Showing
5 changed files
with
192 additions
and
8 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/lorenzovainigli/foodexpirationdates/view/composable/AutoResizedText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.lorenzovainigli.foodexpirationdates.view.composable | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
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.draw.drawWithContent | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.isUnspecified | ||
import com.lorenzovainigli.foodexpirationdates.ui.theme.FoodExpirationDatesTheme | ||
import com.lorenzovainigli.foodexpirationdates.view.preview.DefaultPreviews | ||
|
||
@Composable | ||
fun AutoResizedText( | ||
modifier: Modifier = Modifier, | ||
text: String, | ||
style: TextStyle = MaterialTheme.typography.labelLarge | ||
){ | ||
// From https://stackoverflow.com/a/66090448 | ||
var resizedTextStyle by remember { | ||
mutableStateOf(style) | ||
} | ||
var shouldDraw by remember { | ||
mutableStateOf(false) | ||
} | ||
val defaultFontSize = MaterialTheme.typography.labelLarge.fontSize | ||
Text( | ||
text = text, | ||
style = resizedTextStyle, | ||
softWrap = false, | ||
modifier = modifier.drawWithContent { | ||
if (shouldDraw){ | ||
drawContent() | ||
} | ||
}, | ||
onTextLayout = { result -> | ||
if (result.didOverflowWidth) { | ||
if (style.fontSize.isUnspecified){ | ||
resizedTextStyle = resizedTextStyle.copy( | ||
fontSize = defaultFontSize | ||
) | ||
} | ||
resizedTextStyle = resizedTextStyle.copy( | ||
fontSize = resizedTextStyle.fontSize * 0.95 | ||
) | ||
} else { | ||
shouldDraw = true | ||
} | ||
} | ||
) | ||
} | ||
|
||
@DefaultPreviews | ||
@Composable | ||
fun AutoResizedTextPreview(){ | ||
FoodExpirationDatesTheme { | ||
Column( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
(400 downTo 100 step 100).forEach { | ||
Box( | ||
modifier = Modifier.width(it.dp) | ||
) { | ||
Column { | ||
Button(onClick = {}) { | ||
AutoResizedText( | ||
text = "Lorem ipsum dolor sit amet", | ||
style = MaterialTheme.typography.headlineLarge | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package screenshot | ||
|
||
import app.cash.paparazzi.DeviceConfig.Companion.PIXEL_5 | ||
import app.cash.paparazzi.Paparazzi | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class ScreenshotFrench : Screenshot() { | ||
|
||
@get:Rule | ||
val paparazzi = Paparazzi( | ||
deviceConfig = PIXEL_5.copy( | ||
locale = "fr" | ||
), | ||
theme = "android:Theme.Material.Light.NoActionBar" | ||
) | ||
|
||
/*private val maxImageSize = 2_000 | ||
@Before | ||
fun initMaxImageSize() { | ||
maxImageSize.let { | ||
app.cash.paparazzi.internal.ImageUtils::class.java.declaredFields.firstOrNull { | ||
it.name == "THUMBNAIL_SIZE" | ||
}?.let { | ||
it.isAccessible = true | ||
it.set(paparazzi, maxImageSize) | ||
} | ||
} | ||
}*/ | ||
|
||
@Test | ||
fun screen1MainActivity() { | ||
super.screen1MainActivity(paparazzi) | ||
} | ||
|
||
@Test | ||
fun screen2InsertActivity() { | ||
super.screen2InsertActivity(paparazzi) | ||
} | ||
|
||
@Test | ||
fun screen3SettingsActivity() { | ||
super.screen3SettingsActivity(paparazzi) | ||
} | ||
|
||
@Test | ||
fun screen4InfoActivity() { | ||
super.screen4InfoActivity(paparazzi) | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
app/src/test/java/screenshot/night/ScreenshotFrenchNight.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package screenshot.night | ||
|
||
import app.cash.paparazzi.DeviceConfig.Companion.PIXEL_5 | ||
import app.cash.paparazzi.Paparazzi | ||
import com.android.resources.NightMode | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import screenshot.Screenshot | ||
|
||
class ScreenshotFrenchNight : Screenshot() { | ||
|
||
@get:Rule | ||
val paparazzi = Paparazzi( | ||
deviceConfig = PIXEL_5.copy( | ||
locale = "fr", | ||
nightMode = NightMode.NIGHT | ||
), | ||
theme = "android:Theme.Material.Light.NoActionBar" | ||
) | ||
|
||
@Test | ||
fun screen1MainActivity() { | ||
super.screen1MainActivity(paparazzi) | ||
} | ||
|
||
@Test | ||
fun screen2InsertActivity() { | ||
super.screen2InsertActivity(paparazzi) | ||
} | ||
|
||
@Test | ||
fun screen3SettingsActivity() { | ||
super.screen3SettingsActivity(paparazzi) | ||
} | ||
|
||
@Test | ||
fun screen4InfoActivity() { | ||
super.screen4InfoActivity(paparazzi) | ||
} | ||
|
||
} |