diff --git a/.travis.yml b/.travis.yml index 56c648589..b32619317 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,10 +11,10 @@ cache: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ -#branches: -# only: -# - master -# - 0.7.x +branches: + only: + - master + - 0.7.x android: licenses: diff --git a/app/build.gradle b/app/build.gradle index 4b471bdcc..0e4dbd07d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { testApplicationId "io.github.tests.wulkanowy" minSdkVersion 15 targetSdkVersion 28 - versionCode 27 - versionName "0.7.1" + versionCode 28 + versionName "0.7.2" multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -77,7 +77,7 @@ play { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation('io.github.wulkanowy:api:0.7.1') { exclude module: "threetenbp" } + implementation('com.github.wulkanowy:api:master-SNAPSHOT') { exclude module: "threetenbp" } implementation "androidx.legacy:legacy-support-v4:1.0.0" implementation "androidx.appcompat:appcompat:1.0.2" @@ -86,10 +86,14 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.multidex:multidex:2.0.1' - implementation 'com.takisoft.preferencex:preferencex:1.0.0' + implementation "androidx.work:work-runtime:2.0.0" + implementation "androidx.work:work-rxjava2:2.0.0" - implementation "android.arch.work:work-rxjava2:1.0.0" - implementation "android.arch.work:work-runtime:1.0.0" + implementation "androidx.room:room-runtime:2.1.0-alpha06" + implementation "androidx.room:room-rxjava2:2.1.0-alpha06" + kapt "androidx.room:room-compiler:2.1.0-alpha06" + + implementation 'com.takisoft.preferencex:preferencex:1.0.0' implementation 'com.squareup.inject:assisted-inject-annotations-dagger2:0.3.3' kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.3.3' @@ -98,17 +102,13 @@ dependencies { kapt "com.google.dagger:dagger-compiler:2.21" kapt "com.google.dagger:dagger-android-processor:2.21" - implementation "androidx.room:room-runtime:2.1.0-alpha05" - implementation "androidx.room:room-rxjava2:2.1.0-alpha05" - kapt "androidx.room:room-compiler:2.1.0-alpha05" - implementation "eu.davidea:flexible-adapter:5.1.0" implementation "eu.davidea:flexible-adapter-ui:1.0.0" implementation "com.aurelhubert:ahbottomnavigation:2.3.4" - implementation 'com.ncapdevi:frag-nav:3.1.0' + implementation 'com.ncapdevi:frag-nav:3.2.0' implementation 'com.github.wulkanowy:MaterialChipsInput:b72fd0ee6f' - implementation 'com.github.PhilJay:MPAndroidChart:971640b29d' + implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.2' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' @@ -128,15 +128,15 @@ dependencies { debugImplementation "com.amitshekhar.android:debug-db:1.0.6" testImplementation "junit:junit:4.12" - testImplementation "io.mockk:mockk:1.9.1" - testImplementation "org.mockito:mockito-inline:2.25.0" + testImplementation "io.mockk:mockk:1.9.2" + testImplementation "org.mockito:mockito-inline:2.25.1" testImplementation 'org.threeten:threetenbp:1.3.8' - androidTestImplementation "io.mockk:mockk-android:1.9.1" androidTestImplementation 'androidx.test:core:1.1.0' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.0' - androidTestImplementation 'org.mockito:mockito-android:2.25.0' + androidTestImplementation "io.mockk:mockk-android:1.9.2" + androidTestImplementation 'org.mockito:mockito-android:2.25.1' androidTestImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 352b6d2b6..0c6edab46 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -52,6 +52,7 @@ diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/SemesterDao.kt b/app/src/main/java/io/github/wulkanowy/data/db/dao/SemesterDao.kt index 44de31d85..608a66630 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/dao/SemesterDao.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/SemesterDao.kt @@ -1,8 +1,8 @@ package io.github.wulkanowy.data.db.dao import androidx.room.Dao +import androidx.room.Delete import androidx.room.Insert -import androidx.room.OnConflictStrategy.IGNORE import androidx.room.Query import io.github.wulkanowy.data.db.entities.Semester import io.reactivex.Maybe @@ -12,15 +12,12 @@ import javax.inject.Singleton @Dao interface SemesterDao { - @Insert(onConflict = IGNORE) + @Insert fun insertAll(semester: List) + @Delete + fun deleteAll(semester: List) + @Query("SELECT * FROM Semesters WHERE student_id = :studentId") fun loadAll(studentId: Int): Maybe> - - @Query("UPDATE Semesters SET is_current = 1 WHERE semester_id = :semesterId AND diary_id = :diaryId") - fun updateCurrent(semesterId: Int, diaryId: Int) - - @Query("UPDATE Semesters SET is_current = 0 WHERE student_id = :studentId") - fun resetCurrent(studentId: Int) } diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterLocal.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterLocal.kt index 5be82d7f9..37d4a2687 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterLocal.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterLocal.kt @@ -11,17 +11,14 @@ import javax.inject.Singleton class SemesterLocal @Inject constructor(private val semesterDb: SemesterDao) { fun saveSemesters(semesters: List) { - return semesterDb.insertAll(semesters) + semesterDb.insertAll(semesters) + } + + fun deleteSemesters(semesters: List) { + semesterDb.deleteAll(semesters) } fun getSemesters(student: Student): Maybe> { return semesterDb.loadAll(student.studentId).filter { !it.isEmpty() } } - - fun setCurrentSemester(semester: Semester) { - semesterDb.run { - resetCurrent(semester.studentId) - updateCurrent(semester.semesterId, semester.diaryId) - } - } } diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterRepository.kt index 975868a22..9735f0290 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/semester/SemesterRepository.kt @@ -7,6 +7,7 @@ import io.github.wulkanowy.data.db.entities.Semester import io.github.wulkanowy.data.db.entities.Student import io.reactivex.Maybe import io.reactivex.Single +import timber.log.Timber import java.net.UnknownHostException import javax.inject.Inject import javax.inject.Singleton @@ -25,10 +26,17 @@ class SemesterRepository @Inject constructor( .switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings) .flatMap { if (it) remote.getSemesters(student) else Single.error(UnknownHostException()) - }.map { newSemesters -> - local.apply { - saveSemesters(newSemesters) - setCurrentSemester(newSemesters.single { it.isCurrent }) + }.flatMap { new -> + val currentSemesters = new.filter { it.isCurrent } + if (currentSemesters.size == 1) { + local.getSemesters(student).toSingle(emptyList()) + .doOnSuccess { old -> + local.deleteSemesters(old - new) + local.saveSemesters(new - old) + } + } else { + Timber.i("Current semesters list:\n${currentSemesters.joinToString(separator = "\n")}") + throw IllegalArgumentException("Current semester can be only one.") } }.flatMap { local.getSemesters(student).toSingle(emptyList()) }) } diff --git a/app/src/main/java/io/github/wulkanowy/di/BuilderModule.kt b/app/src/main/java/io/github/wulkanowy/di/BuilderModule.kt index 2616acc38..7f4776304 100644 --- a/app/src/main/java/io/github/wulkanowy/di/BuilderModule.kt +++ b/app/src/main/java/io/github/wulkanowy/di/BuilderModule.kt @@ -3,7 +3,6 @@ package io.github.wulkanowy.di import dagger.Module import dagger.android.ContributesAndroidInjector 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.LoginModule import io.github.wulkanowy.ui.modules.main.MainActivity @@ -30,9 +29,6 @@ internal abstract class BuilderModule { @ContributesAndroidInjector abstract fun bindMessageSendActivity(): SendMessageActivity - @ContributesAndroidInjector - abstract fun bindTimetableWidgetService(): TimetableWidgetService - @ContributesAndroidInjector abstract fun bindTimetableWidgetProvider(): TimetableWidgetProvider } diff --git a/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt b/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt index 70cbf84c8..84409a845 100644 --- a/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt +++ b/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt @@ -9,6 +9,7 @@ import com.squareup.inject.assisted.dagger2.AssistedModule import dagger.Binds import dagger.Module import dagger.Provides +import dagger.android.ContributesAndroidInjector import dagger.multibindings.IntoSet import io.github.wulkanowy.services.sync.works.AttendanceSummaryWork 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.TimetableWork import io.github.wulkanowy.services.sync.works.Work +import io.github.wulkanowy.services.widgets.TimetableWidgetService import javax.inject.Singleton @AssistedModule @@ -48,6 +50,9 @@ abstract class ServicesModule { fun provideNotificationManager(context: Context) = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager } + @ContributesAndroidInjector + abstract fun bindTimetableWidgetService(): TimetableWidgetService + @Binds @IntoSet abstract fun provideGradeWork(work: GradeWork): Work diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt b/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt index ec753b7e2..365939664 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt @@ -11,6 +11,7 @@ import androidx.work.WorkerParameters import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import io.github.wulkanowy.R +import io.github.wulkanowy.api.interceptor.FeatureDisabledException import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository import io.github.wulkanowy.data.repositories.semester.SemesterRepository import io.github.wulkanowy.data.repositories.student.StudentRepository @@ -18,6 +19,7 @@ import io.github.wulkanowy.services.sync.channels.DebugChannel import io.github.wulkanowy.services.sync.works.Work import io.github.wulkanowy.utils.getCompatColor import io.reactivex.Completable +import io.reactivex.Flowable import io.reactivex.Single import timber.log.Timber import kotlin.random.Random @@ -33,19 +35,31 @@ class SyncWorker @AssistedInject constructor( ) : RxWorker(appContext, workerParameters) { override fun createWork(): Single { - return studentRepository.getCurrentStudent() + Timber.i("SyncWorker is starting") + return studentRepository.isStudentSaved() + .filter { true } + .flatMap { studentRepository.getCurrentStudent().toMaybe() } .flatMapCompletable { student -> semesterRepository.getCurrentSemester(student, true) .flatMapCompletable { semester -> - Completable.mergeDelayError(works.map { it.create(student, semester) }) + 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) } } .toSingleDefault(Result.success()) .onErrorReturn { Timber.e(it, "There was an error during synchronization") - Result.retry() + if (it is FeatureDisabledException) Result.success() + else Result.retry() + } + .doOnSuccess { + if (preferencesRepository.isDebugNotificationEnable) notify(it) + Timber.i("SyncWorker result: $it") } - .doOnSuccess { if (preferencesRepository.isDebugNotificationEnable) notify(it) } } private fun notify(result: Result) { diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/works/RecipientWork.kt b/app/src/main/java/io/github/wulkanowy/services/sync/works/RecipientWork.kt index af8de4348..fa610dee4 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/works/RecipientWork.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/works/RecipientWork.kt @@ -13,10 +13,10 @@ class RecipientWork @Inject constructor( ) : Work { override fun create(student: Student, semester: Semester): Completable { - return reportingUnitRepository.getReportingUnits(student) + return reportingUnitRepository.getReportingUnits(student, true) .flatMapCompletable { units -> Completable.mergeDelayError(units.map { - recipientRepository.getRecipients(student, 2, it).ignoreElement() + recipientRepository.getRecipients(student, 2, it, true).ignoreElement() }) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt index 1002f914f..52caf731e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt @@ -43,7 +43,8 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView { .withAboutSpecial3(getString(R.string.about_feedback)) .withFields(R.string::class.java.fields) .withCheckCachedDetection(false) - .withExcludedLibraries("fastadapter", "AndroidIconics", "gson", "Jsoup", "Retrofit", "okio", "OkHttp") + .withExcludedLibraries("fastadapter", "AndroidIconics", "Jsoup", "Retrofit", "okio", + "OkHttp", "Butterknife", "CircleImageView") .withOnExtraListener { presenter.onExtraSelect(it) }) }.let { fragmentCompat.onCreateView(inflater.context, inflater, container, savedInstanceState, it) @@ -68,7 +69,7 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView { data = Uri.parse("mailto:") putExtra(Intent.EXTRA_EMAIL, Array(1) { "wulkanowyinc@gmail.com" }) 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} SDK: ${android.os.Build.VERSION.SDK_INT} Device: ${android.os.Build.MANUFACTURER} ${android.os.Build.MODEL} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt index a564306d5..cb7aabda7 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt @@ -14,12 +14,12 @@ class AccountItem(val student: Student) : AbstractFlexibleItem>?): ViewHolder { + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { return ViewHolder(view, adapter) } - override fun bindViewHolder(adapter: FlexibleAdapter>?, holder: ViewHolder?, position: Int, payloads: MutableList?) { - holder?.apply { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { + holder.apply { accountItemName.text = student.studentName accountItemSchool.text = student.schoolName accountItemImage.setBackgroundResource(if (student.isCurrent) R.drawable.ic_account_circular_border else 0) @@ -38,14 +38,13 @@ class AccountItem(val student: Student) : AbstractFlexibleItem>?) : FlexibleViewHolder(view, adapter), - LayoutContainer { - - override val containerView: View? + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { + override val containerView: View get() = contentView } } - diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceItem.kt index c2698ebba..16a140cbf 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceItem.kt @@ -14,14 +14,13 @@ import kotlinx.android.synthetic.main.item_attendance.* class AttendanceItem(val attendance: Attendance) : AbstractFlexibleItem() { + override fun getLayoutRes() = R.layout.item_attendance + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { return ViewHolder(view, adapter) } - override fun getLayoutRes(): Int = R.layout.item_attendance - - override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, - position: Int, payloads: MutableList?) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { holder.apply { attendanceItemNumber.text = attendance.number.toString() attendanceItemSubject.text = attendance.subject @@ -37,16 +36,17 @@ class AttendanceItem(val attendance: Attendance) : AbstractFlexibleItem) : FlexibleViewHolder(view, adapter), - LayoutContainer { - + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { override val containerView: View get() = contentView } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt index 988681b1e..ec471c16a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt @@ -135,7 +135,7 @@ class AttendancePresenter @Inject constructor( clearData() showNextButton(!currentDate.plusDays(1).isHolidays) showPreButton(!currentDate.minusDays(1).isHolidays) - updateNavigationDay(currentDate.toFormattedString("EEEE \n dd.MM.YYYY").capitalize()) + updateNavigationDay(currentDate.toFormattedString("EEEE\ndd.MM.YYYY").capitalize()) } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/summary/AttendanceSummaryItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/summary/AttendanceSummaryItem.kt index 3102ce116..265d6ce44 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/summary/AttendanceSummaryItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/summary/AttendanceSummaryItem.kt @@ -23,12 +23,12 @@ class AttendanceSummaryItem( override fun getLayoutRes() = R.layout.item_attendance_summary - override fun createViewHolder(view: View?, adapter: FlexibleAdapter>?): ViewHolder { + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { return ViewHolder(view, adapter) } - override fun bindViewHolder(adapter: FlexibleAdapter>?, holder: ViewHolder?, position: Int, payloads: MutableList?) { - holder?.apply { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { + holder.apply { attendanceSummaryMonth.text = month attendanceSummaryPercentage.text = percentage attendanceSummaryPresent.text = present @@ -73,10 +73,8 @@ class AttendanceSummaryItem( return result } - class ViewHolder(view: View?, adapter: FlexibleAdapter>?) : FlexibleViewHolder(view, adapter), - LayoutContainer { - - override val containerView: View? + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { + override val containerView: View get() = contentView } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamItem.kt index 318685e93..8971b4df3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamItem.kt @@ -18,8 +18,7 @@ class ExamItem(header: ExamHeader, val exam: Exam) : AbstractSectionableItem>, holder: ViewHolder, - position: Int, payloads: MutableList?) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { holder.run { examItemSubject.text = exam.subject examItemTeacher.text = exam.teacher @@ -39,12 +38,12 @@ class ExamItem(header: ExamHeader, val exam: Exam) : AbstractSectionableItem) : FlexibleViewHolder(view, adapter), - LayoutContainer { - + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { override val containerView: View get() = contentView } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradePresenter.kt index 98eb2a9f4..2357e0637 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradePresenter.kt @@ -7,9 +7,7 @@ import io.github.wulkanowy.ui.base.session.BaseSessionPresenter import io.github.wulkanowy.ui.base.session.SessionErrorHandler import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.SchedulersProvider -import io.reactivex.Completable import timber.log.Timber -import java.util.concurrent.TimeUnit.MILLISECONDS import javax.inject.Inject class GradePresenter @Inject constructor( @@ -30,15 +28,12 @@ class GradePresenter @Inject constructor( fun onAttachView(view: GradeView, savedIndex: Int?) { super.onAttachView(view) Timber.i("Grade view is attached") - disposable.add(Completable.timer(150, MILLISECONDS, schedulers.mainThread) - .subscribe { - selectedIndex = savedIndex ?: 0 - view.run { - initView() - enableSwipe(false) - } - loadData() - }) + selectedIndex = savedIndex ?: 0 + view.run { + initView() + enableSwipe(false) + } + loadData() } fun onCreateMenu() { @@ -82,7 +77,7 @@ class GradePresenter @Inject constructor( } fun onPageSelected(index: Int) { - loadChild(index) + if (semesters.isNotEmpty()) loadChild(index) } fun onSwipeRefresh() { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsItem.kt index de1d88f7d..1e47eca5d 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsItem.kt @@ -28,10 +28,7 @@ class GradeDetailsItem( } @SuppressLint("SetTextI18n") - override fun bindViewHolder( - adapter: FlexibleAdapter>, holder: ViewHolder, - position: Int, payloads: MutableList? - ) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { holder.run { gradeItemValue.run { text = grade.entry @@ -70,9 +67,7 @@ class GradeDetailsItem( return result } - class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), - LayoutContainer { - + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { override val containerView: View get() = contentView } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt index 5111420d2..5dd485cd5 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt @@ -63,7 +63,7 @@ class GradeStatisticsPresenter @Inject constructor( } fun onSubjectSelected(name: String) { - Timber.i("Select attendance stats subject $name") + Timber.i("Select grade stats subject $name") view?.run { showContent(false) showProgress(true) @@ -77,7 +77,7 @@ class GradeStatisticsPresenter @Inject constructor( } fun onTypeChange(isSemester: Boolean) { - Timber.i("Select attendance stats semester: $isSemester") + Timber.i("Select grade stats semester: $isSemester") disposable.clear() view?.run { showContent(false) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt index 0daf06657..5737a832f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryItem.kt @@ -18,15 +18,12 @@ class GradeSummaryItem( override fun getLayoutRes() = R.layout.item_grade_summary - override fun createViewHolder(view: View?, adapter: FlexibleAdapter>?): ViewHolder { + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { return ViewHolder(view, adapter) } - override fun bindViewHolder( - adapter: FlexibleAdapter>?, holder: ViewHolder?, - position: Int, payloads: MutableList? - ) { - holder?.run { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { + holder.run { gradeSummaryItemTitle.text = title gradeSummaryItemAverage.text = average gradeSummaryItemPredicted.text = predictedGrade @@ -56,10 +53,8 @@ class GradeSummaryItem( return result } - class ViewHolder(view: View?, adapter: FlexibleAdapter>?) : FlexibleViewHolder(view, adapter), - LayoutContainer { - - override val containerView: View? + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { + override val containerView: View get() = contentView } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkItem.kt index a2b8cc0a7..2de9233f2 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkItem.kt @@ -10,9 +10,8 @@ import io.github.wulkanowy.data.db.entities.Homework import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.item_homework.* -class HomeworkItem( - header: HomeworkHeader, val homework: Homework -) : AbstractSectionableItem(header) { +class HomeworkItem(header: HomeworkHeader, val homework: Homework) : + AbstractSectionableItem(header) { override fun getLayoutRes() = R.layout.item_homework @@ -20,10 +19,7 @@ class HomeworkItem( return ViewHolder(view, adapter) } - override fun bindViewHolder( - adapter: FlexibleAdapter>, holder: ViewHolder, - position: Int, payloads: MutableList? - ) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { holder.apply { homeworkItemSubject.text = homework.subject homeworkItemTeacher.text = homework.teacher @@ -42,12 +38,12 @@ class HomeworkItem( } override fun hashCode(): Int { - return homework.hashCode() + var result = homework.hashCode() + result = 31 * result + homework.id.toInt() + return result } - class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), - LayoutContainer { - + class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { override val containerView: View get() = contentView } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectItem.kt index c206a499d..71a7d681e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectItem.kt @@ -8,19 +8,21 @@ import eu.davidea.viewholders.FlexibleViewHolder import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Student import kotlinx.android.extensions.LayoutContainer -import kotlinx.android.synthetic.main.item_login_student_select.view.* +import kotlinx.android.synthetic.main.item_login_student_select.* class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem() { override fun getLayoutRes(): Int = R.layout.item_login_student_select - override fun createViewHolder(view: View?, adapter: FlexibleAdapter>?): ItemViewHolder { + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ItemViewHolder { return ItemViewHolder(view, adapter) } - override fun bindViewHolder(adapter: FlexibleAdapter>?, holder: ItemViewHolder?, - position: Int, payloads: MutableList?) { - holder?.bind(student) + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ItemViewHolder, position: Int, payloads: MutableList?) { + holder.run { + loginItemName.text = student.studentName + loginItemSchool.text = student.schoolName + } } override fun equals(other: Any?): Boolean { @@ -38,17 +40,8 @@ class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem?) - : FlexibleViewHolder(view, adapter), LayoutContainer { - - override val containerView: View? + class ItemViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { + override val containerView: View get() = itemView - - fun bind(item: Student) { - itemView.run { - loginItemName.text = item.studentName - loginItemSchool.text = item.schoolName - } - } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumber/LuckyNumberPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumber/LuckyNumberPresenter.kt index 92ee4e250..74ab0d1fe 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumber/LuckyNumberPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumber/LuckyNumberPresenter.kt @@ -22,7 +22,11 @@ class LuckyNumberPresenter @Inject constructor( override fun onAttachView(view: LuckyNumberView) { super.onAttachView(view) Timber.i("Lucky number view is attached") - view.initView() + view.run { + initView() + showContent(false) + enableSwipe(false) + } loadData() } @@ -35,12 +39,6 @@ class LuckyNumberPresenter @Inject constructor( .flatMapMaybe { luckyNumberRepository.getLuckyNumber(it, forceRefresh) } .subscribeOn(schedulers.backgroundThread) .observeOn(schedulers.mainThread) - .doOnSubscribe { - view?.run { - showContent(false) - enableSwipe(false) - } - } .doFinally { view?.run { hideRefresh() diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt index 5e0ed2b2f..4448e556b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt @@ -2,7 +2,10 @@ package io.github.wulkanowy.ui.modules.main import android.content.Context import android.content.Intent +import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK +import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.os.Bundle +import android.os.Handler import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AlertDialog @@ -68,11 +71,6 @@ class MainActivity : BaseActivity(), MainView { return true } - override fun onStart() { - super.onStart() - presenter.onViewChange() - } - override fun initView() { mainBottomNav.run { addItems( @@ -144,7 +142,9 @@ class MainActivity : BaseActivity(), MainView { } override fun notifyMenuViewReselected() { - (navController.currentStack?.get(0) as? MainView.MainChildView)?.onFragmentReselected() + Handler().postDelayed({ + (navController.currentStack?.get(0) as? MainView.MainChildView)?.onFragmentReselected() + }, 250) } fun showDialogFragment(dialog: DialogFragment) { @@ -165,7 +165,7 @@ class MainActivity : BaseActivity(), MainView { override fun openLoginView() { startActivity(LoginActivity.getStartIntent(this) - .apply { addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) }) + .apply { addFlags(FLAG_ACTIVITY_CLEAR_TASK or FLAG_ACTIVITY_NEW_TASK) }) } override fun onSaveInstanceState(outState: Bundle?) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainModule.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainModule.kt index d1afd9c02..de4405b74 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainModule.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainModule.kt @@ -5,7 +5,6 @@ import dagger.Module import dagger.Provides import dagger.android.ContributesAndroidInjector import io.github.wulkanowy.R -import io.github.wulkanowy.di.scopes.PerActivity import io.github.wulkanowy.di.scopes.PerFragment import io.github.wulkanowy.ui.modules.about.AboutFragment import io.github.wulkanowy.ui.modules.about.AboutModule @@ -33,7 +32,6 @@ abstract class MainModule { companion object { @JvmStatic - @PerActivity @Provides fun provideFragNavController(activity: MainActivity): FragNavController { return FragNavController(activity.supportFragmentManager, R.id.mainFragmentContainer) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainPresenter.kt index a2a973c64..30f3b920f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainPresenter.kt @@ -24,9 +24,9 @@ class MainPresenter @Inject constructor( fun onAttachView(view: MainView, initMenuIndex: Int) { super.onAttachView(view) - Timber.i("Main view is attached with $initMenuIndex menu index") view.run { startMenuIndex = if (initMenuIndex != -1) initMenuIndex else prefRepository.startMenuIndex + Timber.i("Main view is attached with $startMenuIndex menu index") initView() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/MessageItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/MessageItem.kt index ec725a386..26568e22f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/MessageItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/MessageItem.kt @@ -20,12 +20,9 @@ class MessageItem(val message: Message, private val noSubjectString: String) : return ViewHolder(view, adapter) } - override fun getLayoutRes(): Int = R.layout.item_message + override fun getLayoutRes() = R.layout.item_message - override fun bindViewHolder( - adapter: FlexibleAdapter>, holder: ViewHolder, - position: Int, payloads: MutableList? - ) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { holder.apply { val style = if (message.unread) BOLD else NORMAL @@ -58,9 +55,7 @@ class MessageItem(val message: Message, private val noSubjectString: String) : return message.hashCode() } - class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), - LayoutContainer { - + class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { override val containerView: View get() = contentView } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreItem.kt index e8571a8c6..85b604e77 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreItem.kt @@ -14,12 +14,12 @@ class MoreItem(val title: String, private val drawable: Drawable?) : AbstractFle override fun getLayoutRes() = R.layout.item_more - override fun createViewHolder(view: View?, adapter: FlexibleAdapter>?): ViewHolder { + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { return ViewHolder(view, adapter) } - override fun bindViewHolder(adapter: FlexibleAdapter>?, holder: ViewHolder?, position: Int, payloads: MutableList?) { - holder?.apply { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { + holder.apply { moreItemTitle.text = title moreItemImage.setImageDrawable(drawable) } @@ -40,9 +40,8 @@ class MoreItem(val title: String, private val drawable: Drawable?) : AbstractFle return title.hashCode() } - class ViewHolder(view: View?, adapter: FlexibleAdapter<*>?) : FlexibleViewHolder(view, adapter), LayoutContainer { - - override val containerView: View? + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { + override val containerView: View get() = contentView } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteItem.kt index 71562fc49..dabeef74a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteItem.kt @@ -15,16 +15,13 @@ import kotlinx.android.synthetic.main.item_note.* class NoteItem(val note: Note) : AbstractFlexibleItem() { + override fun getLayoutRes() = R.layout.item_note + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): NoteItem.ViewHolder { return NoteItem.ViewHolder(view, adapter) } - override fun getLayoutRes(): Int = R.layout.item_note - - override fun bindViewHolder( - adapter: FlexibleAdapter>, - holder: NoteItem.ViewHolder, position: Int, payloads: MutableList? - ) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: NoteItem.ViewHolder, position: Int, payloads: MutableList?) { holder.apply { noteItemDate.apply { text = note.date.toFormattedString() @@ -57,7 +54,6 @@ class NoteItem(val note: Note) : AbstractFlexibleItem() { } class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { - override val containerView: View get() = contentView } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt index f37c0f515..c721401f3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt @@ -15,18 +15,17 @@ import io.github.wulkanowy.utils.toFormattedString import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.item_timetable.* -class TimetableItem(val lesson: Timetable, private val roomText: String) - : AbstractFlexibleItem() { +class TimetableItem(val lesson: Timetable, private val roomText: String) : + AbstractFlexibleItem() { - override fun getLayoutRes(): Int = R.layout.item_timetable + override fun getLayoutRes() = R.layout.item_timetable override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { return ViewHolder(view, adapter) } @SuppressLint("SetTextI18n") - override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, - position: Int, payloads: MutableList?) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList?) { holder.apply { timetableItemNumber.text = lesson.number.toString() timetableItemSubject.text = lesson.subject @@ -34,8 +33,8 @@ class TimetableItem(val lesson: Timetable, private val roomText: String) timetableItemTime.text = "${lesson.start.toFormattedString("HH:mm")} - ${lesson.end.toFormattedString("HH:mm")}" timetableItemAlert.visibility = if (lesson.changes || lesson.canceled) VISIBLE else GONE timetableItemSubject.paintFlags = - if (lesson.canceled) timetableItemSubject.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG - else timetableItemSubject.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() + if (lesson.canceled) timetableItemSubject.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG + else timetableItemSubject.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() } } @@ -50,12 +49,12 @@ class TimetableItem(val lesson: Timetable, private val roomText: String) } override fun hashCode(): Int { - return lesson.hashCode() + var result = lesson.hashCode() + result = 31 * result + lesson.id.toInt() + return result } - class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), - LayoutContainer { - + class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { override val containerView: View get() = contentView } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt index 3786a362c..ebda3931a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt @@ -128,7 +128,7 @@ class TimetablePresenter @Inject constructor( clearData() showNextButton(!currentDate.plusDays(1).isHolidays) showPreButton(!currentDate.minusDays(1).isHolidays) - updateNavigationDay(currentDate.toFormattedString("EEEE \n dd.MM.YYYY").capitalize()) + updateNavigationDay(currentDate.toFormattedString("EEEE\ndd.MM.YYYY").capitalize()) } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt index ddc81818f..6a14acda5 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/completed/CompletedLessonsPresenter.kt @@ -112,7 +112,7 @@ class CompletedLessonsPresenter @Inject constructor( clearData() showNextButton(!currentDate.plusDays(1).isHolidays) showPreButton(!currentDate.minusDays(1).isHolidays) - updateNavigationDay(currentDate.toFormattedString("EEEE \n dd.MM.YYYY").capitalize()) + updateNavigationDay(currentDate.toFormattedString("EEEE\ndd.MM.YYYY").capitalize()) } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetFactory.kt b/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetFactory.kt index 63560807c..f2d40ba7e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetFactory.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetFactory.kt @@ -17,6 +17,7 @@ import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.timetable.TimetableRepository import io.github.wulkanowy.utils.SchedulersProvider import io.github.wulkanowy.utils.toFormattedString +import io.reactivex.Single import org.threeten.bp.LocalDate import timber.log.Timber @@ -51,9 +52,13 @@ class TimetableWidgetFactory( ?.let { date -> try { lessons = studentRepository.isStudentSaved() - .flatMap { studentRepository.getCurrentStudent() } - .flatMap { semesterRepository.getCurrentSemester(it) } - .flatMap { timetableRepository.getTimetable(it, date, date) } + .flatMap { isSaved -> + if (isSaved) { + studentRepository.getCurrentStudent() + .flatMap { semesterRepository.getCurrentSemester(it) } + .flatMap { timetableRepository.getTimetable(it, date, date) } + } else Single.just(emptyList()) + } .map { item -> item.sortedBy { it.number } } .subscribeOn(schedulers.backgroundThread) .blockingGet() diff --git a/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetProvider.kt b/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetProvider.kt index 290007e44..402366ecf 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetProvider.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/widgets/timetable/TimetableWidgetProvider.kt @@ -62,7 +62,7 @@ class TimetableWidgetProvider : BroadcastReceiver() { private fun onUpdate(context: Context, intent: Intent) { if (intent.getStringExtra(EXTRA_BUTTON_TYPE) === null) { - intent.getIntArrayExtra(EXTRA_APPWIDGET_IDS).forEach { appWidgetId -> + intent.getIntArrayExtra(EXTRA_APPWIDGET_IDS)?.forEach { appWidgetId -> updateWidget(context, appWidgetId, now().nextOrSameSchoolDay) } } else { @@ -95,7 +95,7 @@ class TimetableWidgetProvider : BroadcastReceiver() { .apply { action = createWidgetKey(appWidgetId) }) setOnClickPendingIntent(R.id.timetableWidgetNext, createNavIntent(context, appWidgetId, appWidgetId, BUTTON_NEXT)) setOnClickPendingIntent(R.id.timetableWidgetPrev, createNavIntent(context, -appWidgetId, appWidgetId, BUTTON_PREV)) - createNavIntent(context, Int.MAX_VALUE, appWidgetId, BUTTON_RESET).also { + createNavIntent(context, Int.MAX_VALUE - appWidgetId, appWidgetId, BUTTON_RESET).also { setOnClickPendingIntent(R.id.timetableWidgetDate, it) setOnClickPendingIntent(R.id.timetableWidgetDay, it) } diff --git a/app/src/main/play/release-notes/pl-PL/default.txt b/app/src/main/play/release-notes/pl-PL/default.txt index 6f8a6b0a1..bdf045f52 100644 --- a/app/src/main/play/release-notes/pl-PL/default.txt +++ b/app/src/main/play/release-notes/pl-PL/default.txt @@ -1,18 +1,6 @@ -Dodaliśmy: -- szczęśliwy numerek -- lekcje zrealizowane -- wysyłanie wiadomości -- ucznia na tle klasy -- opcję zmiany kolorów ocen - -Zmieniliśmy: -- wygląd ekranu logowania -- sposób wyświetlania zastępstw -- widok zadań domowych na tygodniowy - Naprawiliśmy: -- automatyczne przełączanie widżetu na nowy dzień -- wyświetlanie powiadomień o starych ocenach -- znikające numery sal w planie lekcji +- problemy ze stabilnością podczas przełączania zakładek +- nierówność w nawigacji między dniami w planie lekcji i frekwencji +- zły wygląd odświeżania w szczęśliwym numerku -Pełna lista zmian: https://github.com/wulkanowy/wulkanowy/releases/tag/0.7.0 +Pełna lista zmian: https://github.com/wulkanowy/wulkanowy/releases/tag/0.7.2 diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/UnitTestInternetObservingStrategy.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/UnitTestInternetObservingStrategy.kt new file mode 100644 index 000000000..28abbb993 --- /dev/null +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/UnitTestInternetObservingStrategy.kt @@ -0,0 +1,19 @@ +package io.github.wulkanowy.data.repositories + +import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingStrategy +import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.error.ErrorHandler +import io.reactivex.Observable +import io.reactivex.Single + +class UnitTestInternetObservingStrategy : InternetObservingStrategy { + + override fun checkInternetConnectivity(host: String?, port: Int, timeoutInMs: Int, httpResponse: Int, errorHandler: ErrorHandler?): Single { + return Single.just(true) + } + + override fun observeInternetConnectivity(initialIntervalInMs: Int, intervalInMs: Int, host: String?, port: Int, timeoutInMs: Int, httpResponse: Int, errorHandler: ErrorHandler?): Observable { + return Observable.just(true) + } + + override fun getDefaultPingHost() = "localhost" +} diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/AttendanceRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/attendance/AttendanceRemoteTest.kt similarity index 92% rename from app/src/test/java/io/github/wulkanowy/data/repositories/remote/AttendanceRemoteTest.kt rename to app/src/test/java/io/github/wulkanowy/data/repositories/attendance/AttendanceRemoteTest.kt index 4842d305c..8adfa83bd 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/AttendanceRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/attendance/AttendanceRemoteTest.kt @@ -1,9 +1,8 @@ -package io.github.wulkanowy.data.repositories.remote +package io.github.wulkanowy.data.repositories.attendance import io.github.wulkanowy.api.Api import io.github.wulkanowy.api.attendance.Attendance import io.github.wulkanowy.data.db.entities.Semester -import io.github.wulkanowy.data.repositories.attendance.AttendanceRemote import io.mockk.MockKAnnotations import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/CompletedLessonsRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/completedlessons/CompletedLessonsRemoteTest.kt similarity index 91% rename from app/src/test/java/io/github/wulkanowy/data/repositories/remote/CompletedLessonsRemoteTest.kt rename to app/src/test/java/io/github/wulkanowy/data/repositories/completedlessons/CompletedLessonsRemoteTest.kt index f4c161bc4..bb9f52945 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/CompletedLessonsRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/completedlessons/CompletedLessonsRemoteTest.kt @@ -1,9 +1,8 @@ -package io.github.wulkanowy.data.repositories.remote +package io.github.wulkanowy.data.repositories.completedlessons import io.github.wulkanowy.api.Api import io.github.wulkanowy.api.timetable.CompletedLesson import io.github.wulkanowy.data.db.entities.Semester -import io.github.wulkanowy.data.repositories.completedlessons.CompletedLessonsRemote import io.mockk.MockKAnnotations import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/ExamRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/exam/ExamRemoteTest.kt similarity index 93% rename from app/src/test/java/io/github/wulkanowy/data/repositories/remote/ExamRemoteTest.kt rename to app/src/test/java/io/github/wulkanowy/data/repositories/exam/ExamRemoteTest.kt index 0cc785482..0c83bed0a 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/ExamRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/exam/ExamRemoteTest.kt @@ -1,9 +1,8 @@ -package io.github.wulkanowy.data.repositories.remote +package io.github.wulkanowy.data.repositories.exam import io.github.wulkanowy.api.Api import io.github.wulkanowy.api.exams.Exam import io.github.wulkanowy.data.db.entities.Semester -import io.github.wulkanowy.data.repositories.exam.ExamRemote import io.mockk.MockKAnnotations import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/GradeStatisticsRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/gradestatistics/GradeStatisticsRemoteTest.kt similarity index 91% rename from app/src/test/java/io/github/wulkanowy/data/repositories/remote/GradeStatisticsRemoteTest.kt rename to app/src/test/java/io/github/wulkanowy/data/repositories/gradestatistics/GradeStatisticsRemoteTest.kt index 14381791d..37d3f2ad6 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/GradeStatisticsRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/gradestatistics/GradeStatisticsRemoteTest.kt @@ -1,9 +1,8 @@ -package io.github.wulkanowy.data.repositories.remote +package io.github.wulkanowy.data.repositories.gradestatistics import io.github.wulkanowy.api.Api import io.github.wulkanowy.api.grades.GradeStatistics import io.github.wulkanowy.data.db.entities.Semester -import io.github.wulkanowy.data.repositories.gradestatistics.GradeStatisticsRemote import io.mockk.MockKAnnotations import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/LuckyNumberRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/luckynumber/LuckyNumberRemoteTest.kt similarity index 95% rename from app/src/test/java/io/github/wulkanowy/data/repositories/remote/LuckyNumberRemoteTest.kt rename to app/src/test/java/io/github/wulkanowy/data/repositories/luckynumber/LuckyNumberRemoteTest.kt index 054f8890d..67e6c2ef6 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/LuckyNumberRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/luckynumber/LuckyNumberRemoteTest.kt @@ -1,4 +1,4 @@ -package io.github.wulkanowy.data.repositories.remote +package io.github.wulkanowy.data.repositories.luckynumber import io.github.wulkanowy.api.Api import io.github.wulkanowy.data.db.entities.Semester diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/semester/SemesterRepositoryTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/semester/SemesterRepositoryTest.kt new file mode 100644 index 000000000..7856b9370 --- /dev/null +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/semester/SemesterRepositoryTest.kt @@ -0,0 +1,74 @@ +package io.github.wulkanowy.data.repositories.semester + +import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings +import io.github.wulkanowy.data.ApiHelper +import io.github.wulkanowy.data.db.entities.Semester +import io.github.wulkanowy.data.db.entities.Student +import io.github.wulkanowy.data.repositories.UnitTestInternetObservingStrategy +import io.reactivex.Maybe +import io.reactivex.Single +import org.junit.Before +import org.junit.Test +import org.mockito.Mock +import org.mockito.Mockito.doNothing +import org.mockito.Mockito.doReturn +import org.mockito.Mockito.verify +import org.mockito.MockitoAnnotations + +class SemesterRepositoryTest { + + @Mock + private lateinit var semesterRemote: SemesterRemote + + @Mock + private lateinit var semesterLocal: SemesterLocal + + @Mock + private lateinit var apiHelper: ApiHelper + + @Mock + private lateinit var student: Student + + private lateinit var semesterRepository: SemesterRepository + + private val settings = InternetObservingSettings.builder() + .strategy(UnitTestInternetObservingStrategy()) + .build() + + @Before + fun initTest() { + MockitoAnnotations.initMocks(this) + semesterRepository = SemesterRepository(semesterRemote, semesterLocal, settings, apiHelper) + } + + @Test + fun singleCurrentSemesterTest() { + val semesters = listOf( + createSemesterEntity(false), + createSemesterEntity(true) + ) + + doNothing().`when`(apiHelper).initApi(student) + doReturn(Maybe.empty()).`when`(semesterLocal).getSemesters(student) + doReturn(Single.just(semesters)).`when`(semesterRemote).getSemesters(student) + + semesterRepository.getSemesters(student).blockingGet() + + verify(semesterLocal).deleteSemesters(emptyList()) + verify(semesterLocal).saveSemesters(semesters) + } + + @Test(expected = IllegalArgumentException::class) + fun twoCurrentSemesterTest() { + val semesters = listOf( + createSemesterEntity(true), + createSemesterEntity(true) + ) + + doNothing().`when`(apiHelper).initApi(student) + doReturn(Maybe.empty()).`when`(semesterLocal).getSemesters(student) + doReturn(Single.just(semesters)).`when`(semesterRemote).getSemesters(student) + + semesterRepository.getSemesters(student).blockingGet() + } +} diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/semester/TestSemesterEnityCreator.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/semester/TestSemesterEnityCreator.kt new file mode 100644 index 000000000..c3377ac51 --- /dev/null +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/semester/TestSemesterEnityCreator.kt @@ -0,0 +1,16 @@ +package io.github.wulkanowy.data.repositories.semester + +import io.github.wulkanowy.data.db.entities.Semester + +fun createSemesterEntity(current: Boolean): Semester { + return Semester( + studentId = 0, + diaryId = 0, + semesterId = 0, + diaryName = "", + classId = 0, + isCurrent = current, + semesterName = 0, + unitId = 0 + ) +} diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/StudentRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/student/StudentRemoteTest.kt similarity index 87% rename from app/src/test/java/io/github/wulkanowy/data/repositories/remote/StudentRemoteTest.kt rename to app/src/test/java/io/github/wulkanowy/data/repositories/student/StudentRemoteTest.kt index 3a26836de..1244239e8 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/StudentRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/student/StudentRemoteTest.kt @@ -1,8 +1,7 @@ -package io.github.wulkanowy.data.repositories.remote +package io.github.wulkanowy.data.repositories.student import io.github.wulkanowy.api.Api import io.github.wulkanowy.api.register.Student -import io.github.wulkanowy.data.repositories.student.StudentRemote import io.reactivex.Single import org.junit.Assert.assertEquals import org.junit.Before diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/TimetableRemoteTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemoteTest.kt similarity index 96% rename from app/src/test/java/io/github/wulkanowy/data/repositories/remote/TimetableRemoteTest.kt rename to app/src/test/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemoteTest.kt index 942b28ed9..4bb4091fb 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/remote/TimetableRemoteTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemoteTest.kt @@ -1,4 +1,4 @@ -package io.github.wulkanowy.data.repositories.remote +package io.github.wulkanowy.data.repositories.timetable import io.github.wulkanowy.api.Api import io.github.wulkanowy.api.timetable.Timetable