Created
June 2, 2026 11:36
-
-
Save costafotjet/18b3da3dc5121569bfd7e0e8002ac81c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @RunWith(RobolectricTestRunner::class) | |
| @Config(sdk = [35]) | |
| @GraphicsMode(GraphicsMode.Mode.NATIVE) | |
| class OfflineScreenDocument { | |
| private fun Context.renderDrawable(resId: Int, scale: Int = 3): Bitmap { | |
| val drawable = AppCompatResources.getDrawable(this, resId)!! | |
| val w = drawable.intrinsicWidth * scale | |
| val h = drawable.intrinsicHeight * scale | |
| val bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888) | |
| val canvas = Canvas(bitmap) | |
| drawable.setBounds(0, 0, w, h) | |
| drawable.draw(canvas) | |
| return bitmap | |
| } | |
| @Test | |
| fun generateOfflineScreen() { | |
| val context = ApplicationProvider.getApplicationContext<Context>() | |
| val displayInfo = RemoteCreationDisplayInfo( | |
| width = 1080, | |
| height = 2400, | |
| densityDpi = 420, | |
| ) | |
| // Render assets | |
| val logo = context.renderDrawable( | |
| com.jet.pie2.logos.R.drawable.pie_logo_brand_lieferando_primary_horizontal_inverse, | |
| ) | |
| val celebration = context.renderDrawable( | |
| com.jet.pie2.illustrations.R.drawable.img_pie_festive_celebration_large, | |
| ) | |
| val doc = runBlocking { | |
| captureSingleRemoteDocument( | |
| context = context, | |
| creationDisplayInfo = displayInfo, | |
| ) { | |
| RemoteColumn( | |
| modifier = RemoteModifier.fillMaxWidth() | |
| .background(PieWhite), | |
| horizontalAlignment = RemoteAlignment.CenterHorizontally, | |
| ) { | |
| // Orange header with logo | |
| RemoteBox( | |
| modifier = RemoteModifier | |
| .fillMaxWidth() | |
| .height(100.rdp) | |
| .background(PieBrandOrange), | |
| contentAlignment = RemoteAlignment.Center, | |
| ) { | |
| RemoteImage( | |
| bitmap = logo.asImageBitmap(), | |
| contentDescription = "Lieferando".rs, | |
| contentScale = ContentScale.Fit, | |
| modifier = RemoteModifier.height(40.rdp), | |
| ) | |
| } | |
| RemoteSpacer(modifier = RemoteModifier.height(SpacingF)) | |
| // Heading | |
| RemoteText( | |
| text = "We are unavailable at\nthe moment", | |
| color = RemoteColor(Color.Black), | |
| fontSize = 28.rsp, | |
| fontWeight = FontWeight.Black, | |
| textAlign = TextAlign.Center, | |
| modifier = RemoteModifier.padding(horizontal = SpacingE), | |
| ) | |
| RemoteSpacer(modifier = RemoteModifier.height(SpacingE)) | |
| // Celebration illustration | |
| RemoteImage( | |
| bitmap = celebration.asImageBitmap(), | |
| contentDescription = "Festive celebration".rs, | |
| contentScale = ContentScale.Fit, | |
| modifier = RemoteModifier.height(160.rdp), | |
| ) | |
| RemoteSpacer(modifier = RemoteModifier.height(SpacingE)) | |
| // Subtitle | |
| RemoteText( | |
| text = "Wishing you a Happy New Year\nfrom all of us.", | |
| color = RemoteColor(PieContentDefault), | |
| fontSize = 18.rsp, | |
| textAlign = TextAlign.Center, | |
| ) | |
| RemoteSpacer(modifier = RemoteModifier.height(SpacingD)) | |
| // Description | |
| RemoteText( | |
| text = "We're currently closed, but don't worry, we\nwill be back online soon!", | |
| color = RemoteColor(PieContentSubdued), | |
| fontSize = 14.rsp, | |
| textAlign = TextAlign.Center, | |
| ) | |
| RemoteSpacer(modifier = RemoteModifier.height(SpacingD)) | |
| // Country | |
| RemoteText( | |
| text = "Country set to United Kingdom", | |
| color = RemoteColor(PieContentSubdued), | |
| fontSize = 14.rsp, | |
| textAlign = TextAlign.Center, | |
| ) | |
| RemoteSpacer(modifier = RemoteModifier.height(SpacingE)) | |
| // Change country button | |
| RemoteBox( | |
| modifier = RemoteModifier | |
| .clip(RemoteRoundedCornerShape(50)) | |
| .background(PieBrandOrange) | |
| .clickable(hostAction("change_country".rs)) | |
| .rippleEffect(), | |
| contentAlignment = RemoteAlignment.Center, | |
| ) { | |
| RemoteText( | |
| text = "Change country", | |
| color = RemoteColor(PieWhite), | |
| fontSize = 18.rsp, | |
| fontWeight = FontWeight.ExtraBold, | |
| modifier = RemoteModifier.padding( | |
| horizontal = SpacingF, | |
| vertical = SpacingD, | |
| ), | |
| ) | |
| } | |
| RemoteSpacer(modifier = RemoteModifier.height(SpacingE)) | |
| } | |
| } | |
| } | |
| File("../output/offline_screen.rc").apply { parentFile?.mkdirs() }.writeBytes(doc.bytes) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment