From 5a4b8b22f317b56c8fde0fc2701029a7b9470376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sat, 14 Jul 2018 14:06:57 +0200 Subject: [PATCH] Stop synchronization on holidays (#142) --- .circleci/config.yml | 16 +- README.md | 2 +- api/build.gradle | 26 ---- .../android-sonarqube.gradle | 0 app/build.gradle | 16 +- app/jacoco.gradle | 56 +++++++ .../wulkanowy/services/jobs/SyncJob.java | 8 + .../wulkanowy/ui/main/MainPresenter.java | 5 +- .../main/attendance/AttendancePresenter.java | 8 +- .../ui/main/exams/ExamsPresenter.java | 8 +- .../ui/main/settings/SettingsFragment.java | 10 +- .../ui/main/timetable/TimetablePresenter.java | 8 +- .../timetable/tab/TimetableTabPresenter.java | 8 +- .../ui/widgets/TimetableWidgetFactory.java | 8 +- .../ui/widgets/TimetableWidgetProvider.java | 5 +- .../io/github/wulkanowy/utils/TimeUtils.java | 81 ---------- .../io/github/wulkanowy/utils/TimeUtils.kt | 97 ++++++++++++ app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../github/wulkanowy/utils/TimeUtilsTest.java | 48 ------ .../github/wulkanowy/utils/TimeUtilsTest.kt | 140 ++++++++++++++++++ build.gradle | 31 +++- jacoco.gradle | 40 ----- 23 files changed, 381 insertions(+), 242 deletions(-) rename android-sonarqube.gradle => app/android-sonarqube.gradle (100%) create mode 100644 app/jacoco.gradle delete mode 100644 app/src/main/java/io/github/wulkanowy/utils/TimeUtils.java create mode 100644 app/src/main/java/io/github/wulkanowy/utils/TimeUtils.kt delete mode 100644 app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.java create mode 100644 app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.kt delete mode 100644 jacoco.gradle diff --git a/.circleci/config.yml b/.circleci/config.yml index fe74ebe6..b017fe23 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -87,11 +87,8 @@ jobs: name: Upload unit code coverage to codecov command: bash <(curl -s https://codecov.io/bash) -F app - store_artifacts: - path: ./app/build/reports/tests/ - destination: tests_reports/ - - store_artifacts: - path: ./app/build/reports/jacoco/jacocoTestDebugUnitTestReport/ - destination: coverage_reports/ + path: ./app/build/reports/ + destination: reports/ - store_test_results: path: ./app/build/test-results - persist_to_workspace: @@ -112,11 +109,8 @@ jobs: name: Upload code coverage to codecov command: bash <(curl -s https://codecov.io/bash) -F api - store_artifacts: - path: ./api/build/reports/tests/ - destination: tests_reports/ - - store_artifacts: - path: ./api/build/reports/jacoco/test/ - destination: coverage_reports/ + path: ./api/build/reports/ + destination: reports/ - store_test_results: path: ./api/build/test-results - persist_to_workspace: @@ -130,7 +124,7 @@ jobs: - *attach_workspace - run: name: Setup emulator - command: sdkmanager "system-images;android-19;google_apis;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-19;google_apis;armeabi-v7a" + command: sdkmanager "system-images;android-16;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-16;default;armeabi-v7a" - run: name: Launch emulator command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on diff --git a/README.md b/README.md index 6ccaa20a..ee11a9c6 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,6 @@ [Pobierz wersję beta](https://play.google.com/store/apps/details?id=io.github.wulkanowy&utm_source=vcs) -[Pobierz wersję rozwojową](https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/master/artifacts/app-debug-bitrise-signed.apk) +[Pobierz wersję DEV](https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/master/artifacts/0) Androidowy klient dziennika VULCAN UONET+. diff --git a/api/build.gradle b/api/build.gradle index 1f7cf197..5e5eeee3 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -119,29 +119,3 @@ artifacts { archives sourcesJar archives javadocJar } - -buildscript { - ext.kotlin_version = '1.2.41' - repositories { - mavenCentral() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -repositories { - mavenCentral() -} - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} diff --git a/android-sonarqube.gradle b/app/android-sonarqube.gradle similarity index 100% rename from android-sonarqube.gradle rename to app/android-sonarqube.gradle diff --git a/app/build.gradle b/app/build.gradle index dc655e90..e8a9ab48 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,11 +17,13 @@ repositories { maven { url 'https://maven.fabric.io/public' } } -apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' // sync warning probably caused by bug https://issuetracker.google.com/issues/74537216 apply plugin: 'io.fabric' -apply from: '../jacoco.gradle' -apply from: '../android-sonarqube.gradle' +apply from: 'jacoco.gradle' +apply from: 'android-sonarqube.gradle' apply plugin: 'com.google.gms.oss.licenses.plugin' apply plugin: 'com.github.triplet.play' @@ -128,12 +130,12 @@ dependencies { transitive = true } - annotationProcessor "com.google.dagger:dagger-android-processor:$dagger2" - annotationProcessor "com.google.dagger:dagger-compiler:$dagger2" - annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + kapt "com.google.dagger:dagger-compiler:$dagger2" + kapt "com.google.dagger:dagger-android-processor:$dagger2" + kapt "com.jakewharton:butterknife-compiler:$butterknife" debugImplementation "com.amitshekhar.android:debug-db:$debugDb" - debugImplementation "net.zetetic:android-database-sqlcipher:$sqlcipher" testImplementation "junit:junit:$junit" testImplementation "org.mockito:mockito-core:$mockito" diff --git a/app/jacoco.gradle b/app/jacoco.gradle new file mode 100644 index 00000000..f59b3857 --- /dev/null +++ b/app/jacoco.gradle @@ -0,0 +1,56 @@ +apply plugin: "jacoco" + +jacoco { + toolVersion "0.8.1" + reportsDir = file("$buildDir/reports") +} + +tasks.withType(Test) { + jacoco.includeNoLocationClasses = true +} + +// run ./gradlew clean createDebugCoverageReport jacocoTestReport +task jacocoTestReport(type: JacocoReport) { + + group = "Reporting" + description = "Generate Jacoco coverage reports" + + reports { + xml.enabled = true + html.enabled = true + } + + def excludes = [ + "**/R.class", + "**/R\$*.class", + "**/*\$ViewInjector*.*", + "**/BuildConfig.*", + "**/Manifest*.*", + "**/*Test*.*", + "android/**/*.*", + "**/*Fragment.*", + "**/*Activity.*" + ] + + // generated classes + classDirectories = fileTree( + // Java generated classes on Android project (debug build) + dir: "$buildDir/intermediates/classes/debug", + excludes: excludes + ) + fileTree( + // Kotlin generated classes on Android project (debug build) + dir: "$buildDir/tmp/kotlin-classes/debug", + excludes: excludes + ) + + // sources + sourceDirectories = files([ + android.sourceSets.main.java.srcDirs, + "src/main/kotlin" + ]) + + executionData = fileTree( + dir: project.projectDir, + includes: ["**/*.exec" , "**/*.ec"] + ) +} diff --git a/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java b/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java index d0fc73d6..9854666e 100644 --- a/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java +++ b/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java @@ -30,6 +30,8 @@ import io.github.wulkanowy.ui.main.MainActivity; import io.github.wulkanowy.utils.FabricUtils; import timber.log.Timber; +import static io.github.wulkanowy.utils.TimeUtilsKt.isHolidays; + public class SyncJob extends SimpleJobService { public static final String JOB_TAG = "SyncJob"; @@ -66,6 +68,12 @@ public class SyncJob extends SimpleJobService { @Override public int onRunJob(JobParameters job) { + if (isHolidays()) { + stop(getApplicationContext()); + + return JobService.RESULT_FAIL_NORETRY; + } + try { repository.getSyncRepo().initLastUser(); repository.getSyncRepo().syncAll(); diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java index c6741c3e..2ca9eefa 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java @@ -1,6 +1,5 @@ package io.github.wulkanowy.ui.main; - import android.support.annotation.NonNull; import javax.inject.Inject; @@ -8,6 +7,8 @@ import javax.inject.Inject; import io.github.wulkanowy.data.RepositoryContract; import io.github.wulkanowy.ui.base.BasePresenter; +import static io.github.wulkanowy.utils.TimeUtilsKt.isHolidays; + public class MainPresenter extends BasePresenter implements MainContract.Presenter { @@ -35,7 +36,7 @@ public class MainPresenter extends BasePresenter getView().initiationBottomNav(tabPosition); getView().initiationViewPager(tabPosition); - if (getRepository().getSharedRepo().isServicesEnable()) { + if (getRepository().getSharedRepo().isServicesEnable() && !isHolidays()) { getView().startSyncService(getRepository().getSharedRepo().getServicesInterval(), getRepository().getSharedRepo().isMobileDisable()); } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendancePresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendancePresenter.java index 9cfb1384..73a2837c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendancePresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendancePresenter.java @@ -10,10 +10,12 @@ import javax.inject.Inject; import io.github.wulkanowy.data.RepositoryContract; import io.github.wulkanowy.ui.base.BasePresenter; import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener; -import io.github.wulkanowy.utils.TimeUtils; import io.github.wulkanowy.utils.async.AbstractTask; import io.github.wulkanowy.utils.async.AsyncListeners; +import static io.github.wulkanowy.utils.TimeUtilsKt.getFirstDayOfCurrentWeek; +import static io.github.wulkanowy.utils.TimeUtilsKt.getMondaysFromCurrentSchoolYear; + public class AttendancePresenter extends BasePresenter implements AttendanceContract.Presenter, AsyncListeners.OnFirstLoadingListener { @@ -42,11 +44,11 @@ public class AttendancePresenter extends BasePresenter } if (dates.isEmpty()) { - dates = TimeUtils.getMondaysFromCurrentSchoolYear(); + dates = getMondaysFromCurrentSchoolYear(); } if (positionToScroll == 0) { - positionToScroll = dates.indexOf(TimeUtils.getDateOfCurrentMonday(true)); + positionToScroll = dates.indexOf(getFirstDayOfCurrentWeek()); } if (!isFirstSight) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/exams/ExamsPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/exams/ExamsPresenter.java index a5bd1055..20c0fe2e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/exams/ExamsPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/exams/ExamsPresenter.java @@ -10,10 +10,12 @@ import javax.inject.Inject; import io.github.wulkanowy.data.RepositoryContract; import io.github.wulkanowy.ui.base.BasePresenter; import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener; -import io.github.wulkanowy.utils.TimeUtils; import io.github.wulkanowy.utils.async.AbstractTask; import io.github.wulkanowy.utils.async.AsyncListeners; +import static io.github.wulkanowy.utils.TimeUtilsKt.getFirstDayOfCurrentWeek; +import static io.github.wulkanowy.utils.TimeUtilsKt.getMondaysFromCurrentSchoolYear; + public class ExamsPresenter extends BasePresenter implements ExamsContract.Presenter, AsyncListeners.OnFirstLoadingListener { @@ -42,11 +44,11 @@ public class ExamsPresenter extends BasePresenter } if (dates.isEmpty()) { - dates = TimeUtils.getMondaysFromCurrentSchoolYear(); + dates = getMondaysFromCurrentSchoolYear(); } if (positionToScroll == 0) { - positionToScroll = dates.indexOf(TimeUtils.getDateOfCurrentMonday(true)); + positionToScroll = dates.indexOf(getFirstDayOfCurrentWeek()); } if (!isFirstSight) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/settings/SettingsFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/settings/SettingsFragment.java index 8bd93024..0f2009be 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/settings/SettingsFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/settings/SettingsFragment.java @@ -18,6 +18,8 @@ import io.github.wulkanowy.services.jobs.SyncJob; import io.github.wulkanowy.ui.main.MainActivity; import io.github.wulkanowy.utils.AppConstant; +import static io.github.wulkanowy.utils.TimeUtilsKt.isHolidays; + public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -86,7 +88,13 @@ public class SettingsFragment extends PreferenceFragmentCompat findPreference(SHARED_KEY_ABOUT_VERSION).setOnPreferenceClickListener(onProgrammerListener); findPreference(SHARED_KEY_ABOUT_REPO).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(AppConstant.REPO_URL))); findPreference(SHARED_KEY_ABOUT_LICENSES).setIntent(new Intent(getActivity(), OssLicensesMenuActivity.class) - .putExtra("title", getString(R.string.pref_about_osl))); + .putExtra("title", R.string.pref_about_osl)); + + if (isHolidays()) { + Preference services = findPreference(SHARED_KEY_SERVICES_ENABLE); + services.setSummary(R.string.pref_services_suspended_on_holidays); + services.setEnabled(false); + } } @Override diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetablePresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetablePresenter.java index 8c9bfaba..1e9cf0b8 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetablePresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetablePresenter.java @@ -10,10 +10,12 @@ import javax.inject.Inject; import io.github.wulkanowy.data.RepositoryContract; import io.github.wulkanowy.ui.base.BasePresenter; import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener; -import io.github.wulkanowy.utils.TimeUtils; import io.github.wulkanowy.utils.async.AbstractTask; import io.github.wulkanowy.utils.async.AsyncListeners; +import static io.github.wulkanowy.utils.TimeUtilsKt.getFirstDayOfCurrentWeek; +import static io.github.wulkanowy.utils.TimeUtilsKt.getMondaysFromCurrentSchoolYear; + public class TimetablePresenter extends BasePresenter implements TimetableContract.Presenter, AsyncListeners.OnFirstLoadingListener { @@ -42,11 +44,11 @@ public class TimetablePresenter extends BasePresenter } if (dates.isEmpty()) { - dates = TimeUtils.getMondaysFromCurrentSchoolYear(); + dates = getMondaysFromCurrentSchoolYear(); } if (positionToScroll == 0) { - positionToScroll = dates.indexOf(TimeUtils.getDateOfCurrentMonday(true)); + positionToScroll = dates.indexOf(getFirstDayOfCurrentWeek()); } if (!isFirstSight) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/tab/TimetableTabPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/tab/TimetableTabPresenter.java index 42f2424d..f30dd804 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/tab/TimetableTabPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/tab/TimetableTabPresenter.java @@ -16,10 +16,12 @@ import io.github.wulkanowy.data.db.dao.entities.Week; import io.github.wulkanowy.ui.base.BasePresenter; import io.github.wulkanowy.utils.AppConstant; import io.github.wulkanowy.utils.FabricUtils; -import io.github.wulkanowy.utils.TimeUtils; import io.github.wulkanowy.utils.async.AbstractTask; import io.github.wulkanowy.utils.async.AsyncListeners; +import static io.github.wulkanowy.utils.TimeUtilsKt.getParsedDate; +import static io.github.wulkanowy.utils.TimeUtilsKt.isDateInWeek; + public class TimetableTabPresenter extends BasePresenter implements TimetableTabContract.Presenter, AsyncListeners.OnRefreshListener, AsyncListeners.OnFirstLoadingListener { @@ -162,9 +164,9 @@ public class TimetableTabPresenter extends BasePresenter getMondaysFromCurrentSchoolYear() { - LocalDate startDate = LocalDate.of(getCurrentSchoolYear(), 9, 1); - LocalDate endDate = LocalDate.of(getCurrentSchoolYear() + 1, 8, 31); - - List dateList = new ArrayList<>(); - - LocalDate thisMonday = startDate.with(DayOfWeek.MONDAY); - - if (startDate.isAfter(thisMonday)) { - startDate = thisMonday.plusWeeks(1); - } else { - startDate = thisMonday; - } - - while (startDate.isBefore(endDate)) { - dateList.add(startDate.format(formatter)); - startDate = startDate.plusWeeks(1); - } - return dateList; - } - - public static int getCurrentSchoolYear() { - LocalDate localDate = LocalDate.now(); - return localDate.getMonthValue() <= 8 ? localDate.getYear() - 1 : localDate.getYear(); - } - - public static String getDateOfCurrentMonday(boolean normalize) { - LocalDate currentDate = LocalDate.now(); - - if (currentDate.getDayOfWeek() == DayOfWeek.SATURDAY && normalize) { - currentDate = currentDate.plusDays(2); - } else if (currentDate.getDayOfWeek() == DayOfWeek.SUNDAY && normalize) { - currentDate = currentDate.plusDays(1); - } else { - currentDate = currentDate.with(DayOfWeek.MONDAY); - } - return currentDate.format(formatter); - } - - public static int getTodayOrNextDayValue(boolean nextDay) { - DayOfWeek day = LocalDate.now().getDayOfWeek(); - if (nextDay) { - if (day == DayOfWeek.SUNDAY) { - return 0; - } - return day.getValue(); - } - return day.getValue() - 1; - } - - public static String getTodayOrNextDay(boolean nextDay) { - LocalDate current = LocalDate.now(); - return nextDay ? current.plusDays(1).format(formatter) : current.format(formatter); - } - - public static boolean isDateInWeek(LocalDate firstWeekDay, LocalDate date) { - return date.isAfter(firstWeekDay.minusDays(1)) && date.isBefore(firstWeekDay.plusDays(5)); - - } -} diff --git a/app/src/main/java/io/github/wulkanowy/utils/TimeUtils.kt b/app/src/main/java/io/github/wulkanowy/utils/TimeUtils.kt new file mode 100644 index 00000000..c61c7e0d --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/utils/TimeUtils.kt @@ -0,0 +1,97 @@ +package io.github.wulkanowy.utils + +import org.threeten.bp.DayOfWeek.* +import org.threeten.bp.LocalDate +import org.threeten.bp.Year +import org.threeten.bp.format.DateTimeFormatter +import org.threeten.bp.temporal.TemporalAdjusters +import java.util.* + +private val formatter = DateTimeFormatter.ofPattern(AppConstant.DATE_PATTERN) + +fun getParsedDate(dateString: String, dateFormat: String): LocalDate { + return LocalDate.parse(dateString, DateTimeFormatter.ofPattern(dateFormat)) +} + +fun getMondaysFromCurrentSchoolYear() = getMondaysFromCurrentSchoolYear(LocalDate.now()) + +fun getMondaysFromCurrentSchoolYear(date: LocalDate): List { + val startDate = getFirstSchoolDay(getSchoolYearForDate(date)) + ?.with(TemporalAdjusters.previousOrSame(MONDAY)) + val endDate = getFirstSchoolDay(getSchoolYearForDate(date) + 1) + ?.with(TemporalAdjusters.previousOrSame(MONDAY)) + + val dateList = ArrayList() + var monday = startDate as LocalDate + while (monday.isBefore(endDate)) { + dateList.add(monday.format(formatter)) + monday = monday.plusWeeks(1) + } + + return dateList +} + +fun getSchoolYearForDate(date: LocalDate): Int { + return if (date.monthValue <= 8) date.year - 1 else date.year +} + +fun getFirstDayOfCurrentWeek(): String = getFirstDayOfCurrentWeek(LocalDate.now()) + +fun getFirstDayOfCurrentWeek(date: LocalDate): String { + return when (date.dayOfWeek) { + SATURDAY -> date.plusDays(2) + SUNDAY -> date.plusDays(1) + else -> date.with(MONDAY) + }.format(formatter) +} + +fun getTodayOrNextDayOrder(next: Boolean): Int = getTodayOrNextDayOrder(next, LocalDate.now()) + +fun getTodayOrNextDayOrder(next: Boolean, date: LocalDate): Int { + val day = date.dayOfWeek + return if (next) { + if (day == SUNDAY) { + 0 + } else day.value + } else day.value - 1 +} + +fun getTodayOrNextDay(next: Boolean): String? = getTodayOrNextDay(next, LocalDate.now()) + +fun getTodayOrNextDay(next: Boolean, date: LocalDate): String? { + return (if (next) { + date.plusDays(1) + } else date).format(formatter) +} + +fun isDateInWeek(firstWeekDay: LocalDate, date: LocalDate): Boolean { + return date.isAfter(firstWeekDay.minusDays(1)) && date.isBefore(firstWeekDay.plusDays(5)) +} + +/** + * [Dz.U. 2016 poz. 1335](http://prawo.sejm.gov.pl/isap.nsf/DocDetails.xsp?id=WDU20160001335) + */ +fun isHolidays(): Boolean = isHolidays(LocalDate.now(), Year.now().value) + +fun isHolidays(day: LocalDate, year: Int): Boolean { + return day.isAfter(getLastSchoolDay(year)) && day.isBefore(getFirstSchoolDay(year)) +} + +fun getFirstSchoolDay(year: Int): LocalDate? { + val firstSeptember = LocalDate.of(year, 9, 1) + + return when (firstSeptember.dayOfWeek) { + FRIDAY, + SATURDAY, + SUNDAY -> firstSeptember.with(TemporalAdjusters.firstInMonth(MONDAY)) + else -> { + firstSeptember + } + } +} + +fun getLastSchoolDay(year: Int): LocalDate? { + return LocalDate + .of(year, 6, 20) + .with(TemporalAdjusters.next(FRIDAY)) +} diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 1af99630..d6f4cc7d 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -136,6 +136,7 @@ Usługi Włącz odświeżanie danych w tle + Zawieszone na wakacjach Interwał między odświeżaniem danych Synchronizacja tylko przez WiFi diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 21e63f5f..32c1efa8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -132,6 +132,7 @@ Services Enable background data refreshing + Suspended on holidays Interval between data refreshing Synchronization via WiFi only diff --git a/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.java b/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.java deleted file mode 100644 index e216392e..00000000 --- a/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.github.wulkanowy.utils; - -import org.junit.Assert; -import org.junit.Test; -import org.threeten.bp.LocalDate; - -public class TimeUtilsTest { - - @Test - public void getParsedDateTest() { - Assert.assertEquals(LocalDate.of(1970, 1, 1), - TimeUtils.getParsedDate("1970-01-01", "yyyy-MM-dd")); - } - - @Test - public void isDateInWeekInsideTest() { - Assert.assertTrue(TimeUtils.isDateInWeek( - LocalDate.of(2018, 5, 28), - LocalDate.of(2018, 5, 31) - )); - } - - @Test - public void isDateInWeekExtremesTest() { - Assert.assertTrue(TimeUtils.isDateInWeek( - LocalDate.of(2018, 5, 28), - LocalDate.of(2018, 5, 28) - )); - - Assert.assertTrue(TimeUtils.isDateInWeek( - LocalDate.of(2018, 5, 28), - LocalDate.of(2018, 6, 1) - )); - } - - @Test - public void isDateInWeekOutOfTest() { - Assert.assertFalse(TimeUtils.isDateInWeek( - LocalDate.of(2018, 5, 28), - LocalDate.of(2018, 6, 2) - )); - - Assert.assertFalse(TimeUtils.isDateInWeek( - LocalDate.of(2018, 5, 28), - LocalDate.of(2018, 5, 27) - )); - } -} diff --git a/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.kt b/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.kt new file mode 100644 index 00000000..2edffbb0 --- /dev/null +++ b/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.kt @@ -0,0 +1,140 @@ +package io.github.wulkanowy.utils + +import org.junit.Test +import org.threeten.bp.LocalDate + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue + +class TimeUtilsTest { + + @Test fun getParsedDateTest() { + assertEquals(LocalDate.of(1970, 1, 1), + getParsedDate("1970-01-01", "yyyy-MM-dd")) + } + + @Test fun getMondaysFromCurrentSchoolYearTest() { + val y201718 = getMondaysFromCurrentSchoolYear(LocalDate.of(2018, 1, 1)) + assertEquals("2017-09-04", y201718.first()) + assertEquals("2018-08-27", y201718.last()) + + val y202122 = getMondaysFromCurrentSchoolYear(LocalDate.of(2022, 1, 1)) + assertEquals("2021-08-30", y202122.first()) + assertEquals("2022-08-22", y202122.last()) + + val y202223 = getMondaysFromCurrentSchoolYear(LocalDate.of(2023, 1, 1)) + assertEquals("2022-08-29", y202223.first()) + assertEquals("2023-08-28", y202223.last()) + } + + @Test fun getCurrentSchoolYearTest() { + assertEquals(2017, getSchoolYearForDate(LocalDate.of(2018, 8, 31))) + assertEquals(2018, getSchoolYearForDate(LocalDate.of(2018, 9, 1))) + } + + @Test fun getFirstWeekDayTest() { + assertEquals("2018-06-18", getFirstDayOfCurrentWeek(LocalDate.of(2018, 6, 21))) + assertEquals("2018-06-18", getFirstDayOfCurrentWeek(LocalDate.of(2018, 6, 22))) + assertEquals("2018-06-25", getFirstDayOfCurrentWeek(LocalDate.of(2018, 6, 23))) + assertEquals("2018-06-25", getFirstDayOfCurrentWeek(LocalDate.of(2018, 6, 24))) + assertEquals("2018-06-25", getFirstDayOfCurrentWeek(LocalDate.of(2018, 6, 25))) + assertEquals("2018-06-25", getFirstDayOfCurrentWeek(LocalDate.of(2018, 6, 26))) + } + + @Test fun getTodayOrNextDayOrderTest() { + assertEquals(0, getTodayOrNextDayOrder(true, LocalDate.of(2018, 6, 24))) // sunday + assertEquals(6, getTodayOrNextDayOrder(false, LocalDate.of(2018, 6, 24))) + assertEquals(1, getTodayOrNextDayOrder(true, LocalDate.of(2018, 6, 25))) + assertEquals(0, getTodayOrNextDayOrder(false, LocalDate.of(2018, 6, 25))) + } + + @Test fun getTodayOrNextDayTest() { + assertEquals("2018-06-26", getTodayOrNextDay(false, LocalDate.of(2018, 6, 26))) + assertEquals("2018-06-27", getTodayOrNextDay(true, LocalDate.of(2018, 6, 26))) + } + + @Test fun isDateInWeekInsideTest() { + assertTrue(isDateInWeek( + LocalDate.of(2018, 5, 28), + LocalDate.of(2018, 5, 31) + )) + } + + @Test fun isDateInWeekExtremesTest() { + assertTrue(isDateInWeek( + LocalDate.of(2018, 5, 28), + LocalDate.of(2018, 5, 28) + )) + + assertTrue(isDateInWeek( + LocalDate.of(2018, 5, 28), + LocalDate.of(2018, 6, 1) + )) + } + + @Test fun isDateInWeekOutOfTest() { + assertFalse(isDateInWeek( + LocalDate.of(2018, 5, 28), + LocalDate.of(2018, 6, 2) + )) + + assertFalse(isDateInWeek( + LocalDate.of(2018, 5, 28), + LocalDate.of(2018, 5, 27) + )) + } + + @Test fun isHolidaysInSchoolEndTest() { + assertFalse(isHolidays(LocalDate.of(2017, 6, 23), 2017)) + assertFalse(isHolidays(LocalDate.of(2018, 6, 22), 2018)) + assertFalse(isHolidays(LocalDate.of(2019, 6, 21), 2019)) + assertFalse(isHolidays(LocalDate.of(2020, 6, 26), 2020)) + assertFalse(isHolidays(LocalDate.of(2021, 6, 25), 2021)) + assertFalse(isHolidays(LocalDate.of(2022, 6, 24), 2022)) + assertFalse(isHolidays(LocalDate.of(2023, 6, 23), 2023)) + assertFalse(isHolidays(LocalDate.of(2024, 6, 21), 2024)) + assertFalse(isHolidays(LocalDate.of(2025, 6, 27), 2025)) + } + + @Test fun isHolidaysInHolidaysStartTest() { + assertTrue(isHolidays(LocalDate.of(2017, 6, 24), 2017)) + assertTrue(isHolidays(LocalDate.of(2018, 6, 23), 2018)) + assertTrue(isHolidays(LocalDate.of(2019, 6, 22), 2019)) + assertTrue(isHolidays(LocalDate.of(2020, 6, 27), 2020)) + assertTrue(isHolidays(LocalDate.of(2021, 6, 26), 2021)) + assertTrue(isHolidays(LocalDate.of(2022, 6, 25), 2022)) + assertTrue(isHolidays(LocalDate.of(2023, 6, 24), 2023)) + assertTrue(isHolidays(LocalDate.of(2024, 6, 22), 2024)) + assertTrue(isHolidays(LocalDate.of(2025, 6, 28), 2025)) + } + + @Test fun isHolidaysInHolidaysEndTest() { + assertTrue(isHolidays(LocalDate.of(2017, 9, 1), 2017)) // friday + assertTrue(isHolidays(LocalDate.of(2017, 9, 2), 2017)) // saturday + assertTrue(isHolidays(LocalDate.of(2017, 9, 3), 2017)) // sunday + assertTrue(isHolidays(LocalDate.of(2018, 9, 1), 2018)) // saturday + assertTrue(isHolidays(LocalDate.of(2018, 9, 2), 2018)) // sunday + assertTrue(isHolidays(LocalDate.of(2019, 9, 1), 2019)) // sunday + assertTrue(isHolidays(LocalDate.of(2020, 8, 31), 2020)) // monday + assertTrue(isHolidays(LocalDate.of(2021, 8, 31), 2021)) // tuesday + assertTrue(isHolidays(LocalDate.of(2022, 8, 31), 2022)) // wednesday + assertTrue(isHolidays(LocalDate.of(2023, 9, 1), 2023)) // friday + assertTrue(isHolidays(LocalDate.of(2023, 9, 2), 2023)) // saturday + assertTrue(isHolidays(LocalDate.of(2023, 9, 3), 2023)) // sunday + assertTrue(isHolidays(LocalDate.of(2024, 9, 1), 2024)) // sunday + assertTrue(isHolidays(LocalDate.of(2025, 8, 31), 2025)) // sunday + } + + @Test fun isHolidaysInSchoolStartTest() { + assertFalse(isHolidays(LocalDate.of(2017, 9, 4), 2017)) // monday + assertFalse(isHolidays(LocalDate.of(2018, 9, 3), 2018)) // monday + assertFalse(isHolidays(LocalDate.of(2019, 9, 2), 2019)) // monday + assertFalse(isHolidays(LocalDate.of(2020, 9, 1), 2020)) // tuesday + assertFalse(isHolidays(LocalDate.of(2021, 9, 1), 2021)) // wednesday + assertFalse(isHolidays(LocalDate.of(2022, 9, 1), 2022)) // thursday + assertFalse(isHolidays(LocalDate.of(2023, 9, 4), 2023)) // monday + assertFalse(isHolidays(LocalDate.of(2024, 9, 2), 2024)) // monday + assertFalse(isHolidays(LocalDate.of(2025, 9, 1), 2025)) // monday + } +} diff --git a/build.gradle b/build.gradle index 760fb09f..2815bd0f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ buildscript { + ext.kotlin_version = '1.2.51' repositories { mavenCentral() google() @@ -8,18 +9,21 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2" - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } plugins { // gradle dependencyUpdates -Drevision=release - id "com.github.ben-manes.versions" version "0.17.0" + id "com.github.ben-manes.versions" version "0.20.0" } project.ext.preDexLibs = !project.hasProperty("disablePreDex") subprojects { + apply plugin: 'build-dashboard' // build/reports/buildDashboard/index.html + project.plugins.whenPluginAdded { plugin -> if ("com.android.build.gradle.AppPlugin" == plugin.class.name) { project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs @@ -52,17 +56,16 @@ ext { slf4jApi = "1.7.25" slf4jTimber = "1.0.1" - timber = "4.7.0" + timber = "4.7.1" - debugDb = "1.0.3" - sqlcipher = "3.5.9" + debugDb = "1.0.4" junit = "4.12" - mockito = "2.18.3" + mockito = "2.19.0" testRunner = "1.0.2" fabricGradle = "1.25.4" - crashlyticsSdk = "2.9.3" + crashlyticsSdk = "2.9.4" crashlyticsAnswers = "1.4.2" playPublisher = "1.2.2" @@ -73,10 +76,22 @@ allprojects { mavenCentral() google() jcenter() - maven { url "https://jitpack.io" } } } task clean(type: Delete) { delete rootProject.buildDir } + +dependencyUpdates.resolutionStrategy { + componentSelection { rules -> + rules.all { ComponentSelection selection -> + boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier -> + selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/ + } + if (rejected) { + selection.reject('Release candidate') + } + } + } +} diff --git a/jacoco.gradle b/jacoco.gradle deleted file mode 100644 index 84a0ce97..00000000 --- a/jacoco.gradle +++ /dev/null @@ -1,40 +0,0 @@ -apply plugin: "jacoco" - -jacoco { - toolVersion "0.8.1" -} - -tasks.withType(Test) { - jacoco.includeNoLocationClasses = true -} - -// run ./gradlew clean createDebugCoverageReport jacocoTestReport -task jacocoTestReport(type: JacocoReport) { - - group = "Reporting" - description = "Generate Jacoco coverage reports" - - reports { - xml.enabled = true - html.enabled = true - } - - def fileFilter = ["**/R.class", - "**/R\$*.class", - "**/BuildConfig.*", - "**/Manifest*.*", - "android/**/*.*", - "**/Lambda.class", - "**/*Lambda.class", - "**/*Lambda*.class", - "**/*Lambda*.*", - "**/*Builder.*" - ] - - def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) - def mainSrc = "${project.projectDir}/src/main/java" - - sourceDirectories = files([mainSrc]) - classDirectories = files([debugTree]) - executionData = fileTree(dir: project.projectDir, includes: ["**/*.exec" , "**/*.ec"]) -}