diff --git a/app-compose/.gitignore b/app-compose/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app-compose/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app-compose/build.gradle b/app-compose/build.gradle new file mode 100644 index 0000000..0033ebf --- /dev/null +++ b/app-compose/build.gradle @@ -0,0 +1,39 @@ +apply from: "${rootProject.rootDir}/buildCommon/commonLibConfig.gradle" +project.ext.setAppDefaultConfig project + +android { + namespace 'com.yinuo.safetywatcher' + + defaultConfig { + applicationId "com.yinuo.safetywatcher" + vectorDrawables { + useSupportLibrary true + } + } + + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion '1.3.2' + } + packagingOptions { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } + } +} + +dependencies { + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1' + implementation platform('androidx.compose:compose-bom:2022.10.00') + implementation 'androidx.activity:activity-compose:1.5.1' + implementation 'androidx.compose.ui:ui' + implementation 'androidx.compose.ui:ui-graphics' + implementation 'androidx.compose.ui:ui-tooling-preview' + implementation 'androidx.compose.material3:material3' + implementation 'androidx.navigation:navigation-runtime-ktx:2.5.2' + implementation "androidx.navigation:navigation-compose:2.4.0-rc01" +} \ No newline at end of file diff --git a/app-compose/proguard-rules.pro b/app-compose/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app-compose/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app-compose/src/main/AndroidManifest.xml b/app-compose/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9d5de03 --- /dev/null +++ b/app-compose/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/MainActivity.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/MainActivity.kt new file mode 100644 index 0000000..dd1b0c1 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/MainActivity.kt @@ -0,0 +1,61 @@ +package com.yinuo.safetywatcher + +import android.os.Bundle +import android.widget.Toast +import androidx.activity.ComponentActivity +import androidx.activity.OnBackPressedCallback +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.ui.Modifier +import androidx.lifecycle.viewmodel.compose.viewModel +import androidx.navigation.compose.rememberNavController +import com.yinuo.safetywatcher.navi.NavigationUtil +import com.yinuo.safetywatcher.navi.NavigationView +import com.yinuo.safetywatcher.ui.SplashView +import com.yinuo.safetywatcher.ui.theme.EasypusherTheme + +class MainActivity : ComponentActivity() { + var exitTime = 0L + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + EasypusherTheme { + // A surface container using the 'background' color from the theme + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + val viewModel: MainViewModel = viewModel() + if (viewModel.isSplash) { + SplashView { viewModel.isSplash = false } + } else { + NavigationUtil.navHostController = rememberNavController() + NavigationView() + } + } + } + } + addBackListener() + } + + private fun addBackListener() { + onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if (NavigationUtil.backAndReturnsIsLastPage()) { + //是主页 + if (System.currentTimeMillis() - exitTime > 2000) { + Toast.makeText(this@MainActivity, "再点一次退出!", Toast.LENGTH_SHORT) + .show() + exitTime = System.currentTimeMillis() + } else { + finish() + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out) + } + } + } + }) + } +} diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/MainViewModel.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/MainViewModel.kt new file mode 100644 index 0000000..3fe0e52 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/MainViewModel.kt @@ -0,0 +1,10 @@ +package com.yinuo.safetywatcher + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.lifecycle.ViewModel + +class MainViewModel: ViewModel() { + var isSplash by mutableStateOf(true) +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/navi/ModelPath.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/navi/ModelPath.kt new file mode 100644 index 0000000..ef77154 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/navi/ModelPath.kt @@ -0,0 +1,10 @@ +package com.yinuo.safetywatcher.navi + +/** + * @Description: todo + * @CreateDate: 2022/1/5 9:42 + */ +sealed class ModelPath(val route: String) { + object Home : ModelPath("home") + object Setting : ModelPath("setting") +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/navi/Navigation.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/navi/Navigation.kt new file mode 100644 index 0000000..fa09969 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/navi/Navigation.kt @@ -0,0 +1,31 @@ +package com.yinuo.safetywatcher.navi + +import androidx.compose.animation.core.tween +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import com.yinuo.safetywatcher.ui.home.HomeView +import com.yinuo.safetywatcher.ui.setting.SettingView + +/** + * @Description: todo + * @CreateDate: 2022/2/22 19:31 + */ +@Composable +fun NavigationView() { + NavHost(navController = NavigationUtil.navHostController, + startDestination = ModelPath.Home.route) { + composable(ModelPath.Home.route) { + HomeView() + } + composable(ModelPath.Setting.route) { + SettingView(Modifier.fillMaxSize()) + } + } +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/navi/NavigationUtil.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/navi/NavigationUtil.kt new file mode 100644 index 0000000..51320df --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/navi/NavigationUtil.kt @@ -0,0 +1,74 @@ +package com.yinuo.safetywatcher.navi + +import android.annotation.SuppressLint +import android.os.Bundle +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.core.net.toUri +import androidx.navigation.* + +/** + * @CreateDate: 2021/8/27 10:06 + */ +object NavigationUtil { + var currentScreen: ModelPath? by mutableStateOf(ModelPath.Home) + val navList = mutableStateListOf(currentScreen) + + @SuppressLint("StaticFieldLeak") + lateinit var navHostController: NavHostController + + /** + * 跳转到某个页面 + */ + fun to(screenName: ModelPath) { + currentScreen = screenName + navHostController.navigate(screenName.route) + navList.add(screenName) + } + + /** + * 跳转到某个页面带参数 + */ + fun toBundle(screenName: ModelPath, bundle: Bundle) { + currentScreen = screenName + navHostController.navigate(screenName.route, bundle) + navList.add(screenName) + } + + private fun NavController.navigate( + route: String, + args: Bundle, + navOptions: NavOptions? = null, + navigatorExtras: Navigator.Extras? = null + ) { + val routeLink = NavDeepLinkRequest.Builder.Companion.fromUri( + NavDestination.Companion.createRoute(route).toUri()) + .build() + + val deepLinkMatch = graph.matchDeepLink(routeLink) + if (deepLinkMatch != null) { + val destination = deepLinkMatch.destination + val id = destination.id + navigate(id, args, navOptions, navigatorExtras) + } else { + navigate(route, navOptions, navigatorExtras) + } + } + + /** + * 返回到上一页 + */ + fun backAndReturnsIsLastPage(): Boolean { + return if (navList.size == 1) { + //当前是最后一页了,返回true + true + } else { + navList.removeLast() + currentScreen = navList.last() + navHostController.navigateUp() + false + } + } +} diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/SplashView.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/SplashView.kt new file mode 100644 index 0000000..f870558 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/SplashView.kt @@ -0,0 +1,55 @@ +package com.yinuo.safetywatcher.ui + +import androidx.compose.animation.animateColorAsState +import androidx.compose.animation.core.tween +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import kotlinx.coroutines.delay + +/** + * @Description: todo + * @Author: yshh + * @CreateDate: 2022/2/22 14:19 + */ + +@Composable +fun SplashView(startMain: () -> Unit) { + var enabled by remember { mutableStateOf(false) } + val bgColor: Color by animateColorAsState( + if (enabled) MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.primary.copy(alpha = 0.3f), + animationSpec = tween(durationMillis = 2000) + ) + val textColor: Color by animateColorAsState( + if (enabled) Color.White + else Color.White.copy(alpha = 0.3f), + animationSpec = tween(durationMillis = 2000) + ) + Box( + Modifier + .fillMaxSize() + .background(Color.White) + ) { + Box( + Modifier + .fillMaxSize() + .background(bgColor), + contentAlignment = Alignment.Center + ) { + Text(text = "Safety Watcher", color = textColor) + } + + } + LaunchedEffect(Unit) { + enabled = true + delay(2000) + startMain.invoke() + } +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/home/HomeView.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/home/HomeView.kt new file mode 100644 index 0000000..df2f562 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/home/HomeView.kt @@ -0,0 +1,21 @@ +package com.yinuo.safetywatcher.ui.home + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.yinuo.safetywatcher.navi.ModelPath +import com.yinuo.safetywatcher.navi.NavigationUtil + +@Composable +fun HomeView() { + Column(modifier = Modifier.fillMaxSize()) { + Text(text = "Home") + + Button(onClick = { NavigationUtil.to(ModelPath.Setting) }) { + Text(text = "设置") + } + } +} diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/setting/SettingView.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/setting/SettingView.kt new file mode 100644 index 0000000..1e0c6cd --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/setting/SettingView.kt @@ -0,0 +1,13 @@ +package com.yinuo.safetywatcher.ui.setting + +import androidx.compose.foundation.layout.Box +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +fun SettingView(modifier: Modifier = Modifier) { + Box(modifier = modifier){ + Text(text = "这是设置页面") + } +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Color.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Color.kt new file mode 100644 index 0000000..8ad3839 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.yinuo.safetywatcher.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Theme.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Theme.kt new file mode 100644 index 0000000..f563594 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Theme.kt @@ -0,0 +1,24 @@ +package com.yinuo.safetywatcher.ui.theme + +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable + + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 +) + +@Composable +fun EasypusherTheme( + content: @Composable () -> Unit +) { + val colorScheme = LightColorScheme + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Type.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Type.kt new file mode 100644 index 0000000..28735bf --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.yinuo.safetywatcher.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/app-compose/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app-compose/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app-compose/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app-compose/src/main/res/drawable/ic_launcher_background.xml b/app-compose/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app-compose/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app-compose/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app-compose/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app-compose/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app-compose/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app-compose/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app-compose/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app-compose/src/main/res/mipmap-hdpi/ic_launcher.webp b/app-compose/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app-compose/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app-compose/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app-compose/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app-compose/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app-compose/src/main/res/mipmap-mdpi/ic_launcher.webp b/app-compose/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app-compose/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app-compose/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app-compose/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app-compose/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app-compose/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app-compose/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app-compose/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app-compose/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app-compose/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app-compose/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app-compose/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app-compose/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app-compose/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app-compose/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app-compose/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app-compose/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app-compose/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app-compose/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app-compose/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app-compose/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app-compose/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app-compose/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app-compose/src/main/res/values/colors.xml b/app-compose/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/app-compose/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app-compose/src/main/res/values/strings.xml b/app-compose/src/main/res/values/strings.xml new file mode 100644 index 0000000..3799d13 --- /dev/null +++ b/app-compose/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + app-compose + \ No newline at end of file diff --git a/app-compose/src/main/res/values/themes.xml b/app-compose/src/main/res/values/themes.xml new file mode 100644 index 0000000..d7055e4 --- /dev/null +++ b/app-compose/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +