forked from github/wulkanowy-mirror
Add logging to sync worker (#300)
This commit is contained in:
parent
6bb03b3be8
commit
1f65b8465e
@ -3,7 +3,6 @@ package io.github.wulkanowy.di
|
|||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
import io.github.wulkanowy.di.scopes.PerActivity
|
import io.github.wulkanowy.di.scopes.PerActivity
|
||||||
import io.github.wulkanowy.services.widgets.TimetableWidgetService
|
|
||||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||||
import io.github.wulkanowy.ui.modules.login.LoginModule
|
import io.github.wulkanowy.ui.modules.login.LoginModule
|
||||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||||
@ -30,9 +29,6 @@ internal abstract class BuilderModule {
|
|||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
abstract fun bindMessageSendActivity(): SendMessageActivity
|
abstract fun bindMessageSendActivity(): SendMessageActivity
|
||||||
|
|
||||||
@ContributesAndroidInjector
|
|
||||||
abstract fun bindTimetableWidgetService(): TimetableWidgetService
|
|
||||||
|
|
||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
abstract fun bindTimetableWidgetProvider(): TimetableWidgetProvider
|
abstract fun bindTimetableWidgetProvider(): TimetableWidgetProvider
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.squareup.inject.assisted.dagger2.AssistedModule
|
|||||||
import dagger.Binds
|
import dagger.Binds
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
|
import dagger.android.ContributesAndroidInjector
|
||||||
import dagger.multibindings.IntoSet
|
import dagger.multibindings.IntoSet
|
||||||
import io.github.wulkanowy.services.sync.works.AttendanceSummaryWork
|
import io.github.wulkanowy.services.sync.works.AttendanceSummaryWork
|
||||||
import io.github.wulkanowy.services.sync.works.AttendanceWork
|
import io.github.wulkanowy.services.sync.works.AttendanceWork
|
||||||
@ -24,6 +25,7 @@ import io.github.wulkanowy.services.sync.works.NoteWork
|
|||||||
import io.github.wulkanowy.services.sync.works.RecipientWork
|
import io.github.wulkanowy.services.sync.works.RecipientWork
|
||||||
import io.github.wulkanowy.services.sync.works.TimetableWork
|
import io.github.wulkanowy.services.sync.works.TimetableWork
|
||||||
import io.github.wulkanowy.services.sync.works.Work
|
import io.github.wulkanowy.services.sync.works.Work
|
||||||
|
import io.github.wulkanowy.services.widgets.TimetableWidgetService
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@AssistedModule
|
@AssistedModule
|
||||||
@ -48,6 +50,9 @@ abstract class ServicesModule {
|
|||||||
fun provideNotificationManager(context: Context) = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
fun provideNotificationManager(context: Context) = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun bindTimetableWidgetService(): TimetableWidgetService
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@IntoSet
|
@IntoSet
|
||||||
abstract fun provideGradeWork(work: GradeWork): Work
|
abstract fun provideGradeWork(work: GradeWork): Work
|
||||||
|
@ -35,25 +35,31 @@ class SyncWorker @AssistedInject constructor(
|
|||||||
) : RxWorker(appContext, workerParameters) {
|
) : RxWorker(appContext, workerParameters) {
|
||||||
|
|
||||||
override fun createWork(): Single<Result> {
|
override fun createWork(): Single<Result> {
|
||||||
|
Timber.i("SyncWorker is starting")
|
||||||
return studentRepository.isStudentSaved()
|
return studentRepository.isStudentSaved()
|
||||||
.flatMapCompletable { isSaved ->
|
.filter { true }
|
||||||
if (isSaved) {
|
.flatMap { studentRepository.getCurrentStudent().toMaybe() }
|
||||||
studentRepository.getCurrentStudent()
|
|
||||||
.flatMapCompletable { student ->
|
.flatMapCompletable { student ->
|
||||||
semesterRepository.getCurrentSemester(student)
|
semesterRepository.getCurrentSemester(student, true)
|
||||||
.flatMapCompletable { semester ->
|
.flatMapCompletable { semester ->
|
||||||
Completable.mergeDelayError(Flowable.fromIterable(works.map { it.create(student, semester) }), 3)
|
Completable.mergeDelayError(Flowable.fromIterable(works.map { work ->
|
||||||
|
work.create(student, semester)
|
||||||
|
.doOnSubscribe { Timber.i("${work::class.java.simpleName} is starting") }
|
||||||
|
.doOnError { Timber.i("${work::class.java.simpleName} result: An exception occurred") }
|
||||||
|
.doOnComplete { Timber.i("${work::class.java.simpleName} result: Success") }
|
||||||
|
}), 3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else Completable.complete()
|
|
||||||
}
|
|
||||||
.toSingleDefault(Result.success())
|
.toSingleDefault(Result.success())
|
||||||
.onErrorReturn {
|
.onErrorReturn {
|
||||||
Timber.e(it, "There was an error during synchronization")
|
Timber.e(it, "There was an error during synchronization")
|
||||||
if (it is FeatureDisabledException) Result.success()
|
if (it is FeatureDisabledException) Result.success()
|
||||||
else Result.retry()
|
else Result.retry()
|
||||||
}
|
}
|
||||||
.doOnSuccess { if (preferencesRepository.isDebugNotificationEnable) notify(it) }
|
.doOnSuccess {
|
||||||
|
if (preferencesRepository.isDebugNotificationEnable) notify(it)
|
||||||
|
Timber.i("SyncWorker result: $it")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notify(result: Result) {
|
private fun notify(result: Result) {
|
||||||
|
@ -13,10 +13,10 @@ class RecipientWork @Inject constructor(
|
|||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override fun create(student: Student, semester: Semester): Completable {
|
override fun create(student: Student, semester: Semester): Completable {
|
||||||
return reportingUnitRepository.getReportingUnits(student)
|
return reportingUnitRepository.getReportingUnits(student, true)
|
||||||
.flatMapCompletable { units ->
|
.flatMapCompletable { units ->
|
||||||
Completable.mergeDelayError(units.map {
|
Completable.mergeDelayError(units.map {
|
||||||
recipientRepository.getRecipients(student, 2, it).ignoreElement()
|
recipientRepository.getRecipients(student, 2, it, true).ignoreElement()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView {
|
|||||||
.withAboutSpecial3(getString(R.string.about_feedback))
|
.withAboutSpecial3(getString(R.string.about_feedback))
|
||||||
.withFields(R.string::class.java.fields)
|
.withFields(R.string::class.java.fields)
|
||||||
.withCheckCachedDetection(false)
|
.withCheckCachedDetection(false)
|
||||||
.withExcludedLibraries("fastadapter", "AndroidIconics", "gson", "Jsoup", "Retrofit", "okio", "OkHttp")
|
.withExcludedLibraries("fastadapter", "AndroidIconics", "Jsoup", "Retrofit", "okio",
|
||||||
|
"OkHttp", "Butterknife", "CircleImageView")
|
||||||
.withOnExtraListener { presenter.onExtraSelect(it) })
|
.withOnExtraListener { presenter.onExtraSelect(it) })
|
||||||
}.let {
|
}.let {
|
||||||
fragmentCompat.onCreateView(inflater.context, inflater, container, savedInstanceState, it)
|
fragmentCompat.onCreateView(inflater.context, inflater, container, savedInstanceState, it)
|
||||||
@ -68,7 +69,7 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView {
|
|||||||
data = Uri.parse("mailto:")
|
data = Uri.parse("mailto:")
|
||||||
putExtra(Intent.EXTRA_EMAIL, Array(1) { "wulkanowyinc@gmail.com" })
|
putExtra(Intent.EXTRA_EMAIL, Array(1) { "wulkanowyinc@gmail.com" })
|
||||||
putExtra(Intent.EXTRA_SUBJECT, "Zgłoszenie błędu")
|
putExtra(Intent.EXTRA_SUBJECT, "Zgłoszenie błędu")
|
||||||
putExtra(Intent.EXTRA_TEXT,"Tu umieść treść zgłoszenia\n\n" + "-".repeat(40) + "\n" + """
|
putExtra(Intent.EXTRA_TEXT, "Tu umieść treść zgłoszenia\n\n" + "-".repeat(40) + "\n" + """
|
||||||
Build: ${BuildConfig.VERSION_CODE}
|
Build: ${BuildConfig.VERSION_CODE}
|
||||||
SDK: ${android.os.Build.VERSION.SDK_INT}
|
SDK: ${android.os.Build.VERSION.SDK_INT}
|
||||||
Device: ${android.os.Build.MANUFACTURER} ${android.os.Build.MODEL}
|
Device: ${android.os.Build.MANUFACTURER} ${android.os.Build.MODEL}
|
||||||
|
@ -63,7 +63,7 @@ class GradeStatisticsPresenter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onSubjectSelected(name: String) {
|
fun onSubjectSelected(name: String) {
|
||||||
Timber.i("Select attendance stats subject $name")
|
Timber.i("Select grade stats subject $name")
|
||||||
view?.run {
|
view?.run {
|
||||||
showContent(false)
|
showContent(false)
|
||||||
showProgress(true)
|
showProgress(true)
|
||||||
@ -77,7 +77,7 @@ class GradeStatisticsPresenter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onTypeChange(isSemester: Boolean) {
|
fun onTypeChange(isSemester: Boolean) {
|
||||||
Timber.i("Select attendance stats semester: $isSemester")
|
Timber.i("Select grade stats semester: $isSemester")
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
view?.run {
|
view?.run {
|
||||||
showContent(false)
|
showContent(false)
|
||||||
|
@ -24,9 +24,9 @@ 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 {
|
||||||
startMenuIndex = if (initMenuIndex != -1) initMenuIndex else prefRepository.startMenuIndex
|
startMenuIndex = if (initMenuIndex != -1) initMenuIndex else prefRepository.startMenuIndex
|
||||||
|
Timber.i("Main view is attached with $startMenuIndex menu index")
|
||||||
initView()
|
initView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user