Skip to content

Commit 5e6601f

Browse files
committed
Add food page, themes, language, and prerelease workflow
1 parent 335bbb9 commit 5e6601f

6 files changed

Lines changed: 169 additions & 17 deletions

File tree

‎.github/workflows/prerelease.yml‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Android pre-release
2+
3+
on:
4+
push:
5+
branches: [test-branch-lexus]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
concurrency:
12+
group: prerelease-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build:
17+
name: Build and publish pre-release APK
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 45
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set build version
24+
run: |
25+
echo "VERSION_CODE=${GITHUB_RUN_NUMBER}" >> "$GITHUB_ENV"
26+
echo "VERSION_NAME=1.0.${GITHUB_RUN_NUMBER}-test" >> "$GITHUB_ENV"
27+
28+
- name: Set up JDK 17
29+
uses: actions/setup-java@v4
30+
with:
31+
distribution: temurin
32+
java-version: '17'
33+
34+
- name: Set up Android SDK
35+
uses: android-actions/setup-android@v3
36+
with:
37+
packages: 'platforms;android-35 build-tools;35.0.0'
38+
39+
- name: Set up Gradle
40+
uses: gradle/actions/setup-gradle@v4
41+
42+
- name: Build debug APK
43+
run: ./gradlew --no-daemon --warning-mode all assembleDebug
44+
45+
- name: Prepare APK
46+
run: cp app/build/outputs/apk/debug/app-debug.apk "mesh-ranker-${VERSION_NAME}.apk"
47+
48+
- name: Publish GitHub pre-release
49+
uses: softprops/action-gh-release@v2
50+
with:
51+
tag_name: test-branch-lexus-${{ github.run_number }}
52+
name: MESH Ranker ${{ env.VERSION_NAME }}
53+
prerelease: true
54+
generate_release_notes: true
55+
files: mesh-ranker-${{ env.VERSION_NAME }}.apk
56+
fail_on_unmatched_files: true
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343
android:label="@string/login_title"
4444
android:theme="@style/Theme.MeshRanker"
4545
android:windowSoftInputMode="adjustResize" />
46+
<activity android:name=".FoodActivity" android:exported="false" />
4647
</application>
4748
</manifest>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ru.meshrating.app
2+
3+
import android.os.Bundle
4+
import android.webkit.WebView
5+
import android.webkit.WebViewClient
6+
import androidx.appcompat.app.AppCompatActivity
7+
import com.google.android.material.appbar.MaterialToolbar
8+
9+
/** Страница питания МЭШ сама загружает баланс и меню в авторизованной web-сессии. */
10+
class FoodActivity : AppCompatActivity() {
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
val root = android.widget.LinearLayout(this).apply { orientation = android.widget.LinearLayout.VERTICAL }
14+
val toolbar = MaterialToolbar(this).apply { title = "Еда и баланс"; setNavigationIcon(androidx.appcompat.R.drawable.abc_ic_ab_back_material); setNavigationOnClickListener { finish() } }
15+
val webView = WebView(this).apply {
16+
settings.javaScriptEnabled = true
17+
settings.domStorageEnabled = true
18+
settings.databaseEnabled = true
19+
userAgentString = MeshCore.USER_AGENT
20+
webViewClient = WebViewClient()
21+
loadUrl("https://school.mos.ru/diary/school/food?food_tab=main")
22+
}
23+
root.addView(toolbar, android.widget.LinearLayout.LayoutParams(-1, -2))
24+
root.addView(webView, android.widget.LinearLayout.LayoutParams(-1, 0, 1f))
25+
setContentView(root)
26+
}
27+
}

‎app/src/main/java/ru/meshrating/app/MainActivity.kt‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,36 @@ class MainActivity : ComponentActivity() {
4343

4444
@Composable
4545
fun MeshRankerTheme(content: @Composable () -> Unit) {
46-
val darkColors = darkColorScheme(
47-
primary = Color(0xFFD1D5DB),
48-
background = Color(0xFF10131A),
49-
surface = Color(0xFF1B2130),
50-
onPrimary = Color(0xFF111111),
51-
onBackground = Color(0xFFE8EDF7),
52-
onSurface = Color(0xFFE8EDF7)
53-
)
54-
MaterialTheme(colorScheme = darkColors, content = content)
46+
val context = LocalContext.current
47+
val prefs = remember { context.getSharedPreferences("mesh_settings", android.content.Context.MODE_PRIVATE) }
48+
var themeId by remember { mutableStateOf(prefs.getString("theme_id", "midnight") ?: "midnight") }
49+
val colors = remember(themeId) { AppTheme.colors(themeId, prefs.getString("theme_colors", null)) }
50+
CompositionLocalProvider(LocalAppTheme provides { themeId = it; prefs.edit().putString("theme_id", it).apply() }) {
51+
MaterialTheme(colorScheme = colors, content = content)
52+
}
53+
}
54+
55+
private val LocalAppTheme = staticCompositionLocalOf<(String) -> Unit>({})
56+
57+
private object AppTheme {
58+
val ids = listOf("midnight", "ocean", "forest", "sunset", "light", "custom")
59+
fun colors(id: String, custom: String?): ColorScheme {
60+
val palettes = mapOf(
61+
"midnight" to Triple(0xFFD1D5DB, 0xFF10131A, 0xFF1B2130),
62+
"ocean" to Triple(0xFF67E8F9, 0xFF071923, 0xFF102A3A),
63+
"forest" to Triple(0xFF86EFAC, 0xFF0D1B16, 0xFF183126),
64+
"sunset" to Triple(0xFFFDA4AF, 0xFF211318, 0xFF352027),
65+
"light" to Triple(0xFF2563EB, 0xFFF5F7FB, 0xFFFFFFFF)
66+
)
67+
val p = if (id == "custom" && !custom.isNullOrBlank()) runCatching {
68+
val parts = custom.split(",").map { it.toLong(16) }
69+
Triple(parts[0], parts[1], parts[2])
70+
}.getOrNull() ?: palettes.getValue("midnight") else palettes[id] ?: palettes.getValue("midnight")
71+
val primary = Color(p.first); val background = Color(p.second); val surface = Color(p.third)
72+
val light = id == "light"
73+
return if (light) lightColorScheme(primary = primary, background = background, surface = surface)
74+
else darkColorScheme(primary = primary, background = background, surface = surface, onPrimary = Color(0xFF111111), onBackground = Color(0xFFE8EDF7), onSurface = Color(0xFFE8EDF7))
75+
}
5576
}
5677

5778
@Composable
@@ -298,6 +319,7 @@ fun MainScaffold(
298319
studentId: String?,
299320
onLogout: () -> Unit
300321
) {
322+
val context = LocalContext.current
301323
var currentTab by remember { mutableStateOf("ranking") }
302324
var rankingSubjectId by remember { mutableStateOf<String?>(null) }
303325
var marksSubjectId by remember { mutableStateOf<String?>(null) }
@@ -347,8 +369,8 @@ fun MainScaffold(
347369
"ranking" -> "Рейтинг"
348370
"marks" -> if (marksSubjectName.isNullOrBlank()) "Оценки" else "Оценки · $marksSubjectName"
349371
"homeworks" -> "Домашние задания"
350-
"schedule" -> "Расписание"
351-
"settings" -> "Настройки"
372+
"schedule" -> if (store.settings(mapOf("language" to "ru"))["language"] == "en") "Schedule" else "Расписание"
373+
"settings" -> if (store.settings(mapOf("language" to "ru"))["language"] == "en") "Settings" else "Настройки"
352374
else -> "МЭШ Рейтинг"
353375
}
354376

@@ -440,9 +462,10 @@ fun MainScaffold(
440462
store,
441463
client,
442464
studentId,
443-
onHomeworkClick = { navigateTo(NavState(tab = "homeworks", target = it)) }
465+
onHomeworkClick = { navigateTo(NavState(tab = "homeworks", target = it)) },
466+
onFoodClick = { context -> context.startActivity(Intent(context, FoodActivity::class.java)) }
444467
)
445-
"settings" -> SettingsScreen(store, client, profile, onLogout)
468+
"settings" -> SettingsScreen(store, client, profile, onLogout, onThemeChange = { LocalAppTheme.current(it) })
446469
}
447470
}
448471
}
@@ -535,4 +558,4 @@ fun LoginScreen(onLogin: (String) -> Unit, loading: Boolean, error: String?) {
535558
Text(it, color = MaterialTheme.colorScheme.error)
536559
}
537560
}
538-
}
561+
}

‎app/src/main/java/ru/meshrating/app/ScheduleScreen.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.ui.Modifier
1111
import androidx.compose.ui.text.font.FontWeight
1212
import androidx.compose.ui.text.style.TextOverflow
1313
import androidx.compose.ui.unit.dp
14+
import androidx.compose.ui.platform.LocalContext
1415
import kotlinx.coroutines.Dispatchers
1516
import kotlinx.coroutines.launch
1617
import kotlinx.coroutines.withContext
@@ -21,8 +22,10 @@ fun ScheduleScreen(
2122
store: SessionStore,
2223
client: MeshClient,
2324
studentId: String?,
24-
onHomeworkClick: (HomeworkTarget) -> Unit = {}
25+
onHomeworkClick: (HomeworkTarget) -> Unit = {},
26+
onFoodClick: (android.content.Context) -> Unit = {}
2527
) {
28+
val context = LocalContext.current
2629
val scope = rememberCoroutineScope()
2730
var loading by remember { mutableStateOf(studentId != null) }
2831
var error by remember { mutableStateOf<String?>(null) }
@@ -56,6 +59,9 @@ fun ScheduleScreen(
5659
onPrev = { selectedDate = MeshCore.addDays(selectedDate, -1) },
5760
onNext = { selectedDate = MeshCore.addDays(selectedDate, 1) }
5861
)
62+
OutlinedButton(onClick = { onFoodClick(context) }, modifier = Modifier.fillMaxWidth()) {
63+
Text(if (store.settings(mapOf("language" to "ru"))["language"] == "en") "Food & balance" else "Еда и баланс")
64+
}
5965
Spacer(Modifier.height(4.dp))
6066

6167
when {

‎app/src/main/java/ru/meshrating/app/SettingsScreen.kt‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlinx.coroutines.withContext
1717
import org.json.JSONObject
1818

1919
@Composable
20-
fun SettingsScreen(store: SessionStore, client: MeshClient, profile: JSONObject?, onLogout: () -> Unit) {
20+
fun SettingsScreen(store: SessionStore, client: MeshClient, profile: JSONObject?, onLogout: () -> Unit, onThemeChange: (String) -> Unit = {}) {
2121
val scope = rememberCoroutineScope()
2222
val context = LocalContext.current
2323
var refreshing by remember { mutableStateOf(false) }
@@ -26,6 +26,12 @@ fun SettingsScreen(store: SessionStore, client: MeshClient, profile: JSONObject?
2626
var checkingUpdates by remember { mutableStateOf(false) }
2727
var updateInfo by remember { mutableStateOf<UpdateInfo?>(null) }
2828
var updateMessage by remember { mutableStateOf<String?>(null) }
29+
val prefs = remember(context) { context.getSharedPreferences("mesh_settings", android.content.Context.MODE_PRIVATE) }
30+
var language by remember { mutableStateOf(prefs.getString("language", "ru") ?: "ru") }
31+
var theme by remember { mutableStateOf(prefs.getString("theme_id", "midnight") ?: "midnight") }
32+
var customName by remember { mutableStateOf(prefs.getString("custom_theme_name", "Моя тема") ?: "Моя тема") }
33+
var customColors by remember { mutableStateOf(prefs.getString("theme_colors", "67E8F9,071923,102A3A") ?: "67E8F9,071923,102A3A") }
34+
val english = language == "en"
2935
val tokenInfo = MeshCore.describeToken(store.token)
3036

3137
Column(
@@ -36,7 +42,38 @@ fun SettingsScreen(store: SessionStore, client: MeshClient, profile: JSONObject?
3642

3743
Card(modifier = Modifier.fillMaxWidth()) {
3844
Column(modifier = Modifier.padding(12.dp)) {
39-
Text("Приложение", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary)
45+
Text(if (english) "Appearance" else "Оформление", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary)
46+
Spacer(Modifier.height(8.dp))
47+
listOf("midnight" to "Полночь", "ocean" to "Океан", "forest" to "Лес", "sunset" to "Закат", "light" to "Светлая", "custom" to customName).forEach { (id, label) ->
48+
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = androidx.compose.ui.Alignment.CenterVertically) {
49+
RadioButton(selected = theme == id, onClick = { theme = id; prefs.edit().putString("theme_id", id).apply(); onThemeChange(id) })
50+
Text(label)
51+
}
52+
}
53+
OutlinedTextField(value = customName, onValueChange = { customName = it; prefs.edit().putString("custom_theme_name", it).apply() }, label = { Text(if (english) "Custom theme name" else "Название своей темы") }, modifier = Modifier.fillMaxWidth(), singleLine = true)
54+
OutlinedTextField(value = customColors, onValueChange = { customColors = it; prefs.edit().putString("theme_colors", it).apply() }, label = { Text(if (english) "Primary, background, surface (hex)" else "Акцент, фон, поверхность (HEX через запятую)") }, modifier = Modifier.fillMaxWidth(), singleLine = true)
55+
Text(if (english) "Example: 67E8F9,071923,102A3A" else "Пример: 67E8F9,071923,102A3A", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
56+
OutlinedButton(onClick = { theme = "custom"; prefs.edit().putString("theme_id", "custom").apply(); onThemeChange("custom") }, modifier = Modifier.fillMaxWidth()) { Text(if (english) "Save and apply custom theme" else "Сохранить и применить свою тему") }
57+
}
58+
}
59+
Spacer(Modifier.height(8.dp))
60+
Card(modifier = Modifier.fillMaxWidth()) {
61+
Column(modifier = Modifier.padding(12.dp)) {
62+
Text(if (english) "Language" else "Язык", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary)
63+
listOf("ru" to "Русский", "en" to "English").forEach { (code, label) ->
64+
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = androidx.compose.ui.Alignment.CenterVertically) {
65+
RadioButton(selected = language == code, onClick = { language = code; prefs.edit().putString("language", code).apply() })
66+
Text(label)
67+
}
68+
}
69+
Text(if (english) "Navigation and settings labels update immediately." else "Подписи навигации и настроек переключаются сразу.", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
70+
}
71+
}
72+
Spacer(Modifier.height(8.dp))
73+
74+
Card(modifier = Modifier.fillMaxWidth()) {
75+
Column(modifier = Modifier.padding(12.dp)) {
76+
Text(if (english) "Application" else "Приложение", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary)
4077
Spacer(Modifier.height(6.dp))
4178
SettingsRow("Сервер", MeshCore.HOST.removePrefix("https://"))
4279
SettingsRow("Хранилище", if (store.isEncrypted()) "зашифровано" else "приватное")

0 commit comments

Comments
 (0)