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

Cleanup

parent 439aded4
...@@ -40,4 +40,8 @@ class EventDetailViewModel: ViewModel() { ...@@ -40,4 +40,8 @@ class EventDetailViewModel: ViewModel() {
fun requestTeachers(usernames: List<String>) { launch { fun requestTeachers(usernames: List<String>) { launch {
_teachers.postValue(model.getTeachers(usernames)) _teachers.postValue(model.getTeachers(usernames))
} } } }
fun changeEventNote(eventId: Int, note: String) {
}
} }
\ No newline at end of file
...@@ -16,13 +16,11 @@ class TasksViewModel : ViewModel() { ...@@ -16,13 +16,11 @@ class TasksViewModel : ViewModel() {
private val _loadingStatus = MutableLiveData<Boolean>() withDefault false private val _loadingStatus = MutableLiveData<Boolean>() withDefault false
private val _refreshResult = MutableLiveData<Result<Unit>>() withDefault NotYet() 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 _tasks = MutableLiveData<List<Task>>() withDefault listOf()
private val _news = MutableLiveData<List<News>>() withDefault listOf() private val _news = MutableLiveData<List<News>>() withDefault listOf()
val loadingStatus: LiveData<Boolean> get() = _loadingStatus val loadingStatus: LiveData<Boolean> get() = _loadingStatus
val refreshResult: LiveData<Result<Unit>> get() = _refreshResult val refreshResult: LiveData<Result<Unit>> get() = _refreshResult
val exams: LiveData<List<Event>> get() = _exams
val tasks: LiveData<List<Task>> get() = _tasks val tasks: LiveData<List<Task>> get() = _tasks
init { init {
...@@ -46,29 +44,17 @@ class TasksViewModel : ViewModel() { ...@@ -46,29 +44,17 @@ class TasksViewModel : ViewModel() {
} }
private fun configTasks() { launch { private fun configTasks() { launch {
// val result = model.getExams() zipTo model.getPinnedEvents()
val combined = combineLiveData(model.getPinnedEvents(), model.getExams(), _news) { val combined = combineLiveData(model.getPinnedEvents(), model.getExams(), _news) {
pinned: List<Event>?, exams: List<Event>?, news: List<News>? -> pinned: List<Event>?, exams: List<Event>?, news: List<News>? ->
val resultTasks = ArrayList<Task>() 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 (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> resultTasks as List<Task>
} }
withContext(UI) { combined passTo _tasks} 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 { ...@@ -56,10 +56,8 @@ abstract class BlackBirdModel {
result = if (response.isSuccessful && response.body() != null) { result = if (response.isSuccessful && response.body() != null) {
Success(response.body()!!) Success(response.body()!!)
} else { } else {
if (response.code() == 401) if (response.code() == 401 && refreshToken() is Success)
if (refreshToken() is Success) fetch(call.clone()) //Clone to not get "Already executed" exception
fetch(call.clone()) //Clone to not get "Already executed" exception
else Failure("Could not refresh token")
else else
Failure(response.errorBody()?.string() ?: "No error message") Failure(response.errorBody()?.string() ?: "No error message")
} }
......
...@@ -7,7 +7,7 @@ buildscript { ...@@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { 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 "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha06" 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