Skip to content

Commit

Permalink
Merge pull request #30 from founchoo/dev
Browse files Browse the repository at this point in the history
1、更新至 BasicTextField2 API
  • Loading branch information
founchoo committed Jun 9, 2024
2 parents 09ae4d1 + 58dbf0f commit c75fe83
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 45 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/dart/campushelper/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import okhttp3.ResponseBody.Companion.toResponseBody
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -38,6 +39,9 @@ object NetworkModule {
): NetworkService {

val client = OkHttpClient.Builder()
.connectTimeout(20, TimeUnit.SECONDS)
.readTimeout(20, TimeUnit.SECONDS)
.writeTimeout(20, TimeUnit.SECONDS)
.followRedirects(false)
.cookieJar(NetworkCookieJar(dataStoreRepo))
.addInterceptor { chain ->
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/dart/campushelper/model/Course.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.dart.campushelper.model

import com.dart.campushelper.utils.parseHtml
import com.google.gson.annotations.SerializedName
import java.util.*

data class Course(
// ID
Expand Down Expand Up @@ -154,7 +153,7 @@ data class Course(
)

companion object {
fun mock() : Course {
fun mock(): Course {
return Course(
id = "123456",
academicYearAndTerm = "2022-2023-2",
Expand Down Expand Up @@ -212,7 +211,7 @@ data class Course(

// 教师名称
val teacherName: String?
get() = teacherNameHtml?.let { parseHtml(it) }
get() = teacherNameHtml?.let { parseHtml(it).replace(",", "\n") }

val className: String?
get() = classNameHtml?.let { parseHtml(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ data class Grade(
get() = creditRaw.orEmpty().toDoubleOrNull() ?: 0.0

val name: String
get() = courseNameRaw?.replace("[${courseId}]", "") ?: ""
get() = courseNameRaw?.substring(courseNameRaw!!.indexOf(']') + 1).toString()

val composition: String
get() = detail.orEmpty().replace(",", "\n")

companion object {
fun mock(): Grade {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class LessonReminderReceiver : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
CoroutineScope(Dispatchers.IO).launch {
val needUpdateDatabase = simplCourseRepo.getAll().isEmpty() || LocalTime.now().hour < 8
val needUpdateDatabase =
simplCourseRepo.getAll().isEmpty() || (LocalTime.now().hour <= 8 && LocalTime.now().minute <= 20)
if (needUpdateDatabase) {
val currentWeek = getWeekCount(
networkRepo.getSemesterStartDate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.dart.campushelper.ui.component

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text2.BasicTextField2
import androidx.compose.foundation.text2.input.TextFieldLineLimits
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextFieldDefaults
Expand All @@ -20,17 +22,17 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun NoBorderTextField(
text: String,
value: String,
placeholderText: String,
onValueChange: (String) -> Unit,
focusRequester: FocusRequester? = null,
) {
val interactionSource = remember { MutableInteractionSource() }
BasicTextField(
value = text,
BasicTextField2(
value = value,
onValueChange = { onValueChange(it) },
interactionSource = interactionSource,
textStyle = TextStyle(
Expand All @@ -40,31 +42,32 @@ fun NoBorderTextField(
modifier = (if (focusRequester == null) Modifier else Modifier
.focusRequester(focusRequester)).fillMaxWidth(),
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
maxLines = 1,
) {
OutlinedTextFieldDefaults.DecorationBox(
value = text,
innerTextField = it,
enabled = true,
singleLine = true,
interactionSource = interactionSource,
visualTransformation = VisualTransformation.None,
placeholder = { Text(placeholderText) },
container = {
OutlinedTextFieldDefaults.ContainerBox(
enabled = true,
isError = false,
interactionSource = interactionSource,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = Color.Transparent,
unfocusedBorderColor = Color.Transparent,
),
focusedBorderThickness = 0.dp,
unfocusedBorderThickness = 0.dp,
)
}
)
}
lineLimits = TextFieldLineLimits.SingleLine,
decorator = @Composable {
OutlinedTextFieldDefaults.DecorationBox(
value = value,
innerTextField = it,
enabled = true,
singleLine = true,
interactionSource = interactionSource,
visualTransformation = VisualTransformation.None,
placeholder = { Text(placeholderText) },
container = {
OutlinedTextFieldDefaults.ContainerBox(
enabled = true,
isError = false,
interactionSource = interactionSource,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = Color.Transparent,
unfocusedBorderColor = Color.Transparent,
),
focusedBorderThickness = 0.dp,
unfocusedBorderThickness = 0.dp,
)
}
)
}
)
LaunchedEffect(Unit) {
focusRequester?.requestFocus()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@ fun GradeDetailDialog(
ListItem(
headlineContent = {
Text(
"${stringResource(R.string.grade_label)} ${
grade.score.toString()
.replaceWithStars(uiState.isScreenshotMode)
} / ${stringResource(R.string.gpa_label)} ${
"${stringResource(R.string.gpa_label)} ${
grade.gradePoint.toString()
.replaceWithStars(uiState.isScreenshotMode)
}"
)
},
supportingContent = {
Text(
(grade.detail ?: "").replaceWithStars(uiState.isScreenshotMode)
grade.composition.replaceWithStars(uiState.isScreenshotMode)
)
},
trailingContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class MainActivity : AppCompatActivity() {
exit = fadeOut(),
) {
NoBorderTextField(
text = gradeUiState.searchKeyword,
value = gradeUiState.searchKeyword,
placeholderText = stringResource(R.string.course_name),
onValueChange = { gradeViewModel.setSearchKeyword(it) },
focusRequester = focusSearchBarRequester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun TeacherScheduleBottomSheet(uiState: ScheduleUiState, viewModel: ScheduleView
) {
Icon(imageVector = Icons.Outlined.Search, contentDescription = null)
NoBorderTextField(
text = uiState.searchTeacherName,
value = uiState.searchTeacherName,
placeholderText = stringResource(R.string.input_teacher_name),
onValueChange = { viewModel.setSearchTeacherName(it) },
focusRequester = focusSearchBarRequester
Expand All @@ -63,7 +63,9 @@ fun TeacherScheduleBottomSheet(uiState: ScheduleUiState, viewModel: ScheduleView
Text(
text = stringResource(R.string.no_teacher_schedule_found),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(top = 5.dp).padding(horizontal = DEFAULT_PADDING),
modifier = Modifier
.padding(top = 5.dp)
.padding(horizontal = DEFAULT_PADDING),
)
},
contentWhenDataSourceIsNotEmpty = {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<string name="course_grade">课程成绩</string>
<string name="course_grades_desc">当前课程列表所列课程的成绩</string>
<string name="arithmetic_mean_score">算数平均分</string>
<string name="rank_title">学年学期排名信息</string>
<string name="rank_title">排名信息</string>
<string name="rank_desc">已筛选学年学期:%1$s 的排名信息</string>
<string name="rank_not_available_title">排名信息不可用</string>
<string name="rank_not_available_desc">当筛选课程性质或检索课程名称时排名信息不可用</string>
Expand Down Expand Up @@ -136,7 +136,7 @@
<string name="current_semester">当前学年学期</string>
<string name="fill_mock_info">没有帐户?填充体验账户</string>
<string name="clear_mock_info">清除体验账户</string>
<string name="login_help_text">不知道到密码?访问 %1$s 了解更多信息</string>
<string name="login_help_text">不知道密码?访问 %1$s 了解更多信息</string>
<string name="teacher_schedule">查找教师课表</string>
<string name="no_teacher_schedule_found">暂无与此教师相关的课表</string>
<string name="input_teacher_name">输入教师姓名</string>
Expand Down

0 comments on commit c75fe83

Please sign in to comment.