|
@@ -3,19 +3,20 @@ package com.convenient.android.lib.ui.sample
|
|
|
import android.os.Bundle
|
|
|
import androidx.activity.ComponentActivity
|
|
|
import androidx.activity.compose.setContent
|
|
|
-import androidx.compose.foundation.layout.Column
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
-import androidx.compose.material.Button
|
|
|
-import androidx.compose.material.Text
|
|
|
-import androidx.compose.runtime.Composable
|
|
|
-import androidx.compose.ui.Alignment
|
|
|
+import androidx.compose.foundation.lazy.LazyColumn
|
|
|
+import androidx.compose.material.*
|
|
|
+import androidx.compose.material.icons.Icons
|
|
|
+import androidx.compose.material.icons.filled.Favorite
|
|
|
+import androidx.compose.runtime.*
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import com.convenient.android.common.extension.readyGo
|
|
|
import com.convenient.android.lib.DateUtilActivity
|
|
|
+import com.convenient.android.lib.MediaSampleActivity
|
|
|
import com.kdanmobile.jetpackcompose.sample.ui.theme.SampleTheme
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
@@ -29,25 +30,92 @@ class MainActivity : ComponentActivity() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+@Preview(showSystemUi = true)
|
|
|
+@Composable
|
|
|
+fun MainPagePreview() {
|
|
|
+ SampleTheme {
|
|
|
+ MainPage()
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
@Composable
|
|
|
private fun MainPage() {
|
|
|
- val context = LocalContext.current
|
|
|
- Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
|
|
|
- Button(modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),onClick = {
|
|
|
- context.readyGo(DateUtilActivity::class.java)
|
|
|
- }) {
|
|
|
- Text(text = "DateUtils 测试")
|
|
|
+
|
|
|
+ var bottomSelectedState by remember { mutableStateOf(0) }
|
|
|
+
|
|
|
+ Scaffold(
|
|
|
+ topBar = {
|
|
|
+ TopAppBar {
|
|
|
+ Text(text = "BaseLib", modifier = Modifier
|
|
|
+ .padding(horizontal = 20.dp)
|
|
|
+ .fillMaxWidth(0.75f)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ },
|
|
|
+ bottomBar = {
|
|
|
+ BottomBarView(bottomSelectedState) {
|
|
|
+ bottomSelectedState = it
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ) {
|
|
|
+ when (bottomSelectedState) {
|
|
|
+ 0 -> FuncListView()
|
|
|
+ else -> Text(text = "建设中")
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
+data class FuncBean(
|
|
|
+ val title: String,
|
|
|
+ val class_: Class<*>,
|
|
|
+)
|
|
|
+
|
|
|
+@Composable
|
|
|
+private fun FuncListView() {
|
|
|
+ val context = LocalContext.current
|
|
|
+ val funcList = arrayListOf(
|
|
|
+ FuncBean("DateUtils", DateUtilActivity::class.java),
|
|
|
+ FuncBean("MediaUtils", MediaSampleActivity::class.java)
|
|
|
+ )
|
|
|
+
|
|
|
+ LazyColumn {
|
|
|
+ items(funcList.size) { index ->
|
|
|
+ Button(modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(horizontal = 16.dp), onClick = {
|
|
|
+ context.readyGo(funcList[index].class_)
|
|
|
+ }) {
|
|
|
+ Text(text = funcList[index].title)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-@Preview(showSystemUi = true)
|
|
|
+data class BottomItem(
|
|
|
+ val title: String,
|
|
|
+)
|
|
|
+
|
|
|
@Composable
|
|
|
-fun MainPagePreview() {
|
|
|
- SampleTheme {
|
|
|
- MainPage()
|
|
|
+private fun BottomBarView(selectedPosition: Int, onItemSelected: (position: Int) -> Unit) {
|
|
|
+ val itemList = arrayListOf(
|
|
|
+ BottomItem(title = "工具"),
|
|
|
+ BottomItem(title = "建设中"),
|
|
|
+ BottomItem(title = "建设中"),
|
|
|
+ BottomItem(title = "建设中")
|
|
|
+ )
|
|
|
+
|
|
|
+ BottomNavigation() {
|
|
|
+ itemList.forEachIndexed { index, bottomItem ->
|
|
|
+ BottomNavigationItem(
|
|
|
+ selected = selectedPosition == index,
|
|
|
+ onClick = { onItemSelected.invoke(index) },
|
|
|
+ icon = {
|
|
|
+ Icon(Icons.Filled.Favorite, contentDescription = null)
|
|
|
+ },
|
|
|
+ label = {
|
|
|
+ Text(bottomItem.title)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|