sample/src/commonMain/kotlin/SampleApp.kt
changeset 47 246422783c0c
child 89 0cc872a9edbf
equal deleted inserted replaced
46:c40e90a1b0fa 47:246422783c0c
       
     1 /*
       
     2  * AboutOss is an utility library to retrieve and display
       
     3  * opensource licenses in Android applications.
       
     4  *
       
     5  * Copyright (C) 2023-2025 by Frederic-Charles Barthelery.
       
     6  *
       
     7  * This file is part of AboutOss.
       
     8  *
       
     9  * AboutOss is free software: you can redistribute it and/or modify
       
    10  * it under the terms of the GNU General Public License as published by
       
    11  * the Free Software Foundation, either version 3 of the License, or
       
    12  * (at your option) any later version.
       
    13  *
       
    14  * AboutOss is distributed in the hope that it will be useful,
       
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    17  * GNU General Public License for more details.
       
    18  *
       
    19  * You should have received a copy of the GNU General Public License
       
    20  * along with AboutOss.  If not, see <http://www.gnu.org/licenses/>.
       
    21  */
       
    22 package com.geekorum.aboutoss.sampleapp
       
    23 
       
    24 import androidx.compose.foundation.layout.Arrangement
       
    25 import androidx.compose.foundation.layout.Column
       
    26 import androidx.compose.foundation.layout.Row
       
    27 import androidx.compose.foundation.layout.fillMaxSize
       
    28 import androidx.compose.foundation.layout.fillMaxWidth
       
    29 import androidx.compose.foundation.layout.padding
       
    30 import androidx.compose.material3.Card
       
    31 import androidx.compose.material3.ExperimentalMaterial3Api
       
    32 import androidx.compose.material3.MaterialTheme
       
    33 import androidx.compose.material3.Surface
       
    34 import androidx.compose.material3.Text
       
    35 import androidx.compose.runtime.Composable
       
    36 import androidx.compose.ui.Modifier
       
    37 import androidx.compose.ui.unit.dp
       
    38 import com.geekorum.aboutoss.sampleapp.ui.theme.AboutOssTheme
       
    39 import org.jetbrains.compose.ui.tooling.preview.Preview
       
    40 
       
    41 @Composable
       
    42 fun SampleApp(
       
    43     onMaterial2Click: () -> Unit,
       
    44     onMaterial3Click: () -> Unit,
       
    45 ) {
       
    46     Surface(
       
    47         modifier = Modifier.fillMaxSize(),
       
    48         color = MaterialTheme.colorScheme.background
       
    49     ) {
       
    50         Column(Modifier.fillMaxSize()) {
       
    51             LaunchActivitySection(onMaterial2Click, onMaterial3Click)
       
    52             CustomViewer(modifier = Modifier.padding(horizontal = 16.dp))
       
    53         }
       
    54     }
       
    55 }
       
    56 
       
    57 @Composable
       
    58 private fun LaunchActivitySection(
       
    59     onMaterial2Click: () -> Unit,
       
    60     onMaterial3Click: () -> Unit,
       
    61     modifier: Modifier = Modifier
       
    62 ) {
       
    63     Column(modifier.padding(16.dp)) {
       
    64         Text(text = "This section launch a new activity to display licences information")
       
    65         Row(
       
    66             horizontalArrangement = Arrangement.SpaceAround, modifier = Modifier
       
    67                 .fillMaxWidth()
       
    68                 .padding(32.dp)
       
    69         ) {
       
    70             Material2Card(onClick = onMaterial2Click)
       
    71             Material3Card(onClick = onMaterial3Click)
       
    72         }
       
    73     }
       
    74 }
       
    75 
       
    76 
       
    77 @Composable
       
    78 @OptIn(ExperimentalMaterial3Api::class)
       
    79 private fun Material2Card(
       
    80     onClick: () -> Unit,
       
    81     modifier: Modifier = Modifier
       
    82 ) {
       
    83     Card(modifier = modifier, onClick = onClick) {
       
    84         Column(Modifier.padding(16.dp)) {
       
    85             Text("Material2 UI", style = MaterialTheme.typography.labelLarge)
       
    86         }
       
    87     }
       
    88 }
       
    89 
       
    90 @Composable
       
    91 @OptIn(ExperimentalMaterial3Api::class)
       
    92 private fun Material3Card(
       
    93     onClick: () -> Unit,
       
    94     modifier: Modifier = Modifier
       
    95 ) {
       
    96     Card(modifier = modifier, onClick = onClick) {
       
    97         Column(Modifier.padding(16.dp)) {
       
    98             Text("Material3 UI", style = MaterialTheme.typography.labelLarge)
       
    99         }
       
   100     }
       
   101 }
       
   102 
       
   103 
       
   104 @Preview
       
   105 @Composable
       
   106 fun LauncherActivitySectionPreview() {
       
   107     AboutOssTheme {
       
   108         Surface {
       
   109             LaunchActivitySection(onMaterial2Click = {}, onMaterial3Click = {})
       
   110         }
       
   111     }
       
   112 }