chore: cleanup
This commit is contained in:
@@ -60,6 +60,5 @@ class AppContainer(context: Context) {
|
||||
val scheduleRepository = ScheduleRepository(
|
||||
api = portalApi,
|
||||
db = database,
|
||||
session = sessionManager
|
||||
)
|
||||
}
|
||||
@@ -11,9 +11,9 @@ class PortalApi (
|
||||
val client: HttpClient,
|
||||
val session: SessionManager
|
||||
) {
|
||||
public val auth = Auth(client, session)
|
||||
public val auth = Auth(client)
|
||||
public val ruzapi = Ruzapi(client, session)
|
||||
public val bitrix = Bitrix(client, session)
|
||||
public val bitrix = Bitrix(client)
|
||||
|
||||
/**
|
||||
* Authorize user by [login] and [password]
|
||||
@@ -40,60 +40,6 @@ class PortalApi (
|
||||
LoginResult.NetworkError
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Save info about current [User] in memory
|
||||
// */
|
||||
// private suspend fun getMyself(login: String): User = coroutineScope {
|
||||
// val idDeferred = async { getId(login) }
|
||||
// val userDeferred = async { getUser() }
|
||||
//
|
||||
// val id = idDeferred.await()
|
||||
// val user = userDeferred.await()
|
||||
//
|
||||
// return@coroutineScope User(
|
||||
// bx_id = null,
|
||||
// ra_id = null,
|
||||
// type = Type.student,
|
||||
// email = user.email,
|
||||
// nameRu = user.nameRu,
|
||||
// nameEn = user.nameEn,
|
||||
// isMale = user.isMale,
|
||||
// birthday = user.birthday,
|
||||
// avatar = user.avatar
|
||||
// )
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// suspend fun getScheduleDay(
|
||||
// date: LocalDate,
|
||||
// type: Type = session.user.value!!.type,
|
||||
// id: Int = ME.unnId!!
|
||||
// ): List<ScheduleUnit> {
|
||||
// if ((type == ME.type) and (id == ME.unnId!!)) {
|
||||
// val schedule = withContext(Dispatchers.IO) { loadSchedule(date) }
|
||||
// Log.d("Schedule", schedule.joinToString())
|
||||
// if (schedule.isNotEmpty())
|
||||
// return schedule
|
||||
// }
|
||||
//
|
||||
// return getSchedule(type, id, date, date)
|
||||
// }
|
||||
//
|
||||
// suspend fun getSchedule(
|
||||
// type: Type = ME.type,
|
||||
// id: Int = ME.unnId!!,
|
||||
// start: LocalDate,
|
||||
// finish: LocalDate
|
||||
// ): ArrayList<ScheduleUnit> {
|
||||
// val schedule = downloadSchedule(type, id, start, finish)
|
||||
//
|
||||
// if ((type == ME.type) and (id == ME.unnId!!))
|
||||
// cacheSchedule(schedule)
|
||||
//
|
||||
// return schedule
|
||||
// }
|
||||
}
|
||||
|
||||
sealed interface LoginResult {
|
||||
|
||||
@@ -37,7 +37,6 @@ const val restURL = "$portalURL/rest"
|
||||
|
||||
class Auth (
|
||||
val client: HttpClient,
|
||||
val session: SessionManager
|
||||
) {
|
||||
/**
|
||||
* Get token (phpsessid header) from portal
|
||||
@@ -181,7 +180,6 @@ class Ruzapi(
|
||||
|
||||
class Bitrix(
|
||||
val client: HttpClient,
|
||||
val session: SessionManager
|
||||
) {
|
||||
suspend fun getCurrentUser(): User {
|
||||
val r = client.get("$vuzapiURL/profile/current")
|
||||
@@ -201,176 +199,3 @@ class Bitrix(
|
||||
return NewsDto.fromJsonArray(JSONArray(r.bodyAsText()))
|
||||
}
|
||||
}
|
||||
|
||||
//suspend fun getId(login: String): Int {
|
||||
// return JSONObject(client.get("$ruzapiURL/studentinfo/") {
|
||||
// header("Cookie", "PHPSESSID=${PHPSESSID}")
|
||||
// parameter("uns", login.drop(1))
|
||||
// }.bodyAsText()).getString("id").toInt()
|
||||
//}
|
||||
//
|
||||
//suspend fun getUser(userId: Int? = null): User {
|
||||
// // WARNING: trailing / is important, 'cuz API devs are eating shit
|
||||
// // TODO: make up another way to get unnId: this is not useful for lectures
|
||||
// val json = JSONObject(
|
||||
// client.get("$vuzapiURL/user/${userId ?: ""}") {
|
||||
// header("Cookie", "PHPSESSID=$PHPSESSID")
|
||||
// }.bodyAsText()
|
||||
// )
|
||||
//
|
||||
// return User(
|
||||
// unnId = null,
|
||||
// userId = json.getInt("id"),
|
||||
// type = if (json.getJSONArray("profiles").getJSONObject(0)
|
||||
// .getString("type") == "employee"
|
||||
// ) Type.employee else Type.student,
|
||||
// email = json.getString("email"),
|
||||
// nameRu = json.getString("fullname"),
|
||||
// nameEn = json.getString("fullname_en"),
|
||||
// isMale = json.getString("sex") == "M",
|
||||
// birthday = Instant
|
||||
// .parse(json.getString("birthdate"))
|
||||
// .atZone(ZoneId.of("Europe/Moscow"))
|
||||
// .toLocalDate(),
|
||||
// avatar = json.getJSONObject("photo").let {
|
||||
// AvatarSet(
|
||||
// it.getString("orig"),
|
||||
// it.getString("thumbnail"),
|
||||
// it.getString("small"),
|
||||
// )
|
||||
// }
|
||||
// )
|
||||
//}
|
||||
//
|
||||
//suspend fun getProfile
|
||||
//
|
||||
///**
|
||||
// * Fetch schedule from Uni API
|
||||
// *
|
||||
// * @return [ArrayList] of all [ru.sweetbread.unn.api.ScheduleUnit]s between [start] and [finish]
|
||||
// */
|
||||
//suspend fun downloadSchedule(
|
||||
// type: Type = ME.type,
|
||||
// id: Int = ME.unnId!!,
|
||||
// start: LocalDate,
|
||||
// finish: LocalDate
|
||||
//): ArrayList<ScheduleUnit> {
|
||||
// val unnDatePattern = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
||||
//
|
||||
// val r = client.get("$ruzapiURL/schedule/${type.name}/$id") {
|
||||
// parameter("start", start.format(unnDatePattern))
|
||||
// parameter("finish", finish.format(unnDatePattern))
|
||||
// parameter("lng", "1")
|
||||
// }
|
||||
//
|
||||
// val json = JSONArray(r.bodyAsText())
|
||||
// val out = arrayListOf<ScheduleUnit>()
|
||||
// for (i in 0 until json.length()) {
|
||||
// val unit = json.getJSONObject(i)
|
||||
// val lecturesJson = unit.getJSONArray("listOfLecturers")
|
||||
// val lecturers = arrayListOf<Lecturer>()
|
||||
//
|
||||
// for (j in 0 until lecturesJson.length()) {
|
||||
// val lecturer = lecturesJson.getJSONObject(j)
|
||||
// lecturers.add(
|
||||
// Lecturer(
|
||||
// name = lecturer.getString("lecturer"),
|
||||
// email = lecturer.getString("lecturerEmail"),
|
||||
// unnId = lecturer.getInt("lecturerOid"),
|
||||
// uid = lecturer.getString("lecturerUID"),
|
||||
// rank = when (lecturer.getString("lecturer_rank")) {
|
||||
// "АССИСТ" -> LecturerRank.Assistant
|
||||
// "СТПРЕП" -> LecturerRank.SLecturer
|
||||
// "ДОЦЕНТ" -> LecturerRank.AProfessor
|
||||
// else -> LecturerRank.Lecturer
|
||||
// }
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// out.add(
|
||||
// ScheduleUnit(
|
||||
// oid = unit.getInt("lessonOid"),
|
||||
// auditorium = Auditorium(
|
||||
// name = unit.getString("auditorium"),
|
||||
// oid = unit.getInt("auditoriumOid"),
|
||||
// floor = unit.getInt("auditoriumfloor"),
|
||||
// building = Building(
|
||||
// name = unit.getString("building"),
|
||||
// gid = unit.getInt("buildingGid"),
|
||||
// oid = unit.getInt("buildingOid")
|
||||
// )
|
||||
// ),
|
||||
// date = LocalDate.parse(unit.getString("date"), unnDatePattern),
|
||||
// discipline = Discipline(
|
||||
// name = unit.getString("discipline"),
|
||||
// oid = unit.getInt("disciplineOid"),
|
||||
// type = unit.getInt("disciplinetypeload")
|
||||
// ),
|
||||
// kindOfWork = KindOfWork(
|
||||
// name = unit.getString("kindOfWork"),
|
||||
// complexity = unit.getInt("kindOfWorkComplexity"),
|
||||
// oid = unit.getInt("kindOfWorkOid"),
|
||||
// uid = unit.getString("kindOfWorkUid")
|
||||
// ),
|
||||
// lecturers = lecturers,
|
||||
// stream = unit.getString("stream"),
|
||||
// begin = LocalTime.parse(
|
||||
// unit.getString("beginLesson"),
|
||||
// DateTimeFormatter.ofPattern("HH:mm")
|
||||
// ),
|
||||
// end = LocalTime.parse(
|
||||
// unit.getString("endLesson"),
|
||||
// DateTimeFormatter.ofPattern("HH:mm")
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// return out
|
||||
//}
|
||||
//
|
||||
//
|
||||
//suspend fun getUserByBitrixId(id: Int): User {
|
||||
// withContext(Dispatchers.IO) {
|
||||
// loadUserByBitrixId(id)
|
||||
// }?.let { return it }
|
||||
//
|
||||
// val userId = JSONObject(client.get("$vuzapiURL/user/bx/$id") {
|
||||
// header("Cookie", "PHPSESSID=${PHPSESSID}")
|
||||
// }.bodyAsText()).getInt("id")
|
||||
//
|
||||
// getUser(userId).let { user ->
|
||||
// withContext(Dispatchers.IO) {
|
||||
// cacheUser(user)
|
||||
// }
|
||||
// return user
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//suspend fun getBlogposts(): ArrayList<Post> {
|
||||
// val r = client.get("$prtl2URL/news.php") {
|
||||
// header("Cookie", "PHPSESSID=${PHPSESSID}")
|
||||
// header("x-bitrix-sessid-token", CSRF)
|
||||
// }
|
||||
// val result = JSONArray(r.bodyAsText())
|
||||
//
|
||||
// val out = arrayListOf<Post>()
|
||||
// for (i in 0 until result.length()) {
|
||||
// val el = result.getJSONObject(i)
|
||||
// out.add(
|
||||
// Post(
|
||||
// id = el.getString("id").toInt(),
|
||||
// authorId = el.getJSONObject("author").getInt("id").toInt(),
|
||||
// enableComments = true, // FIXME: Delete the field or get correct value
|
||||
// numComments = el.getString("commentsnum").toInt(),
|
||||
// date = LocalDateTime.parse(
|
||||
// el.getString("time"),
|
||||
// DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss")
|
||||
// ),
|
||||
// content = el.getString("fulltext")
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
// return out
|
||||
//}
|
||||
|
||||
@@ -48,23 +48,6 @@ import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
|
||||
|
||||
//val defUser = User(
|
||||
// null,
|
||||
// 123,
|
||||
// Type.student,
|
||||
// "cool.email@domain.com",
|
||||
// "Джон Сигма Омегович",
|
||||
// "Jon Sigma Omega",
|
||||
// true,
|
||||
// LocalDate.now(),
|
||||
// AvatarSet(
|
||||
// "https://upload.wikimedia.org/wikipedia/ru/thumb/9/94/%D0%93%D0%B8%D0%B3%D0%B0%D1%87%D0%B0%D0%B4.jpg/500px-%D0%93%D0%B8%D0%B3%D0%B0%D1%87%D0%B0%D0%B4.jpg",
|
||||
// "https://upload.wikimedia.org/wikipedia/ru/thumb/9/94/%D0%93%D0%B8%D0%B3%D0%B0%D1%87%D0%B0%D0%B4.jpg/500px-%D0%93%D0%B8%D0%B3%D0%B0%D1%87%D0%B0%D0%B4.jpg",
|
||||
// "https://upload.wikimedia.org/wikipedia/ru/thumb/9/94/%D0%93%D0%B8%D0%B3%D0%B0%D1%87%D0%B0%D0%B4.jpg/500px-%D0%93%D0%B8%D0%B3%D0%B0%D1%87%D0%B0%D0%B4.jpg"
|
||||
// )
|
||||
//)
|
||||
//
|
||||
//
|
||||
@Composable
|
||||
fun Blogposts(viewModel: NewsViewModel = viewModel(factory = NewsViewModel.Factory)) {
|
||||
val news = viewModel.news.collectAsLazyPagingItems()
|
||||
@@ -168,47 +151,6 @@ fun PostItem(modifier: Modifier = Modifier, post: News, extended: Boolean = fals
|
||||
))
|
||||
}
|
||||
}
|
||||
//
|
||||
//
|
||||
//@Preview
|
||||
//@Composable
|
||||
//fun UserItemPreview() {
|
||||
// UNNTheme {
|
||||
// Surface {
|
||||
// UserItem(
|
||||
// Modifier
|
||||
// .width(300.dp)
|
||||
// .clip(RoundedCornerShape(8.dp))
|
||||
// .background(MaterialTheme.colorScheme.primaryContainer),
|
||||
// defUser,
|
||||
// Type.student.s
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//@Preview
|
||||
//@Composable
|
||||
//fun PostItemPreview() {
|
||||
// val post = Post(
|
||||
// id = 154923,
|
||||
// authorId = 165945,
|
||||
// enableComments = true,
|
||||
// numComments = 0,
|
||||
// date = LocalDateTime.of(2024, 3, 20, 18, 55, 20),
|
||||
// content = stringResource(id = R.string.lorem)
|
||||
// )
|
||||
//
|
||||
// UNNTheme {
|
||||
// Surface {
|
||||
// PostItem(
|
||||
// Modifier
|
||||
// .clip(RoundedCornerShape(8.dp))
|
||||
// .background(MaterialTheme.colorScheme.primaryContainer), post
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
class CoilImageGetter(
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.time.format.DateTimeFormatter
|
||||
class ScheduleRepository (
|
||||
val api: PortalApi,
|
||||
val db: AppDatabase,
|
||||
val session: SessionManager
|
||||
) {
|
||||
fun observeSchedule(date: LocalDate): Flow<List<ScheduleUnit>> =
|
||||
db.scheduleDao()
|
||||
|
||||
@@ -163,11 +163,3 @@ fun LoginPanel(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@Preview(showBackground = true)
|
||||
//@Composable
|
||||
//fun LoginPreview() {
|
||||
// UNNTheme {
|
||||
// LoginPanel(ok = { _, _ -> }, error = {})
|
||||
// }
|
||||
//}
|
||||
@@ -176,7 +176,6 @@ class MainActivity : ComponentActivity() {
|
||||
Box(Modifier.padding(innerPadding)) {
|
||||
NavHost(navController, startDestination = "journal/schedule") {
|
||||
composable("portal/blogposts") {
|
||||
// Text("Not implemented")
|
||||
Blogposts()
|
||||
}
|
||||
composable("journal/schedule") {
|
||||
|
||||
Reference in New Issue
Block a user