主题从公共库获取

master
pan 4 years ago
parent df1349c089
commit 8e527cf491
  1. 2
      background/src/main/java/com/gyf/csams/MainActivity.kt
  2. 44
      background/src/main/java/com/gyf/csams/uikit/theme/Theme.kt
  3. 2
      build.gradle.kts
  4. 2
      foreground/build.gradle.kts
  5. 25
      foreground/src/main/java/com/gyf/csams/account/ui/AccountActivity.kt
  6. 7
      foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt
  7. 7
      foreground/src/main/java/com/gyf/csams/association/ui/RegAssociationActivity.kt
  8. 26
      foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt
  9. 30
      foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt
  10. 9
      foreground/src/main/java/com/gyf/csams/uikit/ViewModel.kt
  11. 8
      foreground/src/main/java/com/gyf/csams/uikit/theme/Color.kt
  12. 11
      foreground/src/main/java/com/gyf/csams/uikit/theme/Shape.kt
  13. 28
      foreground/src/main/java/com/gyf/csams/uikit/theme/Type.kt
  14. 10
      foreground/src/main/java/com/gyf/csams/util/HttpUtil.kt
  15. 12
      foreground/src/test/java/com/gyf/csams/ExampleUnitTest.kt
  16. 13
      lib/build.gradle.kts
  17. 0
      lib/src/main/java/com/gyf/lib/uikit/theme/Color.kt
  18. 0
      lib/src/main/java/com/gyf/lib/uikit/theme/Shape.kt
  19. 3
      lib/src/main/java/com/gyf/lib/uikit/theme/Theme.kt
  20. 0
      lib/src/main/java/com/gyf/lib/uikit/theme/Type.kt

@ -8,7 +8,7 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.gyf.lib.uikit.theme.CSAMSTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {

@ -1,44 +0,0 @@
package com.gyf.csams.uikit.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
private val DarkColorPalette = darkColors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200
)
private val LightColorPalette = lightColors(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200
/* Other default colors to override
background = Color.White,
surface = Color.White,
onPrimary = Color.White,
onSecondary = Color.Black,
onBackground = Color.Black,
onSurface = Color.Black,
*/
)
@Composable
fun CSAMSTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}
MaterialTheme(
colors = colors,
typography = Typography,
shapes = Shapes,
content = content
)
}

@ -7,7 +7,7 @@ buildscript {
//APP应用名字
val foreground_app_name by extra("学生社团")
val SERVER_ADDRESS by extra("http://192.168.50.107:8080")
val room_version by extra("2.2.6")
val room_version by extra("2.3.0")
val kotlin_version by extra("1.4.32")
val background_app_name by extra("社团管理")
repositories {

@ -81,6 +81,6 @@ dependencies {
* 包含核心和基本的 View 匹配器、操作和断言
*/
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:${rootProject.extra["compose_version"]}")
// androidTestImplementation("androidx.compose.ui:ui-test-junit4:${rootProject.extra["compose_version"]}")
}

@ -30,7 +30,6 @@ import com.gyf.csams.account.model.DialogMessage
import com.gyf.csams.uikit.AnimationText
import com.gyf.csams.uikit.BaseTextField
import com.gyf.csams.uikit.Body
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.orhanobut.logger.Logger
@ -44,18 +43,17 @@ class AccountActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
CSAMSTheme {
Body { nav, scaffoldState ->
NavHost(navController = nav, startDestination = AccountRoute.login.name) {
composable(AccountRoute.login.name) {
Account(
scaffoldState = scaffoldState,
route = AccountRoute.login
) { isValidForm: Boolean, accountViewModel: AccountViewModel ->
Spacer(modifier = Modifier.height(10.dp))
OutlinedButton(
onClick = { accountViewModel.login() },
Body { nav, scaffoldState ->
NavHost(navController = nav, startDestination = AccountRoute.login.name) {
composable(AccountRoute.login.name) {
Account(
scaffoldState = scaffoldState,
route = AccountRoute.login
) { isValidForm: Boolean, accountViewModel: AccountViewModel ->
Spacer(modifier = Modifier.height(10.dp))
OutlinedButton(
onClick = { accountViewModel.login() },
enabled = isValidForm,
modifier = Modifier
.fillMaxWidth()
@ -114,7 +112,6 @@ class AccountActivity : ComponentActivity() {
}
}
}
}
}
/**

@ -29,7 +29,6 @@ import com.gyf.csams.R
import com.gyf.csams.activity.ui.ActivityDetailActivity
import com.gyf.csams.association.model.*
import com.gyf.csams.uikit.*
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.gyf.csams.util.randomChinese
import com.orhanobut.logger.Logger
@ -42,8 +41,8 @@ class AssociationActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CSAMSTheme {
Body { nav, scaffoldState ->
Body { nav, scaffoldState ->
val context = LocalContext.current as AssociationActivity
val model: AssociationViewModel = viewModel()
val currentMenuName: AssociationMenu by model.currentMenu.observeAsState(
@ -169,7 +168,7 @@ class AssociationActivity : ComponentActivity() {
}
}
}
}
}

@ -35,7 +35,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.gyf.csams.R
import com.gyf.csams.association.model.RegAssociationViewModel
import com.gyf.csams.uikit.*
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.orhanobut.logger.Logger
@ -47,8 +46,8 @@ class RegAssociationActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CSAMSTheme {
Body { scaffoldState ->
Body { scaffoldState ->
MainFrame(background = {
Background(
BackgroundImage.RegAssociation,
@ -79,7 +78,7 @@ class RegAssociationActivity : ComponentActivity() {
ShowSnackbar(scaffoldState = scaffoldState)
}
}
}
}
}

@ -19,7 +19,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
@ -34,7 +33,6 @@ import com.gyf.csams.association.ui.RegAssociationActivity
import com.gyf.csams.main.model.*
import com.gyf.csams.message.ui.MessageActivity
import com.gyf.csams.uikit.*
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.gyf.csams.util.randomChinese
@ -52,7 +50,7 @@ class MainActivity : ComponentActivity() {
imageModel = ImageModel(application = application, Api.buildUrl(MainApi.HotActivity))
setContent {
CSAMSTheme {
Body { nav, scaffoldState ->
NavHost(navController = nav, startDestination = MainMenu.Main.name) {
composable(MainMenu.Main.name) {
@ -70,15 +68,10 @@ class MainActivity : ComponentActivity() {
}
}
}
}
}
}
override fun onStart() {
super.onStart()
imageModel.start()
}
override fun onResume() {
@ -490,9 +483,14 @@ class MainActivity : ComponentActivity() {
*
*/
@Composable
private fun PosterWithDesc() {
private fun PosterWithDesc(scaffoldModel: ScaffoldModel = viewModel()) {
val context = LocalContext.current as MainActivity
val error by context.imageModel.error.observeAsState()
error?.let {
scaffoldModel.update(message = it)
context.imageModel.clearError()
}
Carousel(imageBitmap = context.imageModel.image) {
Column(modifier = Modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java))
@ -513,14 +511,6 @@ class MainActivity : ComponentActivity() {
}
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
CSAMSTheme {
Text(text = "666")
}
}
}

@ -26,6 +26,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
@ -36,6 +37,7 @@ import androidx.navigation.compose.rememberNavController
import com.gyf.csams.APP
import com.gyf.csams.R
import com.gyf.csams.main.model.MarqueeViewModel
import com.gyf.lib.uikit.theme.CSAMSTheme
import com.orhanobut.logger.Logger
import kotlinx.coroutines.launch
@ -626,11 +628,13 @@ fun Background(image: BackgroundImage, alpha: Float = DefaultAlpha) {
*/
@Composable
fun Body(content: @Composable (scaffoldState: ScaffoldState) -> Unit) {
Surface(color = MaterialTheme.colors.background) {
val scaffoldState = rememberScaffoldState()
CSAMSTheme {
Surface(color = MaterialTheme.colors.background) {
val scaffoldState = rememberScaffoldState()
Scaffold(scaffoldState = scaffoldState) {
content(scaffoldState = scaffoldState)
Scaffold(scaffoldState = scaffoldState) {
content(scaffoldState = scaffoldState)
}
}
}
}
@ -642,12 +646,14 @@ fun Body(content: @Composable (scaffoldState: ScaffoldState) -> Unit) {
*/
@Composable
fun Body(content: @Composable (nav: NavHostController, scaffoldState: ScaffoldState) -> Unit) {
Surface(color = MaterialTheme.colors.background) {
val navController = rememberNavController()
val scaffoldState = rememberScaffoldState()
CSAMSTheme {
Surface(color = MaterialTheme.colors.background) {
val navController = rememberNavController()
val scaffoldState = rememberScaffoldState()
Scaffold(scaffoldState = scaffoldState) {
content(nav = navController, scaffoldState = scaffoldState)
Scaffold(scaffoldState = scaffoldState) {
content(nav = navController, scaffoldState = scaffoldState)
}
}
}
}
@ -776,6 +782,10 @@ fun MyBottomAppBarPreview() {
}
}
@Preview
@Composable
fun TestPreview() {
CSAMSTheme {
Text(text = "fuckyou")
}
}

@ -92,6 +92,12 @@ class ImageModel(application: Application, private val urlPath: String) :
private val _imageUrls = MutableLiveData<List<String>>()
val image: LiveData<ImageBitmap> = _image
private var job: Job? = null
private val _error = MutableLiveData<String>()
val error: LiveData<String> = _error
fun clearError() {
_error.value = null
}
/**
* 加载默认图片
@ -118,7 +124,7 @@ class ImageModel(application: Application, private val urlPath: String) :
job = viewModelScope.launch {
HttpClient.get(
url = urlPath,
SimpleCallback<List<String>>("请求图片url列表", onSuccess = {
SimpleCallback<List<String>>("获取轮播图", onSuccess = {
_imageUrls.postValue(it.body)
var index = 0
_imageUrls.value?.apply {
@ -138,6 +144,7 @@ class ImageModel(application: Application, private val urlPath: String) :
}
}, onFail = {
Logger.e("无法从接口地址:${urlPath}获取图片url列表")
_error.postValue(it)
defaultLoad()
}, type = object : TypeToken<List<String>>() {}.type)
)

@ -1,8 +0,0 @@
package com.gyf.csams.uikit.theme
import androidx.compose.ui.graphics.Color
val Purple200 = Color(0xFFBB86FC)
val Purple500 = Color(0xFF6200EE)
val Purple700 = Color(0xFF3700B3)
val Teal200 = Color(0xFF03DAC5)

@ -1,11 +0,0 @@
package com.gyf.csams.uikit.theme
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.ui.unit.dp
val Shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
)

@ -1,28 +0,0 @@
package com.gyf.csams.uikit.theme
import androidx.compose.material.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(
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
)
/* Other default text styles to override
button = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.W500,
fontSize = 14.sp
),
caption = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 12.sp
)
*/
)

@ -9,6 +9,7 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.IOException
import java.lang.reflect.Type
import java.net.SocketTimeoutException
object HttpClient {
private val httpClient: OkHttpClient = OkHttpClient()
@ -136,7 +137,14 @@ class SimpleCallback<T>(
}
override fun onFailure(call: Call, e: IOException) {
onFail("${action}失败,请联系管理员")
when (e) {
is SocketTimeoutException -> {
onFail("${action}失败,网络连接超时!")
}
else -> {
onFail("${action}失败,请联系管理员")
}
}
Logger.e(e, "${action}请求失败,发生IO异常")
}

@ -4,6 +4,7 @@ import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.gyf.csams.util.ApiResponse
import com.gyf.csams.util.randomChinese
import com.gyf.lib.uikit.TestLib
import org.junit.Assert.assertEquals
import org.junit.Test
@ -34,10 +35,9 @@ class ExampleUnitTest {
}
@Test
fun testCharRange(){
repeat(100){
fun testCharRange() {
repeat(100) {
println(randomChinese())
}
@ -45,5 +45,11 @@ class ExampleUnitTest {
// .format(java.time.Instant.ofEpochMilli(1532358895000)))
}
@Test
fun testLib() {
TestLib.hello()
Fuck()
}
}

@ -1,7 +1,7 @@
plugins {
id("com.android.library")
id("kotlin-android")
id("org.jetbrains.kotlin.plugin.serialization") version "1.4.32"
// id("org.jetbrains.kotlin.plugin.serialization") version "1.4.32"
}
android {
@ -30,7 +30,16 @@ android {
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
)
}
buildFeatures {
compose = true
}
}
dependencies {
@ -90,7 +99,7 @@ dependencies {
/**
* https://kotlinlang.org/docs/serialization.html
*/
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0")
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1")
/**
* https://developer.android.com/jetpack/androidx/releases/navigation
*/

@ -1,10 +1,11 @@
package com.gyf.csams.uikit.theme
package com.gyf.lib.uikit.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import com.gyf.csams.uikit.theme.*
private val DarkColorPalette = darkColors(
primary = Purple200,
Loading…
Cancel
Save