diff --git a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.java b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.java index ab94afa63..e4fd7ca9c 100644 --- a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.java +++ b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.java @@ -45,9 +45,9 @@ public class WulkanowyApp extends Application { } private void initializeUserSession() { - if (repository.getCurrentUserId() != 0) { + if (repository.getSharedRepo().isUserLoggedIn()) { try { - repository.initLastUser(); + repository.getSyncRepo().initLastUser(); } catch (Exception e) { LogUtils.error("An error occurred when the application was started", e); } diff --git a/app/src/main/java/io/github/wulkanowy/data/Repository.java b/app/src/main/java/io/github/wulkanowy/data/Repository.java index 39af21f4e..1516c0279 100644 --- a/app/src/main/java/io/github/wulkanowy/data/Repository.java +++ b/app/src/main/java/io/github/wulkanowy/data/Repository.java @@ -1,240 +1,50 @@ package io.github.wulkanowy.data; -import java.io.IOException; -import java.text.ParseException; -import java.util.List; - import javax.inject.Inject; import javax.inject.Singleton; -import io.github.wulkanowy.api.VulcanException; -import io.github.wulkanowy.data.db.dao.entities.Account; -import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson; -import io.github.wulkanowy.data.db.dao.entities.DaoSession; -import io.github.wulkanowy.data.db.dao.entities.DiaryDao; -import io.github.wulkanowy.data.db.dao.entities.Grade; -import io.github.wulkanowy.data.db.dao.entities.GradeDao; -import io.github.wulkanowy.data.db.dao.entities.SemesterDao; -import io.github.wulkanowy.data.db.dao.entities.StudentDao; -import io.github.wulkanowy.data.db.dao.entities.Subject; -import io.github.wulkanowy.data.db.dao.entities.SymbolDao; -import io.github.wulkanowy.data.db.dao.entities.Week; -import io.github.wulkanowy.data.db.dao.entities.WeekDao; +import io.github.wulkanowy.data.db.dao.DbContract; import io.github.wulkanowy.data.db.resources.ResourcesContract; import io.github.wulkanowy.data.db.shared.SharedPrefContract; import io.github.wulkanowy.data.sync.SyncContract; -import io.github.wulkanowy.data.sync.account.AccountSyncContract; -import io.github.wulkanowy.data.sync.attendance.AttendanceSyncContract; -import io.github.wulkanowy.data.sync.timetable.TimetableSyncContract; -import io.github.wulkanowy.di.annotations.SyncGrades; -import io.github.wulkanowy.di.annotations.SyncSubjects; -import io.github.wulkanowy.utils.security.CryptoException; @Singleton public class Repository implements RepositoryContract { - private final SharedPrefContract sharedPref; + private final DbContract database; private final ResourcesContract resources; - private final DaoSession daoSession; + private final SharedPrefContract sharedPref; - private final AccountSyncContract accountSync; - - private final AttendanceSyncContract attendanceSync; - - private final TimetableSyncContract timetableSync; - - private final SyncContract gradeSync; - - private final SyncContract subjectSync; + private final SyncContract synchronization; @Inject - Repository(SharedPrefContract sharedPref, - ResourcesContract resources, - DaoSession daoSession, - AccountSyncContract accountSync, - AttendanceSyncContract attendanceSync, - TimetableSyncContract timetableSync, - @SyncGrades SyncContract gradeSync, - @SyncSubjects SyncContract subjectSync) { - this.sharedPref = sharedPref; + Repository(DbContract database, ResourcesContract resources, SharedPrefContract sharedPref, + SyncContract synchronization) { + this.database = database; this.resources = resources; - this.daoSession = daoSession; - this.accountSync = accountSync; - this.attendanceSync = attendanceSync; - this.timetableSync = timetableSync; - this.gradeSync = gradeSync; - this.subjectSync = subjectSync; + this.sharedPref = sharedPref; + this.synchronization = synchronization; } @Override - public long getCurrentUserId() { - return sharedPref.getCurrentUserId(); + public SharedPrefContract getSharedRepo() { + return sharedPref; } @Override - public void setTimetableWidgetState(boolean nextDay) { - sharedPref.setTimetableWidgetState(nextDay); + public ResourcesContract getResRepo() { + return resources; } @Override - public boolean getTimetableWidgetState() { - return sharedPref.getTimetableWidgetState(); + public DbContract getDbRepo() { + return database; } @Override - public int getStartupTab() { - return sharedPref.getStartupTab(); - } - - @Override - public boolean isShowGradesSummary() { - return sharedPref.isShowGradesSummary(); - } - - @Override - public int getServicesInterval() { - return sharedPref.getServicesInterval(); - } - - @Override - public boolean isServicesEnable() { - return sharedPref.isServicesEnable(); - } - - @Override - public boolean isNotifyEnable() { - return sharedPref.isNotifyEnable(); - } - - @Override - public boolean isMobileDisable() { - return sharedPref.isMobileDisable(); - } - - @Override - public String[] getSymbolsKeysArray() { - return resources.getSymbolsKeysArray(); - } - - @Override - public String[] getSymbolsValuesArray() { - return resources.getSymbolsValuesArray(); - } - - @Override - public String getErrorLoginMessage(Exception e) { - return resources.getErrorLoginMessage(e); - } - - @Override - public String getAttendanceLessonDescription(AttendanceLesson lesson) { - return resources.getAttendanceLessonDescription(lesson); - } - - @Override - public void registerUser(String email, String password, String symbol) throws VulcanException, - IOException, CryptoException { - accountSync.registerUser(email, password, symbol); - } - - @Override - public void initLastUser() throws VulcanException, IOException, CryptoException { - accountSync.initLastUser(); - } - - @Override - public void syncGrades() throws VulcanException, IOException, ParseException { - gradeSync.sync(getCurrentSemesterId()); - } - - @Override - public void syncSubjects() throws VulcanException, IOException, ParseException { - subjectSync.sync(getCurrentSemesterId()); - } - - @Override - public void syncAttendance() throws ParseException, IOException, VulcanException { - attendanceSync.syncAttendance(getCurrentDiaryId()); - } - - @Override - public void syncAttendance(String date) throws ParseException, IOException, VulcanException { - attendanceSync.syncAttendance(getCurrentDiaryId(), date); - } - - @Override - public void syncTimetable() throws VulcanException, IOException, ParseException { - timetableSync.syncTimetable(getCurrentDiaryId()); - } - - @Override - public void syncTimetable(String date) throws VulcanException, IOException, ParseException { - timetableSync.syncTimetable(getCurrentDiaryId(), date); - } - - @Override - public void syncAll() throws VulcanException, IOException, ParseException { - syncSubjects(); - syncGrades(); - syncAttendance(); - syncTimetable(); - } - - @Override - public Account getCurrentUser() { - return daoSession.getAccountDao().load(sharedPref.getCurrentUserId()); - } - - @Override - public Week getWeek(String date) { - return daoSession.getWeekDao().queryBuilder().where( - WeekDao.Properties.StartDayDate.eq(date), - WeekDao.Properties.DiaryId.eq(getCurrentDiaryId()) - ).unique(); - } - - public List getSubjectList() { - return daoSession.getSemesterDao().load(getCurrentSemesterId()).getSubjectList(); - } - - @Override - public List getNewGrades() { - return daoSession.getGradeDao().queryBuilder().where( - GradeDao.Properties.IsNew.eq(1), - GradeDao.Properties.SemesterId.eq(getCurrentSemesterId()) - ).list(); - } - - @Override - public long getCurrentSymbolId() { - return daoSession.getSymbolDao().queryBuilder().where( - SymbolDao.Properties.UserId.eq(getCurrentUserId()) - ).unique().getId(); - } - - @Override - public long getCurrentStudentId() { - return daoSession.getStudentDao().queryBuilder().where( - StudentDao.Properties.SymbolId.eq(getCurrentSymbolId()), - StudentDao.Properties.Current.eq(true) - ).unique().getId(); - } - - @Override - public long getCurrentDiaryId() { - return daoSession.getDiaryDao().queryBuilder().where( - DiaryDao.Properties.StudentId.eq(getCurrentStudentId()), - DiaryDao.Properties.Current.eq(true) - ).unique().getId(); - } - - @Override - public long getCurrentSemesterId() { - return daoSession.getSemesterDao().queryBuilder().where( - SemesterDao.Properties.DiaryId.eq(getCurrentDiaryId()), - SemesterDao.Properties.Current.eq(true) - ).unique().getId(); + public SyncContract getSyncRepo() { + return synchronization; } } diff --git a/app/src/main/java/io/github/wulkanowy/data/RepositoryContract.java b/app/src/main/java/io/github/wulkanowy/data/RepositoryContract.java index 60599cf9c..ffcfb0466 100644 --- a/app/src/main/java/io/github/wulkanowy/data/RepositoryContract.java +++ b/app/src/main/java/io/github/wulkanowy/data/RepositoryContract.java @@ -1,67 +1,20 @@ package io.github.wulkanowy.data; -import java.io.IOException; -import java.text.ParseException; -import java.util.List; - import javax.inject.Singleton; -import io.github.wulkanowy.api.VulcanException; -import io.github.wulkanowy.data.db.dao.entities.Account; -import io.github.wulkanowy.data.db.dao.entities.Grade; -import io.github.wulkanowy.data.db.dao.entities.Subject; -import io.github.wulkanowy.data.db.dao.entities.Week; +import io.github.wulkanowy.data.db.dao.DbContract; import io.github.wulkanowy.data.db.resources.ResourcesContract; -import io.github.wulkanowy.data.sync.account.AccountSyncContract; +import io.github.wulkanowy.data.db.shared.SharedPrefContract; +import io.github.wulkanowy.data.sync.SyncContract; @Singleton -public interface RepositoryContract extends ResourcesContract, AccountSyncContract { +public interface RepositoryContract { - long getCurrentUserId(); + SharedPrefContract getSharedRepo(); - int getStartupTab(); + ResourcesContract getResRepo(); - void setTimetableWidgetState(boolean nextDay); + DbContract getDbRepo(); - boolean getTimetableWidgetState(); - - boolean isServicesEnable(); - - boolean isNotifyEnable(); - - boolean isShowGradesSummary(); - - int getServicesInterval(); - - boolean isMobileDisable(); - - void syncGrades() throws VulcanException, IOException, ParseException; - - void syncSubjects() throws VulcanException, IOException, ParseException; - - void syncAttendance() throws ParseException, IOException, VulcanException; - - void syncAttendance(String date) throws ParseException, IOException, VulcanException; - - void syncTimetable() throws VulcanException, IOException, ParseException; - - void syncTimetable(String date) throws VulcanException, IOException, ParseException; - - void syncAll() throws VulcanException, IOException, ParseException; - - Account getCurrentUser(); - - Week getWeek(String date); - - List getSubjectList(); - - List getNewGrades(); - - long getCurrentStudentId(); - - long getCurrentSymbolId(); - - long getCurrentDiaryId(); - - long getCurrentSemesterId(); + SyncContract getSyncRepo(); } diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/DbContract.java b/app/src/main/java/io/github/wulkanowy/data/db/dao/DbContract.java new file mode 100644 index 000000000..cd0b774c6 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/DbContract.java @@ -0,0 +1,24 @@ +package io.github.wulkanowy.data.db.dao; + +import java.util.List; + +import io.github.wulkanowy.data.db.dao.entities.Grade; +import io.github.wulkanowy.data.db.dao.entities.Subject; +import io.github.wulkanowy.data.db.dao.entities.Week; + +public interface DbContract { + + Week getWeek(String date); + + List getSubjectList(); + + List getNewGrades(); + + long getCurrentStudentId(); + + long getCurrentSymbolId(); + + long getCurrentDiaryId(); + + long getCurrentSemesterId(); +} diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/DbRepository.java b/app/src/main/java/io/github/wulkanowy/data/db/dao/DbRepository.java new file mode 100644 index 000000000..284c17335 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/DbRepository.java @@ -0,0 +1,82 @@ +package io.github.wulkanowy.data.db.dao; + +import java.util.List; + +import javax.inject.Inject; + +import io.github.wulkanowy.data.db.dao.entities.DaoSession; +import io.github.wulkanowy.data.db.dao.entities.DiaryDao; +import io.github.wulkanowy.data.db.dao.entities.Grade; +import io.github.wulkanowy.data.db.dao.entities.GradeDao; +import io.github.wulkanowy.data.db.dao.entities.SemesterDao; +import io.github.wulkanowy.data.db.dao.entities.StudentDao; +import io.github.wulkanowy.data.db.dao.entities.Subject; +import io.github.wulkanowy.data.db.dao.entities.SymbolDao; +import io.github.wulkanowy.data.db.dao.entities.Week; +import io.github.wulkanowy.data.db.dao.entities.WeekDao; +import io.github.wulkanowy.data.db.shared.SharedPrefContract; + +public class DbRepository implements DbContract { + + private final DaoSession daoSession; + + private final SharedPrefContract sharedPref; + + @Inject + DbRepository(DaoSession daoSession, SharedPrefContract sharedPrefContract) { + this.daoSession = daoSession; + this.sharedPref = sharedPrefContract; + } + + + @Override + public Week getWeek(String date) { + return daoSession.getWeekDao().queryBuilder().where( + WeekDao.Properties.StartDayDate.eq(date), + WeekDao.Properties.DiaryId.eq(getCurrentDiaryId()) + ).unique(); + } + + public List getSubjectList() { + return daoSession.getSemesterDao().load(getCurrentSemesterId()).getSubjectList(); + } + + @Override + public List getNewGrades() { + return daoSession.getGradeDao().queryBuilder().where( + GradeDao.Properties.IsNew.eq(1), + GradeDao.Properties.SemesterId.eq(getCurrentSemesterId()) + ).list(); + } + + @Override + public long getCurrentSymbolId() { + return daoSession.getSymbolDao().queryBuilder().where( + SymbolDao.Properties.UserId.eq(sharedPref.getCurrentUserId()) + ).unique().getId(); + } + + @Override + public long getCurrentStudentId() { + return daoSession.getStudentDao().queryBuilder().where( + StudentDao.Properties.SymbolId.eq(getCurrentSymbolId()), + StudentDao.Properties.Current.eq(true) + ).unique().getId(); + } + + @Override + public long getCurrentDiaryId() { + return daoSession.getDiaryDao().queryBuilder().where( + DiaryDao.Properties.StudentId.eq(getCurrentStudentId()), + DiaryDao.Properties.Current.eq(true) + ).unique().getId(); + } + + @Override + public long getCurrentSemesterId() { + return daoSession.getSemesterDao().queryBuilder().where( + SemesterDao.Properties.DiaryId.eq(getCurrentDiaryId()), + SemesterDao.Properties.Current.eq(true) + ).unique().getId(); + } +} diff --git a/app/src/main/java/io/github/wulkanowy/data/db/resources/ResourcesContract.java b/app/src/main/java/io/github/wulkanowy/data/db/resources/ResourcesContract.java index 0ef45a76d..0e654997b 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/resources/ResourcesContract.java +++ b/app/src/main/java/io/github/wulkanowy/data/db/resources/ResourcesContract.java @@ -1,7 +1,10 @@ package io.github.wulkanowy.data.db.resources; +import javax.inject.Singleton; + import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson; +@Singleton public interface ResourcesContract { String[] getSymbolsKeysArray(); diff --git a/app/src/main/java/io/github/wulkanowy/data/db/resources/AppResources.java b/app/src/main/java/io/github/wulkanowy/data/db/resources/ResourcesRepository.java similarity index 95% rename from app/src/main/java/io/github/wulkanowy/data/db/resources/AppResources.java rename to app/src/main/java/io/github/wulkanowy/data/db/resources/ResourcesRepository.java index 7db62c2b7..26ec36dd4 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/resources/AppResources.java +++ b/app/src/main/java/io/github/wulkanowy/data/db/resources/ResourcesRepository.java @@ -21,12 +21,12 @@ import io.github.wulkanowy.utils.LogUtils; import io.github.wulkanowy.utils.security.CryptoException; @Singleton -public class AppResources implements ResourcesContract { +public class ResourcesRepository implements ResourcesContract { private Resources resources; @Inject - AppResources(@ApplicationContext Context context) { + ResourcesRepository(@ApplicationContext Context context) { resources = context.getResources(); } diff --git a/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPrefContract.java b/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPrefContract.java index 57a7222ee..48e2b1937 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPrefContract.java +++ b/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPrefContract.java @@ -1,9 +1,14 @@ package io.github.wulkanowy.data.db.shared; +import javax.inject.Singleton; + +@Singleton public interface SharedPrefContract { long getCurrentUserId(); + boolean isUserLoggedIn(); + void setCurrentUserId(long userId); void setTimetableWidgetState(boolean nextDay); diff --git a/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPref.java b/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPrefRepository.java similarity index 90% rename from app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPref.java rename to app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPrefRepository.java index 35c623684..35d30ae6c 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPref.java +++ b/app/src/main/java/io/github/wulkanowy/data/db/shared/SharedPrefRepository.java @@ -13,7 +13,7 @@ import io.github.wulkanowy.di.annotations.SharedPreferencesInfo; import io.github.wulkanowy.ui.main.settings.SettingsFragment; @Singleton -public class SharedPref implements SharedPrefContract { +public class SharedPrefRepository implements SharedPrefContract { private static final String SHARED_KEY_USER_ID = "USER_ID"; @@ -24,7 +24,7 @@ public class SharedPref implements SharedPrefContract { private final SharedPreferences settingsSharedPref; @Inject - SharedPref(@ApplicationContext Context context, @SharedPreferencesInfo String sharedName) { + SharedPrefRepository(@ApplicationContext Context context, @SharedPreferencesInfo String sharedName) { appSharedPref = context.getSharedPreferences(sharedName, Context.MODE_PRIVATE); settingsSharedPref = PreferenceManager.getDefaultSharedPreferences(context); } @@ -34,6 +34,11 @@ public class SharedPref implements SharedPrefContract { return appSharedPref.getLong(SHARED_KEY_USER_ID, 0); } + @Override + public boolean isUserLoggedIn() { + return getCurrentUserId() != 0; + } + @Override public void setCurrentUserId(long userId) { appSharedPref.edit().putLong(SHARED_KEY_USER_ID, userId).apply(); diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/account/AccountSync.java b/app/src/main/java/io/github/wulkanowy/data/sync/AccountSync.java similarity index 85% rename from app/src/main/java/io/github/wulkanowy/data/sync/account/AccountSync.java rename to app/src/main/java/io/github/wulkanowy/data/sync/AccountSync.java index ba87cc69d..d701edc0b 100644 --- a/app/src/main/java/io/github/wulkanowy/data/sync/account/AccountSync.java +++ b/app/src/main/java/io/github/wulkanowy/data/sync/AccountSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.data.sync.account; +package io.github.wulkanowy.data.sync; import android.content.Context; @@ -27,7 +27,7 @@ import io.github.wulkanowy.utils.security.CryptoException; import io.github.wulkanowy.utils.security.Scrambler; @Singleton -public class AccountSync implements AccountSyncContract { +public class AccountSync { private final DaoSession daoSession; @@ -46,7 +46,6 @@ public class AccountSync implements AccountSyncContract { this.context = context; } - @Override public void registerUser(String email, String password, String symbol) throws VulcanException, IOException, CryptoException { @@ -119,7 +118,6 @@ public class AccountSync implements AccountSyncContract { daoSession.getSemesterDao().insertInTx(semesterList); } - @Override public void initLastUser() throws IOException, CryptoException { long userId = sharedPref.getCurrentUserId(); @@ -131,26 +129,27 @@ public class AccountSync implements AccountSyncContract { LogUtils.debug("Initialization current user id=" + userId); Account account = daoSession.getAccountDao().load(userId); - String email = account.getEmail(); - String pass = Scrambler.decrypt(account.getEmail(), account.getPassword()); - Symbol symbolE = daoSession.getSymbolDao().queryBuilder().where( + Symbol symbol = daoSession.getSymbolDao().queryBuilder().where( SymbolDao.Properties.UserId.eq(account.getId())).unique(); - String symbol = symbolE.getSymbol(); - String schoolId = symbolE.getSchoolId(); - Student studentE = daoSession.getStudentDao().queryBuilder().where( - StudentDao.Properties.SymbolId.eq(symbolE.getId()), + Student student = daoSession.getStudentDao().queryBuilder().where( + StudentDao.Properties.SymbolId.eq(symbol.getId()), StudentDao.Properties.Current.eq(true) ).unique(); - String studentId = studentE.getRealId(); - Diary diaryE = daoSession.getDiaryDao().queryBuilder().where( - DiaryDao.Properties.StudentId.eq(studentE.getId()), + Diary diary = daoSession.getDiaryDao().queryBuilder().where( + DiaryDao.Properties.StudentId.eq(student.getId()), DiaryDao.Properties.Current.eq(true) ).unique(); - String diaryId = diaryE.getValue(); - vulcan.setCredentials(email, pass, symbol, schoolId, studentId, diaryId); + vulcan.setCredentials( + account.getEmail(), + Scrambler.decrypt(account.getEmail(), account.getPassword()), + symbol.getSymbol(), + symbol.getSchoolId(), + student.getRealId(), + diary.getValue() + ); } } diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/attendance/AttendanceSync.java b/app/src/main/java/io/github/wulkanowy/data/sync/AttendanceSync.java similarity index 94% rename from app/src/main/java/io/github/wulkanowy/data/sync/attendance/AttendanceSync.java rename to app/src/main/java/io/github/wulkanowy/data/sync/AttendanceSync.java index 39dfd4b39..59a6e1a3b 100644 --- a/app/src/main/java/io/github/wulkanowy/data/sync/attendance/AttendanceSync.java +++ b/app/src/main/java/io/github/wulkanowy/data/sync/AttendanceSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.data.sync.attendance; +package io.github.wulkanowy.data.sync; import java.io.IOException; import java.text.ParseException; @@ -23,7 +23,7 @@ import io.github.wulkanowy.utils.LogUtils; import io.github.wulkanowy.utils.TimeUtils; @Singleton -public class AttendanceSync implements AttendanceSyncContract { +public class AttendanceSync { private final DaoSession daoSession; @@ -37,12 +37,6 @@ public class AttendanceSync implements AttendanceSyncContract { this.vulcan = vulcan; } - @Override - public void syncAttendance(long diaryId) throws IOException, ParseException, VulcanException { - syncAttendance(diaryId, null); - } - - @Override public void syncAttendance(long diaryId, String date) throws IOException, ParseException, VulcanException { this.diaryId = diaryId; diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/grades/GradeSync.java b/app/src/main/java/io/github/wulkanowy/data/sync/GradeSync.java similarity index 94% rename from app/src/main/java/io/github/wulkanowy/data/sync/grades/GradeSync.java rename to app/src/main/java/io/github/wulkanowy/data/sync/GradeSync.java index 5c19bab7b..0b70695de 100644 --- a/app/src/main/java/io/github/wulkanowy/data/sync/grades/GradeSync.java +++ b/app/src/main/java/io/github/wulkanowy/data/sync/GradeSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.data.sync.grades; +package io.github.wulkanowy.data.sync; import java.io.IOException; import java.text.ParseException; @@ -14,13 +14,12 @@ import io.github.wulkanowy.data.db.dao.entities.DaoSession; import io.github.wulkanowy.data.db.dao.entities.Grade; import io.github.wulkanowy.data.db.dao.entities.Semester; import io.github.wulkanowy.data.db.dao.entities.SubjectDao; -import io.github.wulkanowy.data.sync.SyncContract; import io.github.wulkanowy.utils.DataObjectConverter; import io.github.wulkanowy.utils.EntitiesCompare; import io.github.wulkanowy.utils.LogUtils; @Singleton -public class GradeSync implements SyncContract { +public class GradeSync { private final DaoSession daoSession; @@ -34,7 +33,6 @@ public class GradeSync implements SyncContract { this.vulcan = vulcan; } - @Override public void sync(long semesterId) throws IOException, VulcanException, ParseException { this.semesterId = semesterId; diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/subjects/SubjectSync.java b/app/src/main/java/io/github/wulkanowy/data/sync/SubjectSync.java similarity index 92% rename from app/src/main/java/io/github/wulkanowy/data/sync/subjects/SubjectSync.java rename to app/src/main/java/io/github/wulkanowy/data/sync/SubjectSync.java index c1b8ccbf6..163a62340 100644 --- a/app/src/main/java/io/github/wulkanowy/data/sync/subjects/SubjectSync.java +++ b/app/src/main/java/io/github/wulkanowy/data/sync/SubjectSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.data.sync.subjects; +package io.github.wulkanowy.data.sync; import java.io.IOException; import java.util.ArrayList; @@ -12,12 +12,11 @@ import io.github.wulkanowy.api.VulcanException; import io.github.wulkanowy.data.db.dao.entities.DaoSession; import io.github.wulkanowy.data.db.dao.entities.Semester; import io.github.wulkanowy.data.db.dao.entities.Subject; -import io.github.wulkanowy.data.sync.SyncContract; import io.github.wulkanowy.utils.DataObjectConverter; import io.github.wulkanowy.utils.LogUtils; @Singleton -public class SubjectSync implements SyncContract { +public class SubjectSync { private final DaoSession daoSession; @@ -31,7 +30,6 @@ public class SubjectSync implements SyncContract { this.vulcan = vulcan; } - @Override public void sync(long semesterId) throws VulcanException, IOException { this.semesterId = semesterId; diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/SyncContract.java b/app/src/main/java/io/github/wulkanowy/data/sync/SyncContract.java index 1da93c1b4..e4f397fc1 100644 --- a/app/src/main/java/io/github/wulkanowy/data/sync/SyncContract.java +++ b/app/src/main/java/io/github/wulkanowy/data/sync/SyncContract.java @@ -3,9 +3,34 @@ package io.github.wulkanowy.data.sync; import java.io.IOException; import java.text.ParseException; -import io.github.wulkanowy.api.VulcanException; +import javax.inject.Singleton; +import io.github.wulkanowy.api.VulcanException; +import io.github.wulkanowy.utils.security.CryptoException; + +@Singleton public interface SyncContract { - void sync(long semesterId) throws VulcanException, IOException, ParseException; + void registerUser(String email, String password, String symbol) throws VulcanException, + IOException, CryptoException; + + void initLastUser() throws IOException, CryptoException; + + void syncGrades(long semesterId) throws VulcanException, IOException, ParseException; + + void syncGrades() throws VulcanException, IOException, ParseException; + + void syncSubjects(long semesterId) throws VulcanException, IOException; + + void syncSubjects() throws VulcanException, IOException; + + void syncAttendance() throws ParseException, IOException, VulcanException; + + void syncAttendance(long diaryId, String date) throws ParseException, IOException, VulcanException; + + void syncTimetable() throws VulcanException, IOException, ParseException; + + void syncTimetable(long diaryId, String date) throws VulcanException, IOException, ParseException; + + void syncAll() throws VulcanException, IOException, ParseException; } diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/SyncRepository.java b/app/src/main/java/io/github/wulkanowy/data/sync/SyncRepository.java new file mode 100644 index 000000000..e8cde9be9 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/data/sync/SyncRepository.java @@ -0,0 +1,105 @@ +package io.github.wulkanowy.data.sync; + +import java.io.IOException; +import java.text.ParseException; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import io.github.wulkanowy.api.VulcanException; +import io.github.wulkanowy.data.db.dao.DbContract; +import io.github.wulkanowy.utils.security.CryptoException; + +@Singleton +public class SyncRepository implements SyncContract { + + private final GradeSync gradeSync; + + private final SubjectSync subjectSync; + + private final AttendanceSync attendanceSync; + + private final TimetableSync timetableSync; + + private final AccountSync accountSync; + + private final DbContract database; + + @Inject + SyncRepository(GradeSync gradeSync, SubjectSync subjectSync, AttendanceSync attendanceSync, + TimetableSync timetableSync, AccountSync accountSync, DbContract database) { + this.gradeSync = gradeSync; + this.subjectSync = subjectSync; + this.attendanceSync = attendanceSync; + this.timetableSync = timetableSync; + this.accountSync = accountSync; + this.database = database; + } + + @Override + public void registerUser(String email, String password, String symbol) throws VulcanException, + IOException, CryptoException { + accountSync.registerUser(email, password, symbol); + } + + @Override + public void initLastUser() throws IOException, CryptoException { + accountSync.initLastUser(); + } + + @Override + public void syncGrades(long semesterId) throws VulcanException, IOException, ParseException { + gradeSync.sync(semesterId); + } + + @Override + public void syncGrades() throws VulcanException, IOException, ParseException { + gradeSync.sync(database.getCurrentSemesterId()); + } + + @Override + public void syncSubjects(long semesterId) throws VulcanException, IOException { + subjectSync.sync(semesterId); + } + + @Override + public void syncSubjects() throws VulcanException, IOException { + subjectSync.sync(database.getCurrentSemesterId()); + } + + @Override + public void syncAttendance() throws ParseException, IOException, VulcanException { + attendanceSync.syncAttendance(database.getCurrentDiaryId(), null); + } + + @Override + public void syncAttendance(long diaryId, String date) throws ParseException, IOException, VulcanException { + if (diaryId != 0) { + attendanceSync.syncAttendance(diaryId, date); + } else { + attendanceSync.syncAttendance(database.getCurrentDiaryId(), date); + } + } + + @Override + public void syncTimetable() throws VulcanException, IOException, ParseException { + timetableSync.syncTimetable(database.getCurrentDiaryId(), null); + } + + @Override + public void syncTimetable(long diaryId, String date) throws VulcanException, IOException, ParseException { + if (diaryId != 0) { + timetableSync.syncTimetable(diaryId, date); + } else { + timetableSync.syncTimetable(database.getCurrentDiaryId(), date); + } + } + + @Override + public void syncAll() throws VulcanException, IOException, ParseException { + syncSubjects(); + syncGrades(); + syncAttendance(); + syncTimetable(); + } +} diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/timetable/TimetableSync.java b/app/src/main/java/io/github/wulkanowy/data/sync/TimetableSync.java similarity index 95% rename from app/src/main/java/io/github/wulkanowy/data/sync/timetable/TimetableSync.java rename to app/src/main/java/io/github/wulkanowy/data/sync/TimetableSync.java index 645250976..40b7eb56a 100644 --- a/app/src/main/java/io/github/wulkanowy/data/sync/timetable/TimetableSync.java +++ b/app/src/main/java/io/github/wulkanowy/data/sync/TimetableSync.java @@ -1,4 +1,4 @@ -package io.github.wulkanowy.data.sync.timetable; +package io.github.wulkanowy.data.sync; import java.io.IOException; import java.text.ParseException; @@ -23,7 +23,7 @@ import io.github.wulkanowy.utils.LogUtils; import io.github.wulkanowy.utils.TimeUtils; @Singleton -public class TimetableSync implements TimetableSyncContract { +public class TimetableSync { private final DaoSession daoSession; @@ -37,12 +37,6 @@ public class TimetableSync implements TimetableSyncContract { this.vulcan = vulcan; } - @Override - public void syncTimetable(long diaryId) throws IOException, ParseException, VulcanException { - syncTimetable(diaryId, null); - } - - @Override public void syncTimetable(long diaryId, String date) throws IOException, ParseException, VulcanException { this.diaryId = diaryId; diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/account/AccountSyncContract.java b/app/src/main/java/io/github/wulkanowy/data/sync/account/AccountSyncContract.java deleted file mode 100644 index 799d320e3..000000000 --- a/app/src/main/java/io/github/wulkanowy/data/sync/account/AccountSyncContract.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.wulkanowy.data.sync.account; - -import java.io.IOException; - -import io.github.wulkanowy.api.VulcanException; -import io.github.wulkanowy.utils.security.CryptoException; - -public interface AccountSyncContract { - - void registerUser(String email, String password, String symbol) - throws VulcanException, IOException, - CryptoException; - - void initLastUser() throws VulcanException, IOException, - CryptoException; -} diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/attendance/AttendanceSyncContract.java b/app/src/main/java/io/github/wulkanowy/data/sync/attendance/AttendanceSyncContract.java deleted file mode 100644 index b86846258..000000000 --- a/app/src/main/java/io/github/wulkanowy/data/sync/attendance/AttendanceSyncContract.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.wulkanowy.data.sync.attendance; - -import java.io.IOException; -import java.text.ParseException; - -import io.github.wulkanowy.api.VulcanException; - -public interface AttendanceSyncContract { - - void syncAttendance(long diaryId, String date) throws IOException, ParseException, VulcanException; - - void syncAttendance(long diaryId) throws IOException, ParseException, VulcanException; -} diff --git a/app/src/main/java/io/github/wulkanowy/data/sync/timetable/TimetableSyncContract.java b/app/src/main/java/io/github/wulkanowy/data/sync/timetable/TimetableSyncContract.java deleted file mode 100644 index 716c1f470..000000000 --- a/app/src/main/java/io/github/wulkanowy/data/sync/timetable/TimetableSyncContract.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.wulkanowy.data.sync.timetable; - -import java.io.IOException; -import java.text.ParseException; - -import io.github.wulkanowy.api.VulcanException; - -public interface TimetableSyncContract { - - void syncTimetable(long diaryId, String date) throws VulcanException, IOException, ParseException; - - void syncTimetable(long diaryId) throws VulcanException, IOException, ParseException; -} diff --git a/app/src/main/java/io/github/wulkanowy/di/annotations/SyncGrades.java b/app/src/main/java/io/github/wulkanowy/di/annotations/SyncGrades.java deleted file mode 100644 index 90e6c02f6..000000000 --- a/app/src/main/java/io/github/wulkanowy/di/annotations/SyncGrades.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.wulkanowy.di.annotations; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import javax.inject.Qualifier; - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -public @interface SyncGrades { -} diff --git a/app/src/main/java/io/github/wulkanowy/di/annotations/SyncSubjects.java b/app/src/main/java/io/github/wulkanowy/di/annotations/SyncSubjects.java deleted file mode 100644 index 81d351bea..000000000 --- a/app/src/main/java/io/github/wulkanowy/di/annotations/SyncSubjects.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.wulkanowy.di.annotations; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import javax.inject.Qualifier; - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -public @interface SyncSubjects { -} diff --git a/app/src/main/java/io/github/wulkanowy/di/modules/ApplicationModule.java b/app/src/main/java/io/github/wulkanowy/di/modules/ApplicationModule.java index e7d2bcc67..7c2b39849 100644 --- a/app/src/main/java/io/github/wulkanowy/di/modules/ApplicationModule.java +++ b/app/src/main/java/io/github/wulkanowy/di/modules/ApplicationModule.java @@ -13,27 +13,20 @@ import dagger.Provides; import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.data.Repository; import io.github.wulkanowy.data.RepositoryContract; +import io.github.wulkanowy.data.db.dao.DbContract; import io.github.wulkanowy.data.db.dao.DbHelper; +import io.github.wulkanowy.data.db.dao.DbRepository; import io.github.wulkanowy.data.db.dao.entities.DaoMaster; import io.github.wulkanowy.data.db.dao.entities.DaoSession; -import io.github.wulkanowy.data.db.resources.AppResources; import io.github.wulkanowy.data.db.resources.ResourcesContract; -import io.github.wulkanowy.data.db.shared.SharedPref; +import io.github.wulkanowy.data.db.resources.ResourcesRepository; import io.github.wulkanowy.data.db.shared.SharedPrefContract; +import io.github.wulkanowy.data.db.shared.SharedPrefRepository; import io.github.wulkanowy.data.sync.SyncContract; -import io.github.wulkanowy.data.sync.account.AccountSync; -import io.github.wulkanowy.data.sync.account.AccountSyncContract; -import io.github.wulkanowy.data.sync.attendance.AttendanceSync; -import io.github.wulkanowy.data.sync.attendance.AttendanceSyncContract; -import io.github.wulkanowy.data.sync.grades.GradeSync; -import io.github.wulkanowy.data.sync.subjects.SubjectSync; -import io.github.wulkanowy.data.sync.timetable.TimetableSync; -import io.github.wulkanowy.data.sync.timetable.TimetableSyncContract; +import io.github.wulkanowy.data.sync.SyncRepository; import io.github.wulkanowy.di.annotations.ApplicationContext; import io.github.wulkanowy.di.annotations.DatabaseInfo; import io.github.wulkanowy.di.annotations.SharedPreferencesInfo; -import io.github.wulkanowy.di.annotations.SyncGrades; -import io.github.wulkanowy.di.annotations.SyncSubjects; import io.github.wulkanowy.utils.AppConstant; @Module @@ -88,46 +81,27 @@ public class ApplicationModule { @Singleton @Provides - SharedPrefContract provideSharedPref(SharedPref sharedPref) { - return sharedPref; + SharedPrefContract provideSharedPref(SharedPrefRepository sharedPrefRepository) { + return sharedPrefRepository; } @Singleton @Provides - ResourcesContract provideAppResources(AppResources appResources) { - return appResources; + ResourcesContract provideAppResources(ResourcesRepository resourcesRepository) { + return resourcesRepository; + } + + + @Singleton + @Provides + DbContract provideDatabase(DbRepository dbRepository) { + return dbRepository; } @Singleton @Provides - AccountSyncContract provideLoginSync(AccountSync accountSync) { - return accountSync; - } - - @SyncGrades - @Singleton - @Provides - SyncContract provideGradesSync(GradeSync gradeSync) { - return gradeSync; - } - - @SyncSubjects - @Singleton - @Provides - SyncContract provideSubjectSync(SubjectSync subjectSync) { - return subjectSync; - } - - @Singleton - @Provides - TimetableSyncContract provideTimetableSync(TimetableSync timetableSync) { - return timetableSync; - } - - @Singleton - @Provides - AttendanceSyncContract provideAttendanceSync(AttendanceSync attendanceSync) { - return attendanceSync; + SyncContract provideSync(SyncRepository syncRepository) { + return syncRepository; } @Provides diff --git a/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java b/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java index 94d5eb51f..fec3987a3 100644 --- a/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java +++ b/app/src/main/java/io/github/wulkanowy/services/jobs/SyncJob.java @@ -65,12 +65,12 @@ public class SyncJob extends SimpleJobService { @Override public int onRunJob(JobParameters job) { try { - repository.initLastUser(); - repository.syncAll(); + repository.getSyncRepo().initLastUser(); + repository.getSyncRepo().syncAll(); - gradeList = repository.getNewGrades(); + gradeList = repository.getDbRepo().getNewGrades(); - if (!gradeList.isEmpty() && repository.isNotifyEnable()) { + if (!gradeList.isEmpty() && repository.getSharedRepo().isNotifyEnable()) { showNotification(); } return JobService.RESULT_SUCCESS; diff --git a/app/src/main/java/io/github/wulkanowy/ui/login/LoginPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/login/LoginPresenter.java index b547f3f6a..3140ad785 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/login/LoginPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/login/LoginPresenter.java @@ -64,10 +64,10 @@ public class LoginPresenter extends BasePresenter public void onDoInBackground(int stepNumber) throws Exception { switch (stepNumber) { case 1: - getRepository().registerUser(email, password, symbol); + getRepository().getSyncRepo().registerUser(email, password, symbol); break; case 2: - getRepository().syncAll(); + getRepository().getSyncRepo().syncAll(); break; } } @@ -93,7 +93,7 @@ public class LoginPresenter extends BasePresenter getView().setErrorSymbolRequired(); getView().showSoftInput(); } else { - getView().onError(getRepository().getErrorLoginMessage(exception)); + getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception)); } getView().showActionBar(true); @@ -121,8 +121,8 @@ public class LoginPresenter extends BasePresenter return AppConstant.DEFAULT_SYMBOL; } - String[] keys = getRepository().getSymbolsKeysArray(); - String[] values = getRepository().getSymbolsValuesArray(); + String[] keys = getRepository().getResRepo().getSymbolsKeysArray(); + String[] values = getRepository().getResRepo().getSymbolsValuesArray(); LinkedHashMap map = new LinkedHashMap<>(); for (int i = 0; i < Math.min(keys.length, values.length); ++i) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java index 6a727b7a0..3cbbfd864 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/MainPresenter.java @@ -27,7 +27,7 @@ public class MainPresenter extends BasePresenter if (tabPositionIntent != -1) { tabPosition = tabPositionIntent; } else { - tabPosition = getRepository().getStartupTab(); + tabPosition = getRepository().getSharedRepo().getStartupTab(); } getView().initiationBottomNav(tabPosition); diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceTabPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceTabPresenter.java index 2106b1e70..effc38bc0 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceTabPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceTabPresenter.java @@ -85,18 +85,18 @@ public class AttendanceTabPresenter extends BasePresenter dayList = week.getDayList(); @@ -118,7 +118,7 @@ public class AttendanceTabPresenter extends BasePresenter subItems = new ArrayList<>(); for (AttendanceLesson lesson : lessonList) { - lesson.setDescription(getRepository().getAttendanceLessonDescription(lesson)); + lesson.setDescription(getRepository().getResRepo().getAttendanceLessonDescription(lesson)); subItems.add(new AttendanceSubItem(headerItem, lesson)); } @@ -155,7 +155,7 @@ public class AttendanceTabPresenter extends BasePresenter @Override public void onDoInBackgroundRefresh() throws Exception { - getRepository().syncSubjects(); - getRepository().syncGrades(); + getRepository().getSyncRepo().syncSubjects(); + getRepository().getSyncRepo().syncGrades(); } @Override @@ -89,7 +89,7 @@ public class GradesPresenter extends BasePresenter loadingTask.setOnFirstLoadingListener(this); loadingTask.execute(); - int numberOfNewGrades = getRepository().getNewGrades().size(); + int numberOfNewGrades = getRepository().getDbRepo().getNewGrades().size(); if (numberOfNewGrades <= 0) { getView().onRefreshSuccessNoGrade(); @@ -97,15 +97,15 @@ public class GradesPresenter extends BasePresenter getView().onRefreshSuccess(numberOfNewGrades); } } else { - getView().onError(getRepository().getErrorLoginMessage(exception)); + getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception)); } getView().hideRefreshingBar(); } @Override public void onDoInBackgroundLoading() { - List subjectList = getRepository().getSubjectList(); - boolean isShowSummary = getRepository().isShowGradesSummary(); + List subjectList = getRepository().getDbRepo().getSubjectList(); + boolean isShowSummary = getRepository().getSharedRepo().isShowGradesSummary(); headerItems = new ArrayList<>(); diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableTabPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableTabPresenter.java index 807097bca..1b4dd83f9 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableTabPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableTabPresenter.java @@ -88,18 +88,18 @@ public class TimetableTabPresenter extends BasePresenter dayList = week.getDayList(); @@ -159,7 +159,7 @@ public class TimetableTabPresenter extends BasePresenter super.onStart(activity); getView().cancelNotifications(); - if (getRepository().isServicesEnable()) { - getView().startSyncService(getRepository().getServicesInterval(), - getRepository().isMobileDisable()); + if (getRepository().getSharedRepo().isServicesEnable()) { + getView().startSyncService(getRepository().getSharedRepo().getServicesInterval(), + getRepository().getSharedRepo().isMobileDisable()); } - if (getRepository().getCurrentUserId() == 0) { - getView().openLoginActivity(); - } else { + if (getRepository().getSharedRepo().isUserLoggedIn()) { getView().openMainActivity(); + } else { + getView().openLoginActivity(); } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetFactory.java b/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetFactory.java index 85acb19cd..78e80580a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetFactory.java +++ b/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetFactory.java @@ -50,10 +50,10 @@ public class TimetableWidgetFactory implements RemoteViewsService.RemoteViewsFac inject(); lessonList = new ArrayList<>(); - if (repository.getCurrentUserId() != 0) { + if (repository.getSharedRepo().isUserLoggedIn()) { - Week week = repository.getWeek(TimeUtils.getDateOfCurrentMonday(true)); - int valueOfDay = TimeUtils.getTodayOrNextDayValue(repository.getTimetableWidgetState()); + Week week = repository.getDbRepo().getWeek(TimeUtils.getDateOfCurrentMonday(true)); + int valueOfDay = TimeUtils.getTodayOrNextDayValue(repository.getSharedRepo().getTimetableWidgetState()); if (valueOfDay != 5 && valueOfDay != 6 && week != null) { week.resetDayList(); diff --git a/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetProvider.java b/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetProvider.java index b5e5a8998..0731c30ef 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetProvider.java +++ b/app/src/main/java/io/github/wulkanowy/ui/widgets/TimetableWidgetProvider.java @@ -49,7 +49,7 @@ public class TimetableWidgetProvider extends AppWidgetProvider { TimetableWidgetProvider.class.getName()); final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); - repository.setTimetableWidgetState(!repository.getTimetableWidgetState()); + repository.getSharedRepo().setTimetableWidgetState(!repository.getSharedRepo().getTimetableWidgetState()); onUpdate(context, appWidgetManager, appWidgetIds); } } @@ -80,7 +80,7 @@ public class TimetableWidgetProvider extends AppWidgetProvider { views.setRemoteAdapter(appWidgetId, R.id.timetable_widget_list, intent); views.setEmptyView(R.id.timetable_widget_list, R.id.timetable_widget_empty); - boolean nextDay = repository.getTimetableWidgetState(); + boolean nextDay = repository.getSharedRepo().getTimetableWidgetState(); String toggleText = context.getString(nextDay ? R.string.widget_timetable_tomorrow : R.string.widget_timetable_today);