1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 00:49:10 -05:00

Refactor model layout (#92)

This commit is contained in:
Rafał Borcz 2018-04-29 12:45:05 +02:00 committed by Mikołaj Pich
parent 3443b01b9a
commit 09a8cc38f9
31 changed files with 359 additions and 454 deletions

View File

@ -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);
}

View File

@ -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<Subject> getSubjectList() {
return daoSession.getSemesterDao().load(getCurrentSemesterId()).getSubjectList();
}
@Override
public List<Grade> 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;
}
}

View File

@ -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<Subject> getSubjectList();
List<Grade> getNewGrades();
long getCurrentStudentId();
long getCurrentSymbolId();
long getCurrentDiaryId();
long getCurrentSemesterId();
SyncContract getSyncRepo();
}

View File

@ -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<Subject> getSubjectList();
List<Grade> getNewGrades();
long getCurrentStudentId();
long getCurrentSymbolId();
long getCurrentDiaryId();
long getCurrentSemesterId();
}

View File

@ -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<Subject> getSubjectList() {
return daoSession.getSemesterDao().load(getCurrentSemesterId()).getSubjectList();
}
@Override
public List<Grade> 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();
}
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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);

View File

@ -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();

View File

@ -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()
);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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

View File

@ -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;

View File

@ -64,10 +64,10 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
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<LoginContract.View>
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<LoginContract.View>
return AppConstant.DEFAULT_SYMBOL;
}
String[] keys = getRepository().getSymbolsKeysArray();
String[] values = getRepository().getSymbolsValuesArray();
String[] keys = getRepository().getResRepo().getSymbolsKeysArray();
String[] values = getRepository().getResRepo().getSymbolsValuesArray();
LinkedHashMap<String, String> map = new LinkedHashMap<>();
for (int i = 0; i < Math.min(keys.length, values.length); ++i) {

View File

@ -27,7 +27,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
if (tabPositionIntent != -1) {
tabPosition = tabPositionIntent;
} else {
tabPosition = getRepository().getStartupTab();
tabPosition = getRepository().getSharedRepo().getStartupTab();
}
getView().initiationBottomNav(tabPosition);

View File

@ -85,18 +85,18 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
getView().onRefreshSuccess();
} else {
getView().onError(getRepository().getErrorLoginMessage(exception));
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
}
getView().hideRefreshingBar();
}
@Override
public void onDoInBackgroundLoading() throws Exception {
Week week = getRepository().getWeek(date);
Week week = getRepository().getDbRepo().getWeek(date);
if (week == null || !week.getAttendanceSynced()) {
syncData();
week = getRepository().getWeek(date);
week = getRepository().getDbRepo().getWeek(date);
}
List<Day> dayList = week.getDayList();
@ -118,7 +118,7 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
List<AttendanceSubItem> 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<AttendanceTabContract.
}
private void syncData() throws Exception {
getRepository().syncAttendance(date);
getRepository().getSyncRepo().syncAttendance(0, date);
}
private void cancelAsyncTasks() {

View File

@ -71,8 +71,8 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
@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<GradesContract.View>
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<GradesContract.View>
getView().onRefreshSuccess(numberOfNewGrades);
}
} else {
getView().onError(getRepository().getErrorLoginMessage(exception));
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
}
getView().hideRefreshingBar();
}
@Override
public void onDoInBackgroundLoading() {
List<Subject> subjectList = getRepository().getSubjectList();
boolean isShowSummary = getRepository().isShowGradesSummary();
List<Subject> subjectList = getRepository().getDbRepo().getSubjectList();
boolean isShowSummary = getRepository().getSharedRepo().isShowGradesSummary();
headerItems = new ArrayList<>();

View File

@ -88,18 +88,18 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
getView().onRefreshSuccess();
} else {
getView().onError(getRepository().getErrorLoginMessage(exception));
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
}
getView().hideRefreshingBar();
}
@Override
public void onDoInBackgroundLoading() throws Exception {
Week week = getRepository().getWeek(date);
Week week = getRepository().getDbRepo().getWeek(date);
if (week == null || !week.getTimetableSynced()) {
syncData();
week = getRepository().getWeek(date);
week = getRepository().getDbRepo().getWeek(date);
}
List<Day> dayList = week.getDayList();
@ -159,7 +159,7 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
}
private void syncData() throws Exception {
getRepository().syncTimetable(date);
getRepository().getSyncRepo().syncTimetable(0, date);
}
private void cancelAsyncTasks() {

View File

@ -20,15 +20,15 @@ public class SplashPresenter extends BasePresenter<SplashContract.View>
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();
}
}
}

View File

@ -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();

View File

@ -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);