Add more logging (#219)

This commit is contained in:
Rafał Borcz 2019-01-19 23:15:14 +01:00 committed by Mikołaj Pich
parent e6d60e670e
commit c5bab52fa2
21 changed files with 221 additions and 36 deletions

View File

@ -15,6 +15,11 @@ class AboutPresenter @Inject constructor(
private val analytics: FirebaseAnalyticsHelper private val analytics: FirebaseAnalyticsHelper
) : BasePresenter<AboutView>(errorHandler) { ) : BasePresenter<AboutView>(errorHandler) {
override fun onAttachView(view: AboutView) {
super.onAttachView(view)
Timber.i("About view is attached")
}
fun onExtraSelect(type: Libs.SpecialButton?) { fun onExtraSelect(type: Libs.SpecialButton?) {
view?.run { view?.run {
when (type) { when (type) {

View File

@ -6,6 +6,7 @@ import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.ui.base.ErrorHandler
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.reactivex.Single import io.reactivex.Single
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class AccountPresenter @Inject constructor( class AccountPresenter @Inject constructor(
@ -16,19 +17,23 @@ class AccountPresenter @Inject constructor(
override fun onAttachView(view: AccountView) { override fun onAttachView(view: AccountView) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Account dialog is attached")
view.initView() view.initView()
loadData() loadData()
} }
fun onAddSelected() { fun onAddSelected() {
Timber.i("Select add account")
view?.openLoginView() view?.openLoginView()
} }
fun onRemoveSelected() { fun onRemoveSelected() {
Timber.i("Select remove account")
view?.showConfirmDialog() view?.showConfirmDialog()
} }
fun onLogoutConfirm() { fun onLogoutConfirm() {
Timber.i("Attempt to logout current user ")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
.flatMapCompletable { studentRepository.logoutStudent(it) } .flatMapCompletable { studentRepository.logoutStudent(it) }
.andThen(studentRepository.getSavedStudents(false)) .andThen(studentRepository.getSavedStudents(false))
@ -41,31 +46,54 @@ class AccountPresenter @Inject constructor(
.doFinally { view?.dismissView() } .doFinally { view?.dismissView() }
.subscribe({ .subscribe({
view?.apply { view?.apply {
if (it.isEmpty()) openClearLoginView() if (it.isEmpty()) {
else recreateView() Timber.i("Logout result: Open login view")
openClearLoginView()
} else {
Timber.i("Logout result: Switch to another student")
recreateView()
}
} }
}, { errorHandler.dispatch(it) })) }, {
Timber.i("Logout result: An exception occurred")
errorHandler.dispatch(it)
}))
} }
fun onItemSelected(item: AbstractFlexibleItem<*>) { fun onItemSelected(item: AbstractFlexibleItem<*>) {
if (item is AccountItem) { if (item is AccountItem) {
Timber.i("Select student item ${item.student.id}")
if (item.student.isCurrent) { if (item.student.isCurrent) {
view?.dismissView() view?.dismissView()
} else { } else {
Timber.i("Attempt to change a student")
disposable.add(studentRepository.switchStudent(item.student) disposable.add(studentRepository.switchStudent(item.student)
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ view?.recreateView() }, { errorHandler.dispatch(it) })) .subscribe({
Timber.i("Change a student result: Success")
view?.recreateView()
}, {
Timber.i("Change a student result: An exception occurred")
errorHandler.dispatch(it)
}))
} }
} }
} }
private fun loadData() { private fun loadData() {
Timber.i("Loading account data started")
disposable.add(studentRepository.getSavedStudents(false) disposable.add(studentRepository.getSavedStudents(false)
.map { it.map { item -> AccountItem(item) } } .map { it.map { item -> AccountItem(item) } }
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ view?.updateData(it) }, { errorHandler.dispatch(it) })) .subscribe({
Timber.i("Loading account result: Success")
view?.updateData(it)
}, {
Timber.i("Loading account result: An exception occurred")
errorHandler.dispatch(it)
}))
} }
} }

View File

@ -18,6 +18,7 @@ import io.github.wulkanowy.utils.toFormattedString
import org.threeten.bp.LocalDate import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDate.now import org.threeten.bp.LocalDate.now
import org.threeten.bp.LocalDate.ofEpochDay import org.threeten.bp.LocalDate.ofEpochDay
import timber.log.Timber
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject import javax.inject.Inject
@ -36,6 +37,7 @@ class AttendancePresenter @Inject constructor(
fun onAttachView(view: AttendanceView, date: Long?) { fun onAttachView(view: AttendanceView, date: Long?) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Attendance view is attached")
view.initView() view.initView()
loadData(ofEpochDay(date ?: now().previousOrSameSchoolDay.toEpochDay())) loadData(ofEpochDay(date ?: now().previousOrSameSchoolDay.toEpochDay()))
reloadView() reloadView()
@ -52,10 +54,12 @@ class AttendancePresenter @Inject constructor(
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the attendance")
loadData(currentDate, true) loadData(currentDate, true)
} }
fun onViewReselected() { fun onViewReselected() {
Timber.i("Attendance view is reselected")
view?.also { view -> view?.also { view ->
if (view.currentStackSize == 1) { if (view.currentStackSize == 1) {
now().previousOrSameSchoolDay.also { now().previousOrSameSchoolDay.also {
@ -69,7 +73,10 @@ class AttendancePresenter @Inject constructor(
} }
fun onAttendanceItemSelected(item: AbstractFlexibleItem<*>?) { fun onAttendanceItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is AttendanceItem) view?.showAttendanceDialog(item.attendance) if (item is AttendanceItem) {
Timber.i("Select attendance item ${item.attendance.id}")
view?.showAttendanceDialog(item.attendance)
}
} }
fun onSummarySwitchSelected(): Boolean { fun onSummarySwitchSelected(): Boolean {
@ -78,6 +85,7 @@ class AttendancePresenter @Inject constructor(
} }
private fun loadData(date: LocalDate, forceRefresh: Boolean = false) { private fun loadData(date: LocalDate, forceRefresh: Boolean = false) {
Timber.i("Loading attendance data started")
currentDate = date currentDate = date
disposable.apply { disposable.apply {
clear() clear()
@ -100,6 +108,7 @@ class AttendancePresenter @Inject constructor(
} }
} }
.subscribe({ .subscribe({
Timber.i("Loading attendance result: Success")
view?.apply { view?.apply {
updateData(it) updateData(it)
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
@ -107,6 +116,7 @@ class AttendancePresenter @Inject constructor(
} }
analytics.logEvent("load_attendance", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd"))) analytics.logEvent("load_attendance", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd")))
}) { }) {
Timber.i("Loading attendance result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
} }
@ -115,6 +125,7 @@ class AttendancePresenter @Inject constructor(
} }
private fun reloadView() { private fun reloadView() {
Timber.i("Reload attendance view with the date ${currentDate.toFormattedString()}")
view?.apply { view?.apply {
showProgress(true) showProgress(true)
showContent(false) showContent(false)

View File

@ -12,6 +12,7 @@ import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.github.wulkanowy.utils.calculatePercentage import io.github.wulkanowy.utils.calculatePercentage
import io.github.wulkanowy.utils.getFormattedName import io.github.wulkanowy.utils.getFormattedName
import timber.log.Timber
import java.lang.String.format import java.lang.String.format
import java.util.Locale.FRANCE import java.util.Locale.FRANCE
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
@ -34,25 +35,31 @@ class AttendanceSummaryPresenter @Inject constructor(
fun onAttachView(view: AttendanceSummaryView, subjectId: Int?) { fun onAttachView(view: AttendanceSummaryView, subjectId: Int?) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Attendance summary view is attached with subject id ${subjectId ?: -1}")
view.initView() view.initView()
loadData(subjectId ?: -1) loadData(subjectId ?: -1)
loadSubjects() loadSubjects()
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the attendance summary")
loadData(currentSubjectId, true) loadData(currentSubjectId, true)
} }
fun onSubjectSelected(name: String) { fun onSubjectSelected(name: String) {
Timber.i("Select attendance summary subject $name")
view?.run { view?.run {
showContent(false) showContent(false)
showProgress(true) showProgress(true)
clearView() clearView()
} }
loadData(subjects.singleOrNull { it.name == name }?.realId ?: -1) (subjects.singleOrNull { it.name == name }?.realId ?: -1).let {
if (it != currentSubjectId) loadData(it)
}
} }
private fun loadData(subjectId: Int, forceRefresh: Boolean = false) { private fun loadData(subjectId: Int, forceRefresh: Boolean = false) {
Timber.i("Loading attendance summary data started")
currentSubjectId = subjectId currentSubjectId = subjectId
disposable.apply { disposable.apply {
clear() clear()
@ -70,6 +77,7 @@ class AttendanceSummaryPresenter @Inject constructor(
} }
} }
.subscribe({ .subscribe({
Timber.i("Loading attendance summary result: Success")
view?.apply { view?.apply {
showEmpty(it.first.isEmpty()) showEmpty(it.first.isEmpty())
showContent(it.first.isNotEmpty()) showContent(it.first.isNotEmpty())
@ -77,6 +85,7 @@ class AttendanceSummaryPresenter @Inject constructor(
} }
analytics.logEvent("load_attendance_summary", mapOf("items" to it.first.size, "force_refresh" to forceRefresh, "item_id" to subjectId)) analytics.logEvent("load_attendance_summary", mapOf("items" to it.first.size, "force_refresh" to forceRefresh, "item_id" to subjectId))
}) { }) {
Timber.i("Loading attendance summary result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
} }
@ -85,6 +94,7 @@ class AttendanceSummaryPresenter @Inject constructor(
} }
private fun loadSubjects() { private fun loadSubjects() {
Timber.i("Loading attendance summary subjects started")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
.flatMap { semesterRepository.getCurrentSemester(it) } .flatMap { semesterRepository.getCurrentSemester(it) }
.flatMap { subjectRepository.getSubjects(it) } .flatMap { subjectRepository.getSubjects(it) }
@ -93,11 +103,15 @@ class AttendanceSummaryPresenter @Inject constructor(
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ .subscribe({
Timber.i("Loading attendance summary subjects result: Success")
view?.run { view?.run {
view?.updateSubjects(it) view?.updateSubjects(it)
showSubjects(true) showSubjects(true)
} }
}, { errorHandler.dispatch(it) }) }, {
Timber.i("Loading attendance summary subjects result: An exception occurred")
errorHandler.dispatch(it)
})
) )
} }

View File

@ -18,6 +18,7 @@ import io.github.wulkanowy.utils.toFormattedString
import org.threeten.bp.LocalDate import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDate.now import org.threeten.bp.LocalDate.now
import org.threeten.bp.LocalDate.ofEpochDay import org.threeten.bp.LocalDate.ofEpochDay
import timber.log.Timber
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject import javax.inject.Inject
@ -35,6 +36,7 @@ class ExamPresenter @Inject constructor(
fun onAttachView(view: ExamView, date: Long?) { fun onAttachView(view: ExamView, date: Long?) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Exam view is attached")
view.initView() view.initView()
loadData(ofEpochDay(date ?: now().nextOrSameSchoolDay.toEpochDay())) loadData(ofEpochDay(date ?: now().nextOrSameSchoolDay.toEpochDay()))
reloadView() reloadView()
@ -51,14 +53,19 @@ class ExamPresenter @Inject constructor(
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the exam")
loadData(currentDate, true) loadData(currentDate, true)
} }
fun onExamItemSelected(item: AbstractFlexibleItem<*>?) { fun onExamItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is ExamItem) view?.showExamDialog(item.exam) if (item is ExamItem) {
Timber.i("Select exam item ${item.exam.id}")
view?.showExamDialog(item.exam)
}
} }
fun onViewReselected() { fun onViewReselected() {
Timber.i("Exam view is reselected")
now().nextOrSameSchoolDay.also { now().nextOrSameSchoolDay.also {
if (currentDate != it) { if (currentDate != it) {
loadData(it) loadData(it)
@ -68,6 +75,7 @@ class ExamPresenter @Inject constructor(
} }
private fun loadData(date: LocalDate, forceRefresh: Boolean = false) { private fun loadData(date: LocalDate, forceRefresh: Boolean = false) {
Timber.i("Loading exam data started")
currentDate = date currentDate = date
disposable.apply { disposable.apply {
clear() clear()
@ -87,6 +95,7 @@ class ExamPresenter @Inject constructor(
} }
} }
.subscribe({ .subscribe({
Timber.i("Loading exam result: Success")
view?.apply { view?.apply {
updateData(it) updateData(it)
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
@ -94,6 +103,7 @@ class ExamPresenter @Inject constructor(
} }
analytics.logEvent("load_exam", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd"))) analytics.logEvent("load_exam", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd")))
}) { }) {
Timber.i("Loading exam result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })
@ -109,6 +119,7 @@ class ExamPresenter @Inject constructor(
} }
private fun reloadView() { private fun reloadView() {
Timber.i("Reload exam view with the date ${currentDate.toFormattedString()}")
view?.apply { view?.apply {
showProgress(true) showProgress(true)
showContent(false) showContent(false)

View File

@ -8,6 +8,7 @@ import io.github.wulkanowy.ui.base.session.SessionErrorHandler
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.reactivex.Completable import io.reactivex.Completable
import timber.log.Timber
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject import javax.inject.Inject
@ -28,6 +29,7 @@ class GradePresenter @Inject constructor(
fun onAttachView(view: GradeView, savedIndex: Int?) { fun onAttachView(view: GradeView, savedIndex: Int?) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Grade view is attached")
disposable.add(Completable.timer(150, MILLISECONDS, schedulers.mainThread) disposable.add(Completable.timer(150, MILLISECONDS, schedulers.mainThread)
.subscribe { .subscribe {
selectedIndex = savedIndex ?: 0 selectedIndex = savedIndex ?: 0
@ -37,6 +39,7 @@ class GradePresenter @Inject constructor(
} }
fun onViewReselected() { fun onViewReselected() {
Timber.i("Grade view is reselected")
view?.run { notifyChildParentReselected(currentPageIndex) } view?.run { notifyChildParentReselected(currentPageIndex) }
} }
@ -47,6 +50,7 @@ class GradePresenter @Inject constructor(
fun onSemesterSelected(index: Int) { fun onSemesterSelected(index: Int) {
if (selectedIndex != index - 1) { if (selectedIndex != index - 1) {
Timber.i("Change semester in grade view to ${index + 1}")
selectedIndex = index + 1 selectedIndex = index + 1
loadedSemesterId.clear() loadedSemesterId.clear()
view?.let { view?.let {
@ -74,6 +78,7 @@ class GradePresenter @Inject constructor(
} }
private fun loadData() { private fun loadData() {
Timber.i("Loading grade data started")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
.flatMap { semesterRepository.getSemesters(it) } .flatMap { semesterRepository.getSemesters(it) }
.doOnSuccess { .doOnSuccess {
@ -84,7 +89,13 @@ class GradePresenter @Inject constructor(
} }
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ view?.run { loadChild(currentPageIndex) } }) { .subscribe({
view?.run {
Timber.i("Loading grade result: Attempt load index $currentPageIndex")
loadChild(currentPageIndex)
}
}) {
Timber.i("Loading grade result: An exception occurred")
errorHandler.dispatch(it) errorHandler.dispatch(it)
view?.run { view?.run {
showProgress(false) showProgress(false)
@ -96,6 +107,7 @@ class GradePresenter @Inject constructor(
private fun loadChild(index: Int, forceRefresh: Boolean = false) { private fun loadChild(index: Int, forceRefresh: Boolean = false) {
semesters.first { it.semesterName == selectedIndex }.semesterId.also { semesters.first { it.semesterName == selectedIndex }.semesterId.also {
if (forceRefresh || loadedSemesterId[index] != it) { if (forceRefresh || loadedSemesterId[index] != it) {
Timber.i("Load grade child view index: $index")
view?.notifyChildLoadData(index, it, forceRefresh) view?.notifyChildLoadData(index, it, forceRefresh)
} }
} }

View File

@ -40,6 +40,7 @@ class GradeDetailsPresenter @Inject constructor(
fun onGradeItemSelected(item: AbstractFlexibleItem<*>?) { fun onGradeItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is GradeDetailsItem) { if (item is GradeDetailsItem) {
Timber.i("Select grade item ${item.grade.id}")
view?.apply { view?.apply {
showGradeDialog(item.grade) showGradeDialog(item.grade)
if (!item.grade.isRead) { if (!item.grade.isRead) {
@ -58,18 +59,29 @@ class GradeDetailsPresenter @Inject constructor(
} }
fun onMarkAsReadSelected(): Boolean { fun onMarkAsReadSelected(): Boolean {
Timber.i("Select mark grades as read")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
.flatMap { semesterRepository.getSemesters(it) } .flatMap { semesterRepository.getSemesters(it) }
.flatMap { gradeRepository.getNewGrades(it.first { item -> item.semesterId == currentSemesterId }) } .flatMap { gradeRepository.getNewGrades(it.first { item -> item.semesterId == currentSemesterId }) }
.map { it.map { grade -> grade.apply { isRead = true } } } .map { it.map { grade -> grade.apply { isRead = true } } }
.flatMapCompletable { gradeRepository.updateGrades(it) } .flatMapCompletable {
Timber.i("Mark as read ${it.size} grades")
gradeRepository.updateGrades(it)
}
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ loadData(currentSemesterId, false) }, { errorHandler.dispatch(it) })) .subscribe({
Timber.i("Mark as read result: Success")
loadData(currentSemesterId, false)
}, {
Timber.i("Mark as read result: An exception occurred")
errorHandler.dispatch(it)
}))
return true return true
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the grade details")
view?.notifyParentRefresh() view?.notifyParentRefresh()
} }
@ -94,6 +106,7 @@ class GradeDetailsPresenter @Inject constructor(
} }
private fun loadData(semesterId: Int, forceRefresh: Boolean) { private fun loadData(semesterId: Int, forceRefresh: Boolean) {
Timber.i("Loading grade details data started")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
.flatMap { semesterRepository.getSemesters(it) } .flatMap { semesterRepository.getSemesters(it) }
.flatMap { gradeRepository.getGrades(it.first { item -> item.semesterId == semesterId }, forceRefresh) } .flatMap { gradeRepository.getGrades(it.first { item -> item.semesterId == semesterId }, forceRefresh) }
@ -110,6 +123,7 @@ class GradeDetailsPresenter @Inject constructor(
} }
} }
.subscribe({ .subscribe({
Timber.i("Loading grade details result: Success")
view?.run { view?.run {
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
showContent(it.isNotEmpty()) showContent(it.isNotEmpty())
@ -117,6 +131,7 @@ class GradeDetailsPresenter @Inject constructor(
} }
analytics.logEvent("load_grade_details", mapOf("items" to it.size, "force_refresh" to forceRefresh)) analytics.logEvent("load_grade_details", mapOf("items" to it.size, "force_refresh" to forceRefresh))
}) { }) {
Timber.i("Loading grade details result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })
@ -152,10 +167,14 @@ class GradeDetailsPresenter @Inject constructor(
} }
private fun updateGrade(grade: Grade) { private fun updateGrade(grade: Grade) {
Timber.i("Attempt to update grade ${grade.id}")
disposable.add(gradeRepository.updateGrade(grade) disposable.add(gradeRepository.updateGrade(grade)
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({}) { error -> errorHandler.dispatch(error) }) .subscribe({ Timber.i("Update grade result: Success") })
Timber.d("Grade ${grade.id} updated") { error ->
Timber.i("Update grade result: An exception occurred")
errorHandler.dispatch(error)
})
} }
} }

View File

@ -12,6 +12,7 @@ import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.github.wulkanowy.utils.calcAverage import io.github.wulkanowy.utils.calcAverage
import io.github.wulkanowy.utils.changeModifier import io.github.wulkanowy.utils.changeModifier
import timber.log.Timber
import java.lang.String.format import java.lang.String.format
import java.util.Locale.FRANCE import java.util.Locale.FRANCE
import javax.inject.Inject import javax.inject.Inject
@ -33,6 +34,7 @@ class GradeSummaryPresenter @Inject constructor(
} }
fun onParentViewLoadData(semesterId: Int, forceRefresh: Boolean) { fun onParentViewLoadData(semesterId: Int, forceRefresh: Boolean) {
Timber.i("Loading grade summary data started")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
.flatMap { semesterRepository.getSemesters(it) } .flatMap { semesterRepository.getSemesters(it) }
.map { semester -> semester.first { it.semesterId == semesterId } } .map { semester -> semester.first { it.semesterId == semesterId } }
@ -64,6 +66,7 @@ class GradeSummaryPresenter @Inject constructor(
notifyParentDataLoaded(semesterId) notifyParentDataLoaded(semesterId)
} }
}.subscribe({ }.subscribe({
Timber.i("Loading grade summary result: Success")
view?.run { view?.run {
showEmpty(it.first.isEmpty()) showEmpty(it.first.isEmpty())
showContent(it.first.isNotEmpty()) showContent(it.first.isNotEmpty())
@ -71,12 +74,14 @@ class GradeSummaryPresenter @Inject constructor(
} }
analytics.logEvent("load_grade_summary", mapOf("items" to it.first.size, "force_refresh" to forceRefresh)) analytics.logEvent("load_grade_summary", mapOf("items" to it.first.size, "force_refresh" to forceRefresh))
}) { }) {
Timber.i("Loading grade summary result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the grade summary")
view?.notifyParentRefresh() view?.notifyParentRefresh()
} }

View File

@ -15,6 +15,7 @@ import io.github.wulkanowy.utils.nextSchoolDay
import io.github.wulkanowy.utils.previousSchoolDay import io.github.wulkanowy.utils.previousSchoolDay
import io.github.wulkanowy.utils.toFormattedString import io.github.wulkanowy.utils.toFormattedString
import org.threeten.bp.LocalDate import org.threeten.bp.LocalDate
import timber.log.Timber
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@ -32,6 +33,7 @@ class HomeworkPresenter @Inject constructor(
fun onAttachView(view: HomeworkView, date: Long?) { fun onAttachView(view: HomeworkView, date: Long?) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Homework view is attached")
view.initView() view.initView()
loadData(LocalDate.ofEpochDay(date ?: LocalDate.now().nextOrSameSchoolDay.toEpochDay())) loadData(LocalDate.ofEpochDay(date ?: LocalDate.now().nextOrSameSchoolDay.toEpochDay()))
reloadView() reloadView()
@ -48,14 +50,19 @@ class HomeworkPresenter @Inject constructor(
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the homework")
loadData(currentDate, true) loadData(currentDate, true)
} }
fun onHomeworkItemSelected(item: AbstractFlexibleItem<*>?) { fun onHomeworkItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is HomeworkItem) view?.showTimetableDialog(item.homework) if (item is HomeworkItem) {
Timber.i("Select homework item ${item.homework.id}")
view?.showTimetableDialog(item.homework)
}
} }
private fun loadData(date: LocalDate, forceRefresh: Boolean = false) { private fun loadData(date: LocalDate, forceRefresh: Boolean = false) {
Timber.i("Loading homework data started")
currentDate = date currentDate = date
disposable.apply { disposable.apply {
clear() clear()
@ -73,6 +80,7 @@ class HomeworkPresenter @Inject constructor(
} }
} }
.subscribe({ .subscribe({
Timber.i("Loading homework result: Success")
view?.apply { view?.apply {
updateData(it) updateData(it)
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
@ -80,6 +88,7 @@ class HomeworkPresenter @Inject constructor(
} }
analytics.logEvent("load_homework", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd"))) analytics.logEvent("load_homework", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd")))
}) { }) {
Timber.i("Loading homework result: An exception occurred")
view?.run { showEmpty(isViewEmpty()) } view?.run { showEmpty(isViewEmpty()) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })
@ -87,6 +96,7 @@ class HomeworkPresenter @Inject constructor(
} }
private fun reloadView() { private fun reloadView() {
Timber.i("Reload homework view with the date ${currentDate.toFormattedString()}")
view?.apply { view?.apply {
showProgress(true) showProgress(true)
showContent(false) showContent(false)

View File

@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.modules.login
import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.ui.base.ErrorHandler
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class LoginPresenter @Inject constructor(errorHandler: ErrorHandler) : BasePresenter<LoginView>(errorHandler) { class LoginPresenter @Inject constructor(errorHandler: ErrorHandler) : BasePresenter<LoginView>(errorHandler) {
@ -12,6 +13,7 @@ class LoginPresenter @Inject constructor(errorHandler: ErrorHandler) : BasePrese
initAdapter() initAdapter()
hideActionBar() hideActionBar()
} }
Timber.i("Login view is attached")
} }
fun onPageSelected(index: Int) { fun onPageSelected(index: Int) {
@ -23,6 +25,7 @@ class LoginPresenter @Inject constructor(errorHandler: ErrorHandler) : BasePrese
} }
fun onBackPressed(default: () -> Unit) { fun onBackPressed(default: () -> Unit) {
Timber.i("Back pressed in login view")
view?.run { view?.run {
if (currentViewIndex == 1) { if (currentViewIndex == 1) {
switchView(0) switchView(0)

View File

@ -45,6 +45,7 @@ class LoginFormPresenter @Inject constructor(
showProgress(true) showProgress(true)
showContent(false) showContent(false)
} }
Timber.i("Login started")
} }
.doFinally { .doFinally {
view?.apply { view?.apply {
@ -58,17 +59,21 @@ class LoginFormPresenter @Inject constructor(
showSymbolInput() showSymbolInput()
wasEmpty = true wasEmpty = true
analytics.logEvent("sign_up_send", mapOf(SUCCESS to false, "students" to 0, "endpoint" to endpoint, GROUP_ID to symbol.ifEmpty { "null" })) analytics.logEvent("sign_up_send", mapOf(SUCCESS to false, "students" to 0, "endpoint" to endpoint, GROUP_ID to symbol.ifEmpty { "null" }))
Timber.i("Login result: Empty student list")
} else if (it.isEmpty() && wasEmpty) { } else if (it.isEmpty() && wasEmpty) {
showSymbolInput() showSymbolInput()
setErrorSymbolIncorrect() setErrorSymbolIncorrect()
analytics.logEvent("sign_up_send", mapOf(SUCCESS to false, "students" to it.size, "endpoint" to endpoint, GROUP_ID to symbol.ifEmpty { "nil" })) analytics.logEvent("sign_up_send", mapOf(SUCCESS to false, "students" to it.size, "endpoint" to endpoint, GROUP_ID to symbol.ifEmpty { "null" }))
Timber.i("Login result: Wrong symbol")
} else { } else {
analytics.logEvent("sign_up_send", mapOf(SUCCESS to true, "students" to it.size, "endpoint" to endpoint, GROUP_ID to symbol)) analytics.logEvent("sign_up_send", mapOf(SUCCESS to true, "students" to it.size, "endpoint" to endpoint, GROUP_ID to symbol))
Timber.i("Login result: Success")
switchOptionsView() switchOptionsView()
} }
} }
}, { }, {
analytics.logEvent(SIGN_UP, mapOf(SUCCESS to false, "endpoint" to endpoint, "message" to it.localizedMessage, GROUP_ID to symbol.ifEmpty { "nil" })) analytics.logEvent(SIGN_UP, mapOf(SUCCESS to false, "endpoint" to endpoint, "message" to it.localizedMessage, GROUP_ID to symbol.ifEmpty { "null" }))
Timber.i("Login result: An exception occurred")
errorHandler.dispatch(it) errorHandler.dispatch(it)
})) }))
} }

View File

@ -12,6 +12,7 @@ import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.reactivex.Single import io.reactivex.Single
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class LoginOptionsPresenter @Inject constructor( class LoginOptionsPresenter @Inject constructor(
@ -26,7 +27,10 @@ class LoginOptionsPresenter @Inject constructor(
super.onAttachView(view) super.onAttachView(view)
view.run { view.run {
initView() initView()
errorHandler.onStudentDuplicate = { showMessage(it) } errorHandler.onStudentDuplicate = {
showMessage(it)
Timber.i("The student already registered in the app was selected")
}
} }
} }
@ -58,11 +62,14 @@ class LoginOptionsPresenter @Inject constructor(
showContent(false) showContent(false)
showActionBar(false) showActionBar(false)
} }
Timber.i("Registration started")
} }
.subscribe({ .subscribe({
analytics.logEvent(SIGN_UP, mapOf(SUCCESS to true, "endpoint" to student.endpoint, "message" to "Success", GROUP_ID to student.symbol)) analytics.logEvent(SIGN_UP, mapOf(SUCCESS to true, "endpoint" to student.endpoint, "message" to "Success", GROUP_ID to student.symbol))
Timber.i("Registration result: Success")
view?.openMainView() view?.openMainView()
}, { }, {
Timber.i("Registration result: An exception occurred ")
errorHandler.dispatch(it) errorHandler.dispatch(it)
view?.apply { view?.apply {
showProgress(false) showProgress(false)

View File

@ -71,7 +71,7 @@ class MainActivity : BaseActivity(), MainView {
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
presenter.onViewStart() presenter.onViewChange()
} }
override fun initView() { override fun initView() {
@ -98,7 +98,7 @@ class MainActivity : BaseActivity(), MainView {
} }
navController.run { navController.run {
setOnViewChangeListener { presenter.onViewStart() } setOnViewChangeListener { presenter.onViewChange() }
fragmentHideStrategy = HIDE fragmentHideStrategy = HIDE
rootFragments = listOf( rootFragments = listOf(
GradeFragment.newInstance(), GradeFragment.newInstance(),

View File

@ -10,6 +10,7 @@ import io.github.wulkanowy.ui.base.ErrorHandler
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.reactivex.Completable import io.reactivex.Completable
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class MainPresenter @Inject constructor( class MainPresenter @Inject constructor(
@ -23,6 +24,7 @@ class MainPresenter @Inject constructor(
fun onAttachView(view: MainView, initMenuIndex: Int) { fun onAttachView(view: MainView, initMenuIndex: Int) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Main view is attached with $initMenuIndex menu index")
view.run { view.run {
cancelNotifications() cancelNotifications()
startMenuIndex = if (initMenuIndex != -1) initMenuIndex else prefRepository.startMenuIndex startMenuIndex = if (initMenuIndex != -1) initMenuIndex else prefRepository.startMenuIndex
@ -38,7 +40,7 @@ class MainPresenter @Inject constructor(
})) }))
} }
fun onViewStart() { fun onViewChange() {
view?.apply { view?.apply {
currentViewTitle?.let { setViewTitle(it) } currentViewTitle?.let { setViewTitle(it) }
currentStackSize?.let { currentStackSize?.let {
@ -49,16 +51,19 @@ class MainPresenter @Inject constructor(
} }
fun onAccountManagerSelected(): Boolean { fun onAccountManagerSelected(): Boolean {
Timber.i("Select account manager")
view?.showAccountPicker() view?.showAccountPicker()
return true return true
} }
fun onUpNavigate(): Boolean { fun onUpNavigate(): Boolean {
Timber.i("Up navigate pressed")
view?.popView() view?.popView()
return true return true
} }
fun onBackPressed(default: () -> Unit) { fun onBackPressed(default: () -> Unit) {
Timber.i("Back pressed in main view")
view?.run { view?.run {
if (isRootView) default() if (isRootView) default()
else popView() else popView()
@ -67,6 +72,7 @@ class MainPresenter @Inject constructor(
fun onTabSelected(index: Int, wasSelected: Boolean): Boolean { fun onTabSelected(index: Int, wasSelected: Boolean): Boolean {
return view?.run { return view?.run {
Timber.i("Switch main tab index: $index, reselected: $wasSelected")
if (wasSelected) { if (wasSelected) {
notifyMenuViewReselected() notifyMenuViewReselected()
false false
@ -78,15 +84,25 @@ class MainPresenter @Inject constructor(
} }
fun onLoginSelected() { fun onLoginSelected() {
Timber.i("Attempt to switch the student after the session expires")
disposable.add(studentRepository.getCurrentStudent(false) disposable.add(studentRepository.getCurrentStudent(false)
.flatMapCompletable { studentRepository.logoutStudent(it) } .flatMapCompletable { studentRepository.logoutStudent(it) }
.andThen(studentRepository.getSavedStudents(false)) .andThen(studentRepository.getSavedStudents(false))
.flatMapCompletable { .flatMapCompletable {
if (it.isNotEmpty()) studentRepository.switchStudent(it[0]) if (it.isNotEmpty()) {
Timber.i("Switching current student")
studentRepository.switchStudent(it[0])
}
else Completable.complete() else Completable.complete()
} }
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ view?.openLoginView() }, { errorHandler.dispatch(it) })) .subscribe({
Timber.i("Switch student result: Open login view")
view?.openLoginView()
}, {
Timber.i("Switch student result: An exception occurred")
errorHandler.dispatch(it)
}))
} }
} }

View File

@ -4,6 +4,7 @@ import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.ui.base.ErrorHandler
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.reactivex.Completable import io.reactivex.Completable
import timber.log.Timber
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject import javax.inject.Inject
@ -14,6 +15,7 @@ class MessagePresenter @Inject constructor(
override fun onAttachView(view: MessageView) { override fun onAttachView(view: MessageView) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Message view is attached")
disposable.add(Completable.timer(150, MILLISECONDS, schedulers.mainThread) disposable.add(Completable.timer(150, MILLISECONDS, schedulers.mainThread)
.subscribe { .subscribe {
view.initView() view.initView()
@ -30,6 +32,7 @@ class MessagePresenter @Inject constructor(
} }
private fun loadChild(index: Int, forceRefresh: Boolean = false) { private fun loadChild(index: Int, forceRefresh: Boolean = false) {
Timber.i("Load message child view index: $index")
view?.notifyChildLoadData(index, forceRefresh) view?.notifyChildLoadData(index, forceRefresh)
} }

View File

@ -8,6 +8,7 @@ import io.github.wulkanowy.ui.base.session.SessionErrorHandler
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.SchedulersProvider
import io.github.wulkanowy.utils.toFormattedString import io.github.wulkanowy.utils.toFormattedString
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class MessagePreviewPresenter @Inject constructor( class MessagePreviewPresenter @Inject constructor(
@ -26,6 +27,7 @@ class MessagePreviewPresenter @Inject constructor(
} }
private fun loadData(id: Int) { private fun loadData(id: Int) {
Timber.i("Loading message $id preview started")
messageId = id messageId = id
disposable.apply { disposable.apply {
clear() clear()
@ -35,6 +37,7 @@ class MessagePreviewPresenter @Inject constructor(
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.doFinally { view?.showProgress(false) } .doFinally { view?.showProgress(false) }
.subscribe({ message -> .subscribe({ message ->
Timber.i("Loading message $id preview result: Success ")
view?.run { view?.run {
message.let { message.let {
setSubject(if (it.subject.isNotBlank()) it.subject else noSubjectString) setSubject(if (it.subject.isNotBlank()) it.subject else noSubjectString)
@ -45,8 +48,9 @@ class MessagePreviewPresenter @Inject constructor(
else setSender(it.sender) else setSender(it.sender)
} }
} }
analytics.logEvent("load_attendance", mapOf(START_DATE to message.date?.toFormattedString("yyyy.MM.dd"), "lenght" to message.content?.length)) analytics.logEvent("load_message_preview", mapOf(START_DATE to message.date?.toFormattedString("yyyy.MM.dd"), "lenght" to message.content?.length))
}) { }) {
Timber.i("Loading message $id preview result: An excception occurred ")
view?.showMessageError() view?.showMessageError()
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })

View File

@ -29,10 +29,12 @@ class MessageTabPresenter @Inject constructor(
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the $folder message")
onParentViewLoadData(true) onParentViewLoadData(true)
} }
fun onParentViewLoadData(forceRefresh: Boolean) { fun onParentViewLoadData(forceRefresh: Boolean) {
Timber.i("Loading $folder message data started")
disposable.apply { disposable.apply {
clear() clear()
add(studentRepository.getCurrentStudent() add(studentRepository.getCurrentStudent()
@ -48,6 +50,7 @@ class MessageTabPresenter @Inject constructor(
} }
} }
.subscribe({ .subscribe({
Timber.i("Loading $folder message result: Success")
view?.run { view?.run {
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
showContent(it.isNotEmpty()) showContent(it.isNotEmpty())
@ -55,6 +58,7 @@ class MessageTabPresenter @Inject constructor(
} }
analytics.logEvent("load_messages", mapOf("items" to it.size, "folder" to folder.name)) analytics.logEvent("load_messages", mapOf("items" to it.size, "folder" to folder.name))
}) { }) {
Timber.i("Loading $folder message result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })
@ -63,6 +67,7 @@ class MessageTabPresenter @Inject constructor(
fun onMessageItemSelected(item: AbstractFlexibleItem<*>) { fun onMessageItemSelected(item: AbstractFlexibleItem<*>) {
if (item is MessageItem) { if (item is MessageItem) {
Timber.i("Select message ${item.message.realId} item")
view?.run { view?.run {
openMessage(item.message.realId) openMessage(item.message.realId)
if (item.message.unread == true) { if (item.message.unread == true) {
@ -75,12 +80,14 @@ class MessageTabPresenter @Inject constructor(
} }
private fun updateMessage(message: Message) { private fun updateMessage(message: Message) {
Timber.i("Attempt to update message ${message.realId}")
disposable.add(messagesRepository.updateMessage(message) disposable.add(messagesRepository.updateMessage(message)
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ .subscribe({ Timber.d("Update message ${message.realId} result: Success") })
Timber.d("Message ${message.realId} updated") { error ->
}) { error -> errorHandler.dispatch(error) } Timber.i("Update message ${message.realId} result: An exception occurred")
) errorHandler.dispatch(error)
})
} }
} }

View File

@ -3,18 +3,21 @@ package io.github.wulkanowy.ui.modules.more
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.ui.base.ErrorHandler
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class MorePresenter @Inject constructor(errorHandler: ErrorHandler) : BasePresenter<MoreView>(errorHandler) { class MorePresenter @Inject constructor(errorHandler: ErrorHandler) : BasePresenter<MoreView>(errorHandler) {
override fun onAttachView(view: MoreView) { override fun onAttachView(view: MoreView) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("More view is attached")
view.initView() view.initView()
loadData() loadData()
} }
fun onItemSelected(item: AbstractFlexibleItem<*>?) { fun onItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is MoreItem) { if (item is MoreItem) {
Timber.i("Select more item \"${item.title}\"")
view?.run { view?.run {
when (item.title) { when (item.title) {
messagesRes?.first -> openMessagesView() messagesRes?.first -> openMessagesView()
@ -28,10 +31,12 @@ class MorePresenter @Inject constructor(errorHandler: ErrorHandler) : BasePresen
} }
fun onViewReselected() { fun onViewReselected() {
Timber.i("More view is reselected")
view?.popView() view?.popView()
} }
private fun loadData() { private fun loadData() {
Timber.i("Load items for more view")
view?.run { view?.run {
updateData(listOfNotNull( updateData(listOfNotNull(
messagesRes?.let { MoreItem(it.first, it.second) }, messagesRes?.let { MoreItem(it.first, it.second) },

View File

@ -23,15 +23,18 @@ class NotePresenter @Inject constructor(
override fun onAttachView(view: NoteView) { override fun onAttachView(view: NoteView) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Note view is attached")
view.initView() view.initView()
loadData() loadData()
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the note")
loadData(true) loadData(true)
} }
private fun loadData(forceRefresh: Boolean = false) { private fun loadData(forceRefresh: Boolean = false) {
Timber.i("Loading note data started")
disposable.add(studentRepository.getCurrentStudent() disposable.add(studentRepository.getCurrentStudent()
.flatMap { semesterRepository.getCurrentSemester(it) } .flatMap { semesterRepository.getCurrentSemester(it) }
.flatMap { noteRepository.getNotes(it, forceRefresh) } .flatMap { noteRepository.getNotes(it, forceRefresh) }
@ -45,6 +48,7 @@ class NotePresenter @Inject constructor(
showProgress(false) showProgress(false)
} }
}.subscribe({ }.subscribe({
Timber.i("Loading note result: Success")
view?.apply { view?.apply {
updateData(it) updateData(it)
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
@ -52,6 +56,7 @@ class NotePresenter @Inject constructor(
} }
analytics.logEvent("load_note", mapOf("items" to it.size, "force_refresh" to forceRefresh)) analytics.logEvent("load_note", mapOf("items" to it.size, "force_refresh" to forceRefresh))
}, { }, {
Timber.i("Loading note result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })
@ -60,6 +65,7 @@ class NotePresenter @Inject constructor(
fun onNoteItemSelected(item: AbstractFlexibleItem<*>?) { fun onNoteItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is NoteItem) { if (item is NoteItem) {
Timber.i("Select note item ${item.note.id}")
view?.run { view?.run {
showNoteDialog(item.note) showNoteDialog(item.note)
if (!item.note.isRead) { if (!item.note.isRead) {
@ -72,12 +78,14 @@ class NotePresenter @Inject constructor(
} }
private fun updateNote(note: Note) { private fun updateNote(note: Note) {
Timber.i("Attempt to update note ${note.id}")
disposable.add(noteRepository.updateNote(note) disposable.add(noteRepository.updateNote(note)
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.subscribe({ .subscribe({ Timber.i("Update note result: Success") })
Timber.d("Note ${note.id} updated") { error ->
}) { error -> errorHandler.dispatch(error) } Timber.i("Update note result: An exception occurred")
) errorHandler.dispatch(error)
})
} }
} }

View File

@ -1,7 +1,6 @@
package io.github.wulkanowy.ui.modules.settings package io.github.wulkanowy.ui.modules.settings
import com.readystatesoftware.chuck.api.ChuckCollector import com.readystatesoftware.chuck.api.ChuckCollector
import io.github.wulkanowy.data.RepositoryModule_ProvideChuckCollectorFactory
import io.github.wulkanowy.data.repositories.PreferencesRepository import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.services.job.ServiceHelper import io.github.wulkanowy.services.job.ServiceHelper
import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.BasePresenter
@ -9,6 +8,7 @@ import io.github.wulkanowy.ui.base.ErrorHandler
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
import io.github.wulkanowy.utils.isHolidays import io.github.wulkanowy.utils.isHolidays
import org.threeten.bp.LocalDate.now import org.threeten.bp.LocalDate.now
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class SettingsPresenter @Inject constructor( class SettingsPresenter @Inject constructor(
@ -21,6 +21,7 @@ class SettingsPresenter @Inject constructor(
override fun onAttachView(view: SettingsView) { override fun onAttachView(view: SettingsView) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Settings view is attached")
view.run { view.run {
setServicesSuspended(preferencesRepository.serviceEnablesKey, now().isHolidays) setServicesSuspended(preferencesRepository.serviceEnablesKey, now().isHolidays)
@ -28,6 +29,7 @@ class SettingsPresenter @Inject constructor(
} }
fun onSharedPreferenceChanged(key: String) { fun onSharedPreferenceChanged(key: String) {
Timber.i("Change settings $key")
when (key) { when (key) {
preferencesRepository.serviceEnablesKey -> { preferencesRepository.serviceEnablesKey -> {
if (preferencesRepository.isServiceEnabled) serviceHelper.startFullSyncService() if (preferencesRepository.isServiceEnabled) serviceHelper.startFullSyncService()
@ -44,7 +46,6 @@ class SettingsPresenter @Inject constructor(
chuckCollector.showNotification(preferencesRepository.isShowChuckerNotification) chuckCollector.showNotification(preferencesRepository.isShowChuckerNotification)
} }
} }
analytics.logEvent("setting_changed", mapOf("name" to key)) analytics.logEvent("setting_changed", mapOf("name" to key))
} }
} }

View File

@ -17,6 +17,7 @@ import io.github.wulkanowy.utils.toFormattedString
import org.threeten.bp.LocalDate import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDate.now import org.threeten.bp.LocalDate.now
import org.threeten.bp.LocalDate.ofEpochDay import org.threeten.bp.LocalDate.ofEpochDay
import timber.log.Timber
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject import javax.inject.Inject
@ -34,6 +35,7 @@ class TimetablePresenter @Inject constructor(
fun onAttachView(view: TimetableView, date: Long?) { fun onAttachView(view: TimetableView, date: Long?) {
super.onAttachView(view) super.onAttachView(view)
Timber.i("Timetable is attached")
view.initView() view.initView()
loadData(ofEpochDay(date ?: now().nextOrSameSchoolDay.toEpochDay())) loadData(ofEpochDay(date ?: now().nextOrSameSchoolDay.toEpochDay()))
reloadView() reloadView()
@ -50,10 +52,12 @@ class TimetablePresenter @Inject constructor(
} }
fun onSwipeRefresh() { fun onSwipeRefresh() {
Timber.i("Force refreshing the timetable")
loadData(currentDate, true) loadData(currentDate, true)
} }
fun onViewReselected() { fun onViewReselected() {
Timber.i("Exam view is reselected")
now().nextOrSameSchoolDay.also { now().nextOrSameSchoolDay.also {
if (currentDate != it) { if (currentDate != it) {
loadData(it) loadData(it)
@ -63,10 +67,14 @@ class TimetablePresenter @Inject constructor(
} }
fun onTimetableItemSelected(item: AbstractFlexibleItem<*>?) { fun onTimetableItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is TimetableItem) view?.showTimetableDialog(item.lesson) if (item is TimetableItem) {
Timber.i("Select exam item ${item.lesson.id}")
view?.showTimetableDialog(item.lesson)
}
} }
private fun loadData(date: LocalDate, forceRefresh: Boolean = false) { private fun loadData(date: LocalDate, forceRefresh: Boolean = false) {
Timber.i("Loading timetable data started")
currentDate = date currentDate = date
disposable.apply { disposable.apply {
clear() clear()
@ -85,13 +93,15 @@ class TimetablePresenter @Inject constructor(
} }
} }
.subscribe({ .subscribe({
Timber.i("Loading timetable result: Success")
view?.apply { view?.apply {
updateData(it) updateData(it)
showEmpty(it.isEmpty()) showEmpty(it.isEmpty())
showContent(it.isNotEmpty()) showContent(it.isNotEmpty())
} }
analytics.logEvent("load_attendance", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd"))) analytics.logEvent("load_timetable", mapOf("items" to it.size, "force_refresh" to forceRefresh, START_DATE to currentDate.toFormattedString("yyyy-MM-dd")))
}) { }) {
Timber.i("Loading timetable result: An exception occurred")
view?.run { showEmpty(isViewEmpty) } view?.run { showEmpty(isViewEmpty) }
errorHandler.dispatch(it) errorHandler.dispatch(it)
}) })
@ -99,6 +109,7 @@ class TimetablePresenter @Inject constructor(
} }
private fun reloadView() { private fun reloadView() {
Timber.i("Reload timetable view with the date ${currentDate.toFormattedString()}")
view?.apply { view?.apply {
showProgress(true) showProgress(true)
showContent(false) showContent(false)