主题从公共库获取

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. 3
      foreground/src/main/java/com/gyf/csams/account/ui/AccountActivity.kt
  6. 5
      foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt
  7. 5
      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. 12
      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. 8
      foreground/src/main/java/com/gyf/csams/util/HttpUtil.kt
  15. 8
      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.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import com.gyf.csams.uikit.theme.CSAMSTheme import com.gyf.lib.uikit.theme.CSAMSTheme
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { 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应用名字 //APP应用名字
val foreground_app_name by extra("学生社团") val foreground_app_name by extra("学生社团")
val SERVER_ADDRESS by extra("http://192.168.50.107:8080") 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 kotlin_version by extra("1.4.32")
val background_app_name by extra("社团管理") val background_app_name by extra("社团管理")
repositories { repositories {

@ -81,6 +81,6 @@ dependencies {
* 包含核心和基本的 View 匹配器、操作和断言 * 包含核心和基本的 View 匹配器、操作和断言
*/ */
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0") 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.AnimationText
import com.gyf.csams.uikit.BaseTextField import com.gyf.csams.uikit.BaseTextField
import com.gyf.csams.uikit.Body import com.gyf.csams.uikit.Body
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
@ -44,7 +43,6 @@ class AccountActivity : ComponentActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
CSAMSTheme {
Body { nav, scaffoldState -> Body { nav, scaffoldState ->
NavHost(navController = nav, startDestination = AccountRoute.login.name) { NavHost(navController = nav, startDestination = AccountRoute.login.name) {
composable(AccountRoute.login.name) { composable(AccountRoute.login.name) {
@ -115,7 +113,6 @@ class AccountActivity : ComponentActivity() {
} }
} }
} }
}
/** /**
* 帐号表单 * 帐号表单

@ -29,7 +29,6 @@ import com.gyf.csams.R
import com.gyf.csams.activity.ui.ActivityDetailActivity import com.gyf.csams.activity.ui.ActivityDetailActivity
import com.gyf.csams.association.model.* import com.gyf.csams.association.model.*
import com.gyf.csams.uikit.* import com.gyf.csams.uikit.*
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.gyf.csams.util.randomChinese import com.gyf.csams.util.randomChinese
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
@ -42,7 +41,7 @@ class AssociationActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
CSAMSTheme {
Body { nav, scaffoldState -> Body { nav, scaffoldState ->
val context = LocalContext.current as AssociationActivity val context = LocalContext.current as AssociationActivity
val model: AssociationViewModel = viewModel() val model: AssociationViewModel = viewModel()
@ -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.R
import com.gyf.csams.association.model.RegAssociationViewModel import com.gyf.csams.association.model.RegAssociationViewModel
import com.gyf.csams.uikit.* import com.gyf.csams.uikit.*
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
@ -47,7 +46,7 @@ class RegAssociationActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
CSAMSTheme {
Body { scaffoldState -> Body { scaffoldState ->
MainFrame(background = { MainFrame(background = {
Background( Background(
@ -79,7 +78,7 @@ class RegAssociationActivity : ComponentActivity() {
ShowSnackbar(scaffoldState = scaffoldState) ShowSnackbar(scaffoldState = scaffoldState)
} }
} }
}
} }
} }

@ -19,7 +19,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController 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.main.model.*
import com.gyf.csams.message.ui.MessageActivity import com.gyf.csams.message.ui.MessageActivity
import com.gyf.csams.uikit.* import com.gyf.csams.uikit.*
import com.gyf.csams.uikit.theme.CSAMSTheme
import com.gyf.csams.util.randomChinese import com.gyf.csams.util.randomChinese
@ -52,7 +50,7 @@ class MainActivity : ComponentActivity() {
imageModel = ImageModel(application = application, Api.buildUrl(MainApi.HotActivity)) imageModel = ImageModel(application = application, Api.buildUrl(MainApi.HotActivity))
setContent { setContent {
CSAMSTheme {
Body { nav, scaffoldState -> Body { nav, scaffoldState ->
NavHost(navController = nav, startDestination = MainMenu.Main.name) { NavHost(navController = nav, startDestination = MainMenu.Main.name) {
composable(MainMenu.Main.name) { composable(MainMenu.Main.name) {
@ -70,15 +68,10 @@ class MainActivity : ComponentActivity() {
} }
} }
}
}
} }
override fun onStart() {
super.onStart()
imageModel.start()
} }
override fun onResume() { override fun onResume() {
@ -490,9 +483,14 @@ class MainActivity : ComponentActivity() {
* *
*/ */
@Composable @Composable
private fun PosterWithDesc() { private fun PosterWithDesc(scaffoldModel: ScaffoldModel = viewModel()) {
val context = LocalContext.current as MainActivity 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) { Carousel(imageBitmap = context.imageModel.image) {
Column(modifier = Modifier.clickable(onClick = { Column(modifier = Modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java)) 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.ImeAction
import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
@ -36,6 +37,7 @@ import androidx.navigation.compose.rememberNavController
import com.gyf.csams.APP import com.gyf.csams.APP
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.main.model.MarqueeViewModel import com.gyf.csams.main.model.MarqueeViewModel
import com.gyf.lib.uikit.theme.CSAMSTheme
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -626,6 +628,7 @@ fun Background(image: BackgroundImage, alpha: Float = DefaultAlpha) {
*/ */
@Composable @Composable
fun Body(content: @Composable (scaffoldState: ScaffoldState) -> Unit) { fun Body(content: @Composable (scaffoldState: ScaffoldState) -> Unit) {
CSAMSTheme {
Surface(color = MaterialTheme.colors.background) { Surface(color = MaterialTheme.colors.background) {
val scaffoldState = rememberScaffoldState() val scaffoldState = rememberScaffoldState()
@ -634,6 +637,7 @@ fun Body(content: @Composable (scaffoldState: ScaffoldState) -> Unit) {
} }
} }
} }
}
/** /**
* 带导航的主体 * 带导航的主体
@ -642,6 +646,7 @@ fun Body(content: @Composable (scaffoldState: ScaffoldState) -> Unit) {
*/ */
@Composable @Composable
fun Body(content: @Composable (nav: NavHostController, scaffoldState: ScaffoldState) -> Unit) { fun Body(content: @Composable (nav: NavHostController, scaffoldState: ScaffoldState) -> Unit) {
CSAMSTheme {
Surface(color = MaterialTheme.colors.background) { Surface(color = MaterialTheme.colors.background) {
val navController = rememberNavController() val navController = rememberNavController()
val scaffoldState = rememberScaffoldState() val scaffoldState = rememberScaffoldState()
@ -651,6 +656,7 @@ fun Body(content: @Composable (nav: NavHostController, scaffoldState: ScaffoldSt
} }
} }
} }
}
/** /**
* 活动海报 * 活动海报
@ -776,6 +782,10 @@ fun MyBottomAppBarPreview() {
} }
} }
@Preview
@Composable
fun TestPreview() { fun TestPreview() {
CSAMSTheme {
Text(text = "fuckyou")
}
} }

@ -92,6 +92,12 @@ class ImageModel(application: Application, private val urlPath: String) :
private val _imageUrls = MutableLiveData<List<String>>() private val _imageUrls = MutableLiveData<List<String>>()
val image: LiveData<ImageBitmap> = _image val image: LiveData<ImageBitmap> = _image
private var job: Job? = null 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 { job = viewModelScope.launch {
HttpClient.get( HttpClient.get(
url = urlPath, url = urlPath,
SimpleCallback<List<String>>("请求图片url列表", onSuccess = { SimpleCallback<List<String>>("获取轮播图", onSuccess = {
_imageUrls.postValue(it.body) _imageUrls.postValue(it.body)
var index = 0 var index = 0
_imageUrls.value?.apply { _imageUrls.value?.apply {
@ -138,6 +144,7 @@ class ImageModel(application: Application, private val urlPath: String) :
} }
}, onFail = { }, onFail = {
Logger.e("无法从接口地址:${urlPath}获取图片url列表") Logger.e("无法从接口地址:${urlPath}获取图片url列表")
_error.postValue(it)
defaultLoad() defaultLoad()
}, type = object : TypeToken<List<String>>() {}.type) }, 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 okhttp3.RequestBody.Companion.toRequestBody
import java.io.IOException import java.io.IOException
import java.lang.reflect.Type import java.lang.reflect.Type
import java.net.SocketTimeoutException
object HttpClient { object HttpClient {
private val httpClient: OkHttpClient = OkHttpClient() private val httpClient: OkHttpClient = OkHttpClient()
@ -136,7 +137,14 @@ class SimpleCallback<T>(
} }
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
when (e) {
is SocketTimeoutException -> {
onFail("${action}失败,网络连接超时!")
}
else -> {
onFail("${action}失败,请联系管理员") onFail("${action}失败,请联系管理员")
}
}
Logger.e(e, "${action}请求失败,发生IO异常") Logger.e(e, "${action}请求失败,发生IO异常")
} }

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

@ -1,7 +1,7 @@
plugins { plugins {
id("com.android.library") id("com.android.library")
id("kotlin-android") id("kotlin-android")
id("org.jetbrains.kotlin.plugin.serialization") version "1.4.32" // id("org.jetbrains.kotlin.plugin.serialization") version "1.4.32"
} }
android { android {
@ -30,7 +30,16 @@ android {
} }
kotlinOptions { kotlinOptions {
jvmTarget = "1.8" jvmTarget = "1.8"
freeCompilerArgs = listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
)
}
buildFeatures {
compose = true
} }
} }
dependencies { dependencies {
@ -90,7 +99,7 @@ dependencies {
/** /**
* https://kotlinlang.org/docs/serialization.html * 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 * 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.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors import androidx.compose.material.darkColors
import androidx.compose.material.lightColors import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import com.gyf.csams.uikit.theme.*
private val DarkColorPalette = darkColors( private val DarkColorPalette = darkColors(
primary = Purple200, primary = Purple200,
Loading…
Cancel
Save