Skip to content

Instantly share code, notes, and snippets.

View LethalMaus's full-sized avatar

James Cullimore LethalMaus

View GitHub Profile
@LethalMaus
LethalMaus / ScreenshotTestRule.kt
Last active August 29, 2023 19:12
Android Screenshot Test Rule
import android.util.Log
import androidx.test.runner.screenshot.Screenshot
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import java.io.*
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
@LethalMaus
LethalMaus / BuildFlavors1.gradle
Last active August 29, 2023 19:13
BuildFlavors1
android {
...
flavorDimensions "version"
productFlavors {
free {
dimension "version"
}
paid {
dimension "version"
}
@LethalMaus
LethalMaus / BuildFlavors2.gradle
Last active August 29, 2023 19:13
BuildFlavors2
android {
...
productFlavors {
free {
applicationIdSuffix ".free"
resValue "string", "app_name", "My Free App"
}
paid {
resValue "string", "app_name", "My Paid App"
}
@LethalMaus
LethalMaus / BuildFlavors3.gradle
Last active August 29, 2023 19:13
BuildFlavors3
android {
...
flavorDimensions "environment"
productFlavors {
dev {
dimension "environment"
}
integration {
dimension "environment"
}
@LethalMaus
LethalMaus / BuildFlavors4.gradle
Last active August 29, 2023 19:13
BuildFlavors4
android {
...
productFlavors {
dev {
buildConfigField "String", "BASE_URL", "\"https://api.dev.example.com\""
buildConfigField "boolean", "DEBUG", "true"
}
integration {
buildConfigField "String", "BASE_URL", "\"https://api.integration.example.com\""
buildConfigField "boolean", "DEBUG", "true"
@LethalMaus
LethalMaus / BuildFlavors5.kt
Last active August 29, 2023 19:14
BuildFlavors5
if (BuildConfig.FLAVOR.equals("dev")) {
// Code for the development environment
} else if (BuildConfig.FLAVOR.equals("integration")) {
// Code for the integration environment
} else if (BuildConfig.FLAVOR.equals("production")) {
// Code for the production environment
}
@LethalMaus
LethalMaus / BuildFlavors6.gradle
Last active August 29, 2023 19:14
BuildFlavors6
android {
...
flavorDimensions "testing"
productFlavors {
mock {
dimension "testing"
}
// Other flavors (dev, production, etc.)
}
}
@LethalMaus
LethalMaus / BuildFlavors7.gradle
Last active August 29, 2023 19:14
BuildFlavors7
android {
...
productFlavors {
mock {
buildConfigField "String", "BASE_URL", "\"http://mockserver.example.com\""
// Other testing-specific configurations
}
// Other flavors' configurations
}
}
@LethalMaus
LethalMaus / BuildFlavors8.kt
Last active August 29, 2023 19:14
BuildFlavors8
class UiTests {
@get:Rule
val serverRule = MockWebServerRule(BuildConfig.BASE_URL)
@Test
fun testUiWithMockServer() {
// Set up mock server responses
@LethalMaus
LethalMaus / Font1.xml
Last active August 29, 2023 19:14
Font1
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:font="@font/MyFont-Regular"
app:fontStyle="normal"
app:fontWeight="400" />
</font-family>