From 7e6a73d1f340ff0df4bc052a4f531feca69eb777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Tue, 2 Jan 2018 21:55:58 +0100 Subject: [PATCH] Prepare app for MVP (#40) --- .bettercodehub.yml | 2 +- app/build.gradle | 5 +- .../{ => db}/dao/DatabaseAccessTest.java | 10 ++-- .../{ => db}/dao/entities/AccountTest.java | 5 +- .../{ => db}/dao/entities/DayTest.java | 2 +- .../{ => db}/dao/entities/GradeTest.java | 6 +- .../{ => db}/dao/entities/LessonTest.java | 2 +- .../{ => db}/dao/entities/SubjectTest.java | 5 +- .../{ => db}/dao/entities/WeekTest.java | 5 +- .../services/VulcanSynchronizationTest.java | 30 ---------- .../CurrentAccountLoginTest.java | 23 ++++---- .../FirstAccountLoginTest.java | 19 +++--- .../GradeSyncTest.java} | 26 ++++----- .../SubjectSyncTest.java} | 22 +++---- .../TimetableSyncTest.java} | 36 +++++------- .../services/sync/VulcanSyncTest.java | 30 ++++++++++ .../{ => utils}/security/SafetyTest.java | 2 +- .../{ => utils}/security/ScramblerTest.java | 2 +- app/src/main/AndroidManifest.xml | 2 +- .../wulkanowy/{ui => }/WulkanowyApp.java | 18 +++--- .../{ => db}/dao/DatabaseAccess.java | 8 +-- .../{ => db}/dao/entities/Account.java | 2 +- .../wulkanowy/{ => db}/dao/entities/Day.java | 2 +- .../{ => db}/dao/entities/Grade.java | 2 +- .../{ => db}/dao/entities/Lesson.java | 2 +- .../{ => db}/dao/entities/Subject.java | 2 +- .../wulkanowy/{ => db}/dao/entities/Week.java | 2 +- .../di/modules/ApplicationModule.java | 27 +++++++++ .../wulkanowy/services/jobs/FullSyncJob.java | 14 ++--- .../services/jobs/VulcanJobHelper.java | 6 +- .../CurrentAccountLogin.java | 13 ++--- .../FirstAccountLogin.java | 13 ++--- .../GradesSync.java} | 23 ++++---- .../services/{ => sync}/LoginSession.java | 5 +- .../SubjectsSync.java} | 13 ++--- .../TimetableSync.java} | 58 ++++++++++--------- .../VulcanSync.java} | 39 ++++++------- .../wulkanowy/ui/login/LoginActivity.java | 16 +---- .../github/wulkanowy/ui/login/LoginTask.java | 36 +++++------- .../wulkanowy/ui/main/AbstractFragment.java | 8 +-- .../github/wulkanowy/ui/main/RefreshTask.java | 2 +- .../ui/main/grades/GradesAdapter.java | 4 +- .../ui/main/grades/GradesDialogFragment.java | 2 +- .../ui/main/grades/GradesFragment.java | 32 +++++----- .../ui/main/grades/SubjectWithGrades.java | 2 +- .../timetable/TimetableDialogFragment.java | 2 +- .../ui/main/timetable/TimetableFragment.java | 4 +- .../main/timetable/TimetableFragmentTab.java | 12 ++-- .../main/timetable/TimetableHeaderItem.java | 2 +- .../ui/main/timetable/TimetableSubItem.java | 3 +- .../utilities/ConnectionUtilities.java | 23 -------- .../wulkanowy/utilities/RootUtilities.java | 41 ------------- .../AverageCalculator.java | 18 +++--- .../DataObjectConverter.java} | 16 ++--- .../{dao => utils}/EntitiesCompare.java | 16 ++--- .../github/wulkanowy/utils/KeyboardUtils.java | 33 +++++++++++ .../github/wulkanowy/utils/NetworkUtils.java | 18 ++++++ .../github/wulkanowy/utils/RootChecker.java | 38 ++++++++++++ .../TimeUtils.java} | 6 +- .../{ => utils}/security/CryptoException.java | 2 +- .../{ => utils}/security/Safety.java | 6 +- .../{ => utils}/security/Scrambler.java | 2 +- .../{ => db}/dao/entities/GradeTest.java | 2 +- .../ui/main/grades/SubjectWithGradesTest.java | 2 +- .../AverageCalculatorTest.java | 4 +- .../DataObjectConverterTest.java} | 28 ++++----- .../{dao => utils}/EntitiesCompareTest.java | 4 +- .../NetworkUtilsTest.java} | 8 +-- .../TimeUtilsTest.java} | 22 +++---- 69 files changed, 455 insertions(+), 442 deletions(-) rename app/src/androidTest/java/io/github/wulkanowy/{ => db}/dao/DatabaseAccessTest.java (83%) rename app/src/androidTest/java/io/github/wulkanowy/{ => db}/dao/entities/AccountTest.java (78%) rename app/src/androidTest/java/io/github/wulkanowy/{ => db}/dao/entities/DayTest.java (89%) rename app/src/androidTest/java/io/github/wulkanowy/{ => db}/dao/entities/GradeTest.java (79%) rename app/src/androidTest/java/io/github/wulkanowy/{ => db}/dao/entities/LessonTest.java (93%) rename app/src/androidTest/java/io/github/wulkanowy/{ => db}/dao/entities/SubjectTest.java (78%) rename app/src/androidTest/java/io/github/wulkanowy/{ => db}/dao/entities/WeekTest.java (71%) delete mode 100644 app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java rename app/src/androidTest/java/io/github/wulkanowy/services/{synchronization => sync}/CurrentAccountLoginTest.java (87%) rename app/src/androidTest/java/io/github/wulkanowy/services/{synchronization => sync}/FirstAccountLoginTest.java (89%) rename app/src/androidTest/java/io/github/wulkanowy/services/{synchronization/GradeSynchronizationTest.java => sync/GradeSyncTest.java} (79%) rename app/src/androidTest/java/io/github/wulkanowy/services/{synchronization/SubjectSynchronizationTest.java => sync/SubjectSyncTest.java} (81%) rename app/src/androidTest/java/io/github/wulkanowy/services/{synchronization/TimetableSynchronizationTest.java => sync/TimetableSyncTest.java} (74%) create mode 100644 app/src/androidTest/java/io/github/wulkanowy/services/sync/VulcanSyncTest.java rename app/src/androidTest/java/io/github/wulkanowy/{ => utils}/security/SafetyTest.java (94%) rename app/src/androidTest/java/io/github/wulkanowy/{ => utils}/security/ScramblerTest.java (97%) rename app/src/main/java/io/github/wulkanowy/{ui => }/WulkanowyApp.java (77%) rename app/src/main/java/io/github/wulkanowy/{ => db}/dao/DatabaseAccess.java (65%) rename app/src/main/java/io/github/wulkanowy/{ => db}/dao/entities/Account.java (99%) rename app/src/main/java/io/github/wulkanowy/{ => db}/dao/entities/Day.java (99%) rename app/src/main/java/io/github/wulkanowy/{ => db}/dao/entities/Grade.java (99%) rename app/src/main/java/io/github/wulkanowy/{ => db}/dao/entities/Lesson.java (99%) rename app/src/main/java/io/github/wulkanowy/{ => db}/dao/entities/Subject.java (99%) rename app/src/main/java/io/github/wulkanowy/{ => db}/dao/entities/Week.java (98%) create mode 100644 app/src/main/java/io/github/wulkanowy/di/modules/ApplicationModule.java rename app/src/main/java/io/github/wulkanowy/services/{synchronisation => sync}/CurrentAccountLogin.java (84%) rename app/src/main/java/io/github/wulkanowy/services/{synchronisation => sync}/FirstAccountLogin.java (84%) rename app/src/main/java/io/github/wulkanowy/services/{synchronisation/GradesSynchronisation.java => sync/GradesSync.java} (73%) rename app/src/main/java/io/github/wulkanowy/services/{ => sync}/LoginSession.java (93%) rename app/src/main/java/io/github/wulkanowy/services/{synchronisation/SubjectsSynchronisation.java => sync/SubjectsSync.java} (71%) rename app/src/main/java/io/github/wulkanowy/services/{synchronisation/TimetableSynchronization.java => sync/TimetableSync.java} (55%) rename app/src/main/java/io/github/wulkanowy/services/{VulcanSynchronization.java => sync/VulcanSync.java} (65%) delete mode 100644 app/src/main/java/io/github/wulkanowy/utilities/ConnectionUtilities.java delete mode 100644 app/src/main/java/io/github/wulkanowy/utilities/RootUtilities.java rename app/src/main/java/io/github/wulkanowy/{utilities => utils}/AverageCalculator.java (72%) rename app/src/main/java/io/github/wulkanowy/{utilities/ConversionVulcanObject.java => utils/DataObjectConverter.java} (90%) rename app/src/main/java/io/github/wulkanowy/{dao => utils}/EntitiesCompare.java (71%) create mode 100644 app/src/main/java/io/github/wulkanowy/utils/KeyboardUtils.java create mode 100644 app/src/main/java/io/github/wulkanowy/utils/NetworkUtils.java create mode 100644 app/src/main/java/io/github/wulkanowy/utils/RootChecker.java rename app/src/main/java/io/github/wulkanowy/{utilities/TimeUtilities.java => utils/TimeUtils.java} (95%) rename app/src/main/java/io/github/wulkanowy/{ => utils}/security/CryptoException.java (74%) rename app/src/main/java/io/github/wulkanowy/{ => utils}/security/Safety.java (88%) rename app/src/main/java/io/github/wulkanowy/{ => utils}/security/Scrambler.java (99%) rename app/src/test/java/io/github/wulkanowy/{ => db}/dao/entities/GradeTest.java (97%) rename app/src/test/java/io/github/wulkanowy/{utilities => utils}/AverageCalculatorTest.java (94%) rename app/src/test/java/io/github/wulkanowy/{utilities/ConversionVulcanObjectTest.java => utils/DataObjectConverterTest.java} (62%) rename app/src/test/java/io/github/wulkanowy/{dao => utils}/EntitiesCompareTest.java (97%) rename app/src/test/java/io/github/wulkanowy/{utilities/ConnectionUtilitiesTest.java => utils/NetworkUtilsTest.java} (85%) rename app/src/test/java/io/github/wulkanowy/{utilities/TimeUtilitiesTest.java => utils/TimeUtilsTest.java} (57%) diff --git a/.bettercodehub.yml b/.bettercodehub.yml index 96055d7d6..c7394280f 100644 --- a/.bettercodehub.yml +++ b/.bettercodehub.yml @@ -1,5 +1,5 @@ exclude: -- /app/src/main/java/io/github/wulkanowy/dao/entities/.* +- /app/src/main/java/io/github/wulkanowy/db/dao/entities/.* component_depth: 1 languages: - java diff --git a/app/build.gradle b/app/build.gradle index 96076b3a8..26a0aa9fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,11 +63,14 @@ dependencies { implementation 'com.jakewharton:butterknife:8.8.1' implementation 'joda-time:joda-time:2.9.9' implementation 'com.github.javiersantos:AppUpdater:2.6.4' + implementation 'com.google.dagger:dagger-android:2.14.1' + implementation 'com.google.dagger:dagger-android-support:2.14.1' + annotationProcessor 'com.google.dagger:dagger-android-processor:2.14.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' debugImplementation 'com.amitshekhar.android:debug-db:1.0.1' - debugImplementation 'net.zetetic:android-database-sqlcipher:3.5.7@aar' + debugImplementation 'net.zetetic:android-database-sqlcipher:3.5.9' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.11.0' diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/DatabaseAccessTest.java b/app/src/androidTest/java/io/github/wulkanowy/db/dao/DatabaseAccessTest.java similarity index 83% rename from app/src/androidTest/java/io/github/wulkanowy/dao/DatabaseAccessTest.java rename to app/src/androidTest/java/io/github/wulkanowy/db/dao/DatabaseAccessTest.java index f5270d294..c9156676f 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/dao/DatabaseAccessTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/db/dao/DatabaseAccessTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.dao; +package io.github.wulkanowy.db.dao; import android.support.test.InstrumentationRegistry; @@ -9,9 +9,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import io.github.wulkanowy.dao.entities.DaoMaster; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.DaoMaster; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.db.dao.entities.Grade; public class DatabaseAccessTest extends DatabaseAccess { @@ -20,7 +20,7 @@ public class DatabaseAccessTest extends DatabaseAccess { @BeforeClass public static void setUpClass() { DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext() - , "wulkanowyTest-database"); + , "wulkanowyTest-db"); Database database = devOpenHelper.getWritableDb(); daoSession = new DaoMaster(database).newSession(); diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/AccountTest.java b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/AccountTest.java similarity index 78% rename from app/src/androidTest/java/io/github/wulkanowy/dao/entities/AccountTest.java rename to app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/AccountTest.java index c943a560b..78ea561df 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/AccountTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/AccountTest.java @@ -1,10 +1,7 @@ -package io.github.wulkanowy.dao.entities; - -import android.support.test.filters.SmallTest; +package io.github.wulkanowy.db.dao.entities; import org.greenrobot.greendao.test.AbstractDaoTestLongPk; -@SmallTest public class AccountTest extends AbstractDaoTestLongPk { public AccountTest() { diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/DayTest.java b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/DayTest.java similarity index 89% rename from app/src/androidTest/java/io/github/wulkanowy/dao/entities/DayTest.java rename to app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/DayTest.java index 4c978c575..7574addbb 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/DayTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/DayTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.dao.entities; +package io.github.wulkanowy.db.dao.entities; import org.greenrobot.greendao.test.AbstractDaoTestLongPk; diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/GradeTest.java b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/GradeTest.java similarity index 79% rename from app/src/androidTest/java/io/github/wulkanowy/dao/entities/GradeTest.java rename to app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/GradeTest.java index 70f12510f..7cabfa27c 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/GradeTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/GradeTest.java @@ -1,10 +1,7 @@ -package io.github.wulkanowy.dao.entities; - -import android.support.test.filters.SmallTest; +package io.github.wulkanowy.db.dao.entities; import org.greenrobot.greendao.test.AbstractDaoTestLongPk; -@SmallTest public class GradeTest extends AbstractDaoTestLongPk { public GradeTest() { @@ -16,6 +13,7 @@ public class GradeTest extends AbstractDaoTestLongPk { Grade entity = new Grade(); entity.setId(key); entity.setIsNew(false); + entity.setRead(false); return entity; } diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/LessonTest.java b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/LessonTest.java similarity index 93% rename from app/src/androidTest/java/io/github/wulkanowy/dao/entities/LessonTest.java rename to app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/LessonTest.java index 96d50e234..4e3523f72 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/LessonTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/LessonTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.dao.entities; +package io.github.wulkanowy.db.dao.entities; import org.greenrobot.greendao.test.AbstractDaoTestLongPk; diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/SubjectTest.java b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/SubjectTest.java similarity index 78% rename from app/src/androidTest/java/io/github/wulkanowy/dao/entities/SubjectTest.java rename to app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/SubjectTest.java index 59c9da45f..85b986dfc 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/SubjectTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/SubjectTest.java @@ -1,10 +1,7 @@ -package io.github.wulkanowy.dao.entities; - -import android.support.test.filters.SmallTest; +package io.github.wulkanowy.db.dao.entities; import org.greenrobot.greendao.test.AbstractDaoTestLongPk; -@SmallTest public class SubjectTest extends AbstractDaoTestLongPk { public SubjectTest() { diff --git a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/WeekTest.java b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/WeekTest.java similarity index 71% rename from app/src/androidTest/java/io/github/wulkanowy/dao/entities/WeekTest.java rename to app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/WeekTest.java index 1302989c1..6920ae206 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/dao/entities/WeekTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/db/dao/entities/WeekTest.java @@ -1,10 +1,7 @@ -package io.github.wulkanowy.dao.entities; +package io.github.wulkanowy.db.dao.entities; import org.greenrobot.greendao.test.AbstractDaoTestLongPk; -import io.github.wulkanowy.dao.entities.Week; -import io.github.wulkanowy.dao.entities.WeekDao; - public class WeekTest extends AbstractDaoTestLongPk { public WeekTest() { diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java deleted file mode 100644 index 0a92e4ecb..000000000 --- a/app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.wulkanowy.services; - -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.IOException; - -@RunWith(AndroidJUnit4.class) -public class VulcanSynchronizationTest { - - @Test(expected = IOException.class) - public void syncNoLoginSessionSubjectTest() throws IOException { - VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession()); - vulcanSynchronization.syncSubjectsAndGrades(); - } - - @Test(expected = IOException.class) - public void syncNoLoginSessionGradeTest() throws IOException { - VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession()); - vulcanSynchronization.syncGrades(); - } - - @Test(expected = IOException.class) - public void syncNoLoginSessionTimetableTest() throws IOException { - VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession()); - vulcanSynchronization.syncTimetable(); - } -} diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/CurrentAccountLoginTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/sync/CurrentAccountLoginTest.java similarity index 87% rename from app/src/androidTest/java/io/github/wulkanowy/services/synchronization/CurrentAccountLoginTest.java rename to app/src/androidTest/java/io/github/wulkanowy/services/sync/CurrentAccountLoginTest.java index 8b45dd6f8..65da82e21 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/CurrentAccountLoginTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/sync/CurrentAccountLoginTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronization; +package io.github.wulkanowy.services.sync; import android.content.Context; import android.content.SharedPreferences; @@ -21,14 +21,12 @@ import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.LoginErrorException; import io.github.wulkanowy.api.login.VulcanOfflineException; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.AccountDao; -import io.github.wulkanowy.dao.entities.DaoMaster; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.security.CryptoException; -import io.github.wulkanowy.security.Safety; -import io.github.wulkanowy.services.LoginSession; -import io.github.wulkanowy.services.synchronisation.CurrentAccountLogin; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.AccountDao; +import io.github.wulkanowy.db.dao.entities.DaoMaster; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.utils.security.CryptoException; +import io.github.wulkanowy.utils.security.Safety; @RunWith(AndroidJUnit4.class) public class CurrentAccountLoginTest { @@ -41,11 +39,12 @@ public class CurrentAccountLoginTest { @BeforeClass public static void setUpClass() { - - DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-database"); + DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-db"); Database database = devOpenHelper.getWritableDb(); - daoSession = new DaoMaster(database).newSession(); + + DaoMaster.dropAllTables(database, true); + DaoMaster.createAllTables(database, true); } @Before diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/FirstAccountLoginTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/sync/FirstAccountLoginTest.java similarity index 89% rename from app/src/androidTest/java/io/github/wulkanowy/services/synchronization/FirstAccountLoginTest.java rename to app/src/androidTest/java/io/github/wulkanowy/services/sync/FirstAccountLoginTest.java index 958503c35..f21049e5b 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/FirstAccountLoginTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/sync/FirstAccountLoginTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronization; +package io.github.wulkanowy.services.sync; import android.content.Context; import android.content.SharedPreferences; @@ -16,12 +16,10 @@ import io.github.wulkanowy.api.StudentAndParent; import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.user.BasicInformation; import io.github.wulkanowy.api.user.PersonalData; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.DaoMaster; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.security.Safety; -import io.github.wulkanowy.services.LoginSession; -import io.github.wulkanowy.services.synchronisation.FirstAccountLogin; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.DaoMaster; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.utils.security.Safety; public class FirstAccountLoginTest { @@ -31,11 +29,12 @@ public class FirstAccountLoginTest { @BeforeClass public static void setUpClass() { - - DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-database"); + DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-db"); Database database = devOpenHelper.getWritableDb(); - daoSession = new DaoMaster(database).newSession(); + + DaoMaster.dropAllTables(database, true); + DaoMaster.createAllTables(database, true); } @Before diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/GradeSynchronizationTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/sync/GradeSyncTest.java similarity index 79% rename from app/src/androidTest/java/io/github/wulkanowy/services/synchronization/GradeSynchronizationTest.java rename to app/src/androidTest/java/io/github/wulkanowy/services/sync/GradeSyncTest.java index e23f56480..111767192 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/GradeSynchronizationTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/sync/GradeSyncTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronization; +package io.github.wulkanowy.services.sync; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; @@ -18,24 +18,24 @@ import java.util.List; import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.grades.Grade; import io.github.wulkanowy.api.grades.GradesList; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.DaoMaster; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.dao.entities.Subject; -import io.github.wulkanowy.services.LoginSession; -import io.github.wulkanowy.services.synchronisation.GradesSynchronisation; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.DaoMaster; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.db.dao.entities.Subject; @RunWith(AndroidJUnit4.class) -public class GradeSynchronizationTest { +public class GradeSyncTest { private static DaoSession daoSession; @BeforeClass public static void setUpClass() { - DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-database"); + DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-db"); Database database = devOpenHelper.getWritableDb(); - daoSession = new DaoMaster(database).newSession(); + + DaoMaster.dropAllTables(database, true); + DaoMaster.createAllTables(database, true); } @Before @@ -65,10 +65,10 @@ public class GradeSynchronizationTest { Mockito.doReturn(daoSession).when(loginSession).getDaoSession(); Mockito.doReturn(userId).when(loginSession).getUserId(); - GradesSynchronisation gradesSynchronisation = new GradesSynchronisation(); - gradesSynchronisation.sync(loginSession); + GradesSync gradesSync = new GradesSync(); + gradesSync.sync(loginSession); - io.github.wulkanowy.dao.entities.Grade grade = daoSession.getGradeDao().load(1L); + io.github.wulkanowy.db.dao.entities.Grade grade = daoSession.getGradeDao().load(1L); Assert.assertNotNull(grade); Assert.assertEquals(userId, grade.getUserId()); diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/SubjectSynchronizationTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/sync/SubjectSyncTest.java similarity index 81% rename from app/src/androidTest/java/io/github/wulkanowy/services/synchronization/SubjectSynchronizationTest.java rename to app/src/androidTest/java/io/github/wulkanowy/services/sync/SubjectSyncTest.java index 317d8ecde..38e70bc08 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/SubjectSynchronizationTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/sync/SubjectSyncTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronization; +package io.github.wulkanowy.services.sync; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; @@ -17,23 +17,23 @@ import java.util.List; import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.grades.SubjectsList; -import io.github.wulkanowy.dao.entities.DaoMaster; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.dao.entities.Subject; -import io.github.wulkanowy.services.LoginSession; -import io.github.wulkanowy.services.synchronisation.SubjectsSynchronisation; +import io.github.wulkanowy.db.dao.entities.DaoMaster; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.db.dao.entities.Subject; @RunWith(AndroidJUnit4.class) -public class SubjectSynchronizationTest { +public class SubjectSyncTest { private static DaoSession daoSession; @BeforeClass public static void setUpClass() { - DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-database"); + DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-db"); Database database = devOpenHelper.getWritableDb(); - daoSession = new DaoMaster(database).newSession(); + + DaoMaster.dropAllTables(database, true); + DaoMaster.createAllTables(database, true); } @Before @@ -61,8 +61,8 @@ public class SubjectSynchronizationTest { Mockito.doReturn(2L).when(loginSession).getUserId(); Mockito.doReturn(daoSession).when(loginSession).getDaoSession(); - SubjectsSynchronisation subjectsSynchronisation = new SubjectsSynchronisation(); - subjectsSynchronisation.sync(loginSession); + SubjectsSync subjectsSync = new SubjectsSync(); + subjectsSync.sync(loginSession); Subject subject = daoSession.getSubjectDao().load(1L); diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/TimetableSynchronizationTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/sync/TimetableSyncTest.java similarity index 74% rename from app/src/androidTest/java/io/github/wulkanowy/services/synchronization/TimetableSynchronizationTest.java rename to app/src/androidTest/java/io/github/wulkanowy/services/sync/TimetableSyncTest.java index 1140a3d3b..d08ae4f0f 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/TimetableSynchronizationTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/sync/TimetableSyncTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronization; +package io.github.wulkanowy.services.sync; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; @@ -6,7 +6,6 @@ import android.support.test.runner.AndroidJUnit4; import org.greenrobot.greendao.database.Database; import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -19,27 +18,27 @@ import io.github.wulkanowy.api.timetable.Day; import io.github.wulkanowy.api.timetable.Lesson; import io.github.wulkanowy.api.timetable.Timetable; import io.github.wulkanowy.api.timetable.Week; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.DaoMaster; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.services.LoginSession; -import io.github.wulkanowy.services.synchronisation.TimetableSynchronization; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.DaoMaster; +import io.github.wulkanowy.db.dao.entities.DaoSession; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @RunWith(AndroidJUnit4.class) -public class TimetableSynchronizationTest { +public class TimetableSyncTest { private static DaoSession daoSession; @BeforeClass public static void setUpClass() { - DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-database"); + DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-db"); Database database = devOpenHelper.getWritableDb(); - daoSession = new DaoMaster(database).newSession(); + + DaoMaster.dropAllTables(database, true); + DaoMaster.createAllTables(database, true); } @Test @@ -70,11 +69,11 @@ public class TimetableSynchronizationTest { doReturn(daoSession).when(loginSession).getDaoSession(); doReturn(userId).when(loginSession).getUserId(); - TimetableSynchronization timetableSynchronization = new TimetableSynchronization(); - timetableSynchronization.sync(loginSession, null); + TimetableSync timetableSync = new TimetableSync(); + timetableSync.sync(loginSession, null); - List dayEntityList = daoSession.getDayDao().loadAll(); - List lessonEntityList = dayEntityList.get(0).getLessons(); + List dayEntityList = daoSession.getDayDao().loadAll(); + List lessonEntityList = dayEntityList.get(0).getLessons(); Assert.assertNotNull(dayEntityList.get(0)); Assert.assertEquals(userId, dayEntityList.get(0).getUserId()); @@ -85,19 +84,12 @@ public class TimetableSynchronizationTest { } - @Before - public void setUp() { - daoSession.getAccountDao().deleteAll(); - daoSession.getDayDao().deleteAll(); - daoSession.getLessonDao().deleteAll(); - daoSession.clear(); - } - @AfterClass public static void cleanUp() { daoSession.getAccountDao().deleteAll(); daoSession.getDayDao().deleteAll(); daoSession.getLessonDao().deleteAll(); + daoSession.getWeekDao().deleteAll(); daoSession.clear(); } } diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/sync/VulcanSyncTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/sync/VulcanSyncTest.java new file mode 100644 index 000000000..df07d462d --- /dev/null +++ b/app/src/androidTest/java/io/github/wulkanowy/services/sync/VulcanSyncTest.java @@ -0,0 +1,30 @@ +package io.github.wulkanowy.services.sync; + +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; + +@RunWith(AndroidJUnit4.class) +public class VulcanSyncTest { + + @Test(expected = IOException.class) + public void syncNoLoginSessionSubjectTest() throws IOException { + VulcanSync vulcanSync = new VulcanSync(new LoginSession()); + vulcanSync.syncSubjectsAndGrades(); + } + + @Test(expected = IOException.class) + public void syncNoLoginSessionGradeTest() throws IOException { + VulcanSync vulcanSync = new VulcanSync(new LoginSession()); + vulcanSync.syncGrades(); + } + + @Test(expected = IOException.class) + public void syncNoLoginSessionTimetableTest() throws IOException { + VulcanSync vulcanSync = new VulcanSync(new LoginSession()); + vulcanSync.syncTimetable(); + } +} diff --git a/app/src/androidTest/java/io/github/wulkanowy/security/SafetyTest.java b/app/src/androidTest/java/io/github/wulkanowy/utils/security/SafetyTest.java similarity index 94% rename from app/src/androidTest/java/io/github/wulkanowy/security/SafetyTest.java rename to app/src/androidTest/java/io/github/wulkanowy/utils/security/SafetyTest.java index 63d268a35..17813d423 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/security/SafetyTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/utils/security/SafetyTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.security; +package io.github.wulkanowy.utils.security; import android.content.Context; import android.support.test.InstrumentationRegistry; diff --git a/app/src/androidTest/java/io/github/wulkanowy/security/ScramblerTest.java b/app/src/androidTest/java/io/github/wulkanowy/utils/security/ScramblerTest.java similarity index 97% rename from app/src/androidTest/java/io/github/wulkanowy/security/ScramblerTest.java rename to app/src/androidTest/java/io/github/wulkanowy/utils/security/ScramblerTest.java index 0b7e5b5c1..16034ed48 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/security/ScramblerTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/utils/security/ScramblerTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.security; +package io.github.wulkanowy.utils.security; import android.content.Context; import android.os.Build; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b9ecb1f06..cc127ca43 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,7 @@ { +public class FullSyncJob extends VulcanJobHelper { private static final String UNIQUE_TAG = "FullSync"; @@ -51,7 +51,7 @@ public class FullSyncJob extends VulcanJobHelper { public void workToBePerformed() throws Exception { DaoSession daoSession = ((WulkanowyApp) getApplication()).getDaoSession(); - VulcanSynchronization synchronization = new VulcanSynchronization() + VulcanSync synchronization = new VulcanSync() .loginCurrentUser(getApplicationContext(), daoSession); synchronization.syncAll(); List newGradeList = new DatabaseAccess().getNewGrades(daoSession); diff --git a/app/src/main/java/io/github/wulkanowy/services/jobs/VulcanJobHelper.java b/app/src/main/java/io/github/wulkanowy/services/jobs/VulcanJobHelper.java index a2d21fcbd..f435c2e14 100644 --- a/app/src/main/java/io/github/wulkanowy/services/jobs/VulcanJobHelper.java +++ b/app/src/main/java/io/github/wulkanowy/services/jobs/VulcanJobHelper.java @@ -8,16 +8,14 @@ import com.firebase.jobdispatcher.FirebaseJobDispatcher; import com.firebase.jobdispatcher.GooglePlayDriver; import com.firebase.jobdispatcher.Job; -public abstract class VulcanJobHelper { +public abstract class VulcanJobHelper { public static final String DEBUG_TAG = "SynchronizationService"; - @SuppressWarnings("unchecked") - public final T scheduledJob(Context context) { + public final void scheduledJob(Context context) { FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context)); dispatcher.mustSchedule(createJob(dispatcher)); Log.i(DEBUG_TAG, "Wulkanowy Job is initiation: " + this.toString()); - return (T) this; } protected abstract Job createJob(FirebaseJobDispatcher dispatcher); diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/CurrentAccountLogin.java b/app/src/main/java/io/github/wulkanowy/services/sync/CurrentAccountLogin.java similarity index 84% rename from app/src/main/java/io/github/wulkanowy/services/synchronisation/CurrentAccountLogin.java rename to app/src/main/java/io/github/wulkanowy/services/sync/CurrentAccountLogin.java index 7ea2c5a98..30ec717c2 100644 --- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/CurrentAccountLogin.java +++ b/app/src/main/java/io/github/wulkanowy/services/sync/CurrentAccountLogin.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronisation; +package io.github.wulkanowy.services.sync; import android.content.Context; import android.util.Log; @@ -10,13 +10,12 @@ import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.LoginErrorException; import io.github.wulkanowy.api.login.VulcanOfflineException; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.AccountDao; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.security.CryptoException; -import io.github.wulkanowy.security.Safety; -import io.github.wulkanowy.services.LoginSession; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.AccountDao; +import io.github.wulkanowy.db.dao.entities.DaoSession; import io.github.wulkanowy.services.jobs.VulcanJobHelper; +import io.github.wulkanowy.utils.security.CryptoException; +import io.github.wulkanowy.utils.security.Safety; public class CurrentAccountLogin { diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/FirstAccountLogin.java b/app/src/main/java/io/github/wulkanowy/services/sync/FirstAccountLogin.java similarity index 84% rename from app/src/main/java/io/github/wulkanowy/services/synchronisation/FirstAccountLogin.java rename to app/src/main/java/io/github/wulkanowy/services/sync/FirstAccountLogin.java index afae82249..794dc3cf6 100644 --- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/FirstAccountLogin.java +++ b/app/src/main/java/io/github/wulkanowy/services/sync/FirstAccountLogin.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronisation; +package io.github.wulkanowy.services.sync; import android.content.Context; import android.content.SharedPreferences; @@ -10,12 +10,11 @@ import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.NotLoggedInErrorException; import io.github.wulkanowy.api.login.VulcanOfflineException; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.AccountDao; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.security.CryptoException; -import io.github.wulkanowy.security.Safety; -import io.github.wulkanowy.services.LoginSession; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.AccountDao; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.utils.security.CryptoException; +import io.github.wulkanowy.utils.security.Safety; public class FirstAccountLogin { diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/GradesSynchronisation.java b/app/src/main/java/io/github/wulkanowy/services/sync/GradesSync.java similarity index 73% rename from app/src/main/java/io/github/wulkanowy/services/synchronisation/GradesSynchronisation.java rename to app/src/main/java/io/github/wulkanowy/services/sync/GradesSync.java index 2c9d486c2..78069b9da 100644 --- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/GradesSynchronisation.java +++ b/app/src/main/java/io/github/wulkanowy/services/sync/GradesSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronisation; +package io.github.wulkanowy.services.sync; import android.util.Log; @@ -11,18 +11,17 @@ import java.util.List; import io.github.wulkanowy.api.grades.GradesList; import io.github.wulkanowy.api.login.NotLoggedInErrorException; -import io.github.wulkanowy.dao.EntitiesCompare; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.AccountDao; -import io.github.wulkanowy.dao.entities.Grade; -import io.github.wulkanowy.dao.entities.GradeDao; -import io.github.wulkanowy.dao.entities.Subject; -import io.github.wulkanowy.dao.entities.SubjectDao; -import io.github.wulkanowy.services.LoginSession; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.AccountDao; +import io.github.wulkanowy.db.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.GradeDao; +import io.github.wulkanowy.db.dao.entities.Subject; +import io.github.wulkanowy.db.dao.entities.SubjectDao; import io.github.wulkanowy.services.jobs.VulcanJobHelper; -import io.github.wulkanowy.utilities.ConversionVulcanObject; +import io.github.wulkanowy.utils.DataObjectConverter; +import io.github.wulkanowy.utils.EntitiesCompare; -public class GradesSynchronisation { +public class GradesSync { public void sync(LoginSession loginSession) throws IOException, ParseException, NotLoggedInErrorException { @@ -39,7 +38,7 @@ public class GradesSynchronisation { account.resetSubjectList(); List gradesFromDb = account.getGradeList(); - List gradeEntitiesList = ConversionVulcanObject.gradesToGradeEntities(gradesList.getAll()); + List gradeEntitiesList = DataObjectConverter.gradesToGradeEntities(gradesList.getAll()); List updatedList = EntitiesCompare.compareGradeList(gradeEntitiesList, gradesFromDb); List lastList = new ArrayList<>(); diff --git a/app/src/main/java/io/github/wulkanowy/services/LoginSession.java b/app/src/main/java/io/github/wulkanowy/services/sync/LoginSession.java similarity index 93% rename from app/src/main/java/io/github/wulkanowy/services/LoginSession.java rename to app/src/main/java/io/github/wulkanowy/services/sync/LoginSession.java index f5f12c423..1d3e91ba7 100644 --- a/app/src/main/java/io/github/wulkanowy/services/LoginSession.java +++ b/app/src/main/java/io/github/wulkanowy/services/sync/LoginSession.java @@ -1,11 +1,12 @@ -package io.github.wulkanowy.services; +package io.github.wulkanowy.services.sync; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import io.github.wulkanowy.api.Vulcan; -import io.github.wulkanowy.dao.entities.DaoSession; +import io.github.wulkanowy.db.dao.entities.DaoSession; + public class LoginSession { diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/SubjectsSynchronisation.java b/app/src/main/java/io/github/wulkanowy/services/sync/SubjectsSync.java similarity index 71% rename from app/src/main/java/io/github/wulkanowy/services/synchronisation/SubjectsSynchronisation.java rename to app/src/main/java/io/github/wulkanowy/services/sync/SubjectsSync.java index 1a3cdf571..065e8106e 100644 --- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/SubjectsSynchronisation.java +++ b/app/src/main/java/io/github/wulkanowy/services/sync/SubjectsSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronisation; +package io.github.wulkanowy.services.sync; import android.util.Log; @@ -8,13 +8,12 @@ import java.util.List; import io.github.wulkanowy.api.grades.SubjectsList; import io.github.wulkanowy.api.login.NotLoggedInErrorException; -import io.github.wulkanowy.dao.entities.Subject; -import io.github.wulkanowy.dao.entities.SubjectDao; -import io.github.wulkanowy.services.LoginSession; +import io.github.wulkanowy.db.dao.entities.Subject; +import io.github.wulkanowy.db.dao.entities.SubjectDao; import io.github.wulkanowy.services.jobs.VulcanJobHelper; -import io.github.wulkanowy.utilities.ConversionVulcanObject; +import io.github.wulkanowy.utils.DataObjectConverter; -public class SubjectsSynchronisation { +public class SubjectsSync { public void sync(LoginSession loginSession) throws IOException, NotLoggedInErrorException { @@ -22,7 +21,7 @@ public class SubjectsSynchronisation { SubjectsList subjectsList = loginSession.getVulcan().getSubjectsList(); SubjectDao subjectDao = loginSession.getDaoSession().getSubjectDao(); - List subjectEntitiesList = ConversionVulcanObject.subjectsToSubjectEntities(subjectsList.getAll()); + List subjectEntitiesList = DataObjectConverter.subjectsToSubjectEntities(subjectsList.getAll()); List preparedList = new ArrayList<>(); for (Subject subject : subjectEntitiesList) { diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/TimetableSynchronization.java b/app/src/main/java/io/github/wulkanowy/services/sync/TimetableSync.java similarity index 55% rename from app/src/main/java/io/github/wulkanowy/services/synchronisation/TimetableSynchronization.java rename to app/src/main/java/io/github/wulkanowy/services/sync/TimetableSync.java index 69205a46f..0fd13723a 100644 --- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/TimetableSynchronization.java +++ b/app/src/main/java/io/github/wulkanowy/services/sync/TimetableSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services.synchronisation; +package io.github.wulkanowy.services.sync; import android.support.annotation.NonNull; @@ -15,16 +15,15 @@ import java.util.List; import io.github.wulkanowy.api.login.NotLoggedInErrorException; import io.github.wulkanowy.api.timetable.Day; import io.github.wulkanowy.api.timetable.Week; -import io.github.wulkanowy.dao.entities.DayDao; -import io.github.wulkanowy.dao.entities.Lesson; -import io.github.wulkanowy.dao.entities.LessonDao; -import io.github.wulkanowy.dao.entities.WeekDao; -import io.github.wulkanowy.services.LoginSession; +import io.github.wulkanowy.db.dao.entities.DayDao; +import io.github.wulkanowy.db.dao.entities.Lesson; +import io.github.wulkanowy.db.dao.entities.LessonDao; +import io.github.wulkanowy.db.dao.entities.WeekDao; import io.github.wulkanowy.services.jobs.VulcanJobHelper; -import io.github.wulkanowy.utilities.ConversionVulcanObject; -import io.github.wulkanowy.utilities.TimeUtilities; +import io.github.wulkanowy.utils.DataObjectConverter; +import io.github.wulkanowy.utils.TimeUtils; -public class TimetableSynchronization { +public class TimetableSync { public void sync(@NonNull LoginSession loginSession, @Nullable String dateOfMonday) throws NotLoggedInErrorException, IOException, ParseException { @@ -36,17 +35,17 @@ public class TimetableSynchronization { Week week = dateOfMonday == null ? loginSession.getVulcan().getTimetable().getWeekTable() : loginSession.getVulcan().getTimetable() - .getWeekTable(String.valueOf(TimeUtilities.getNetTicks(dateOfMonday, "yyyy-MM-dd"))); + .getWeekTable(String.valueOf(TimeUtils.getNetTicks(dateOfMonday, "yyyy-MM-dd"))); - Query weekQuery = weekDao.queryBuilder() + Query weekQuery = weekDao.queryBuilder() .where(WeekDao.Properties.UserId.eq(loginSession.getUserId()), WeekDao.Properties.StartDayDate.eq(week.getStartDayDate())).build(); - io.github.wulkanowy.dao.entities.Week week1 = weekQuery.unique(); + io.github.wulkanowy.db.dao.entities.Week week1 = weekQuery.unique(); if (week1 != null) { weekId = week1.getId(); } else { - weekId = weekDao.insert(ConversionVulcanObject.weekToWeekEntitie(week).setUserId(loginSession.getUserId())); + weekId = weekDao.insert(DataObjectConverter.weekToWeekEntitie(week).setUserId(loginSession.getUserId())); } List dayList = week.getDays(); @@ -56,29 +55,34 @@ public class TimetableSynchronization { Log.d(VulcanJobHelper.DEBUG_TAG, "Synchronization days (amount = " + dayList.size() + ")"); List lessonList = new ArrayList<>(); - lessonList.addAll(getPreparedLessonsList(dayList, dayDao, lessonDao)); + lessonList.addAll(getPreparedLessonsList(dayList, dayDao, lessonDao, loginSession.getUserId(), weekId)); lessonDao.saveInTx(lessonList); Log.d(VulcanJobHelper.DEBUG_TAG, "Synchronization lessons (amount = " + lessonList.size() + ")"); } - private List getPreparedLessonsList(List dayList, DayDao dayDao, LessonDao lessonDao) { + private List getPreparedLessonsList(List dayList, DayDao dayDao, LessonDao lessonDao, long userId, long weekId) { List allLessonsList = new ArrayList<>(); for (Day day : dayList) { - Query dayQuery = dayDao.queryBuilder() - .where(DayDao.Properties.Date.eq(day.getDate())) + Query dayQuery = dayDao.queryBuilder() + .where(DayDao.Properties.Date.eq(day.getDate()), + DayDao.Properties.UserId.eq(userId), + DayDao.Properties.WeekId.eq(weekId)) .build(); - List lessonEntityList = ConversionVulcanObject.lessonsToLessonsEntities(day.getLessons()); + List lessonEntityList = DataObjectConverter.lessonsToLessonsEntities(day.getLessons()); List updatedLessonEntityList = new ArrayList<>(); for (Lesson lesson : lessonEntityList) { - Query lessonQuery = lessonDao.queryBuilder().where(LessonDao.Properties.DayId.eq(dayQuery.uniqueOrThrow().getId()), LessonDao.Properties.Date.eq(lesson.getDate()), - LessonDao.Properties.StartTime.eq(lesson.getStartTime()), LessonDao.Properties.EndTime.eq(lesson.getEndTime())).build(); - Lesson lesson1 = lessonQuery.unique(); + Lesson lesson1 = lessonDao.queryBuilder() + .where(LessonDao.Properties.DayId.eq(dayQuery.uniqueOrThrow().getId()), + LessonDao.Properties.Date.eq(lesson.getDate()), + LessonDao.Properties.StartTime.eq(lesson.getStartTime()), + LessonDao.Properties.EndTime.eq(lesson.getEndTime())) + .unique(); if (lesson1 != null) { lesson.setId(lesson1.getId()); @@ -94,15 +98,15 @@ public class TimetableSynchronization { return allLessonsList; } - private List getPreparedDaysList(List dayList, long userId, long weekId, DayDao dayDao) { - List updatedDayList = new ArrayList<>(); - List dayEntityList = ConversionVulcanObject + private List getPreparedDaysList(List dayList, long userId, long weekId, DayDao dayDao) { + List updatedDayList = new ArrayList<>(); + List dayEntityList = DataObjectConverter .daysToDaysEntities(dayList); - for (io.github.wulkanowy.dao.entities.Day day : dayEntityList) { + for (io.github.wulkanowy.db.dao.entities.Day day : dayEntityList) { - Query dayQuery = dayDao.queryBuilder().where(DayDao.Properties.UserId.eq(userId), DayDao.Properties.WeekId.eq(weekId), DayDao.Properties.Date.eq(day.getDate())).build(); + Query dayQuery = dayDao.queryBuilder().where(DayDao.Properties.UserId.eq(userId), DayDao.Properties.WeekId.eq(weekId), DayDao.Properties.Date.eq(day.getDate())).build(); - io.github.wulkanowy.dao.entities.Day day1 = dayQuery.unique(); + io.github.wulkanowy.db.dao.entities.Day day1 = dayQuery.unique(); if (day1 != null) { day.setId(day1.getId()); diff --git a/app/src/main/java/io/github/wulkanowy/services/VulcanSynchronization.java b/app/src/main/java/io/github/wulkanowy/services/sync/VulcanSync.java similarity index 65% rename from app/src/main/java/io/github/wulkanowy/services/VulcanSynchronization.java rename to app/src/main/java/io/github/wulkanowy/services/sync/VulcanSync.java index 0f66ee282..ee9ee15df 100644 --- a/app/src/main/java/io/github/wulkanowy/services/VulcanSynchronization.java +++ b/app/src/main/java/io/github/wulkanowy/services/sync/VulcanSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.services; +package io.github.wulkanowy.services.sync; import android.content.Context; import android.support.annotation.Nullable; @@ -12,24 +12,19 @@ import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.LoginErrorException; import io.github.wulkanowy.api.login.NotLoggedInErrorException; import io.github.wulkanowy.api.login.VulcanOfflineException; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.security.CryptoException; +import io.github.wulkanowy.db.dao.entities.DaoSession; import io.github.wulkanowy.services.jobs.VulcanJobHelper; -import io.github.wulkanowy.services.synchronisation.CurrentAccountLogin; -import io.github.wulkanowy.services.synchronisation.FirstAccountLogin; -import io.github.wulkanowy.services.synchronisation.GradesSynchronisation; -import io.github.wulkanowy.services.synchronisation.SubjectsSynchronisation; -import io.github.wulkanowy.services.synchronisation.TimetableSynchronization; +import io.github.wulkanowy.utils.security.CryptoException; -public class VulcanSynchronization { +public class VulcanSync { private LoginSession loginSession; - public VulcanSynchronization(LoginSession loginSession) { + public VulcanSync(LoginSession loginSession) { this.loginSession = loginSession; } - public VulcanSynchronization() { + public VulcanSync() { this.loginSession = new LoginSession(); } @@ -39,12 +34,12 @@ public class VulcanSynchronization { loginSession = firstAccountLogin.login(email, password, symbol); } - public VulcanSynchronization loginCurrentUser(Context context, DaoSession daoSession) throws CryptoException, + public VulcanSync loginCurrentUser(Context context, DaoSession daoSession) throws CryptoException, BadCredentialsException, AccountPermissionException, LoginErrorException, IOException, VulcanOfflineException { return loginCurrentUser(context, daoSession, new Vulcan()); } - public VulcanSynchronization loginCurrentUser(Context context, DaoSession daoSession, Vulcan vulcan) + public VulcanSync loginCurrentUser(Context context, DaoSession daoSession, Vulcan vulcan) throws CryptoException, BadCredentialsException, AccountPermissionException, LoginErrorException, IOException, VulcanOfflineException { @@ -60,31 +55,31 @@ public class VulcanSynchronization { public void syncGrades() throws IOException { if (loginSession != null) { - GradesSynchronisation gradesSynchronisation = new GradesSynchronisation(); + GradesSync gradesSync = new GradesSync(); try { - gradesSynchronisation.sync(loginSession); + gradesSync.sync(loginSession); } catch (Exception e) { Log.e(VulcanJobHelper.DEBUG_TAG, "Synchronisation of grades failed", e); throw new IOException(e.getCause()); } } else { - Log.e(VulcanJobHelper.DEBUG_TAG, "Before synchronization, should login user to log", + Log.e(VulcanJobHelper.DEBUG_TAG, "Before sync, should login user to log", new UnsupportedOperationException()); } } public void syncSubjectsAndGrades() throws IOException { if (loginSession != null) { - SubjectsSynchronisation subjectsSynchronisation = new SubjectsSynchronisation(); + SubjectsSync subjectsSync = new SubjectsSync(); try { - subjectsSynchronisation.sync(loginSession); + subjectsSync.sync(loginSession); syncGrades(); } catch (Exception e) { Log.e(VulcanJobHelper.DEBUG_TAG, "Synchronisation of subjects failed", e); throw new IOException(e.getCause()); } } else { - Log.e(VulcanJobHelper.DEBUG_TAG, "Before synchronization, should login user to log", + Log.e(VulcanJobHelper.DEBUG_TAG, "Before sync, should login user to log", new UnsupportedOperationException()); } } @@ -95,15 +90,15 @@ public class VulcanSynchronization { public void syncTimetable(@Nullable String date) throws IOException { if (loginSession != null) { - TimetableSynchronization timetableSynchronization = new TimetableSynchronization(); + TimetableSync timetableSync = new TimetableSync(); try { - timetableSynchronization.sync(loginSession, date); + timetableSync.sync(loginSession, date); } catch (Exception e) { Log.e(VulcanJobHelper.DEBUG_TAG, "Synchronization of timetable failed", e); throw new IOException(e.getCause()); } } else { - Log.e(VulcanJobHelper.DEBUG_TAG, "Before synchronization, should login user to log", + Log.e(VulcanJobHelper.DEBUG_TAG, "Before sync, should login user to log", new UnsupportedOperationException()); } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java b/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java index 322e75c22..713f71a51 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java +++ b/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java @@ -1,7 +1,6 @@ package io.github.wulkanowy.ui.login; import android.app.Activity; -import android.content.Context; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; @@ -12,7 +11,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; @@ -23,6 +21,7 @@ import java.util.LinkedHashMap; import io.github.wulkanowy.R; import io.github.wulkanowy.services.Updater; +import io.github.wulkanowy.utils.KeyboardUtils; /** * A login screen that offers login via email/password. @@ -178,7 +177,7 @@ public class LoginActivity extends Activity { LoginTask authTask = new LoginTask(this, email, password, symbol); authTask.showProgress(true); authTask.execute(); - hideSoftKeyboard(); + KeyboardUtils.hideSoftInput(this); } } @@ -190,15 +189,6 @@ public class LoginActivity extends Activity { return password.length() > 4; } - private void hideSoftKeyboard() { - InputMethodManager manager = (InputMethodManager) - getSystemService(Context.INPUT_METHOD_SERVICE); - if (manager != null) { - manager.hideSoftInputFromWindow(getWindow() - .getDecorView().getApplicationWindowToken(), 0); - } - } - @Override public boolean dispatchTouchEvent(MotionEvent ev) { @@ -220,7 +210,7 @@ public class LoginActivity extends Activity { float y = ev.getRawY() + view.getTop() - coordinators[1]; if (x < view.getLeft() || x > view.getRight() || y < view.getTop() || y > view.getBottom()) { - hideSoftKeyboard(); + KeyboardUtils.hideSoftInput(this); } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java b/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java index 37b141220..6e8a5596d 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java +++ b/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java @@ -3,7 +3,6 @@ package io.github.wulkanowy.ui.login; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.app.Activity; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; @@ -11,7 +10,6 @@ import android.support.design.widget.Snackbar; import android.support.design.widget.TextInputLayout; import android.support.v7.app.AlertDialog; import android.view.View; -import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; @@ -21,18 +19,19 @@ import java.net.SocketTimeoutException; import java.net.UnknownHostException; import io.github.wulkanowy.R; +import io.github.wulkanowy.WulkanowyApp; import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.NotLoggedInErrorException; import io.github.wulkanowy.api.login.VulcanOfflineException; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.security.CryptoException; -import io.github.wulkanowy.services.LoginSession; -import io.github.wulkanowy.services.VulcanSynchronization; +import io.github.wulkanowy.db.dao.entities.DaoSession; import io.github.wulkanowy.services.jobs.FullSyncJob; -import io.github.wulkanowy.ui.WulkanowyApp; +import io.github.wulkanowy.services.sync.LoginSession; +import io.github.wulkanowy.services.sync.VulcanSync; import io.github.wulkanowy.ui.main.DashboardActivity; -import io.github.wulkanowy.utilities.ConnectionUtilities; +import io.github.wulkanowy.utils.KeyboardUtils; +import io.github.wulkanowy.utils.NetworkUtils; +import io.github.wulkanowy.utils.security.CryptoException; /** * Represents an asynchronous login/registration task used to authenticate @@ -68,16 +67,16 @@ public class LoginTask extends AsyncTask { @Override protected Integer doInBackground(Void... params) { - if (ConnectionUtilities.isOnline(activity.get())) { + if (NetworkUtils.isOnline(activity.get())) { DaoSession daoSession = ((WulkanowyApp) activity.get().getApplication()).getDaoSession(); - VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession()); + VulcanSync vulcanSync = new VulcanSync(new LoginSession()); try { publishProgress("1", activity.get().getResources().getString(R.string.step_login)); - vulcanSynchronization.firstLoginSignInStep(activity.get(), daoSession, email, password, symbol); + vulcanSync.firstLoginSignInStep(activity.get(), daoSession, email, password, symbol); publishProgress("2", activity.get().getResources().getString(R.string.step_synchronization)); - vulcanSynchronization.syncAll(); + vulcanSync.syncAll(); } catch (BadCredentialsException e) { return R.string.login_bad_credentials_text; } catch (AccountPermissionException e) { @@ -127,7 +126,7 @@ public class LoginTask extends AsyncTask { EditText passwordView = activity.get().findViewById(R.id.password); passwordView.setError(activity.get().getString(R.string.error_incorrect_password)); passwordView.requestFocus(); - showSoftKeyboard(passwordView); + KeyboardUtils.showSoftInput(passwordView, activity.get()); break; // if no permission @@ -139,7 +138,7 @@ public class LoginTask extends AsyncTask { EditText symbolView = activity.get().findViewById(R.id.symbol); symbolView.setError(activity.get().getString(R.string.error_bad_account_permission)); symbolView.requestFocus(); - showSoftKeyboard(symbolView); + KeyboardUtils.showSoftInput(symbolView, activity.get()); break; // if rooted and SDK < 18 @@ -182,15 +181,6 @@ public class LoginTask extends AsyncTask { changeProgressVisibility(show, animTime); } - private void showSoftKeyboard(EditText editText) { - InputMethodManager manager = (InputMethodManager) - activity.get().getSystemService(Context.INPUT_METHOD_SERVICE); - if (manager != null) { - manager.showSoftInput(editText, - InputMethodManager.SHOW_IMPLICIT); - } - } - private void changeLoginFormVisibility(final boolean show, final int animTime) { loginFormView.get().setVisibility(show ? View.GONE : View.VISIBLE); loginFormView.get().animate().setDuration(animTime).alpha( diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/AbstractFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/AbstractFragment.java index 161fd7358..681aa751e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/AbstractFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/AbstractFragment.java @@ -22,9 +22,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager; import eu.davidea.flexibleadapter.items.AbstractExpandableHeaderItem; import io.github.wulkanowy.R; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.ui.WulkanowyApp; -import io.github.wulkanowy.utilities.ConnectionUtilities; +import io.github.wulkanowy.WulkanowyApp; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.utils.NetworkUtils; public abstract class AbstractFragment extends Fragment implements AsyncResponse { @@ -158,7 +158,7 @@ public abstract class AbstractFragment e return new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - if (ConnectionUtilities.isOnline(getContext())) { + if (NetworkUtils.isOnline(getContext())) { new RefreshTask(AbstractFragment.this).execute(); } else { Toast.makeText(getContext(), R.string.noInternet_text, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java b/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java index 5ea01d65c..67697ba9f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java @@ -42,7 +42,7 @@ public class RefreshTask extends AsyncTask> { return null; } catch (Exception e) { stringEventId = R.string.refresh_error_text; - Log.e(DEBUG_TAG, "There was a synchronization problem", e); + Log.e(DEBUG_TAG, "There was a sync problem", e); return null; } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesAdapter.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesAdapter.java index a50c15277..36742fec1 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesAdapter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesAdapter.java @@ -18,8 +18,8 @@ import java.lang.ref.WeakReference; import java.util.List; import io.github.wulkanowy.R; -import io.github.wulkanowy.dao.entities.Grade; -import io.github.wulkanowy.utilities.AverageCalculator; +import io.github.wulkanowy.db.dao.entities.Grade; +import io.github.wulkanowy.utils.AverageCalculator; public class GradesAdapter extends ExpandableRecyclerViewAdapter { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesDialogFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesDialogFragment.java index 8370034a0..e566d5c6a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesDialogFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesDialogFragment.java @@ -13,7 +13,7 @@ import android.widget.Button; import android.widget.TextView; import io.github.wulkanowy.R; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Grade; public class GradesDialogFragment extends DialogFragment { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java index 985002f5f..074837766 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java @@ -21,19 +21,19 @@ import java.util.ArrayList; import java.util.List; import io.github.wulkanowy.R; +import io.github.wulkanowy.WulkanowyApp; import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.login.VulcanOfflineException; -import io.github.wulkanowy.dao.DatabaseAccess; -import io.github.wulkanowy.dao.entities.Account; -import io.github.wulkanowy.dao.entities.AccountDao; -import io.github.wulkanowy.dao.entities.DaoSession; -import io.github.wulkanowy.dao.entities.Grade; -import io.github.wulkanowy.dao.entities.Subject; -import io.github.wulkanowy.services.LoginSession; -import io.github.wulkanowy.services.VulcanSynchronization; +import io.github.wulkanowy.db.dao.DatabaseAccess; +import io.github.wulkanowy.db.dao.entities.Account; +import io.github.wulkanowy.db.dao.entities.AccountDao; +import io.github.wulkanowy.db.dao.entities.DaoSession; +import io.github.wulkanowy.db.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Subject; import io.github.wulkanowy.services.jobs.VulcanJobHelper; -import io.github.wulkanowy.ui.WulkanowyApp; -import io.github.wulkanowy.utilities.ConnectionUtilities; +import io.github.wulkanowy.services.sync.LoginSession; +import io.github.wulkanowy.services.sync.VulcanSync; +import io.github.wulkanowy.utils.NetworkUtils; public class GradesFragment extends Fragment { @@ -106,7 +106,7 @@ public class GradesFragment extends Fragment { swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - if (ConnectionUtilities.isOnline(getContext())) { + if (NetworkUtils.isOnline(getContext())) { new RefreshTask(getActivity(), mainView, daoSession).execute(); } else { Toast.makeText(mainView.getContext(), R.string.noInternet_text, Toast.LENGTH_SHORT).show(); @@ -163,17 +163,17 @@ public class GradesFragment extends Fragment { @Override protected Integer doInBackground(Void... params) { - VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession()); + VulcanSync vulcanSync = new VulcanSync(new LoginSession()); try { - vulcanSynchronization.loginCurrentUser(activity.get(), daoSession, new Vulcan()); - vulcanSynchronization.syncGrades(); + vulcanSync.loginCurrentUser(activity.get(), daoSession, new Vulcan()); + vulcanSync.syncGrades(); downloadGradesFormDatabase(daoSession); return 1; } catch (VulcanOfflineException e) { - Log.e(VulcanJobHelper.DEBUG_TAG, "There was a synchronization problem, because vulcan is offline", e); + Log.e(VulcanJobHelper.DEBUG_TAG, "There was a sync problem, because vulcan is offline", e); return R.string.error_host_offline; } catch (Exception e) { - Log.e(VulcanJobHelper.DEBUG_TAG, "There was a synchronization problem", e); + Log.e(VulcanJobHelper.DEBUG_TAG, "There was a sync problem", e); return R.string.refresh_error_text; } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/SubjectWithGrades.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/SubjectWithGrades.java index 38d630e42..b343c2006 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/SubjectWithGrades.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/SubjectWithGrades.java @@ -5,7 +5,7 @@ import com.thoughtbot.expandablerecyclerview.models.ExpandableGroup; import java.util.List; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Grade; public class SubjectWithGrades extends ExpandableGroup { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableDialogFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableDialogFragment.java index 54380b8fa..3845d26c0 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableDialogFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableDialogFragment.java @@ -14,7 +14,7 @@ import android.widget.TextView; import org.apache.commons.lang3.StringUtils; import io.github.wulkanowy.R; -import io.github.wulkanowy.dao.entities.Lesson; +import io.github.wulkanowy.db.dao.entities.Lesson; public class TimetableDialogFragment extends DialogFragment { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragment.java index 3801e9ac1..ec25c7dd7 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragment.java @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.List; import io.github.wulkanowy.R; -import io.github.wulkanowy.utilities.TimeUtilities; +import io.github.wulkanowy.utils.TimeUtils; public class TimetableFragment extends Fragment { @@ -81,7 +81,7 @@ public class TimetableFragment extends Fragment { private void setDateStringList() { if (dateStringList.isEmpty()) { - dateStringList = TimeUtilities.getMondaysFromCurrentSchoolYear(DATE_PATTERN); + dateStringList = TimeUtils.getMondaysFromCurrentSchoolYear(DATE_PATTERN); } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragmentTab.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragmentTab.java index b77394b79..12a38daa3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragmentTab.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableFragmentTab.java @@ -17,11 +17,11 @@ import java.util.ArrayList; import java.util.List; import io.github.wulkanowy.R; -import io.github.wulkanowy.dao.entities.Day; -import io.github.wulkanowy.dao.entities.Lesson; -import io.github.wulkanowy.dao.entities.Week; -import io.github.wulkanowy.dao.entities.WeekDao; -import io.github.wulkanowy.services.VulcanSynchronization; +import io.github.wulkanowy.db.dao.entities.Day; +import io.github.wulkanowy.db.dao.entities.Lesson; +import io.github.wulkanowy.db.dao.entities.Week; +import io.github.wulkanowy.db.dao.entities.WeekDao; +import io.github.wulkanowy.services.sync.VulcanSync; import io.github.wulkanowy.ui.main.AbstractFragment; public class TimetableFragmentTab extends AbstractFragment { @@ -119,7 +119,7 @@ public class TimetableFragmentTab extends AbstractFragment @Override public void onRefresh() throws Exception { - VulcanSynchronization synchronization = new VulcanSynchronization(); + VulcanSync synchronization = new VulcanSync(); synchronization.loginCurrentUser(getContext(), getDaoSession()); synchronization.syncTimetable(date); } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java index 6355c1cb5..e40c6689a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java @@ -14,7 +14,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.items.AbstractExpandableHeaderItem; import eu.davidea.viewholders.ExpandableViewHolder; import io.github.wulkanowy.R; -import io.github.wulkanowy.dao.entities.Day; +import io.github.wulkanowy.db.dao.entities.Day; public class TimetableHeaderItem extends AbstractExpandableHeaderItem { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableSubItem.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableSubItem.java index cdbf99420..025f50317 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableSubItem.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableSubItem.java @@ -15,7 +15,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.items.AbstractSectionableItem; import eu.davidea.viewholders.FlexibleViewHolder; import io.github.wulkanowy.R; -import io.github.wulkanowy.dao.entities.Lesson; +import io.github.wulkanowy.db.dao.entities.Lesson; + public class TimetableSubItem extends AbstractSectionableItem { diff --git a/app/src/main/java/io/github/wulkanowy/utilities/ConnectionUtilities.java b/app/src/main/java/io/github/wulkanowy/utilities/ConnectionUtilities.java deleted file mode 100644 index 4701cf5a8..000000000 --- a/app/src/main/java/io/github/wulkanowy/utilities/ConnectionUtilities.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.wulkanowy.utilities; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - -public class ConnectionUtilities { - - private ConnectionUtilities() { - throw new IllegalStateException("Utility class"); - } - - public static boolean isOnline(Context context) { - ConnectivityManager connectivityManager = - (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (connectivityManager != null) { - NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); - return networkInfo != null && networkInfo.isConnectedOrConnecting(); - } else { - return false; - } - } -} diff --git a/app/src/main/java/io/github/wulkanowy/utilities/RootUtilities.java b/app/src/main/java/io/github/wulkanowy/utilities/RootUtilities.java deleted file mode 100644 index b7320c14e..000000000 --- a/app/src/main/java/io/github/wulkanowy/utilities/RootUtilities.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.wulkanowy.utilities; - -import android.os.Build; - -import java.io.File; - -public class RootUtilities { - - private RootUtilities() { - throw new IllegalStateException("Utility class"); - } - - public static boolean isRooted() { - String buildTags = Build.TAGS; - if (buildTags != null && buildTags.contains("test-keys")) { - return true; - } - - try { - File file = new File("/system/app/Superuser.apk"); - if (file.exists()) { - return true; - } - } catch (Exception e) { - // ignore - } - return canExecuteCommand("/system/xbin/which su") - || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su"); - } - - private static boolean canExecuteCommand(String command) { - boolean executedSuccesfully; - try { - Runtime.getRuntime().exec(command); - executedSuccesfully = true; - } catch (Exception e) { - executedSuccesfully = false; - } - return executedSuccesfully; - } -} diff --git a/app/src/main/java/io/github/wulkanowy/utilities/AverageCalculator.java b/app/src/main/java/io/github/wulkanowy/utils/AverageCalculator.java similarity index 72% rename from app/src/main/java/io/github/wulkanowy/utilities/AverageCalculator.java rename to app/src/main/java/io/github/wulkanowy/utils/AverageCalculator.java index 9c665fd41..e7640c917 100644 --- a/app/src/main/java/io/github/wulkanowy/utilities/AverageCalculator.java +++ b/app/src/main/java/io/github/wulkanowy/utils/AverageCalculator.java @@ -1,10 +1,10 @@ -package io.github.wulkanowy.utilities; +package io.github.wulkanowy.utils; import java.util.List; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Grade; -public class AverageCalculator { +public final class AverageCalculator { private AverageCalculator() { throw new IllegalStateException("Utility class"); @@ -33,14 +33,18 @@ public class AverageCalculator { } private static float getMathematicalValueOfGrade(String valueOfGrade) { - if (valueOfGrade.matches("[-|+|=]{0,2}[0-6]") || valueOfGrade.matches("[0-6][-|+|=]{0,2}")) { - if (valueOfGrade.matches("[-][0-6]") || valueOfGrade.matches("[0-6][-]")) { + if (valueOfGrade.matches("[-|+|=]{0,2}[0-6]") + || valueOfGrade.matches("[0-6][-|+|=]{0,2}")) { + if (valueOfGrade.matches("[-][0-6]") + || valueOfGrade.matches("[0-6][-]")) { String replacedValue = valueOfGrade.replaceAll("[-]", ""); return Float.valueOf(replacedValue) - 0.25f; - } else if (valueOfGrade.matches("[+][0-6]") || valueOfGrade.matches("[0-6][+]")) { + } else if (valueOfGrade.matches("[+][0-6]") + || valueOfGrade.matches("[0-6][+]")) { String replacedValue = valueOfGrade.replaceAll("[+]", ""); return Float.valueOf((replacedValue)) + 0.25f; - } else if (valueOfGrade.matches("[-|=]{1,2}[0-6]") || valueOfGrade.matches("[0-6][-|=]{1,2}")) { + } else if (valueOfGrade.matches("[-|=]{1,2}[0-6]") + || valueOfGrade.matches("[0-6][-|=]{1,2}")) { String replacedValue = valueOfGrade.replaceAll("[-|=]{1,2}", ""); return Float.valueOf((replacedValue)) - 0.5f; } else { diff --git a/app/src/main/java/io/github/wulkanowy/utilities/ConversionVulcanObject.java b/app/src/main/java/io/github/wulkanowy/utils/DataObjectConverter.java similarity index 90% rename from app/src/main/java/io/github/wulkanowy/utilities/ConversionVulcanObject.java rename to app/src/main/java/io/github/wulkanowy/utils/DataObjectConverter.java index 6cd456fb7..fcede01d9 100644 --- a/app/src/main/java/io/github/wulkanowy/utilities/ConversionVulcanObject.java +++ b/app/src/main/java/io/github/wulkanowy/utils/DataObjectConverter.java @@ -1,18 +1,18 @@ -package io.github.wulkanowy.utilities; +package io.github.wulkanowy.utils; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.dao.entities.Day; -import io.github.wulkanowy.dao.entities.Grade; -import io.github.wulkanowy.dao.entities.Lesson; -import io.github.wulkanowy.dao.entities.Subject; -import io.github.wulkanowy.dao.entities.Week; +import io.github.wulkanowy.db.dao.entities.Day; +import io.github.wulkanowy.db.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Lesson; +import io.github.wulkanowy.db.dao.entities.Subject; +import io.github.wulkanowy.db.dao.entities.Week; -public class ConversionVulcanObject { +public final class DataObjectConverter { - private ConversionVulcanObject() { + private DataObjectConverter() { throw new IllegalStateException("Utility class"); } diff --git a/app/src/main/java/io/github/wulkanowy/dao/EntitiesCompare.java b/app/src/main/java/io/github/wulkanowy/utils/EntitiesCompare.java similarity index 71% rename from app/src/main/java/io/github/wulkanowy/dao/EntitiesCompare.java rename to app/src/main/java/io/github/wulkanowy/utils/EntitiesCompare.java index 4b815d772..878db5c36 100644 --- a/app/src/main/java/io/github/wulkanowy/dao/EntitiesCompare.java +++ b/app/src/main/java/io/github/wulkanowy/utils/EntitiesCompare.java @@ -1,13 +1,13 @@ -package io.github.wulkanowy.dao; +package io.github.wulkanowy.utils; import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Grade; -public class EntitiesCompare { +public final class EntitiesCompare { private EntitiesCompare() { throw new IllegalStateException("Utility class"); @@ -29,13 +29,13 @@ public class EntitiesCompare { updatedList.add(grade); } - for (Grade grade : updatedList) { - for (Grade grade1 : oldList) { - if (grade.equals(grade1)) { - grade.setRead(grade1.getRead()); + for (Grade updateGrade : updatedList) { + for (Grade oldGrade : oldList) { + if (updateGrade.equals(oldGrade)) { + updateGrade.setRead(oldGrade.getRead()); } } - lastList.add(grade); + lastList.add(updateGrade); } return lastList; } diff --git a/app/src/main/java/io/github/wulkanowy/utils/KeyboardUtils.java b/app/src/main/java/io/github/wulkanowy/utils/KeyboardUtils.java new file mode 100644 index 000000000..6be1b76f4 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/utils/KeyboardUtils.java @@ -0,0 +1,33 @@ +package io.github.wulkanowy.utils; + +import android.app.Activity; +import android.content.Context; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +public final class KeyboardUtils { + + private KeyboardUtils() { + throw new IllegalStateException("Utility class"); + } + + public static void hideSoftInput(Activity activity) { + InputMethodManager manager = (InputMethodManager) + activity.getSystemService(Context.INPUT_METHOD_SERVICE); + if (manager != null) { + manager.hideSoftInputFromWindow(activity.getWindow() + .getDecorView().getApplicationWindowToken(), 0); + } + } + + public static void showSoftInput(EditText editText, Context context) { + editText.setFocusable(true); + editText.setFocusableInTouchMode(true); + editText.requestFocus(); + InputMethodManager inputMethodManager = (InputMethodManager) context + .getSystemService(Context.INPUT_METHOD_SERVICE); + if (inputMethodManager != null) { + inputMethodManager.showSoftInput(editText, 0); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/github/wulkanowy/utils/NetworkUtils.java b/app/src/main/java/io/github/wulkanowy/utils/NetworkUtils.java new file mode 100644 index 000000000..a1484eb9e --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/utils/NetworkUtils.java @@ -0,0 +1,18 @@ +package io.github.wulkanowy.utils; + +import android.content.Context; +import android.net.ConnectivityManager; + +public final class NetworkUtils { + + private NetworkUtils() { + throw new IllegalStateException("Utility class"); + } + + public static boolean isOnline(Context context) { + ConnectivityManager connectivityManager = + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + return connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null + && connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting(); + } +} diff --git a/app/src/main/java/io/github/wulkanowy/utils/RootChecker.java b/app/src/main/java/io/github/wulkanowy/utils/RootChecker.java new file mode 100644 index 000000000..9c23c217f --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/utils/RootChecker.java @@ -0,0 +1,38 @@ +package io.github.wulkanowy.utils; + +import android.os.Build; + +import java.io.File; + +public final class RootChecker { + + private RootChecker() { + throw new IllegalStateException("Utility class"); + } + + public static boolean isRooted() { + return checkOne() || checkTwo() || checkThree(); + } + + private static boolean checkOne() { + return Build.TAGS != null && Build.TAGS.contains("test-keys"); + } + + private static boolean checkTwo() { + return new File("/system/app/Superuser.apk").exists(); + } + + private static boolean checkThree() { + String[] commands = {"/system/xbin/which su", "/system/bin/which su", "which su"}; + for (String command : commands) { + try { + Runtime.getRuntime().exec(command); + return true; + } catch (Exception e) { + // ignore + } + } + return false; + } + +} diff --git a/app/src/main/java/io/github/wulkanowy/utilities/TimeUtilities.java b/app/src/main/java/io/github/wulkanowy/utils/TimeUtils.java similarity index 95% rename from app/src/main/java/io/github/wulkanowy/utilities/TimeUtilities.java rename to app/src/main/java/io/github/wulkanowy/utils/TimeUtils.java index 1f3086521..70a8ec5fa 100644 --- a/app/src/main/java/io/github/wulkanowy/utilities/TimeUtilities.java +++ b/app/src/main/java/io/github/wulkanowy/utils/TimeUtils.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.utilities; +package io.github.wulkanowy.utils; import org.joda.time.DateTime; import org.joda.time.DateTimeConstants; @@ -13,13 +13,13 @@ import java.util.List; import java.util.Locale; import java.util.TimeZone; -public class TimeUtilities { +public final class TimeUtils { private static final long TICKS_AT_EPOCH = 621355968000000000L; private static final long TICKS_PER_MILLISECOND = 10000; - private TimeUtilities() { + private TimeUtils() { throw new IllegalStateException("Utility class"); } diff --git a/app/src/main/java/io/github/wulkanowy/security/CryptoException.java b/app/src/main/java/io/github/wulkanowy/utils/security/CryptoException.java similarity index 74% rename from app/src/main/java/io/github/wulkanowy/security/CryptoException.java rename to app/src/main/java/io/github/wulkanowy/utils/security/CryptoException.java index 62abcf76e..1ee4a9fa8 100644 --- a/app/src/main/java/io/github/wulkanowy/security/CryptoException.java +++ b/app/src/main/java/io/github/wulkanowy/utils/security/CryptoException.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.security; +package io.github.wulkanowy.utils.security; public class CryptoException extends Exception { diff --git a/app/src/main/java/io/github/wulkanowy/security/Safety.java b/app/src/main/java/io/github/wulkanowy/utils/security/Safety.java similarity index 88% rename from app/src/main/java/io/github/wulkanowy/security/Safety.java rename to app/src/main/java/io/github/wulkanowy/utils/security/Safety.java index f55f7518c..ca7808753 100644 --- a/app/src/main/java/io/github/wulkanowy/security/Safety.java +++ b/app/src/main/java/io/github/wulkanowy/utils/security/Safety.java @@ -1,10 +1,10 @@ -package io.github.wulkanowy.security; +package io.github.wulkanowy.utils.security; import android.content.Context; import android.os.Build; import android.util.Base64; -import io.github.wulkanowy.utilities.RootUtilities; +import io.github.wulkanowy.utils.RootChecker; public class Safety extends Scrambler { @@ -15,7 +15,7 @@ public class Safety extends Scrambler { generateNewKey(email, context); return encryptString(email, plainText); } else { - if (RootUtilities.isRooted()) { + if (RootChecker.isRooted()) { return new String(Base64.encode(plainText.getBytes(), Base64.DEFAULT)); } else { throw new UnsupportedOperationException("Stored data in this devices isn't safe because android is rooted"); diff --git a/app/src/main/java/io/github/wulkanowy/security/Scrambler.java b/app/src/main/java/io/github/wulkanowy/utils/security/Scrambler.java similarity index 99% rename from app/src/main/java/io/github/wulkanowy/security/Scrambler.java rename to app/src/main/java/io/github/wulkanowy/utils/security/Scrambler.java index 1c32af292..62ffbd725 100644 --- a/app/src/main/java/io/github/wulkanowy/security/Scrambler.java +++ b/app/src/main/java/io/github/wulkanowy/utils/security/Scrambler.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.security; +package io.github.wulkanowy.utils.security; import android.annotation.TargetApi; diff --git a/app/src/test/java/io/github/wulkanowy/dao/entities/GradeTest.java b/app/src/test/java/io/github/wulkanowy/db/dao/entities/GradeTest.java similarity index 97% rename from app/src/test/java/io/github/wulkanowy/dao/entities/GradeTest.java rename to app/src/test/java/io/github/wulkanowy/db/dao/entities/GradeTest.java index 176f42262..54a67d026 100644 --- a/app/src/test/java/io/github/wulkanowy/dao/entities/GradeTest.java +++ b/app/src/test/java/io/github/wulkanowy/db/dao/entities/GradeTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.dao.entities; +package io.github.wulkanowy.db.dao.entities; import org.junit.Assert; import org.junit.Test; diff --git a/app/src/test/java/io/github/wulkanowy/ui/main/grades/SubjectWithGradesTest.java b/app/src/test/java/io/github/wulkanowy/ui/main/grades/SubjectWithGradesTest.java index 8b2991577..2b2710170 100644 --- a/app/src/test/java/io/github/wulkanowy/ui/main/grades/SubjectWithGradesTest.java +++ b/app/src/test/java/io/github/wulkanowy/ui/main/grades/SubjectWithGradesTest.java @@ -7,7 +7,7 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Grade; public class SubjectWithGradesTest { diff --git a/app/src/test/java/io/github/wulkanowy/utilities/AverageCalculatorTest.java b/app/src/test/java/io/github/wulkanowy/utils/AverageCalculatorTest.java similarity index 94% rename from app/src/test/java/io/github/wulkanowy/utilities/AverageCalculatorTest.java rename to app/src/test/java/io/github/wulkanowy/utils/AverageCalculatorTest.java index 303930cf1..113e342ed 100644 --- a/app/src/test/java/io/github/wulkanowy/utilities/AverageCalculatorTest.java +++ b/app/src/test/java/io/github/wulkanowy/utils/AverageCalculatorTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.utilities; +package io.github.wulkanowy.utils; import org.junit.Assert; import org.junit.Test; @@ -6,7 +6,7 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Grade; public class AverageCalculatorTest { diff --git a/app/src/test/java/io/github/wulkanowy/utilities/ConversionVulcanObjectTest.java b/app/src/test/java/io/github/wulkanowy/utils/DataObjectConverterTest.java similarity index 62% rename from app/src/test/java/io/github/wulkanowy/utilities/ConversionVulcanObjectTest.java rename to app/src/test/java/io/github/wulkanowy/utils/DataObjectConverterTest.java index 8414cf7af..c619d9d6e 100644 --- a/app/src/test/java/io/github/wulkanowy/utilities/ConversionVulcanObjectTest.java +++ b/app/src/test/java/io/github/wulkanowy/utils/DataObjectConverterTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.utilities; +package io.github.wulkanowy.utils; import org.junit.Assert; import org.junit.Test; @@ -11,14 +11,14 @@ import io.github.wulkanowy.api.grades.Subject; import io.github.wulkanowy.api.timetable.Day; import io.github.wulkanowy.api.timetable.Lesson; -public class ConversionVulcanObjectTest { +public class DataObjectConverterTest { @Test public void subjectConversionTest() { List subjectList = new ArrayList<>(); subjectList.add(new Subject().setName("Matematyka")); - List subjectEntitiesList = - ConversionVulcanObject.subjectsToSubjectEntities(subjectList); + List subjectEntitiesList = + DataObjectConverter.subjectsToSubjectEntities(subjectList); Assert.assertEquals("Matematyka", subjectEntitiesList.get(0).getName()); } @@ -26,15 +26,15 @@ public class ConversionVulcanObjectTest { @Test public void subjectConversionEmptyTest() { Assert.assertEquals(new ArrayList<>(), - ConversionVulcanObject.subjectsToSubjectEntities(new ArrayList())); + DataObjectConverter.subjectsToSubjectEntities(new ArrayList())); } @Test public void gradesConversionTest() { List gradeList = new ArrayList<>(); gradeList.add(new Grade().setDescription("Lorem ipsum")); - List gradeEntitiesList = - ConversionVulcanObject.gradesToGradeEntities(gradeList); + List gradeEntitiesList = + DataObjectConverter.gradesToGradeEntities(gradeList); Assert.assertEquals("Lorem ipsum", gradeEntitiesList.get(0).getDescription()); } @@ -42,21 +42,21 @@ public class ConversionVulcanObjectTest { @Test public void gradeConversionEmptyTest() { Assert.assertEquals(new ArrayList<>(), - ConversionVulcanObject.gradesToGradeEntities(new ArrayList())); + DataObjectConverter.gradesToGradeEntities(new ArrayList())); } @Test public void dayConversionEmptyTest() { Assert.assertEquals(new ArrayList<>(), - ConversionVulcanObject.daysToDaysEntities(new ArrayList())); + DataObjectConverter.daysToDaysEntities(new ArrayList())); } @Test public void dayConversionTest() { List dayList = new ArrayList<>(); dayList.add(new Day().setDate("20.12.2012")); - List dayEntityList = - ConversionVulcanObject.daysToDaysEntities(dayList); + List dayEntityList = + DataObjectConverter.daysToDaysEntities(dayList); Assert.assertEquals("20.12.2012", dayEntityList.get(0).getDate()); } @@ -64,15 +64,15 @@ public class ConversionVulcanObjectTest { @Test public void lessonConversionEmptyTest() { Assert.assertEquals(new ArrayList<>(), - ConversionVulcanObject.lessonsToLessonsEntities(new ArrayList())); + DataObjectConverter.lessonsToLessonsEntities(new ArrayList())); } @Test public void lessonConversionTest() { List lessonList = new ArrayList<>(); lessonList.add(new Lesson().setRoom("20")); - List lessonEntityList = - ConversionVulcanObject.lessonsToLessonsEntities(lessonList); + List lessonEntityList = + DataObjectConverter.lessonsToLessonsEntities(lessonList); Assert.assertEquals("20", lessonEntityList.get(0).getRoom()); } diff --git a/app/src/test/java/io/github/wulkanowy/dao/EntitiesCompareTest.java b/app/src/test/java/io/github/wulkanowy/utils/EntitiesCompareTest.java similarity index 97% rename from app/src/test/java/io/github/wulkanowy/dao/EntitiesCompareTest.java rename to app/src/test/java/io/github/wulkanowy/utils/EntitiesCompareTest.java index a5e84d7f3..f06cf07c5 100644 --- a/app/src/test/java/io/github/wulkanowy/dao/EntitiesCompareTest.java +++ b/app/src/test/java/io/github/wulkanowy/utils/EntitiesCompareTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.dao; +package io.github.wulkanowy.utils; import org.junit.Assert; import org.junit.Before; @@ -7,7 +7,7 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.dao.entities.Grade; +import io.github.wulkanowy.db.dao.entities.Grade; public class EntitiesCompareTest { diff --git a/app/src/test/java/io/github/wulkanowy/utilities/ConnectionUtilitiesTest.java b/app/src/test/java/io/github/wulkanowy/utils/NetworkUtilsTest.java similarity index 85% rename from app/src/test/java/io/github/wulkanowy/utilities/ConnectionUtilitiesTest.java rename to app/src/test/java/io/github/wulkanowy/utils/NetworkUtilsTest.java index 12decc077..bfcb156c3 100644 --- a/app/src/test/java/io/github/wulkanowy/utilities/ConnectionUtilitiesTest.java +++ b/app/src/test/java/io/github/wulkanowy/utils/NetworkUtilsTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.utilities; +package io.github.wulkanowy.utils; import android.content.Context; import android.net.ConnectivityManager; @@ -10,7 +10,7 @@ import org.junit.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class ConnectionUtilitiesTest { +public class NetworkUtilsTest { @Test public void isOnlineTrueTest() { @@ -23,7 +23,7 @@ public class ConnectionUtilitiesTest { Context context = mock(Context.class); when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager); - Assert.assertTrue(ConnectionUtilities.isOnline(context)); + Assert.assertTrue(NetworkUtils.isOnline(context)); } @Test @@ -37,6 +37,6 @@ public class ConnectionUtilitiesTest { Context context = mock(Context.class); when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager); - Assert.assertFalse(ConnectionUtilities.isOnline(context)); + Assert.assertFalse(NetworkUtils.isOnline(context)); } } diff --git a/app/src/test/java/io/github/wulkanowy/utilities/TimeUtilitiesTest.java b/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.java similarity index 57% rename from app/src/test/java/io/github/wulkanowy/utilities/TimeUtilitiesTest.java rename to app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.java index 7be625d4d..3c29ce02c 100644 --- a/app/src/test/java/io/github/wulkanowy/utilities/TimeUtilitiesTest.java +++ b/app/src/test/java/io/github/wulkanowy/utils/TimeUtilsTest.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.utilities; +package io.github.wulkanowy.utils; import org.junit.Assert; import org.junit.Test; @@ -11,7 +11,7 @@ import java.util.Date; import java.util.Locale; import java.util.TimeZone; -public class TimeUtilitiesTest { +public class TimeUtilsTest { @Test public void getTicksDateObjectTest() throws Exception { @@ -19,32 +19,32 @@ public class TimeUtilitiesTest { format.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = format.parse("31.07.2017"); - Assert.assertEquals(636370560000000000L, TimeUtilities.getNetTicks(date)); + Assert.assertEquals(636370560000000000L, TimeUtils.getNetTicks(date)); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_YEAR, -14); Date dateTwoWeekBefore = calendar.getTime(); - Assert.assertEquals(636358464000000000L, TimeUtilities.getNetTicks(dateTwoWeekBefore)); + Assert.assertEquals(636358464000000000L, TimeUtils.getNetTicks(dateTwoWeekBefore)); } @Test(expected = ParseException.class) public void getTicsStringInvalidFormatTest() throws Exception { - Assert.assertEquals(636370560000000000L, TimeUtilities.getNetTicks("31.07.2017", "dd.MMM.yyyy")); + Assert.assertEquals(636370560000000000L, TimeUtils.getNetTicks("31.07.2017", "dd.MMM.yyyy")); } @Test public void getTicsStringFormatTest() throws Exception { - Assert.assertEquals(636370560000000000L, TimeUtilities.getNetTicks("31.07.2017", "dd.MM.yyyy")); + Assert.assertEquals(636370560000000000L, TimeUtils.getNetTicks("31.07.2017", "dd.MM.yyyy")); } @Test public void getTicsStringTest() throws Exception { - Assert.assertEquals(636370560000000000L, TimeUtilities.getNetTicks("31.07.2017")); - Assert.assertEquals(636334272000000000L, TimeUtilities.getNetTicks("19.06.2017")); - Assert.assertEquals(636189120000000000L, TimeUtilities.getNetTicks("02.01.2017")); - Assert.assertEquals(636080256000000000L, TimeUtilities.getNetTicks("29.08.2016")); + Assert.assertEquals(636370560000000000L, TimeUtils.getNetTicks("31.07.2017")); + Assert.assertEquals(636334272000000000L, TimeUtils.getNetTicks("19.06.2017")); + Assert.assertEquals(636189120000000000L, TimeUtils.getNetTicks("02.01.2017")); + Assert.assertEquals(636080256000000000L, TimeUtils.getNetTicks("29.08.2016")); } @Test @@ -53,6 +53,6 @@ public class TimeUtilitiesTest { format.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = format.parse("31.07.2017"); - Assert.assertEquals(date, TimeUtilities.getDate(636370560000000000L)); + Assert.assertEquals(date, TimeUtils.getDate(636370560000000000L)); } }