Commit 4080a753 authored by Filip Wiesner's avatar Filip Wiesner

Cleanup

parent 439aded4
......@@ -40,4 +40,8 @@ class EventDetailViewModel: ViewModel() {
fun requestTeachers(usernames: List<String>) { launch {
_teachers.postValue(model.getTeachers(usernames))
} }
fun changeEventNote(eventId: Int, note: String) {
}
}
\ No newline at end of file
......@@ -16,13 +16,11 @@ class TasksViewModel : ViewModel() {
private val _loadingStatus = MutableLiveData<Boolean>() withDefault false
private val _refreshResult = MutableLiveData<Result<Unit>>() withDefault NotYet()
private val _exams = MutableLiveData<List<Event>>() withDefault listOf()
private val _tasks = MutableLiveData<List<Task>>() withDefault listOf()
private val _news = MutableLiveData<List<News>>() withDefault listOf()
val loadingStatus: LiveData<Boolean> get() = _loadingStatus
val refreshResult: LiveData<Result<Unit>> get() = _refreshResult
val exams: LiveData<List<Event>> get() = _exams
val tasks: LiveData<List<Task>> get() = _tasks
init {
......@@ -46,29 +44,17 @@ class TasksViewModel : ViewModel() {
}
private fun configTasks() { launch {
// val result = model.getExams() zipTo model.getPinnedEvents()
val combined = combineLiveData(model.getPinnedEvents(), model.getExams(), _news) {
pinned: List<Event>?, exams: List<Event>?, news: List<News>? ->
val resultTasks = ArrayList<Task>()
if (pinned != null) for (item in pinned) resultTasks.add(PinnedTask(item))
if (exams != null) for (item in exams) resultTasks.add(ExamTask(item))
if (news != null && news.isNotEmpty()) resultTasks.add(NewsTask(news))
if (pinned != null) resultTasks.addAll(pinned.map { PinnedTask(it) })
if (exams != null) resultTasks.addAll(exams.map { ExamTask(it) })
resultTasks as List<Task>
}
withContext(UI) { combined passTo _tasks}
// withContext(UI) {
// result.observeForever { (exams, pinned) ->
// val resultTasks = ArrayList<Task>()
// for (item in pinned) resultTasks.add(PinnedTask(item))
// for (item in exams) resultTasks.add(ExamTask(item))
// _tasks.postValue(resultTasks)
// }
// }
} }
}
\ No newline at end of file
......@@ -56,10 +56,8 @@ abstract class BlackBirdModel {
result = if (response.isSuccessful && response.body() != null) {
Success(response.body()!!)
} else {
if (response.code() == 401)
if (refreshToken() is Success)
fetch(call.clone()) //Clone to not get "Already executed" exception
else Failure("Could not refresh token")
if (response.code() == 401 && refreshToken() is Success)
fetch(call.clone()) //Clone to not get "Already executed" exception
else
Failure(response.errorBody()?.string() ?: "No error message")
}
......
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha12'
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha06"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment