|
@@ -1,32 +1,22 @@
|
|
|
package com.convenient.android.lib.ui.sample
|
|
|
|
|
|
-import android.Manifest
|
|
|
-import android.app.Activity
|
|
|
-import android.content.Intent
|
|
|
-import android.net.Uri
|
|
|
-import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
-import android.os.Environment
|
|
|
-import android.provider.Settings
|
|
|
import androidx.activity.ComponentActivity
|
|
|
-import androidx.activity.compose.rememberLauncherForActivityResult
|
|
|
import androidx.activity.compose.setContent
|
|
|
-import androidx.activity.result.contract.ActivityResultContracts
|
|
|
-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.common.utils.ToastUtil
|
|
|
import com.convenient.android.lib.DateUtilActivity
|
|
|
-import com.convenient.android.lib.ui.sample.media.MediaSampleActivity
|
|
|
+import com.convenient.android.lib.MediaSampleActivity
|
|
|
import com.kdanmobile.jetpackcompose.sample.ui.theme.SampleTheme
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
@@ -40,64 +30,92 @@ class MainActivity : ComponentActivity() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+@Preview(showSystemUi = true)
|
|
|
+@Composable
|
|
|
+fun MainPagePreview() {
|
|
|
+ SampleTheme {
|
|
|
+ MainPage()
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
@Composable
|
|
|
private fun MainPage() {
|
|
|
- val context = LocalContext.current
|
|
|
- val androidRStoragePermissionLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult(), onResult = {
|
|
|
- if (it.resultCode == Activity.RESULT_OK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
- if (Environment.isExternalStorageManager()) {
|
|
|
- ToastUtil.showToast(context, "访问所有文件权限获取成功")
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- val permissionLaunch = rememberLauncherForActivityResult(contract = ActivityResultContracts.RequestPermission(), onResult = {
|
|
|
- if (it) {
|
|
|
- ToastUtil.showToast(context, "存储权限获取成功")
|
|
|
- }
|
|
|
- })
|
|
|
|
|
|
- Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
|
|
|
+ var bottomSelectedState by remember { mutableStateOf(0) }
|
|
|
|
|
|
- FunItem(title = "获取存储权限") {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
- if (Environment.isExternalStorageManager().not()) {
|
|
|
- androidRStoragePermissionLauncher.launch(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:${context.packageName}")))
|
|
|
- }else{
|
|
|
- ToastUtil.showToast(context, "已获取存储权限")
|
|
|
- }
|
|
|
- } else {
|
|
|
- permissionLaunch.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
+ Scaffold(
|
|
|
+ topBar = {
|
|
|
+ TopAppBar {
|
|
|
+ Text(text = "BaseLib", modifier = Modifier
|
|
|
+ .padding(horizontal = 20.dp)
|
|
|
+ .fillMaxWidth(0.75f)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ },
|
|
|
+ bottomBar = {
|
|
|
+ BottomBarView(bottomSelectedState) {
|
|
|
+ bottomSelectedState = it
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- FunItem(title = "DateUtils 测试") {
|
|
|
- context.readyGo(DateUtilActivity::class.java)
|
|
|
- }
|
|
|
- FunItem(title = "MediaStore 测试") {
|
|
|
- context.readyGo(MediaSampleActivity::class.java)
|
|
|
+ ) {
|
|
|
+ when (bottomSelectedState) {
|
|
|
+ 0 -> FuncListView()
|
|
|
+ else -> Text(text = "建设中")
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+data class FuncBean(
|
|
|
+ val title: String,
|
|
|
+ val class_: Class<*>,
|
|
|
+)
|
|
|
+
|
|
|
@Composable
|
|
|
-private fun FunItem(title: String, onClick: () -> Unit) {
|
|
|
- Button(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .padding(horizontal = 16.dp), onClick = onClick
|
|
|
- ) {
|
|
|
- Text(text = title)
|
|
|
+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)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+data class BottomItem(
|
|
|
+ val title: String,
|
|
|
+)
|
|
|
|
|
|
-@Preview(showSystemUi = true)
|
|
|
@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)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|