Compare commits
7
Commits
dev
..
e9151f281b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9151f281b | ||
|
|
05ec933b15 | ||
|
|
bf530b6214
|
||
|
|
b7647d7267
|
||
|
|
5b76f55cb7
|
||
|
|
d5194c2e6f
|
||
|
|
008ec3030b
|
@@ -1,11 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Copyright (c) 2026 Gleb Zaharov. License: GPLv3 (see LICENSE). -->
|
<!-- Copyright (c) 2025 Gleb Zaharov. License: GPLv3 (see LICENSE). -->
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".app.UNNApp"
|
android:name=".app.UNNApp"
|
||||||
|
|||||||
+23
-8
@@ -1,12 +1,19 @@
|
|||||||
// Copyright (c) 2026 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
// Copyright (c) 2026 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
||||||
|
|
||||||
package ru.sweetbread.unn.model
|
package ru.sweetbread.unn.api
|
||||||
|
|
||||||
import ru.sweetbread.unn.R
|
import ru.sweetbread.unn.R
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.LocalTime
|
import java.time.LocalTime
|
||||||
|
|
||||||
|
enum class LecturerRank(val id: Int) {
|
||||||
|
Assistant(R.string.assistant),
|
||||||
|
Lecturer(R.string.lecturer),
|
||||||
|
SLecturer(R.string.slecturer),
|
||||||
|
AProfessor(R.string.aprofessor)
|
||||||
|
}
|
||||||
|
|
||||||
class ScheduleUnit(
|
class ScheduleUnit(
|
||||||
val oid: Int,
|
val oid: Int,
|
||||||
val auditorium: Auditorium,
|
val auditorium: Auditorium,
|
||||||
@@ -20,13 +27,6 @@ class ScheduleUnit(
|
|||||||
val lastUpdated: LocalDateTime,
|
val lastUpdated: LocalDateTime,
|
||||||
)
|
)
|
||||||
|
|
||||||
enum class LecturerRank(val id: Int) {
|
|
||||||
Assistant(R.string.assistant),
|
|
||||||
Lecturer(R.string.lecturer),
|
|
||||||
SLecturer(R.string.slecturer),
|
|
||||||
AProfessor(R.string.aprofessor)
|
|
||||||
}
|
|
||||||
|
|
||||||
class Auditorium(
|
class Auditorium(
|
||||||
val name: String,
|
val name: String,
|
||||||
val oid: Int,
|
val oid: Int,
|
||||||
@@ -59,4 +59,19 @@ class Lecturer(
|
|||||||
val email: String,
|
val email: String,
|
||||||
val unnId: Int,
|
val unnId: Int,
|
||||||
val uid: String
|
val uid: String
|
||||||
|
)
|
||||||
|
|
||||||
|
class Post(
|
||||||
|
val id: Int,
|
||||||
|
val authorId: Int,
|
||||||
|
val enableComments: Boolean,
|
||||||
|
val numComments: Int,
|
||||||
|
val date: LocalDateTime,
|
||||||
|
val content: String
|
||||||
|
)
|
||||||
|
|
||||||
|
class AvatarSet(
|
||||||
|
val original: String,
|
||||||
|
val thumbnail: String,
|
||||||
|
val small: String
|
||||||
)
|
)
|
||||||
@@ -38,6 +38,7 @@ import androidx.compose.ui.text.input.KeyboardType
|
|||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import ru.sweetbread.unn.R
|
import ru.sweetbread.unn.R
|
||||||
import ru.sweetbread.unn.core.AuthRepository
|
import ru.sweetbread.unn.core.AuthRepository
|
||||||
import ru.sweetbread.unn.ui.theme.UNNTheme
|
import ru.sweetbread.unn.ui.theme.UNNTheme
|
||||||
@@ -50,10 +51,12 @@ class LoginActivity : ComponentActivity() {
|
|||||||
|
|
||||||
val authRepo = (application as UNNApp).container.authRepo
|
val authRepo = (application as UNNApp).container.authRepo
|
||||||
|
|
||||||
if (authRepo.hasSavedCredentials()) {
|
|
||||||
start<MainActivity>()
|
runBlocking {
|
||||||
finish()
|
if (authRepo.restoreSession()) {
|
||||||
return
|
start<MainActivity>()
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
@@ -158,4 +161,4 @@ fun LoginPanel(
|
|||||||
Text(stringResource(R.string.sign_in))
|
Text(stringResource(R.string.sign_in))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,5 @@
|
|||||||
// Copyright (c) 2026 Gleb Zaharov. License: GPLv3 (see LICENSE).
|
|
||||||
|
|
||||||
package ru.sweetbread.unn.app
|
package ru.sweetbread.unn.app
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.net.ConnectivityManager
|
|
||||||
import android.net.Network
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
@@ -55,33 +50,23 @@ import androidx.compose.ui.text.font.FontWeight
|
|||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import coil3.compose.AsyncImage
|
import coil3.compose.AsyncImage
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import ru.sweetbread.unn.R
|
import ru.sweetbread.unn.R
|
||||||
import ru.sweetbread.unn.core.network.LoginResult
|
|
||||||
import ru.sweetbread.unn.core.network.portalURL
|
import ru.sweetbread.unn.core.network.portalURL
|
||||||
import ru.sweetbread.unn.feature.About
|
|
||||||
import ru.sweetbread.unn.feature.news.Blogposts
|
import ru.sweetbread.unn.feature.news.Blogposts
|
||||||
import ru.sweetbread.unn.feature.schedule.Schedule
|
import ru.sweetbread.unn.feature.schedule.Schedule
|
||||||
|
import ru.sweetbread.unn.feature.About
|
||||||
import ru.sweetbread.unn.ui.theme.UNNTheme
|
import ru.sweetbread.unn.ui.theme.UNNTheme
|
||||||
import splitties.resources.appStr
|
import splitties.resources.appStr
|
||||||
import splitties.toast.toast
|
import splitties.toast.toast
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private lateinit var connectivityManager: ConnectivityManager
|
|
||||||
private var restoreSessionJob: Job? = null
|
|
||||||
private val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
|
||||||
override fun onAvailable(network: Network) {
|
|
||||||
restoreSavedSession()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -89,15 +74,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
|
||||||
val authRepo = (application as UNNApp).container.authRepo
|
|
||||||
lifecycleScope.launch {
|
|
||||||
authRepo.authenticationFailures.collect {
|
|
||||||
openLogin()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
connectivityManager = getSystemService(ConnectivityManager::class.java)
|
|
||||||
restoreSavedSession()
|
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
UNNTheme {
|
UNNTheme {
|
||||||
Surface(
|
Surface(
|
||||||
@@ -217,44 +193,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
|
||||||
super.onStart()
|
|
||||||
connectivityManager.registerDefaultNetworkCallback(networkCallback)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStop() {
|
|
||||||
connectivityManager.unregisterNetworkCallback(networkCallback)
|
|
||||||
super.onStop()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun restoreSavedSession() {
|
|
||||||
val container = (application as UNNApp).container
|
|
||||||
|
|
||||||
if (
|
|
||||||
container.sessionManager.sessionId != null ||
|
|
||||||
restoreSessionJob?.isActive == true
|
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
restoreSessionJob = lifecycleScope.launch {
|
|
||||||
if (container.authRepo.restoreSession() == LoginResult.InvalidCredentials) {
|
|
||||||
openLogin()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun openLogin() {
|
|
||||||
if (isFinishing) return
|
|
||||||
|
|
||||||
startActivity(
|
|
||||||
Intent(this, LoginActivity::class.java).apply {
|
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
}
|
|
||||||
)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DrawerContent(modifier: Modifier = Modifier, navController: NavController) {
|
fun DrawerContent(modifier: Modifier = Modifier, navController: NavController) {
|
||||||
val me = (application as UNNApp).container.sessionManager.user.collectAsState().value
|
val me = (application as UNNApp).container.sessionManager.user.collectAsState().value
|
||||||
@@ -349,4 +287,4 @@ class MainActivity : ComponentActivity() {
|
|||||||
Text("User not found")
|
Text("User not found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,7 @@ import ru.sweetbread.unn.core.AuthRepository
|
|||||||
import ru.sweetbread.unn.core.CredentialsStore
|
import ru.sweetbread.unn.core.CredentialsStore
|
||||||
import ru.sweetbread.unn.core.SessionManager
|
import ru.sweetbread.unn.core.SessionManager
|
||||||
import ru.sweetbread.unn.core.db.AppDatabase
|
import ru.sweetbread.unn.core.db.AppDatabase
|
||||||
import ru.sweetbread.unn.core.network.LoginResult
|
|
||||||
import ru.sweetbread.unn.core.network.PortalApi
|
import ru.sweetbread.unn.core.network.PortalApi
|
||||||
import ru.sweetbread.unn.core.network.SessionRefreshHandler
|
|
||||||
import ru.sweetbread.unn.core.network.createHttpClient
|
import ru.sweetbread.unn.core.network.createHttpClient
|
||||||
import ru.sweetbread.unn.feature.news.NewsRepository
|
import ru.sweetbread.unn.feature.news.NewsRepository
|
||||||
import ru.sweetbread.unn.feature.profile.UserRepository
|
import ru.sweetbread.unn.feature.profile.UserRepository
|
||||||
@@ -35,9 +33,8 @@ class UNNApp : Application() {
|
|||||||
class AppContainer(context: Context) {
|
class AppContainer(context: Context) {
|
||||||
val credentialsStore = CredentialsStore(context)
|
val credentialsStore = CredentialsStore(context)
|
||||||
val sessionManager = SessionManager()
|
val sessionManager = SessionManager()
|
||||||
val sessionRefreshHandler = SessionRefreshHandler()
|
|
||||||
|
|
||||||
val httpClient = createHttpClient(sessionRefreshHandler)
|
val httpClient = createHttpClient()
|
||||||
|
|
||||||
val portalApi = PortalApi(
|
val portalApi = PortalApi(
|
||||||
client = httpClient,
|
client = httpClient,
|
||||||
@@ -46,12 +43,6 @@ class AppContainer(context: Context) {
|
|||||||
|
|
||||||
val authRepo = AuthRepository(credentialsStore, portalApi)
|
val authRepo = AuthRepository(credentialsStore, portalApi)
|
||||||
|
|
||||||
init {
|
|
||||||
sessionRefreshHandler.setRefreshAction {
|
|
||||||
authRepo.restoreSession() == LoginResult.Success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val database = roomDb<AppDatabase>(name = "cache") {
|
val database = roomDb<AppDatabase>(name = "cache") {
|
||||||
fallbackToDestructiveMigration(dropAllTables = true)
|
fallbackToDestructiveMigration(dropAllTables = true)
|
||||||
}
|
}
|
||||||
@@ -70,4 +61,4 @@ class AppContainer(context: Context) {
|
|||||||
api = portalApi,
|
api = portalApi,
|
||||||
db = database,
|
db = database,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
package ru.sweetbread.unn.core
|
package ru.sweetbread.unn.core
|
||||||
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import android.util.Log
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
import kotlinx.io.IOException
|
||||||
import kotlinx.coroutines.sync.Mutex
|
|
||||||
import kotlinx.coroutines.sync.withLock
|
|
||||||
import ru.sweetbread.unn.core.network.LoginResult
|
import ru.sweetbread.unn.core.network.LoginResult
|
||||||
import ru.sweetbread.unn.core.network.PortalApi
|
import ru.sweetbread.unn.core.network.PortalApi
|
||||||
|
|
||||||
@@ -13,10 +11,6 @@ class AuthRepository(
|
|||||||
private val credentialsStore: CredentialsStore,
|
private val credentialsStore: CredentialsStore,
|
||||||
private val api: PortalApi
|
private val api: PortalApi
|
||||||
) {
|
) {
|
||||||
private val restoreMutex = Mutex()
|
|
||||||
private val _authenticationFailures = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
|
||||||
val authenticationFailures = _authenticationFailures.asSharedFlow()
|
|
||||||
|
|
||||||
suspend fun login(
|
suspend fun login(
|
||||||
login: String,
|
login: String,
|
||||||
password: String
|
password: String
|
||||||
@@ -32,22 +26,21 @@ class AuthRepository(
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasSavedCredentials(): Boolean = credentialsStore.get() != null
|
suspend fun restoreSession(): Boolean {
|
||||||
|
val credentials =
|
||||||
|
credentialsStore.get()
|
||||||
|
?: return false
|
||||||
|
|
||||||
suspend fun restoreSession(): LoginResult? = restoreMutex.withLock {
|
return try {
|
||||||
val credentials = credentialsStore.get() ?: return@withLock null
|
val res = api.login(
|
||||||
|
credentials.login,
|
||||||
|
credentials.password
|
||||||
|
)
|
||||||
|
|
||||||
val result = api.login(
|
res != LoginResult.InvalidCredentials
|
||||||
credentials.login,
|
} catch (e: IOException) {
|
||||||
credentials.password
|
Log.e("AuthRepo", "restoreSession error", e)
|
||||||
)
|
false
|
||||||
|
|
||||||
if (result == LoginResult.InvalidCredentials) {
|
|
||||||
credentialsStore.clear()
|
|
||||||
api.session.clear()
|
|
||||||
_authenticationFailures.emit(Unit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import android.security.keystore.KeyGenParameterSpec
|
|||||||
import android.security.keystore.KeyProperties
|
import android.security.keystore.KeyProperties
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import java.security.GeneralSecurityException
|
|
||||||
import java.security.KeyStore
|
import java.security.KeyStore
|
||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
import javax.crypto.KeyGenerator
|
import javax.crypto.KeyGenerator
|
||||||
@@ -98,55 +97,48 @@ class CredentialsStore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun get(): Credentials? {
|
fun get(): Credentials? {
|
||||||
return try {
|
val encryptedString =
|
||||||
val encryptedString =
|
prefs.getString("data", null)
|
||||||
prefs.getString("data", null)
|
?: return null
|
||||||
?: return null
|
|
||||||
|
|
||||||
val ivString =
|
val ivString =
|
||||||
prefs.getString("iv", null)
|
prefs.getString("iv", null)
|
||||||
?: return null
|
?: return null
|
||||||
|
|
||||||
val encrypted = Base64.decode(
|
val encrypted = Base64.decode(
|
||||||
encryptedString,
|
encryptedString,
|
||||||
Base64.NO_WRAP
|
Base64.NO_WRAP
|
||||||
)
|
)
|
||||||
|
|
||||||
val iv = Base64.decode(
|
val iv = Base64.decode(
|
||||||
ivString,
|
ivString,
|
||||||
Base64.NO_WRAP
|
Base64.NO_WRAP
|
||||||
)
|
)
|
||||||
|
|
||||||
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
|
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
|
||||||
|
|
||||||
cipher.init(
|
cipher.init(
|
||||||
Cipher.DECRYPT_MODE,
|
Cipher.DECRYPT_MODE,
|
||||||
key,
|
key,
|
||||||
GCMParameterSpec(128, iv)
|
GCMParameterSpec(128, iv)
|
||||||
)
|
)
|
||||||
|
|
||||||
val plainText = cipher
|
val plainText = cipher
|
||||||
.doFinal(encrypted)
|
.doFinal(encrypted)
|
||||||
.decodeToString()
|
.decodeToString()
|
||||||
|
|
||||||
val parts = plainText.split('\u0000', limit = 2)
|
val parts = plainText.split('\u0000', limit = 2)
|
||||||
|
|
||||||
if (parts.size != 2)
|
if (parts.size != 2)
|
||||||
null
|
return null
|
||||||
else Credentials(
|
|
||||||
login = parts[0],
|
return Credentials(
|
||||||
password = parts[1]
|
login = parts[0],
|
||||||
)
|
password = parts[1]
|
||||||
} catch (_: GeneralSecurityException) {
|
)
|
||||||
clear()
|
|
||||||
null
|
|
||||||
} catch (_: IllegalArgumentException) {
|
|
||||||
clear()
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clear() {
|
fun clear() {
|
||||||
prefs.edit { clear() }
|
prefs.edit { clear() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,12 +22,9 @@ interface NewsDao {
|
|||||||
@Query("SELECT * FROM newsDB ORDER BY `publishedAt` DESC")
|
@Query("SELECT * FROM newsDB ORDER BY `publishedAt` DESC")
|
||||||
fun paging(): PagingSource<Int, NewsDB>
|
fun paging(): PagingSource<Int, NewsDB>
|
||||||
|
|
||||||
@Query("DELETE FROM newsDB")
|
|
||||||
suspend fun clear()
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(news: List<NewsDB>)
|
suspend fun insertAll(news: List<NewsDB>)
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
suspend fun delete(unit: NewsDB)
|
suspend fun delete(unit: NewsDB)
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ import androidx.room.ColumnInfo
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
|
import ru.sweetbread.unn.api.Auditorium
|
||||||
import ru.sweetbread.unn.core.db.AppDatabase
|
import ru.sweetbread.unn.core.db.AppDatabase
|
||||||
import ru.sweetbread.unn.model.Auditorium
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package ru.sweetbread.unn.core.db.entity
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import ru.sweetbread.unn.model.Building
|
import ru.sweetbread.unn.api.Building
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@@ -18,4 +18,4 @@ data class BuildingDB(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun BuildingDB.toModel() = Building(name, gid, oid)
|
fun BuildingDB.toModel() = Building(name, gid, oid)
|
||||||
fun Building.toEntity() = BuildingDB(oid, name, gid, LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME))
|
fun Building.toEntity() = BuildingDB(oid, name, gid, LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME))
|
||||||
@@ -5,7 +5,7 @@ package ru.sweetbread.unn.core.db.entity
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import ru.sweetbread.unn.model.Discipline
|
import ru.sweetbread.unn.api.Discipline
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@@ -19,4 +19,4 @@ data class DisciplineDB(
|
|||||||
|
|
||||||
fun DisciplineDB.toModel() = Discipline(name, oid, type)
|
fun DisciplineDB.toModel() = Discipline(name, oid, type)
|
||||||
fun Discipline.toEntity() = DisciplineDB(oid, name, type, LocalDateTime.now().format(
|
fun Discipline.toEntity() = DisciplineDB(oid, name, type, LocalDateTime.now().format(
|
||||||
DateTimeFormatter.ISO_DATE_TIME))
|
DateTimeFormatter.ISO_DATE_TIME))
|
||||||
@@ -5,7 +5,7 @@ package ru.sweetbread.unn.core.db.entity
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import ru.sweetbread.unn.model.KindOfWork
|
import ru.sweetbread.unn.api.KindOfWork
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@@ -25,4 +25,4 @@ fun KindOfWork.toEntity() = KindOfWorkDB(
|
|||||||
uid,
|
uid,
|
||||||
complexity,
|
complexity,
|
||||||
LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)
|
LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)
|
||||||
)
|
)
|
||||||
@@ -5,8 +5,8 @@ package ru.sweetbread.unn.core.db.entity
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import ru.sweetbread.unn.model.Lecturer
|
import ru.sweetbread.unn.api.Lecturer
|
||||||
import ru.sweetbread.unn.model.LecturerRank
|
import ru.sweetbread.unn.api.LecturerRank
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import androidx.room.ColumnInfo
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
|
import ru.sweetbread.unn.api.ScheduleUnit
|
||||||
import ru.sweetbread.unn.core.db.AppDatabase
|
import ru.sweetbread.unn.core.db.AppDatabase
|
||||||
import ru.sweetbread.unn.model.ScheduleUnit
|
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.LocalTime
|
import java.time.LocalTime
|
||||||
@@ -67,4 +67,4 @@ suspend fun cacheSchedule(db: AppDatabase, units: List<ScheduleUnit>) {
|
|||||||
db.lecturerDao().insert(units.flatMap { it.lecturers }.map { it.toEntity() })
|
db.lecturerDao().insert(units.flatMap { it.lecturers }.map { it.toEntity() })
|
||||||
db.scheduleDao().insert(units.map { it.toEntity() })
|
db.scheduleDao().insert(units.map { it.toEntity() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ import androidx.room.ColumnInfo
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import io.ktor.util.reflect.instanceOf
|
import io.ktor.util.reflect.instanceOf
|
||||||
import ru.sweetbread.unn.model.AvatarSet
|
import ru.sweetbread.unn.api.AvatarSet
|
||||||
import ru.sweetbread.unn.model.Student
|
import ru.sweetbread.unn.model.Student
|
||||||
import ru.sweetbread.unn.model.Type
|
import ru.sweetbread.unn.model.Type
|
||||||
import ru.sweetbread.unn.model.User
|
import ru.sweetbread.unn.model.User
|
||||||
|
|||||||
@@ -6,37 +6,14 @@ import android.util.Log
|
|||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.engine.android.Android
|
import io.ktor.client.engine.android.Android
|
||||||
import io.ktor.client.plugins.HttpRequestRetry
|
import io.ktor.client.plugins.HttpRequestRetry
|
||||||
import io.ktor.client.plugins.HttpSend
|
|
||||||
import io.ktor.client.plugins.HttpTimeout
|
import io.ktor.client.plugins.HttpTimeout
|
||||||
import io.ktor.client.plugins.cache.HttpCache
|
import io.ktor.client.plugins.cache.HttpCache
|
||||||
import io.ktor.client.plugins.cookies.HttpCookies
|
import io.ktor.client.plugins.cookies.HttpCookies
|
||||||
import io.ktor.client.plugins.logging.LogLevel
|
import io.ktor.client.plugins.logging.LogLevel
|
||||||
import io.ktor.client.plugins.logging.Logger
|
import io.ktor.client.plugins.logging.Logger
|
||||||
import io.ktor.client.plugins.logging.Logging
|
import io.ktor.client.plugins.logging.Logging
|
||||||
import io.ktor.client.plugins.plugin
|
|
||||||
import io.ktor.client.request.HttpRequestBuilder
|
|
||||||
import io.ktor.http.HttpStatusCode
|
|
||||||
import io.ktor.util.AttributeKey
|
|
||||||
|
|
||||||
private val SkipSessionRefresh = AttributeKey<Unit>("SkipSessionRefresh")
|
fun createHttpClient() = HttpClient(Android) {
|
||||||
private val SessionRefreshAttempted = AttributeKey<Unit>("SessionRefreshAttempted")
|
|
||||||
|
|
||||||
fun HttpRequestBuilder.skipSessionRefresh() {
|
|
||||||
attributes.put(SkipSessionRefresh, Unit)
|
|
||||||
}
|
|
||||||
|
|
||||||
class SessionRefreshHandler {
|
|
||||||
@Volatile
|
|
||||||
private var refresh: suspend () -> Boolean = { false }
|
|
||||||
|
|
||||||
fun setRefreshAction(action: suspend () -> Boolean) {
|
|
||||||
refresh = action
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun refreshSession(): Boolean = refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createHttpClient(sessionRefreshHandler: SessionRefreshHandler) = HttpClient(Android) {
|
|
||||||
install(HttpCache)
|
install(HttpCache)
|
||||||
install(HttpCookies)
|
install(HttpCookies)
|
||||||
install(Logging) {
|
install(Logging) {
|
||||||
@@ -57,24 +34,4 @@ fun createHttpClient(sessionRefreshHandler: SessionRefreshHandler) = HttpClient(
|
|||||||
request.headers.append("x-retry-count", retryCount.toString())
|
request.headers.append("x-retry-count", retryCount.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.apply {
|
}
|
||||||
plugin(HttpSend).intercept { request ->
|
|
||||||
val call = execute(request)
|
|
||||||
|
|
||||||
if (
|
|
||||||
call.response.status == HttpStatusCode.Forbidden &&
|
|
||||||
request.attributes.getOrNull(SkipSessionRefresh) == null &&
|
|
||||||
request.attributes.getOrNull(SessionRefreshAttempted) == null
|
|
||||||
) {
|
|
||||||
request.attributes.put(SessionRefreshAttempted, Unit)
|
|
||||||
|
|
||||||
if (sessionRefreshHandler.refreshSession()) {
|
|
||||||
execute(request)
|
|
||||||
} else {
|
|
||||||
call
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
call
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,15 +11,15 @@ import io.ktor.client.statement.bodyAsText
|
|||||||
import io.ktor.http.parameters
|
import io.ktor.http.parameters
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import ru.sweetbread.unn.api.Auditorium
|
||||||
|
import ru.sweetbread.unn.api.Building
|
||||||
|
import ru.sweetbread.unn.api.Discipline
|
||||||
|
import ru.sweetbread.unn.api.KindOfWork
|
||||||
|
import ru.sweetbread.unn.api.Lecturer
|
||||||
|
import ru.sweetbread.unn.api.LecturerRank
|
||||||
|
import ru.sweetbread.unn.api.ScheduleUnit
|
||||||
import ru.sweetbread.unn.core.SessionManager
|
import ru.sweetbread.unn.core.SessionManager
|
||||||
import ru.sweetbread.unn.model.Auditorium
|
|
||||||
import ru.sweetbread.unn.model.Building
|
|
||||||
import ru.sweetbread.unn.model.Discipline
|
|
||||||
import ru.sweetbread.unn.model.KindOfWork
|
|
||||||
import ru.sweetbread.unn.model.Lecturer
|
|
||||||
import ru.sweetbread.unn.model.LecturerRank
|
|
||||||
import ru.sweetbread.unn.model.NewsDto
|
import ru.sweetbread.unn.model.NewsDto
|
||||||
import ru.sweetbread.unn.model.ScheduleUnit
|
|
||||||
import ru.sweetbread.unn.model.User
|
import ru.sweetbread.unn.model.User
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@@ -50,10 +50,7 @@ class Auth (
|
|||||||
append("USER_LOGIN", login)
|
append("USER_LOGIN", login)
|
||||||
append("USER_PASSWORD", password)
|
append("USER_PASSWORD", password)
|
||||||
}
|
}
|
||||||
) {
|
) { retry { noRetry() } }
|
||||||
retry { noRetry() }
|
|
||||||
skipSessionRefresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r.status.value == 302)
|
if (r.status.value == 302)
|
||||||
return """PHPSESSID=([\w\d]+)""".toRegex().find(r.headers["Set-Cookie"]!!)!!.groupValues[1]
|
return """PHPSESSID=([\w\d]+)""".toRegex().find(r.headers["Set-Cookie"]!!)!!.groupValues[1]
|
||||||
@@ -185,9 +182,7 @@ class Bitrix(
|
|||||||
val client: HttpClient,
|
val client: HttpClient,
|
||||||
) {
|
) {
|
||||||
suspend fun getCurrentUser(): User {
|
suspend fun getCurrentUser(): User {
|
||||||
val r = client.get("$vuzapiURL/profile/current") {
|
val r = client.get("$vuzapiURL/profile/current")
|
||||||
skipSessionRefresh()
|
|
||||||
}
|
|
||||||
return User.fromProfile(JSONObject(r.bodyAsText()))
|
return User.fromProfile(JSONObject(r.bodyAsText()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,4 +198,4 @@ class Bitrix(
|
|||||||
}
|
}
|
||||||
return NewsDto.fromJsonArray(JSONArray(r.bodyAsText()))
|
return NewsDto.fromJsonArray(JSONArray(r.bodyAsText()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,9 +64,9 @@ class NewsRemoteMediator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
if (loadType == LoadType.REFRESH) {
|
// if (loadType == LoadType.REFRESH) {
|
||||||
db.newsDao().clear()
|
// db.newsDao().clear()
|
||||||
}
|
// }
|
||||||
|
|
||||||
db.newsDao().insertAll(
|
db.newsDao().insertAll(
|
||||||
news.map { it.toEntity() }
|
news.map { it.toEntity() }
|
||||||
@@ -86,4 +86,4 @@ class NewsRemoteMediator(
|
|||||||
MediatorResult.Error(e)
|
MediatorResult.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,20 +44,16 @@ import androidx.compose.ui.zIndex
|
|||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import ru.sweetbread.unn.R
|
import ru.sweetbread.unn.R
|
||||||
import ru.sweetbread.unn.app.UNNApp
|
import ru.sweetbread.unn.api.Auditorium
|
||||||
|
import ru.sweetbread.unn.api.Building
|
||||||
|
import ru.sweetbread.unn.api.Discipline
|
||||||
|
import ru.sweetbread.unn.api.KindOfWork
|
||||||
|
import ru.sweetbread.unn.api.Lecturer
|
||||||
|
import ru.sweetbread.unn.api.LecturerRank
|
||||||
|
import ru.sweetbread.unn.api.ScheduleUnit
|
||||||
import ru.sweetbread.unn.feature.schedule.components.BoundedWeekPicker
|
import ru.sweetbread.unn.feature.schedule.components.BoundedWeekPicker
|
||||||
import ru.sweetbread.unn.feature.schedule.components.GroupsNameText
|
import ru.sweetbread.unn.feature.schedule.components.GroupsNameText
|
||||||
import ru.sweetbread.unn.model.Auditorium
|
|
||||||
import ru.sweetbread.unn.model.Building
|
|
||||||
import ru.sweetbread.unn.model.Discipline
|
|
||||||
import ru.sweetbread.unn.model.KindOfWork
|
|
||||||
import ru.sweetbread.unn.model.Lecturer
|
|
||||||
import ru.sweetbread.unn.model.LecturerRank
|
|
||||||
import ru.sweetbread.unn.model.ScheduleUnit
|
|
||||||
import ru.sweetbread.unn.model.Student
|
|
||||||
import ru.sweetbread.unn.model.Type
|
|
||||||
import ru.sweetbread.unn.ui.theme.UNNTheme
|
import ru.sweetbread.unn.ui.theme.UNNTheme
|
||||||
import splitties.init.appCtx
|
|
||||||
import splitties.resources.appStr
|
import splitties.resources.appStr
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@@ -117,9 +113,6 @@ fun ScheduleDay(modifier: Modifier = Modifier, viewModel: ScheduleViewModel) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ScheduleItem(modifier: Modifier = Modifier, unit: ScheduleUnit, expanded: Boolean = false) {
|
fun ScheduleItem(modifier: Modifier = Modifier, unit: ScheduleUnit, expanded: Boolean = false) {
|
||||||
val me = (appCtx as UNNApp).container.sessionManager.user.collectAsState().value
|
|
||||||
val currentGroup = if (me?.type == Type.Student) (me as Student).group else null
|
|
||||||
|
|
||||||
fun getRatio(): Float {
|
fun getRatio(): Float {
|
||||||
val begin = LocalDateTime.of(unit.date, unit.begin).atZone(ZoneId.of("Europe/Moscow")).toEpochSecond()
|
val begin = LocalDateTime.of(unit.date, unit.begin).atZone(ZoneId.of("Europe/Moscow")).toEpochSecond()
|
||||||
val end = LocalDateTime.of(unit.date, unit.end).atZone(ZoneId.of("Europe/Moscow")).toEpochSecond()
|
val end = LocalDateTime.of(unit.date, unit.end).atZone(ZoneId.of("Europe/Moscow")).toEpochSecond()
|
||||||
@@ -209,9 +202,7 @@ fun ScheduleItem(modifier: Modifier = Modifier, unit: ScheduleUnit, expanded: Bo
|
|||||||
AnimatedVisibility (expanded) {
|
AnimatedVisibility (expanded) {
|
||||||
GroupsNameText(
|
GroupsNameText(
|
||||||
unit.stream,
|
unit.stream,
|
||||||
highlightColor = MaterialTheme.colorScheme.inversePrimary,
|
highlightColor = MaterialTheme.colorScheme.inversePrimary
|
||||||
currentGroupName = currentGroup,
|
|
||||||
currentGroupColor = MaterialTheme.colorScheme.inverseSurface
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ package ru.sweetbread.unn.feature.schedule
|
|||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import ru.sweetbread.unn.api.ScheduleUnit
|
||||||
|
import ru.sweetbread.unn.core.SessionManager
|
||||||
import ru.sweetbread.unn.core.db.AppDatabase
|
import ru.sweetbread.unn.core.db.AppDatabase
|
||||||
import ru.sweetbread.unn.core.db.entity.cacheSchedule
|
import ru.sweetbread.unn.core.db.entity.cacheSchedule
|
||||||
import ru.sweetbread.unn.core.db.entity.toModel
|
import ru.sweetbread.unn.core.db.entity.toModel
|
||||||
import ru.sweetbread.unn.core.network.PortalApi
|
import ru.sweetbread.unn.core.network.PortalApi
|
||||||
import ru.sweetbread.unn.model.ScheduleUnit
|
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
@@ -42,4 +43,4 @@ class ScheduleRepository (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.flatMapLatest
|
|||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import ru.sweetbread.unn.app.UNNApp
|
import ru.sweetbread.unn.app.UNNApp
|
||||||
import ru.sweetbread.unn.model.ScheduleUnit
|
import ru.sweetbread.unn.api.ScheduleUnit
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
data class ScheduleUiState(
|
data class ScheduleUiState(
|
||||||
@@ -88,4 +88,4 @@ class ScheduleViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,25 +20,14 @@ import androidx.compose.ui.unit.dp
|
|||||||
fun GroupsNameText(
|
fun GroupsNameText(
|
||||||
text: String,
|
text: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
highlightColor: Color = MaterialTheme.colorScheme.tertiaryContainer,
|
highlightColor: Color = MaterialTheme.colorScheme.secondaryContainer,
|
||||||
highlightPadding: PaddingValues = PaddingValues(horizontal = 6.dp, vertical = 2.dp),
|
highlightPadding: PaddingValues = PaddingValues(horizontal = 6.dp, vertical = 2.dp),
|
||||||
highlightShape: Shape = MaterialTheme.shapes.small,
|
highlightShape: Shape = MaterialTheme.shapes.small,
|
||||||
currentGroupName: String? = null,
|
|
||||||
currentGroupColor: Color = MaterialTheme.colorScheme.secondaryContainer,
|
|
||||||
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
|
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
|
||||||
) {
|
) {
|
||||||
val suffix = if (text.endsWith("-В-OUP")) "-В-OUP" else null
|
val suffix = if (text.endsWith("-В-OUP")) "-В-OUP" else null
|
||||||
val mainPart = if (suffix != null) text.dropLast(6) else text
|
val mainPart = if (suffix != null) text.dropLast(6) else text
|
||||||
val blocks = if (mainPart.startsWith("Поток_(") && mainPart.endsWith(')')) {
|
val blocks = mainPart.split('|')
|
||||||
mainPart
|
|
||||||
.removePrefix("Поток_(")
|
|
||||||
.dropLast(1)
|
|
||||||
.split(';')
|
|
||||||
.map(String::trim)
|
|
||||||
.filter(String::isNotEmpty)
|
|
||||||
} else {
|
|
||||||
mainPart.split('|')
|
|
||||||
}
|
|
||||||
|
|
||||||
FlowRow(
|
FlowRow(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
@@ -49,10 +38,7 @@ fun GroupsNameText(
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(end = 2.dp)
|
.padding(end = 2.dp)
|
||||||
.background(
|
.background(highlightColor, highlightShape)
|
||||||
if (currentGroupName == block) currentGroupColor
|
|
||||||
else highlightColor, highlightShape
|
|
||||||
)
|
|
||||||
.padding(highlightPadding)
|
.padding(highlightPadding)
|
||||||
) {
|
) {
|
||||||
Text(text = block)
|
Text(text = block)
|
||||||
@@ -61,4 +47,4 @@ fun GroupsNameText(
|
|||||||
|
|
||||||
suffix?.let { Text(text = it) }
|
suffix?.let { Text(text = it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,15 @@ package ru.sweetbread.unn.model
|
|||||||
|
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import ru.sweetbread.unn.R
|
import ru.sweetbread.unn.R
|
||||||
|
import ru.sweetbread.unn.api.AvatarSet
|
||||||
import splitties.resources.appStr
|
import splitties.resources.appStr
|
||||||
|
|
||||||
enum class Type(val s: String) {
|
enum class Type(val s: String) {
|
||||||
Student(appStr(R.string.student)),
|
student(appStr(R.string.student)),
|
||||||
Lecturer(appStr(R.string.lecturer)),
|
// group("group"),
|
||||||
Employee(appStr(R.string.employee))
|
lecturer(appStr(R.string.lecturer)),
|
||||||
|
// auditorium("auditorium"),
|
||||||
|
employee(appStr(R.string.employee))
|
||||||
}
|
}
|
||||||
|
|
||||||
open class User(
|
open class User(
|
||||||
@@ -29,8 +32,8 @@ open class User(
|
|||||||
.getJSONObject(0)
|
.getJSONObject(0)
|
||||||
.getString("type")
|
.getString("type")
|
||||||
) {
|
) {
|
||||||
"student" -> Type.Student
|
"student" -> Type.student
|
||||||
else -> Type.Employee
|
else -> Type.employee
|
||||||
},
|
},
|
||||||
json.getString("email"),
|
json.getString("email"),
|
||||||
json.getString("fullname"),
|
json.getString("fullname"),
|
||||||
@@ -46,17 +49,17 @@ open class User(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromProfile(json: JSONObject): User {
|
fun fromProfile(json: JSONObject): User {
|
||||||
val userField = json.getJSONObject("user")
|
val user = json.getJSONObject("user")
|
||||||
val user = User(
|
return User(
|
||||||
userField.getInt("id"),
|
user.getInt("id"),
|
||||||
when (json.getString("type")) {
|
when (json.getString("type")) {
|
||||||
"student" -> Type.Student
|
"student" -> Type.student
|
||||||
else -> Type.Employee
|
else -> Type.employee
|
||||||
},
|
},
|
||||||
userField.getString("email"),
|
user.getString("email"),
|
||||||
userField.getString("fullname"),
|
user.getString("fullname"),
|
||||||
userField.getString("fullname_en"),
|
user.getString("fullname_en"),
|
||||||
userField.getJSONObject("photo").let {
|
user.getJSONObject("photo").let {
|
||||||
AvatarSet(
|
AvatarSet(
|
||||||
it.getString("orig"),
|
it.getString("orig"),
|
||||||
it.getString("thumbnail"),
|
it.getString("thumbnail"),
|
||||||
@@ -64,16 +67,11 @@ open class User(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (user.type == Type.Student)
|
|
||||||
user = Student()
|
|
||||||
|
|
||||||
return user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPlaceholder() = User(
|
fun getPlaceholder() = User(
|
||||||
0,
|
0,
|
||||||
Type.Employee,
|
Type.employee,
|
||||||
"",
|
"",
|
||||||
"Удалённый пользователь",
|
"Удалённый пользователь",
|
||||||
"Deleted user",
|
"Deleted user",
|
||||||
@@ -109,10 +107,4 @@ class Student(
|
|||||||
user.avatar,
|
user.avatar,
|
||||||
group
|
group
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class AvatarSet(
|
|
||||||
val original: String,
|
|
||||||
val thumbnail: String,
|
|
||||||
val small: String
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user