taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

ScreenshotController.kt (9550B)


      1 package net.taler.merchantpos.debug
      2 
      3 import android.content.Context
      4 import android.util.Base64
      5 import net.taler.common.Amount
      6 import net.taler.common.Tax
      7 import net.taler.merchantlib.MerchantConfig
      8 import net.taler.merchantpos.config.Category
      9 import net.taler.merchantpos.config.ConfigProduct
     10 import net.taler.merchantpos.config.PosConfig
     11 
     12 object ScreenshotController {
     13 
     14     const val isActive: Boolean = false
     15 
     16     private const val FIXTURE_ASSET_DIR = "screenshot-products"
     17     private const val CURRENCY = "CHF"
     18 
     19     fun buildFixture(context: Context): FixtureData {
     20         val categories = listOf(
     21             Category(id = 1, name = "Drinks"),
     22             Category(id = 2, name = "Bakery"),
     23             Category(id = 3, name = "Lunch"),
     24             Category(id = 4, name = "Snacks"),
     25             Category(id = 5, name = "Specials"),
     26         )
     27         val products = listOf(
     28             ConfigProduct(
     29                 id = "coffee",
     30                 productId = "coffee",
     31                 productName = "House Coffee",
     32                 description = "Freshly brewed fair-trade blend",
     33                 price = Amount.fromString(CURRENCY, "3.80"),
     34                 categories = listOf(1),
     35                 image = assetDataUri(context, "coffee.png"),
     36                 taxes = setOf(vat("0.29")),
     37                 totalStock = 12,
     38                 totalSold = 4,
     39             ),
     40             ConfigProduct(
     41                 id = "tea",
     42                 productId = "tea",
     43                 productName = "Herbal Tea",
     44                 description = "Mint and lemon verbena infusion",
     45                 price = Amount.fromString(CURRENCY, "3.40"),
     46                 categories = listOf(1),
     47                 image = assetDataUri(context, "tea.png"),
     48                 taxes = setOf(vat("0.26")),
     49                 totalStock = 18,
     50                 totalSold = 6,
     51             ),
     52             ConfigProduct(
     53                 id = "juice",
     54                 productId = "juice",
     55                 productName = "Apple Juice",
     56                 description = "Pressed Swiss apples, 30 cl",
     57                 price = Amount.fromString(CURRENCY, "4.20"),
     58                 categories = listOf(1),
     59                 image = assetDataUri(context, "juice.png"),
     60                 taxes = setOf(vat("0.32")),
     61                 totalStock = 9,
     62                 totalSold = 1,
     63             ),
     64             ConfigProduct(
     65                 id = "espresso",
     66                 productId = "espresso",
     67                 productName = "Espresso",
     68                 description = "Single origin, short pull",
     69                 price = Amount.fromString(CURRENCY, "3.20"),
     70                 categories = listOf(1),
     71                 image = assetDataUri(context, "espresso.png"),
     72                 taxes = setOf(vat("0.24")),
     73                 totalStock = 20,
     74                 totalSold = 8,
     75             ),
     76             ConfigProduct(
     77                 id = "lemonade",
     78                 productId = "lemonade",
     79                 productName = "Lemonade",
     80                 description = "Sparkling lemon and ginger",
     81                 price = Amount.fromString(CURRENCY, "4.40"),
     82                 categories = listOf(1, 5),
     83                 image = assetDataUri(context, "lemonade.png"),
     84                 taxes = setOf(vat("0.33")),
     85                 totalStock = 14,
     86                 totalSold = 4,
     87             ),
     88             ConfigProduct(
     89                 id = "croissant",
     90                 productId = "croissant",
     91                 productName = "Butter Croissant",
     92                 description = "All-butter pastry baked this morning",
     93                 price = Amount.fromString(CURRENCY, "2.90"),
     94                 categories = listOf(2),
     95                 image = assetDataUri(context, "croissant.png"),
     96                 taxes = setOf(vat("0.22")),
     97                 totalStock = 16,
     98                 totalSold = 7,
     99             ),
    100             ConfigProduct(
    101                 id = "muffin",
    102                 productId = "muffin",
    103                 productName = "Blueberry Muffin",
    104                 description = "With lemon crumble topping",
    105                 price = Amount.fromString(CURRENCY, "4.60"),
    106                 categories = listOf(2, 4),
    107                 image = assetDataUri(context, "muffin.png"),
    108                 taxes = setOf(vat("0.35")),
    109                 totalStock = 10,
    110                 totalSold = 3,
    111             ),
    112             ConfigProduct(
    113                 id = "bagel",
    114                 productId = "bagel",
    115                 productName = "Sesame Bagel",
    116                 description = "Toasted with cream cheese",
    117                 price = Amount.fromString(CURRENCY, "5.20"),
    118                 categories = listOf(2),
    119                 image = assetDataUri(context, "bagel.png"),
    120                 taxes = setOf(vat("0.39")),
    121                 totalStock = 9,
    122                 totalSold = 2,
    123             ),
    124             ConfigProduct(
    125                 id = "sandwich",
    126                 productId = "sandwich",
    127                 productName = "Veggie Sandwich",
    128                 description = "Grilled vegetables, hummus, seeded roll",
    129                 price = Amount.fromString(CURRENCY, "8.50"),
    130                 categories = listOf(3),
    131                 image = assetDataUri(context, "sandwich.png"),
    132                 taxes = setOf(vat("0.64")),
    133                 totalStock = 8,
    134                 totalSold = 2,
    135             ),
    136             ConfigProduct(
    137                 id = "wrap",
    138                 productId = "wrap",
    139                 productName = "Chicken Wrap",
    140                 description = "Herbs, salad, yogurt dressing",
    141                 price = Amount.fromString(CURRENCY, "8.90"),
    142                 categories = listOf(3),
    143                 image = assetDataUri(context, "wrap.png"),
    144                 taxes = setOf(vat("0.67")),
    145                 totalStock = 7,
    146                 totalSold = 3,
    147             ),
    148             ConfigProduct(
    149                 id = "salad",
    150                 productId = "salad",
    151                 productName = "Market Salad",
    152                 description = "Greens, grains, roasted seeds",
    153                 price = Amount.fromString(CURRENCY, "9.80"),
    154                 categories = listOf(3, 5),
    155                 image = assetDataUri(context, "salad.png"),
    156                 taxes = setOf(vat("0.74")),
    157                 totalStock = 6,
    158                 totalSold = 1,
    159             ),
    160             ConfigProduct(
    161                 id = "soup",
    162                 productId = "soup",
    163                 productName = "Pumpkin Soup",
    164                 description = "Seasonal special, served warm",
    165                 price = Amount.fromString(CURRENCY, "7.20"),
    166                 categories = listOf(3, 5),
    167                 image = assetDataUri(context, "soup.png"),
    168                 taxes = setOf(vat("0.54")),
    169                 totalStock = 5,
    170                 totalSold = 5,
    171             ),
    172             ConfigProduct(
    173                 id = "quiche",
    174                 productId = "quiche",
    175                 productName = "Vegetable Quiche",
    176                 description = "Daily special with garden vegetables",
    177                 price = Amount.fromString(CURRENCY, "7.90"),
    178                 categories = listOf(3, 5),
    179                 image = assetDataUri(context, "quiche.png"),
    180                 taxes = setOf(vat("0.60")),
    181                 totalStock = 6,
    182                 totalSold = 2,
    183             ),
    184             ConfigProduct(
    185                 id = "granola",
    186                 productId = "granola",
    187                 productName = "Granola Cup",
    188                 description = "Yogurt, berries, toasted oats",
    189                 price = Amount.fromString(CURRENCY, "5.70"),
    190                 categories = listOf(4, 5),
    191                 image = assetDataUri(context, "granola.png"),
    192                 taxes = setOf(vat("0.43")),
    193                 totalStock = 7,
    194                 totalSold = 2,
    195             ),
    196             ConfigProduct(
    197                 id = "chips",
    198                 productId = "chips",
    199                 productName = "Lentil Chips",
    200                 description = "Sea salt snack bag",
    201                 price = Amount.fromString(CURRENCY, "3.60"),
    202                 categories = listOf(4),
    203                 image = assetDataUri(context, "chips.png"),
    204                 taxes = setOf(vat("0.27")),
    205                 totalStock = 15,
    206                 totalSold = 5,
    207             ),
    208             ConfigProduct(
    209                 id = "fruit",
    210                 productId = "fruit",
    211                 productName = "Fruit Cup",
    212                 description = "Seasonal sliced fruit",
    213                 price = Amount.fromString(CURRENCY, "4.90"),
    214                 categories = listOf(4, 5),
    215                 image = assetDataUri(context, "fruit.png"),
    216                 taxes = setOf(vat("0.37")),
    217                 totalStock = 8,
    218                 totalSold = 2,
    219             ),
    220         )
    221         return FixtureData(
    222             posConfig = PosConfig(categories = categories, products = products),
    223             merchantConfig = MerchantConfig(
    224                 baseUrl = "https://merchant.example.invalid/instances/demo",
    225                 apiKey = "",
    226             ),
    227         )
    228     }
    229 
    230     private fun assetDataUri(context: Context, fileName: String): String {
    231         val bytes = context.assets.open("$FIXTURE_ASSET_DIR/$fileName").use { it.readBytes() }
    232         val encoded = Base64.encodeToString(bytes, Base64.NO_WRAP)
    233         return "data:image/png;base64,$encoded"
    234     }
    235 
    236     private fun vat(amount: String) = Tax(
    237         name = "VAT",
    238         tax = Amount.fromString(CURRENCY, amount),
    239     )
    240 
    241     data class FixtureData(
    242         val posConfig: PosConfig,
    243         val merchantConfig: MerchantConfig,
    244     )
    245 }