1
0

Compare commits

..

19 Commits
0.3.1 ... 0.4.0

Author SHA1 Message Date
3105e9e53b Version 0.4.0 2018-05-07 19:45:37 +02:00
8e855bd375 Save current tab position in exams (#102) 2018-05-07 18:18:05 +02:00
67f83a4d2f Mark current week (#100) 2018-05-07 17:57:58 +02:00
d7f0fcad30 Remove backup rules (#101) 2018-05-07 17:44:28 +02:00
f29689c6cd Add about section in settings (#99) 2018-05-07 16:05:57 +02:00
dd2c69601a Change description date in exam and fix styles (#98) 2018-05-06 21:16:03 +02:00
bfaa3d196b Fix animations on expand and collapse (#97) 2018-05-06 20:28:24 +02:00
ffd20c94dd Add exams (#87)
* [API/exams] Fix parsing empty list
* [API/exams] Fix date format
* [API/exams] Set day name from api
2018-05-03 19:47:34 +02:00
1740047aea [API] Add support for adfs login (#76) 2018-05-03 14:14:47 +02:00
cb2d4a905d Add option to hide present in attendance (#96) 2018-05-03 12:49:33 +02:00
89350e5793 Update dependencies (#95) 2018-05-03 12:29:10 +02:00
4ef3334bf7 Add semester switch in grades (#94) 2018-05-02 21:51:23 +02:00
cb6d39fe15 Fix widget state change during update (#93) 2018-04-29 19:47:01 +02:00
09a8cc38f9 Refactor model layout (#92) 2018-04-29 12:45:05 +02:00
3443b01b9a Fix grade regex (#91) 2018-04-27 01:36:40 +02:00
7dde13585c Add info about predicted and final ratings (#88) 2018-04-27 00:03:37 +02:00
176d17e1ec Fix notification intent (#89) 2018-04-24 23:52:53 +02:00
119e38254a Refactor entites (#86) 2018-04-24 22:05:46 +02:00
6fcf09e2b7 Add timetable widget (#84) 2018-04-24 21:27:45 +02:00
182 changed files with 5042 additions and 1979 deletions

View File

@ -31,9 +31,18 @@ jobs:
- run:
name: Setup environment
command: ./gradlew dependencies --no-daemon --stacktrace --console=plain -PdisablePreDex || true
- run:
name: Decrypt keys
command: |
openssl aes-256-cbc -d -in ./app/key-encrypted.p12 -k $ENCRYPT_KEY >> ./app/key.p12
openssl aes-256-cbc -d -in ./app/upload-key-encrypted.jks -k $ENCRYPT_KEY >> ./app/upload-key.jks
- run:
name: Initial build
command: ./gradlew build assembleDebug -x test -x lint -x fabricGenerateResourcesRelease --no-daemon --stacktrace --console=plain -PdisablePreDex
- run:
name: Clear keys
command: |
rm ./app/key.p12 ./app/upload-key.jks
- store_artifacts:
path: ./app/build/outputs/apk/
destination: apks/
@ -172,6 +181,21 @@ jobs:
name: Run sonarqube runner
command: ./gradlew -x test -x lint sonarqube -Dsonar.host.url=$SONAR_HOST -Dsonar.organization=$SONAR_ORG -Dsonar.login=$SONAR_KEY -Dsonar.branch.name=$CIRCLE_BRANCH --no-daemon --stacktrace --console=plain -PdisablePreDex
deploy:
<<: *container_config
steps:
- *attach_workspace
- restore_cache:
<<: *general_cache_key
- run:
name: Decrypt keys
command: |
openssl aes-256-cbc -d -in ./app/key-encrypted.p12 -k $ENCRYPT_KEY >> ./app/key.p12
openssl aes-256-cbc -d -in ./app/upload-key-encrypted.jks -k $ENCRYPT_KEY >> ./app/upload-key.jks
- run:
name: Publish release
command: ./gradlew publishRelease --no-daemon --stacktrace --console=plain -PdisablePreDex
workflows:
version: 2
@ -199,3 +223,9 @@ workflows:
- app-test
- api-test
- instrumented
- deploy:
requires:
- instrumented
filters:
tags:
only: /.*/

4
.gitignore vendored
View File

@ -44,3 +44,7 @@ local.properties
.Trashes
ehthumbs.db
Thumbs.db
.idea/codeStyles/
.idea/caches/
./app/key.p12
./app/upload-key.jks

View File

@ -44,7 +44,11 @@ public class Client {
String[] url = creds[0].split("://");
protocol = url[0];
host = url[1];
String[] path = url[1].split("/");
host = path[0];
if (path.length > 1) {
symbol = path[1];
}
email = creds[2];
}
}

View File

@ -4,8 +4,6 @@ public class Diary implements ParamItem {
private String id = "";
private String studentId = "";
private String name = "";
private boolean current = false;
@ -19,16 +17,6 @@ public class Diary implements ParamItem {
return this;
}
public String getStudentId() {
return studentId;
}
@Override
public Diary setStudentId(String studentId) {
this.studentId = studentId;
return this;
}
public String getName() {
return name;
}

View File

@ -4,8 +4,6 @@ interface ParamItem {
ParamItem setId(String id);
ParamItem setStudentId(String id);
ParamItem setName(String name);
ParamItem setCurrent(boolean isCurrent);

View File

@ -4,8 +4,6 @@ public class Semester implements ParamItem {
private String id = "";
private String studentId = "";
private String name = "";
private boolean current = false;
@ -19,16 +17,6 @@ public class Semester implements ParamItem {
return this;
}
public String getStudentId() {
return studentId;
}
@Override
public Semester setStudentId(String studentId) {
this.studentId = studentId;
return this;
}
public String getName() {
return name;
}

View File

@ -17,15 +17,6 @@ public class Student implements ParamItem {
return this;
}
public String getStudentId() {
return getId();
}
@Override
public Student setStudentId(String studentId) {
return setId(studentId);
}
public String getName() {
return name;
}

View File

@ -140,8 +140,8 @@ public class StudentAndParent implements SnP {
for (Element e : semesterOptions) {
Semester semester = new Semester()
.setId(e.text())
.setName(e.attr("value"));
.setId(e.attr("value"))
.setName(e.text());
if (isCurrent(e)) {
semester.setCurrent(true);
@ -167,9 +167,6 @@ public class StudentAndParent implements SnP {
if (isCurrent(e)) {
item.setCurrent(true);
}
if (item instanceof Diary) {
item.setStudentId(getStudentID());
}
list.add((T) item);
} catch (Exception ex) {

View File

@ -2,7 +2,7 @@ package io.github.wulkanowy.api;
public class VulcanException extends Exception {
protected VulcanException(String message) {
public VulcanException(String message) {
super(message);
}

View File

@ -1,12 +1,17 @@
package io.github.wulkanowy.api.exams;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import io.github.wulkanowy.api.SnP;
import io.github.wulkanowy.api.VulcanException;
@ -22,11 +27,11 @@ public class ExamsWeek {
this.snp = snp;
}
public Week<ExamDay> getCurrent() throws IOException, VulcanException {
public Week<ExamDay> getCurrent() throws IOException, VulcanException, ParseException {
return getWeek("", true);
}
public Week<ExamDay> getWeek(String tick, final boolean onlyNotEmpty) throws IOException, VulcanException {
public Week<ExamDay> getWeek(String tick, final boolean onlyNotEmpty) throws IOException, VulcanException, ParseException {
Document examsPage = snp.getSnPPageDocument(EXAMS_PAGE_URL + tick);
Elements examsDays = examsPage.select(".mainContainer > div:not(.navigation)");
@ -41,7 +46,9 @@ public class ExamsWeek {
}
if (null != dayHeading) {
day.setDate(dayHeading.text().split(", ")[1]);
String[] dateHeader = dayHeading.text().split(", ");
day.setDayName(StringUtils.capitalize(dateHeader[0]));
day.setDate(getFormattedDate(dateHeader[1]));
}
Elements exams = item.select("article");
@ -51,15 +58,24 @@ public class ExamsWeek {
.setType(snp.getRowDataChildValue(e, 2))
.setDescription(snp.getRowDataChildValue(e, 3))
.setTeacher(snp.getRowDataChildValue(e, 4).split(", ")[0])
.setEntryDate(snp.getRowDataChildValue(e, 4).split(", ")[1])
.setEntryDate(getFormattedDate(snp.getRowDataChildValue(e, 4).split(", ")[1]))
);
}
days.add(day);
}
return new Week<ExamDay>()
.setStartDayDate(examsDays.select("h2").first().text().split(" ")[1])
.setStartDayDate(getFormattedDate(examsPage.select(".mainContainer > h2")
.first().text().split(" ")[1]))
.setDays(days);
}
private String getFormattedDate(String date) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
Date d = sdf.parse(date);
sdf.applyPattern("yyyy-MM-dd");
return sdf.format(d);
}
}

View File

@ -11,10 +11,6 @@ public class Day {
private String dayName = "";
private boolean isFreeDay = false;
private String freeDayName = "";
public Lesson getLesson(int index) {
return lessons.get(index);
}
@ -44,20 +40,4 @@ public class Day {
public void setDayName(String dayName) {
this.dayName = dayName;
}
public boolean isFreeDay() {
return isFreeDay;
}
public void setFreeDay(boolean freeDay) {
isFreeDay = freeDay;
}
public String getFreeDayName() {
return freeDayName;
}
public void setFreeDayName(String freeDayName) {
this.freeDayName = freeDayName;
}
}

View File

@ -18,8 +18,6 @@ public class Grade {
private String teacher = "";
private String semester = "";
public String getSubject() {
return subject;
}
@ -99,14 +97,4 @@ public class Grade {
return this;
}
public String getSemester() {
return semester;
}
public Grade setSemester(String semester) {
this.semester = semester;
return this;
}
}

View File

@ -14,7 +14,6 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.github.wulkanowy.api.Semester;
import io.github.wulkanowy.api.SnP;
import io.github.wulkanowy.api.VulcanException;
@ -42,24 +41,18 @@ public class GradesList {
Document gradesPage = snp.getSnPPageDocument(getGradesPageUrl() + semester);
Elements gradesRows = gradesPage.select(".ocenySzczegoly-table > tbody > tr");
if ("".equals(semester)) {
List<Semester> semesterList = snp.getSemesters(gradesPage);
Semester currentSemester = snp.getCurrent(semesterList);
semester = currentSemester.getName();
}
for (Element row : gradesRows) {
if ("Brak ocen".equals(row.select("td:nth-child(2)").text())) {
continue;
}
grades.add(getGrade(row, semester));
grades.add(getGrade(row));
}
return grades;
}
private Grade getGrade(Element row, String semester) throws ParseException {
private Grade getGrade(Element row) throws ParseException {
String descriptions = row.select("td:nth-child(3)").text();
String symbol = descriptions.split(", ")[0];
@ -75,8 +68,7 @@ public class GradesList {
.setDescription(description)
.setWeight(row.select("td:nth-child(4)").text())
.setDate(date)
.setTeacher(row.select("td:nth-child(6)").text())
.setSemester(semester);
.setTeacher(row.select("td:nth-child(6)").text());
}
private String getColor(String styleAttr) {

View File

@ -13,16 +13,21 @@ import io.github.wulkanowy.api.VulcanException;
public class SubjectsList {
private static final String SUBJECTS_PAGE_URL = "Oceny/Wszystkie?details=1";
private static final String SUBJECTS_PAGE_URL = "Oceny/Wszystkie?details=1&okres=";
private SnP snp = null;
private SnP snp;
public SubjectsList(SnP snp) {
this.snp = snp;
}
public List<Subject> getAll() throws IOException, VulcanException {
Document subjectPage = snp.getSnPPageDocument(SUBJECTS_PAGE_URL);
return getAll("");
}
public List<Subject> getAll(String semester) throws IOException, VulcanException {
Document subjectPage = snp.getSnPPageDocument(SUBJECTS_PAGE_URL + semester);
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");

View File

@ -31,12 +31,27 @@ public class Login {
}
Document sendCredentials(String email, String password) throws IOException, VulcanException {
Document html = client.postPageByUrl(LOGIN_PAGE_URL, new String[][]{
String[][] credentials = new String[][]{
{"LoginName", email},
{"Password", password}
});
};
Element errorMessage = html.select(".ErrorMessage").first();
String nextUrl = LOGIN_PAGE_URL;
Document loginPage = client.getPageByUrl(nextUrl, false);
Element formFirst = loginPage.select("#form1").first();
if (null != formFirst) { // on adfs login
Document formSecond = client.postPageByUrl(
formFirst.attr("abs:action"),
getFormStateParams(formFirst, "", "")
);
credentials = getFormStateParams(formSecond, email, password);
nextUrl = formSecond.select("#form1").first().attr("abs:action");
}
Document html = client.postPageByUrl(nextUrl, credentials);
Element errorMessage = html.select(".ErrorMessage, #ErrorTextLabel").first();
if (null != errorMessage) {
throw new BadCredentialsException(errorMessage.text());
}
@ -44,6 +59,21 @@ public class Login {
return html;
}
private String[][] getFormStateParams(Element form, String email, String password) {
return new String[][]{
{"__VIEWSTATE", form.select("#__VIEWSTATE").val()},
{"__VIEWSTATEGENERATOR", form.select("#__VIEWSTATEGENERATOR").val()},
{"__EVENTVALIDATION", form.select("#__EVENTVALIDATION").val()},
{"__db", form.select("input[name=__db]").val()},
{"PassiveSignInButton.x", "0"},
{"PassiveSignInButton.y", "0"},
{"SubmitButton.x", "0"},
{"SubmitButton.y", "0"},
{"UsernameTextBox", email},
{"PasswordTextBox", password},
};
}
String sendCertificate(Document doc, String defaultSymbol) throws IOException, VulcanException {
String certificate = doc.select("input[name=wresult]").val();
@ -53,6 +83,10 @@ public class Login {
Document targetDoc = sendCertData(doc);
String title = targetDoc.select("title").text();
if ("Working...".equals(title)) { // on adfs login
title = sendCertData(targetDoc).select("title").text();
}
if ("Logowanie".equals(title)) {
throw new AccountPermissionException("No account access. Try another symbol");
}

View File

@ -14,7 +14,6 @@ import java.util.Locale;
import io.github.wulkanowy.api.SnP;
import io.github.wulkanowy.api.VulcanException;
import io.github.wulkanowy.api.generic.Day;
import io.github.wulkanowy.api.generic.Lesson;
import io.github.wulkanowy.api.generic.Week;
@ -28,25 +27,25 @@ public class Timetable {
this.snp = snp;
}
public Week<Day> getWeekTable() throws IOException, ParseException, VulcanException {
public Week<TimetableDay> getWeekTable() throws IOException, ParseException, VulcanException {
return getWeekTable("");
}
public Week<Day> getWeekTable(final String tick) throws IOException, ParseException, VulcanException {
public Week<TimetableDay> getWeekTable(final String tick) throws IOException, ParseException, VulcanException {
Element table = snp.getSnPPageDocument(TIMETABLE_PAGE_URL + tick)
.select(".mainContainer .presentData").first();
List<Day> days = getDays(table.select("thead th"));
List<TimetableDay> days = getDays(table.select("thead th"));
setLessonToDays(table, days);
return new Week<Day>()
return new Week<TimetableDay>()
.setStartDayDate(days.get(0).getDate())
.setDays(days);
}
private List<Day> getDays(Elements tableHeaderCells) throws ParseException {
List<Day> days = new ArrayList<>();
private List<TimetableDay> getDays(Elements tableHeaderCells) throws ParseException {
List<TimetableDay> days = new ArrayList<>();
for (int i = 2; i < 7; i++) {
String[] dayHeaderCell = tableHeaderCells.get(i).html().split("<br>");
@ -55,7 +54,7 @@ public class Timetable {
Date d = sdf.parse(dayHeaderCell[1].trim());
sdf.applyPattern("yyyy-MM-dd");
Day day = new Day();
TimetableDay day = new TimetableDay();
day.setDayName(dayHeaderCell[0]);
day.setDate(sdf.format(d));
@ -70,7 +69,7 @@ public class Timetable {
return days;
}
private void setLessonToDays(Element table, List<Day> days) {
private void setLessonToDays(Element table, List<TimetableDay> days) {
for (Element row : table.select("tbody tr")) {
Elements hours = row.select("td");
@ -95,12 +94,15 @@ public class Timetable {
moveWarningToLessonNode(e);
switch (e.size()) {
case 2:
Element span = e.last().select("span").first();
if (span.hasClass(LessonTypes.CLASS_MOVED_OR_CANCELED)) {
lesson.setNewMovedInOrChanged(true);
lesson.setDescription("poprzednio: " + getLessonAndGroupInfoFromSpan(span)[0]);
}
case 1:
addLessonInfoFromElement(lesson, e.first());
break;
case 2:
addLessonInfoFromElement(lesson, e.last());
break;
case 3:
addLessonInfoFromElement(lesson, e.get(1));
break;

View File

@ -0,0 +1,26 @@
package io.github.wulkanowy.api.timetable;
import io.github.wulkanowy.api.generic.Day;
public class TimetableDay extends Day {
private boolean isFreeDay = false;
private String freeDayName = "";
public boolean isFreeDay() {
return isFreeDay;
}
public void setFreeDay(boolean freeDay) {
isFreeDay = freeDay;
}
public String getFreeDayName() {
return freeDayName;
}
public void setFreeDayName(String freeDayName) {
this.freeDayName = freeDayName;
}
}

View File

@ -96,12 +96,12 @@ public class StudentAndParentTest {
Assert.assertEquals(2, semesters.size());
Assert.assertEquals("1", semesters.get(0).getId());
Assert.assertEquals("1234", semesters.get(0).getName());
Assert.assertEquals("1", semesters.get(0).getName());
Assert.assertEquals("1234", semesters.get(0).getId());
Assert.assertFalse(semesters.get(0).isCurrent());
Assert.assertEquals("2", semesters.get(1).getId());
Assert.assertEquals("1235", semesters.get(1).getName());
Assert.assertEquals("2", semesters.get(1).getName());
Assert.assertEquals("1235", semesters.get(1).getId());
Assert.assertTrue(semesters.get(1).isCurrent());
}
@ -150,9 +150,7 @@ public class StudentAndParentTest {
Assert.assertFalse(snp.getDiaries().get(1).isCurrent());
Assert.assertFalse(snp.getDiaries().get(2).isCurrent());
Assert.assertEquals("100", snp.getDiaries().get(0).getStudentId());
Assert.assertEquals("Jan Kowal", snp.getStudents().get(0).getName());
Assert.assertEquals("100", snp.getStudents().get(0).getStudentId());
Assert.assertEquals("100", snp.getStudents().get(0).getId());
}
}

View File

@ -12,20 +12,25 @@ public class ExamsWeekTest extends StudentAndParentTestCase {
private ExamsWeek onePerDay;
private ExamsWeek empty;
@Before
public void getCurrent() throws Exception {
onePerDay = new ExamsWeek(getSnp("Sprawdziany-one-per-day.html"));
empty = new ExamsWeek(getSnp("Sprawdziany-empty.html"));
}
@Test
public void getWeekTest() throws Exception {
Assert.assertEquals("23.10.2017", onePerDay.getCurrent().getStartDayDate());
Assert.assertEquals("2017-10-23", onePerDay.getCurrent().getStartDayDate());
Assert.assertEquals("2018-04-30", empty.getCurrent().getStartDayDate());
}
@Test
public void getDaysListTest() throws Exception {
Assert.assertEquals(3, onePerDay.getCurrent().getDays().size());
Assert.assertEquals(7, onePerDay.getWeek("", false).getDays().size());
Assert.assertEquals(0, empty.getCurrent().getDays().size());
}
@Test
@ -45,9 +50,18 @@ public class ExamsWeekTest extends StudentAndParentTestCase {
public void getDayDateTest() throws Exception {
List<ExamDay> dayList = onePerDay.getCurrent().getDays();
Assert.assertEquals("23.10.2017", dayList.get(0).getDate());
Assert.assertEquals("24.10.2017", dayList.get(1).getDate());
Assert.assertEquals("27.10.2017", dayList.get(2).getDate());
Assert.assertEquals("2017-10-23", dayList.get(0).getDate());
Assert.assertEquals("2017-10-24", dayList.get(1).getDate());
Assert.assertEquals("2017-10-27", dayList.get(2).getDate());
}
@Test
public void getDayNameTest() throws Exception {
List<ExamDay> dayList = onePerDay.getCurrent().getDays();
Assert.assertEquals("Poniedziałek", dayList.get(0).getDayName());
Assert.assertEquals("Wtorek", dayList.get(1).getDayName());
Assert.assertEquals("Piątek", dayList.get(2).getDayName());
}
@Test
@ -90,8 +104,8 @@ public class ExamsWeekTest extends StudentAndParentTestCase {
public void getExamEntryDateTest() throws Exception {
List<ExamDay> dayList = onePerDay.getCurrent().getDays();
Assert.assertEquals("16.10.2017", dayList.get(0).getExamList().get(0).getEntryDate());
Assert.assertEquals("17.10.2017", dayList.get(1).getExamList().get(0).getEntryDate());
Assert.assertEquals("16.10.2017", dayList.get(2).getExamList().get(0).getEntryDate());
Assert.assertEquals("2017-10-16", dayList.get(0).getExamList().get(0).getEntryDate());
Assert.assertEquals("2017-10-17", dayList.get(1).getExamList().get(0).getEntryDate());
Assert.assertEquals("2017-10-16", dayList.get(2).getExamList().get(0).getEntryDate());
}
}

View File

@ -101,14 +101,4 @@ public class GradesListTest extends StudentAndParentTestCase {
Assert.assertEquals("Klaudia Dziedzic", list.get(4).getTeacher());
Assert.assertEquals("Amelia Stępień", list.get(5).getTeacher());
}
@Test
public void getSemesterTest() throws Exception {
List<Grade> list = filled.getAll();
Assert.assertEquals("7654321", list.get(0).getSemester());
Assert.assertEquals("7654321", list.get(3).getSemester());
Assert.assertEquals("7654321", list.get(4).getSemester());
Assert.assertEquals("7654321", list.get(5).getSemester());
}
}

View File

@ -24,6 +24,7 @@ public class LoginTest {
Client client = Mockito.mock(Client.class);
Mockito.when(client.postPageByUrl(Mockito.anyString(), Mockito.any(String[][].class))).thenReturn(doc);
Mockito.when(client.getPageByUrl(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(doc);
return client;
}
@ -56,10 +57,8 @@ public class LoginTest {
Login login = new Login(client);
Assert.assertEquals(
getFixtureAsString("cert.xml").replaceAll("\\s+",""),
login.sendCredentials("a@a", "passwd")
.select("input[name=wresult]").attr("value")
.replaceAll("\\s+","")
getFixtureAsString("cert-stock.xml").replaceAll("\\s+",""),
login.sendCredentials("a@a", "passwd").select("input[name=wresult]").attr("value").replaceAll("\\s+","")
);
}
@ -83,21 +82,21 @@ public class LoginTest {
public void sendCertificateAccountPermissionTest() throws Exception {
Login login = new Login(getClient("Logowanie-brak-dostepu.html"));
login.sendCertificate(getFixtureAsDocument("cert.xml"), "demo123");
login.sendCertificate(getFixtureAsDocument("cert-stock.xml"), "demo123");
}
@Test(expected = LoginErrorException.class)
public void sendCertificateLoginErrorTest() throws Exception {
Login login = new Login(getClient("Logowanie-certyfikat.html")); // change to other document
login.sendCertificate(getFixtureAsDocument("cert.xml"), "demo123");
login.sendCertificate(getFixtureAsDocument("cert-stock.xml"), "demo123");
}
@Test
public void findSymbolInCertificateTest() throws Exception {
Login login = new Login(getClient("Logowanie-certyfikat.html"));
String certificate = getFixtureAsString("cert.xml");
String certificate = getFixtureAsString("cert-stock.xml");
Assert.assertEquals("demo12345", login.findSymbolInCertificate(certificate));
}

View File

@ -110,6 +110,7 @@ public class TimetableTest extends StudentAndParentTestCase {
Assert.assertEquals("Uroczyste zakończenie roku szkolnego", full.getWeekTable().getDay(4).getLesson(0).getSubject());
Assert.assertEquals("Fizyka", full.getWeekTable().getDay(0).getLesson(0).getSubject());
Assert.assertEquals("Metodologia programowania", full.getWeekTable().getDay(1).getLesson(0).getSubject());
Assert.assertEquals("Język niemiecki", full.getWeekTable().getDay(4).getLesson(2).getSubject());
Assert.assertEquals("", holidays.getWeekTable().getDay(3).getLesson(3).getSubject());
}
@ -122,6 +123,7 @@ public class TimetableTest extends StudentAndParentTestCase {
Assert.assertEquals("Nowak Jadwiga", full.getWeekTable().getDay(2).getLesson(0).getTeacher());
Assert.assertEquals("Nowicka Irena", full.getWeekTable().getDay(3).getLesson(1).getTeacher());
Assert.assertEquals("Baran Małgorzata", full.getWeekTable().getDay(4).getLesson(0).getTeacher());
Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getTeacher());
Assert.assertEquals("", holidays.getWeekTable().getDay(3).getLesson(3).getTeacher());
}
@ -148,7 +150,10 @@ public class TimetableTest extends StudentAndParentTestCase {
Assert.assertEquals("zastępstwo (poprzednio: Religia)", full.getWeekTable().getDay(2).getLesson(0).getDescription());
Assert.assertEquals("zastępstwo (poprzednio: Wychowanie fizyczne)", full.getWeekTable().getDay(3).getLesson(1).getDescription());
Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(0).getDescription());
Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getDescription());
Assert.assertEquals("poprzednio: Wychowanie fizyczne", full.getWeekTable().getDay(4).getLesson(2).getDescription());
Assert.assertEquals("egzamin", full.getWeekTable().getDay(3).getLesson(0).getDescription());
Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getDescription());
Assert.assertEquals("", holidays.getWeekTable().getDay(3).getLesson(3).getDescription());
}
@ -237,6 +242,8 @@ public class TimetableTest extends StudentAndParentTestCase {
Assert.assertTrue(full.getWeekTable().getDay(1).getLesson(2).isNewMovedInOrChanged());
Assert.assertTrue(full.getWeekTable().getDay(1).getLesson(3).isNewMovedInOrChanged());
Assert.assertTrue(full.getWeekTable().getDay(3).getLesson(1).isNewMovedInOrChanged());
Assert.assertFalse(full.getWeekTable().getDay(4).getLesson(1).isNewMovedInOrChanged());
Assert.assertTrue(full.getWeekTable().getDay(4).getLesson(2).isNewMovedInOrChanged());
Assert.assertFalse(holidays.getWeekTable().getDay(3).getLesson(3).isNewMovedInOrChanged());
}
}

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Witryna ucznia i rodzica Terminarz sprawdzian&#243;w</title>
</head>
<body>
<main class="mainContainer">
<h1>Sprawdziany</h1>
<h2>Tydzień 30.04.2018 - 06.05.2018</h2>
<h2>Nie zaplanowano żadnych sprawdzian&#243;w na wybrany tydzień</h2>
<div class="navigation">
<a href="/symbol/123456/Sprawdziany.mvc/Terminarz?data=636600384000000000&amp;rokSzkolny=2017&amp;rodzajWidoku=2" class="button-prev">Poprzedni tydzień</a>
<a href="/symbol/123456/Sprawdziany.mvc/Terminarz?data=636612480000000000&amp;rokSzkolny=2017&amp;rodzajWidoku=2" class="button-next">Następny tydzień</a>
</div>
</main>
<footer>wersja: 17.09.0009.26859</footer>
</body>
</html>

View File

@ -3,10 +3,10 @@
<title>Working...</title>
</head>
<body>
<form method="POST" name="hiddenform" action="https://fake-log.com/Default/LoginEndpoint.aspx">
<form method="POST" name="hiddenform" action="https://fakelog.cf/Default/LoginEndpoint.aspx">
<input type="hidden" name="wa" value="wsignin1.0">
<input type="hidden" name="wresult" value="<trust:RequestSecurityTokenResponseCollection xmlns:trust=&quot;http://docs.oasis-open.org/ws-sx/ws-trust/200512&quot;><trust:RequestSecurityTokenResponse Context=&quot;https://uonetplus.fake-log.com/Default/LoginEndpoint.aspx&quot;><trust:RequestedSecurityToken><saml:Assertion AssertionID=&quot;_12345678-1234-1234-1234-1234567890ab&quot; IssueInstant=&quot;2017-10-18T22:00:29.006Z&quot; Issuer=&quot;CUFSTokenService&quot; MajorVersion=&quot;1&quot; MinorVersion=&quot;1&quot; xmlns:saml=&quot;urn:oasis:names:tc:SAML:1.0:assertion&quot;><saml:AttributeStatement><saml:Attribute AttributeName=&quot;UserInstance&quot; AttributeNamespace=&quot;http://schemas.fake-log.com/ws/identity/claims&quot;><saml:AttributeValue>Default</saml:AttributeValue><saml:AttributeValue>demo12345</saml:AttributeValue><saml:AttributeValue>incorrect value</saml:AttributeValue><saml:AttributeValue>warszawa</saml:AttributeValue><saml:AttributeValue>asdf</saml:AttributeValue><saml:AttributeValue>asdfsdf</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion></trust:RequestedSecurityToken></trust:RequestSecurityTokenResponse></trust:RequestSecurityTokenResponseCollection>">
<input type="hidden" name="wctx" value="https://fake-log.com/Default/LoginEndpoint.aspx">
<input type="hidden" name="wresult" value="<trust:RequestSecurityTokenResponseCollection xmlns:trust=&quot;http://docs.oasis-open.org/ws-sx/ws-trust/200512&quot;><trust:RequestSecurityTokenResponse Context=&quot;https://uonetplus.fakelog.cf/Default/LoginEndpoint.aspx&quot;><trust:RequestedSecurityToken><saml:Assertion AssertionID=&quot;_12345678-1234-1234-1234-1234567890ab&quot; IssueInstant=&quot;2017-10-18T22:00:29.006Z&quot; Issuer=&quot;CUFSTokenService&quot; MajorVersion=&quot;1&quot; MinorVersion=&quot;1&quot; xmlns:saml=&quot;urn:oasis:names:tc:SAML:1.0:assertion&quot;><saml:AttributeStatement><saml:Attribute AttributeName=&quot;UserInstance&quot; AttributeNamespace=&quot;http://schemas.fakelog.cf/ws/identity/claims&quot;><saml:AttributeValue>Default</saml:AttributeValue><saml:AttributeValue>demo12345</saml:AttributeValue><saml:AttributeValue>incorrect value</saml:AttributeValue><saml:AttributeValue>warszawa</saml:AttributeValue><saml:AttributeValue>asdf</saml:AttributeValue><saml:AttributeValue>asdfsdf</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion></trust:RequestedSecurityToken></trust:RequestSecurityTokenResponse></trust:RequestSecurityTokenResponseCollection>">
<input type="hidden" name="wctx" value="https://fakelog.cf/Default/LoginEndpoint.aspx">
<noscript>
<p>Script is disabled. Click Submit to continue.</p>
<input type="submit" value="Submit">

View File

@ -1,9 +1,9 @@
<trust:RequestSecurityTokenResponseCollection xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
<trust:RequestSecurityTokenResponse Context="https://uonetplus.fake-log.com/Default/LoginEndpoint.aspx">
<trust:RequestSecurityTokenResponse Context="https://uonetplus.fakelog.cf/Default/LoginEndpoint.aspx">
<trust:RequestedSecurityToken>
<saml:Assertion AssertionID="_12345678-1234-1234-1234-1234567890ab" IssueInstant="2017-10-18T22:00:29.006Z" Issuer="CUFSTokenService" MajorVersion="1" MinorVersion="1" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
<saml:AttributeStatement>
<saml:Attribute AttributeName="UserInstance" AttributeNamespace="http://schemas.fake-log.com/ws/identity/claims">
<saml:Attribute AttributeName="UserInstance" AttributeNamespace="http://schemas.fakelog.cf/ws/identity/claims">
<saml:AttributeValue>Default</saml:AttributeValue>
<saml:AttributeValue>demo12345</saml:AttributeValue>
<saml:AttributeValue>incorrect value</saml:AttributeValue>

View File

@ -82,13 +82,6 @@
</div>
</td>
<td>
<div>
<span class="x-treelabel-ppl x-treelabel-inv">Metodologia programowania [zaw2]</span>
<span class="x-treelabel-ppl x-treelabel-inv"></span>
<span class="x-treelabel-ppl x-treelabel-inv">Baran Małgorzata</span>
<span class="x-treelabel-ppl x-treelabel-inv">36</span>
<span class="x-treelabel-rlz">(zmiana organizacji zajęć)</span>
</div>
<div>
<span class="x-treelabel-ppl x-treelabel-zas">Wychowanie fizyczne [zaw2]</span>
<span class="x-treelabel-ppl x-treelabel-zas"></span>
@ -96,6 +89,13 @@
<span class="x-treelabel-ppl x-treelabel-zas">G3</span>
<span class="x-treelabel-rlz">(przeniesiona z lekcji 7, 01.12.2017)</span>
</div>
<div>
<span class="x-treelabel-ppl x-treelabel-inv">Metodologia programowania [zaw2]</span>
<span class="x-treelabel-ppl x-treelabel-inv"></span>
<span class="x-treelabel-ppl x-treelabel-inv">Baran Małgorzata</span>
<span class="x-treelabel-ppl x-treelabel-inv">36</span>
<span class="x-treelabel-rlz">(zmiana organizacji zajęć)</span>
</div>
</td>
<td>
<div>
@ -118,7 +118,18 @@
<span class="x-treelabel-rlz">(zastępstwo)</span>
</div>
</td>
<td></td>
<td>
<div>
<span class="">Uroczyste rozpoczecie roku szkolnego 2017/2018</span>
<span class=""></span>
<span class=""></span>
</div>
<div>
<span class="x-treelabel-ppl">Uroczyste rozpoczecie roku szkolnego 2017/2018</span>
<span class="x-treelabel-ppl"></span>
<span class="x-treelabel-ppl"></span>
</div>
</td>
</tr>
<tr>
<td>2</td>
@ -165,7 +176,20 @@
<span></span>
</div>
</td>
<td></td>
<td>
<div>
<span class="">Język niemiecki [wf_grupa_2]</span>
<span class=""></span>
<span class=""></span>
<span class=""></span>
</div>
<div>
<span class="x-treelabel-ppl x-treelabel-inv">Wychowanie fizyczne [wf_grupa_2]</span>
<span class="x-treelabel-ppl x-treelabel-inv"></span>
<span class="x-treelabel-ppl x-treelabel-inv">Nauczycielel</span>
<span class="x-treelabel-ppl x-treelabel-inv">106</span>
</div>
</td>
</tr>
<tr>
<td>3</td>

View File

@ -2,11 +2,14 @@ buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
classpath 'io.fabric.tools:gradle:1.25.1'
classpath "org.greenrobot:greendao-gradle-plugin:$greenDaoGradle"
classpath "io.fabric.tools:gradle:$fabricGradle"
classpath "com.google.gms:oss-licenses:0.9.2"
classpath 'com.github.triplet.gradle:play-publisher:1.2.0'
}
}
@ -19,28 +22,49 @@ apply plugin: 'org.greenrobot.greendao'
apply plugin: 'io.fabric'
apply from: '../jacoco.gradle'
apply from: '../android-sonarqube.gradle'
apply plugin: 'com.google.gms.oss.licenses.plugin'
apply plugin: 'com.github.triplet.play'
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
playAccountConfigs {
defaultAccountConfig {
serviceAccountEmail = System.getenv("PLAY_SERVICE_ACCOUNT_EMAIL")
pk12File = file('key.p12')
}
}
defaultConfig {
applicationId "io.github.wulkanowy"
testApplicationId "io.github.tests.wulkanowy"
minSdkVersion 15
targetSdkVersion 26
versionCode 7
versionName "0.3.1"
versionCode 8
versionName "0.4.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
playAccountConfig = playAccountConfigs.defaultAccountConfig
manifestPlaceholders = [
fabricApiKey: System.getenv("FABRIC_API_KEY") ?: "null"
]
}
signingConfigs {
release {
storeFile file("upload-key.jks")
storePassword System.getenv("PLAY_STORE_PASSWORD")
keyAlias System.getenv("PLAY_KEY_ALIAS")
keyPassword System.getenv("PLAY_KEY_PASSWORD")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
applicationIdSuffix ".dev"
@ -61,11 +85,20 @@ android {
}
}
play {
track = 'alpha'
uploadImages = true
}
greendao {
schemaVersion 23
schemaVersion 26
generateTests = true
}
configurations.all {
resolutionStrategy.force "com.android.support:support-annotations:$supportVersion"
}
dependencies {
implementation project(':api')
implementation "com.android.support:support-v4:$supportVersion"
@ -83,6 +116,7 @@ dependencies {
implementation "com.google.dagger:dagger-android-support:$dagger2"
implementation "com.aurelhubert:ahbottomnavigation:$ahbottom"
implementation "com.jakewharton.threetenabp:threetenabp:$threeTenABP"
implementation "com.google.android.gms:play-services-oss-licenses:$ossLicenses"
implementation("com.crashlytics.sdk.android:crashlytics:$crashlyticsSdk@aar") {
transitive = true

BIN
app/key-encrypted.p12 Normal file

Binary file not shown.

View File

@ -12,13 +12,13 @@ public class AttendanceLessonTest extends AbstractDaoTestLongPk<AttendanceLesson
protected AttendanceLesson createEntity(Long key) {
AttendanceLesson entity = new AttendanceLesson();
entity.setId(key);
entity.setIsPresence(false);
entity.setIsAbsenceUnexcused(false);
entity.setIsAbsenceExcused(false);
entity.setIsUnexcusedLateness(false);
entity.setIsAbsenceForSchoolReasons(false);
entity.setIsExcusedLateness(false);
entity.setIsExemption(false);
entity.setPresence(false);
entity.setAbsenceUnexcused(false);
entity.setAbsenceExcused(false);
entity.setUnexcusedLateness(false);
entity.setAbsenceForSchoolReasons(false);
entity.setExcusedLateness(false);
entity.setExemption(false);
return entity;
}

View File

@ -12,7 +12,7 @@ public class DayTest extends AbstractDaoTestLongPk<DayDao, Day> {
protected Day createEntity(Long key) {
Day entity = new Day();
entity.setId(key);
entity.setIsFreeDay(false);
entity.setFreeDay(false);
return entity;
}

View File

@ -12,7 +12,7 @@ public class DiaryTest extends AbstractDaoTestLongPk<DiaryDao, Diary> {
protected Diary createEntity(Long key) {
Diary entity = new Diary();
entity.setId(key);
entity.setIsCurrent(false);
entity.setCurrent(false);
return entity;
}

View File

@ -0,0 +1,18 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
public class ExamTest extends AbstractDaoTestLongPk<ExamDao, Exam> {
public ExamTest() {
super(ExamDao.class);
}
@Override
protected Exam createEntity(Long key) {
Exam entity = new Exam();
entity.setId(key);
return entity;
}
}

View File

@ -0,0 +1,21 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
import io.github.wulkanowy.data.db.dao.entities.Semester;
import io.github.wulkanowy.data.db.dao.entities.SemesterDao;
public class SemesterTest extends AbstractDaoTestLongPk<SemesterDao, Semester> {
public SemesterTest() {
super(SemesterDao.class);
}
@Override
protected Semester createEntity(Long key) {
Semester entity = new Semester();
entity.setId(key);
return entity;
}
}

View File

@ -0,0 +1,21 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
import io.github.wulkanowy.data.db.dao.entities.Student;
import io.github.wulkanowy.data.db.dao.entities.StudentDao;
public class StudentTest extends AbstractDaoTestLongPk<StudentDao, Student> {
public StudentTest() {
super(StudentDao.class);
}
@Override
protected Student createEntity(Long key) {
Student entity = new Student();
entity.setId(key);
return entity;
}
}

View File

@ -0,0 +1,21 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
import io.github.wulkanowy.data.db.dao.entities.Symbol;
import io.github.wulkanowy.data.db.dao.entities.SymbolDao;
public class SymbolTest extends AbstractDaoTestLongPk<SymbolDao, Symbol> {
public SymbolTest() {
super(SymbolDao.class);
}
@Override
protected Symbol createEntity(Long key) {
Symbol entity = new Symbol();
entity.setId(key);
return entity;
}
}

View File

@ -12,12 +12,12 @@ public class TimetableLessonTest extends AbstractDaoTestLongPk<TimetableLessonDa
protected TimetableLesson createEntity(Long key) {
TimetableLesson entity = new TimetableLesson();
entity.setId(key);
entity.setIsEmpty(false);
entity.setIsDivisionIntoGroups(false);
entity.setIsPlanning(false);
entity.setIsRealized(false);
entity.setIsMovedOrCanceled(false);
entity.setIsNewMovedInOrChanged(false);
entity.setEmpty(false);
entity.setDivisionIntoGroups(false);
entity.setPlanning(false);
entity.setRealized(false);
entity.setMovedOrCanceled(false);
entity.setNewMovedInOrChanged(false);
return entity;
}

View File

@ -10,8 +10,7 @@
<application
android:name=".WulkanowyApp"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
@ -32,19 +31,40 @@
android:name=".ui.login.LoginActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_login"
android:theme="@style/WulkanowyTheme.LoginTheme"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".ui.main.MainActivity"
android:configChanges="orientation|screenSize"
android:label="@string/activity_dashboard_text" />
android:label="@string/activity_dashboard_text"
android:launchMode="singleTop"
android:theme="@style/WulkanowyTheme" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/WulkanowyTheme.LoginTheme" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:theme="@style/WulkanowyTheme.LoginTheme" />
<service
android:name=".services.SyncJob"
android:name=".services.jobs.SyncJob"
android:exported="false">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE" />
</intent-filter>
</service>
<service
android:name=".services.widgets.TimetableWidgetServices"
android:permission="android.permission.BIND_REMOTEVIEWS" />
<receiver android:name=".ui.widgets.TimetableWidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider" />
</receiver>
<meta-data
android:name="io.fabric.ApiKey"

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,184 +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.Grade;
import io.github.wulkanowy.data.db.dao.entities.GradeDao;
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 int getStartupTab() {
return sharedPref.getStartupTab();
public ResourcesContract getResRepo() {
return resources;
}
@Override
public int getServicesInterval() {
return sharedPref.getServicesInterval();
public DbContract getDbRepo() {
return database;
}
@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();
}
@Override
public void syncSubjects() throws VulcanException, IOException, ParseException {
subjectSync.sync();
}
@Override
public void syncAttendance() throws ParseException, IOException, VulcanException {
attendanceSync.syncAttendance();
}
@Override
public void syncAttendance(String date) throws ParseException, IOException, VulcanException {
attendanceSync.syncAttendance(date);
}
@Override
public void syncTimetable() throws VulcanException, IOException, ParseException {
timetableSync.syncTimetable();
}
@Override
public void syncTimetable(String date) throws VulcanException, IOException, ParseException {
timetableSync.syncTimetable(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.UserId.eq(getCurrentUserId()))
.unique();
}
@Override
public List<Grade> getNewGrades() {
return daoSession.getGradeDao().queryBuilder()
.where(GradeDao.Properties.IsNew.eq(1))
.list();
public SyncContract getSyncRepo() {
return synchronization;
}
}

View File

@ -1,45 +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.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.sync.attendance.AttendanceSyncContract;
import io.github.wulkanowy.data.sync.timetable.TimetableSyncContract;
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
import io.github.wulkanowy.data.sync.SyncContract;
@Singleton
public interface RepositoryContract extends ResourcesContract, AccountSyncContract,
AttendanceSyncContract, TimetableSyncContract {
public interface RepositoryContract {
long getCurrentUserId();
SharedPrefContract getSharedRepo();
int getStartupTab();
ResourcesContract getResRepo();
boolean isServicesEnable();
DbContract getDbRepo();
boolean isNotifyEnable();
int getServicesInterval();
boolean isMobileDisable();
void syncGrades() throws VulcanException, IOException, ParseException;
void syncSubjects() throws VulcanException, IOException, ParseException;
void syncAll() throws VulcanException, IOException, ParseException;
Account getCurrentUser();
Week getWeek(String date);
List<Grade> getNewGrades();
SyncContract getSyncRepo();
}

View File

@ -0,0 +1,30 @@
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);
Week getWeek(long diaryId, String date);
List<Subject> getSubjectList(int semesterName);
List<Grade> getNewGrades(int semesterName);
long getCurrentStudentId();
long getCurrentSymbolId();
long getCurrentDiaryId();
long getSemesterId(int name);
long getCurrentSemesterId();
int getCurrentSemesterName();
}

View File

@ -17,6 +17,7 @@ import javax.inject.Singleton;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
import io.github.wulkanowy.data.db.dao.migrations.Migration23;
import io.github.wulkanowy.data.db.dao.migrations.Migration26;
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
import io.github.wulkanowy.di.annotations.ApplicationContext;
import io.github.wulkanowy.di.annotations.DatabaseInfo;
@ -39,11 +40,9 @@ public class DbHelper extends DaoMaster.OpenHelper {
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Database database = new StandardDatabase(db);
DaoMaster.dropAllTables(database, true);
onCreate(database);
sharedPref.setCurrentUserId(0);
LogUtils.info("Cleaning user data oldVersion=" + oldVersion + " newVersion=" + newVersion);
Database database = new StandardDatabase(db);
recreateDatabase(database);
}
@Override
@ -59,17 +58,24 @@ public class DbHelper extends DaoMaster.OpenHelper {
LogUtils.info("Migration " + migration.getVersion() + " complete");
} catch (Exception e) {
e.printStackTrace();
DaoMaster.dropAllTables(db, true);
sharedPref.setCurrentUserId(0);
recreateDatabase(db);
break;
}
}
}
}
private void recreateDatabase(Database db) {
LogUtils.info("Database is recreating...");
sharedPref.setCurrentUserId(0);
DaoMaster.dropAllTables(db, true);
onCreate(db);
}
private List<Migration> getMigrations() {
List<Migration> migrations = new ArrayList<>();
migrations.add(new Migration23());
migrations.add(new Migration26());
// Sorting just to be safe, in case other people add migrations in the wrong order.
Comparator<Migration> migrationComparator = new Comparator<Migration>() {

View File

@ -0,0 +1,106 @@
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.Semester;
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 getWeek(getCurrentDiaryId(), date);
}
@Override
public Week getWeek(long diaryId, String date) {
return daoSession.getWeekDao().queryBuilder().where(
WeekDao.Properties.StartDayDate.eq(date),
WeekDao.Properties.DiaryId.eq(diaryId)
).unique();
}
@Override
public List<Subject> getSubjectList(int semesterName) {
return daoSession.getSemesterDao().load(getSemesterId(semesterName)).getSubjectList();
}
@Override
public List<Grade> getNewGrades(int semesterName) {
return daoSession.getGradeDao().queryBuilder().where(
GradeDao.Properties.IsNew.eq(1),
GradeDao.Properties.SemesterId.eq(getSemesterId(semesterName))
).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 getSemesterId(int name) {
return daoSession.getSemesterDao().queryBuilder().where(
SemesterDao.Properties.DiaryId.eq(getCurrentDiaryId()),
SemesterDao.Properties.Name.eq(String.valueOf(name))
).unique().getId();
}
@Override
public long getCurrentSemesterId() {
return getCurrentSemester().getId();
}
@Override
public int getCurrentSemesterName() {
return Integer.valueOf(getCurrentSemester().getName());
}
private Semester getCurrentSemester() {
return daoSession.getSemesterDao().queryBuilder().where(
SemesterDao.Properties.DiaryId.eq(getCurrentDiaryId()),
SemesterDao.Properties.Current.eq(true)
).unique();
}
}

View File

@ -4,10 +4,9 @@ import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.JoinProperty;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.Unique;
import java.util.List;
@ -20,38 +19,15 @@ public class Account {
@Id(autoincrement = true)
private Long id;
@Index(unique = true)
@Property(nameInDb = "REAL_ID")
private String realId;
@Property(nameInDb = "SYMBOL")
private String symbol;
@Property(nameInDb = "SCHOOL_ID")
private String schoolId;
@Property(nameInDb = "NAME")
private String name;
@Property(nameInDb = "E_MAIL")
@Unique
@Property(nameInDb = "email")
private String email;
@Property(nameInDb = "PASSWORD")
@Property(nameInDb = "password")
private String password;
@ToMany(joinProperties = {
@JoinProperty(name = "realId", referencedName = "studentId")
})
private List<Diary> diaryList;
@ToMany(referencedJoinProperty = "userId")
private List<Subject> subjectList;
@ToMany(referencedJoinProperty = "userId")
private List<Grade> gradeList;
@ToMany(referencedJoinProperty = "userId")
private List<Day> dayList;
private List<Symbol> symbolList;
/**
* Used to resolve relations
@ -65,14 +41,9 @@ public class Account {
@Generated(hash = 335469827)
private transient AccountDao myDao;
@Generated(hash = 727721142)
public Account(Long id, String realId, String symbol, String schoolId, String name,
String email, String password) {
@Generated(hash = 1104194311)
public Account(Long id, String email, String password) {
this.id = id;
this.realId = realId;
this.symbol = symbol;
this.schoolId = schoolId;
this.name = name;
this.email = email;
this.password = password;
}
@ -82,34 +53,15 @@ public class Account {
}
public Long getId() {
return id;
return this.id;
}
public Account setId(Long id) {
public void setId(Long id) {
this.id = id;
return this;
}
public String getRealId() {
return realId;
}
public Account setRealId(String realId) {
this.realId = realId;
return this;
}
public String getName() {
return name;
}
public Account setName(String name) {
this.name = name;
return this;
}
public String getEmail() {
return email;
return this.email;
}
public Account setEmail(String email) {
@ -118,7 +70,7 @@ public class Account {
}
public String getPassword() {
return password;
return this.password;
}
public Account setPassword(String password) {
@ -126,180 +78,34 @@ public class Account {
return this;
}
public String getSymbol() {
return symbol;
}
public Account setSymbol(String symbol) {
this.symbol = symbol;
return this;
}
public String getSchoolId() {
return schoolId;
}
public Account setSchoolId(String schoolId) {
this.schoolId = schoolId;
return this;
}
public Account setDiaryList(List<Diary> diaryList) {
this.diaryList = diaryList;
return this;
}
public Account setSubjectList(List<Subject> subjectList) {
this.subjectList = subjectList;
return this;
}
public Account setGradeList(List<Grade> gradeList) {
this.gradeList = gradeList;
return this;
}
public Account setDayList(List<Day> dayList) {
this.dayList = dayList;
return this;
}
public DaoSession getDaoSession() {
return daoSession;
}
public Account setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
return this;
}
public AccountDao getMyDao() {
return myDao;
}
public Account setMyDao(AccountDao myDao) {
this.myDao = myDao;
return this;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1472214466)
public List<Diary> getDiaryList() {
if (diaryList == null) {
@Generated(hash = 822972496)
public List<Symbol> getSymbolList() {
if (symbolList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
DiaryDao targetDao = daoSession.getDiaryDao();
List<Diary> diaryListNew = targetDao._queryAccount_DiaryList(realId);
SymbolDao targetDao = daoSession.getSymbolDao();
List<Symbol> symbolListNew = targetDao._queryAccount_SymbolList(id);
synchronized (this) {
if (diaryList == null) {
diaryList = diaryListNew;
if (symbolList == null) {
symbolList = symbolListNew;
}
}
}
return diaryList;
return symbolList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1078514341)
public synchronized void resetDiaryList() {
diaryList = null;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1800750450)
public List<Subject> getSubjectList() {
if (subjectList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
SubjectDao targetDao = daoSession.getSubjectDao();
List<Subject> subjectListNew = targetDao._queryAccount_SubjectList(id);
synchronized (this) {
if (subjectList == null) {
subjectList = subjectListNew;
}
}
}
return subjectList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 594294258)
public synchronized void resetSubjectList() {
subjectList = null;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1040074549)
public List<Grade> getGradeList() {
if (gradeList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
GradeDao targetDao = daoSession.getGradeDao();
List<Grade> gradeListNew = targetDao._queryAccount_GradeList(id);
synchronized (this) {
if (gradeList == null) {
gradeList = gradeListNew;
}
}
}
return gradeList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1939990047)
public synchronized void resetGradeList() {
gradeList = null;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 300459794)
public List<Day> getDayList() {
if (dayList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
DayDao targetDao = daoSession.getDayDao();
List<Day> dayListNew = targetDao._queryAccount_DayList(id);
synchronized (this) {
if (dayList == null) {
dayList = dayListNew;
}
}
}
return dayList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1010399236)
public synchronized void resetDayList() {
dayList = null;
@Generated(hash = 1716801695)
public synchronized void resetSymbolList() {
symbolList = null;
}
/**

View File

@ -20,38 +20,38 @@ public class AttendanceLesson implements Serializable {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "DAY_ID")
@Property(nameInDb = "day_id")
private Long dayId;
@Property(nameInDb = "DATE")
@Property(nameInDb = "date")
private String date = "";
@Property(nameInDb = "NUMBER_OF_LESSON")
@Property(nameInDb = "number_of_lesson")
private int number = 0;
@Property(nameInDb = "SUBJECT_NAME")
@Property(nameInDb = "subject")
private String subject = "";
@Property(nameInDb = "IS_PRESENCE")
private boolean isPresence = false;
@Property(nameInDb = "presence")
private boolean presence = false;
@Property(nameInDb = "IS_ABSENCE_UNEXCUSED")
private boolean isAbsenceUnexcused = false;
@Property(nameInDb = "absence_unexcused")
private boolean absenceUnexcused = false;
@Property(nameInDb = "IS_ABSENCE_EXCUSED")
private boolean isAbsenceExcused = false;
@Property(nameInDb = "absence_excused")
private boolean absenceExcused = false;
@Property(nameInDb = "IS_UNEXCUSED_LATENESS")
private boolean isUnexcusedLateness = false;
@Property(nameInDb = "unexcused_lateness")
private boolean unexcusedLateness = false;
@Property(nameInDb = "IS_ABSENCE_FOR_SCHOOL_REASONS")
private boolean isAbsenceForSchoolReasons = false;
@Property(nameInDb = "absence_for_school_reasons")
private boolean absenceForSchoolReasons = false;
@Property(nameInDb = "IS_EXCUSED_LATENESS")
private boolean isExcusedLateness = false;
@Property(nameInDb = "excused_lateness")
private boolean excusedLateness = false;
@Property(nameInDb = "IS_EXEMPTION")
private boolean isExemption = false;
@Property(nameInDb = "exemption")
private boolean exemption = false;
@Transient
private String description = "";
@ -70,24 +70,24 @@ public class AttendanceLesson implements Serializable {
@Generated(hash = 1936953859)
private transient AttendanceLessonDao myDao;
@Generated(hash = 1428129046)
@Generated(hash = 1741231228)
public AttendanceLesson(Long id, Long dayId, String date, int number,
String subject, boolean isPresence, boolean isAbsenceUnexcused,
boolean isAbsenceExcused, boolean isUnexcusedLateness,
boolean isAbsenceForSchoolReasons, boolean isExcusedLateness,
boolean isExemption) {
String subject, boolean presence, boolean absenceUnexcused,
boolean absenceExcused, boolean unexcusedLateness,
boolean absenceForSchoolReasons, boolean excusedLateness,
boolean exemption) {
this.id = id;
this.dayId = dayId;
this.date = date;
this.number = number;
this.subject = subject;
this.isPresence = isPresence;
this.isAbsenceUnexcused = isAbsenceUnexcused;
this.isAbsenceExcused = isAbsenceExcused;
this.isUnexcusedLateness = isUnexcusedLateness;
this.isAbsenceForSchoolReasons = isAbsenceForSchoolReasons;
this.isExcusedLateness = isExcusedLateness;
this.isExemption = isExemption;
this.presence = presence;
this.absenceUnexcused = absenceUnexcused;
this.absenceExcused = absenceExcused;
this.unexcusedLateness = unexcusedLateness;
this.absenceForSchoolReasons = absenceForSchoolReasons;
this.excusedLateness = excusedLateness;
this.exemption = exemption;
}
@Generated(hash = 921806575)
@ -137,66 +137,66 @@ public class AttendanceLesson implements Serializable {
return this;
}
public boolean getIsPresence() {
return this.isPresence;
public boolean getPresence() {
return this.presence;
}
public AttendanceLesson setIsPresence(boolean isPresence) {
this.isPresence = isPresence;
public AttendanceLesson setPresence(boolean presence) {
this.presence = presence;
return this;
}
public boolean getIsAbsenceUnexcused() {
return this.isAbsenceUnexcused;
public boolean getAbsenceUnexcused() {
return this.absenceUnexcused;
}
public AttendanceLesson setIsAbsenceUnexcused(boolean isAbsenceUnexcused) {
this.isAbsenceUnexcused = isAbsenceUnexcused;
public AttendanceLesson setAbsenceUnexcused(boolean absenceUnexcused) {
this.absenceUnexcused = absenceUnexcused;
return this;
}
public boolean getIsAbsenceExcused() {
return this.isAbsenceExcused;
public boolean getAbsenceExcused() {
return this.absenceExcused;
}
public AttendanceLesson setIsAbsenceExcused(boolean isAbsenceExcused) {
this.isAbsenceExcused = isAbsenceExcused;
public AttendanceLesson setAbsenceExcused(boolean absenceExcused) {
this.absenceExcused = absenceExcused;
return this;
}
public boolean getIsUnexcusedLateness() {
return this.isUnexcusedLateness;
public boolean getUnexcusedLateness() {
return this.unexcusedLateness;
}
public AttendanceLesson setIsUnexcusedLateness(boolean isUnexcusedLateness) {
this.isUnexcusedLateness = isUnexcusedLateness;
public AttendanceLesson setUnexcusedLateness(boolean unexcusedLateness) {
this.unexcusedLateness = unexcusedLateness;
return this;
}
public boolean getIsAbsenceForSchoolReasons() {
return this.isAbsenceForSchoolReasons;
public boolean getAbsenceForSchoolReasons() {
return this.absenceForSchoolReasons;
}
public AttendanceLesson setIsAbsenceForSchoolReasons(boolean isAbsenceForSchoolReasons) {
this.isAbsenceForSchoolReasons = isAbsenceForSchoolReasons;
public AttendanceLesson setAbsenceForSchoolReasons(boolean absenceForSchoolReasons) {
this.absenceForSchoolReasons = absenceForSchoolReasons;
return this;
}
public boolean getIsExcusedLateness() {
return this.isExcusedLateness;
public boolean getExcusedLateness() {
return this.excusedLateness;
}
public AttendanceLesson setIsExcusedLateness(boolean isExcusedLateness) {
this.isExcusedLateness = isExcusedLateness;
public AttendanceLesson setExcusedLateness(boolean excusedLateness) {
this.excusedLateness = excusedLateness;
return this;
}
public boolean getIsExemption() {
return this.isExemption;
public boolean getExemption() {
return this.exemption;
}
public AttendanceLesson setIsExemption(boolean isExemption) {
this.isExemption = isExemption;
public AttendanceLesson setExemption(boolean exemption) {
this.exemption = exemption;
return this;
}

View File

@ -5,7 +5,6 @@ import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.OrderBy;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;
@ -14,38 +13,37 @@ import java.util.List;
@Entity(
nameInDb = "Days",
active = true,
indexes = {@Index(value = "userId,weekId,date", unique = true)}
indexes = {@Index(value = "weekId,date", unique = true)}
)
public class Day {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "USER_ID")
private Long userId;
@Property(nameInDb = "WEEK_ID")
@Property(nameInDb = "week_id")
private Long weekId;
@Property(nameInDb = "DATE")
@Property(nameInDb = "date")
private String date = "";
@Property(nameInDb = "DAY_NAME")
@Property(nameInDb = "day_name")
private String dayName = "";
@Property(nameInDb = "IS_FREE_DAY")
private boolean isFreeDay = false;
@Property(nameInDb = "free_day")
private boolean freeDay = false;
@Property(nameInDb = "FREE_DAY_NAME")
@Property(nameInDb = "free_day_name")
private String freeDayName = "";
@ToMany(referencedJoinProperty = "dayId")
private List<TimetableLesson> timetableLessons;
@ToMany(referencedJoinProperty = "dayId")
@OrderBy("number ASC")
private List<AttendanceLesson> attendanceLessons;
@ToMany(referencedJoinProperty = "dayId")
private List<Exam> exams;
/**
* Used to resolve relations
*/
@ -58,15 +56,14 @@ public class Day {
@Generated(hash = 312167767)
private transient DayDao myDao;
@Generated(hash = 723729681)
public Day(Long id, Long userId, Long weekId, String date, String dayName,
boolean isFreeDay, String freeDayName) {
@Generated(hash = 523139020)
public Day(Long id, Long weekId, String date, String dayName, boolean freeDay,
String freeDayName) {
this.id = id;
this.userId = userId;
this.weekId = weekId;
this.date = date;
this.dayName = dayName;
this.isFreeDay = isFreeDay;
this.freeDay = freeDay;
this.freeDayName = freeDayName;
}
@ -82,26 +79,16 @@ public class Day {
this.id = id;
}
public Long getUserId() {
return userId;
}
public Long getWeekId() {
return weekId;
return this.weekId;
}
public Day setWeekId(Long weekId) {
public void setWeekId(Long weekId) {
this.weekId = weekId;
return this;
}
public Day setUserId(Long userId) {
this.userId = userId;
return this;
}
public String getDate() {
return date;
return this.date;
}
public Day setDate(String date) {
@ -110,7 +97,7 @@ public class Day {
}
public String getDayName() {
return dayName;
return this.dayName;
}
public Day setDayName(String dayName) {
@ -118,17 +105,17 @@ public class Day {
return this;
}
public boolean getIsFreeDay() {
return this.isFreeDay;
public boolean getFreeDay() {
return this.freeDay;
}
public Day setIsFreeDay(boolean isFreeDay) {
this.isFreeDay = isFreeDay;
public Day setFreeDay(boolean freeDay) {
this.freeDay = freeDay;
return this;
}
public String getFreeDayName() {
return freeDayName;
return this.freeDayName;
}
public Day setFreeDayName(String freeDayName) {
@ -159,7 +146,9 @@ public class Day {
return timetableLessons;
}
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1687683740)
public synchronized void resetTimetableLessons() {
timetableLessons = null;
@ -188,7 +177,9 @@ public class Day {
return attendanceLessons;
}
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1343075564)
public synchronized void resetAttendanceLessons() {
attendanceLessons = null;
@ -230,6 +221,36 @@ public class Day {
myDao.update(this);
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1231531946)
public List<Exam> getExams() {
if (exams == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
ExamDao targetDao = daoSession.getExamDao();
List<Exam> examsNew = targetDao._queryDay_Exams(id);
synchronized (this) {
if (exams == null) {
exams = examsNew;
}
}
}
return exams;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 841969952)
public synchronized void resetExams() {
exams = null;
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 1409317752)
public void __setDaoSession(DaoSession daoSession) {

View File

@ -5,6 +5,9 @@ import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;
import java.util.List;
@Entity(
nameInDb = "Diaries",
@ -15,17 +18,20 @@ public class Diary {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "STUDENT_ID")
private String studentId;
@Property(nameInDb = "student_id")
private Long studentId;
@Property(nameInDb = "NAME")
@Property(nameInDb = "current")
private boolean current;
@Property(nameInDb = "name")
private String name;
@Property(nameInDb = "VALUE")
@Property(nameInDb = "value")
private String value;
@Property(nameInDb = "IS_CURRENT")
private boolean isCurrent;
@ToMany(referencedJoinProperty = "diaryId")
private List<Semester> semesterList;
/**
* Used to resolve relations
@ -39,14 +45,13 @@ public class Diary {
@Generated(hash = 21166549)
private transient DiaryDao myDao;
@Generated(hash = 459332202)
public Diary(Long id, String studentId, String name, String value,
boolean isCurrent) {
@Generated(hash = 277096196)
public Diary(Long id, Long studentId, boolean current, String name, String value) {
this.id = id;
this.studentId = studentId;
this.current = current;
this.name = name;
this.value = value;
this.isCurrent = isCurrent;
}
@Generated(hash = 112123061)
@ -54,25 +59,24 @@ public class Diary {
}
public Long getId() {
return id;
return this.id;
}
public Diary setId(Long id) {
public void setId(Long id) {
this.id = id;
return this;
}
public String getStudentId() {
return studentId;
public Long getStudentId() {
return this.studentId;
}
public Diary setStudentId(String studentId) {
public Diary setStudentId(Long studentId) {
this.studentId = studentId;
return this;
}
public String getName() {
return name;
return this.name;
}
public Diary setName(String name) {
@ -81,7 +85,7 @@ public class Diary {
}
public String getValue() {
return value;
return this.value;
}
public Diary setValue(String value) {
@ -89,31 +93,43 @@ public class Diary {
return this;
}
public boolean getIsCurrent() {
return isCurrent;
public boolean getCurrent() {
return this.current;
}
public Diary setIsCurrent(boolean current) {
isCurrent = current;
public Diary setCurrent(boolean current) {
this.current = current;
return this;
}
public DaoSession getDaoSession() {
return daoSession;
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1738383053)
public List<Semester> getSemesterList() {
if (semesterList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
SemesterDao targetDao = daoSession.getSemesterDao();
List<Semester> semesterListNew = targetDao._queryDiary_SemesterList(id);
synchronized (this) {
if (semesterList == null) {
semesterList = semesterListNew;
}
}
}
return semesterList;
}
public Diary setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
return this;
}
public DiaryDao getMyDao() {
return myDao;
}
public Diary setMyDao(DiaryDao myDao) {
this.myDao = myDao;
return this;
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 995060657)
public synchronized void resetSemesterList() {
semesterList = null;
}
/**

View File

@ -0,0 +1,175 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import java.io.Serializable;
@Entity(
nameInDb = "Exams",
active = true
)
public class Exam implements Serializable {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "day_id")
private Long dayId;
@Property(nameInDb = "subject_and_group")
private String subjectAndGroup = "";
@Property(nameInDb = "type")
private String type = "";
@Property(nameInDb = "description")
private String description = "";
@Property(nameInDb = "teacher")
private String teacher = "";
@Property(nameInDb = "entry_date")
private String entryDate = "";
private static final long serialVersionUID = 42L;
/**
* Used to resolve relations
*/
@Generated(hash = 2040040024)
private transient DaoSession daoSession;
/**
* Used for active entity operations.
*/
@Generated(hash = 973692038)
private transient ExamDao myDao;
@Generated(hash = 998653360)
public Exam(Long id, Long dayId, String subjectAndGroup, String type, String description,
String teacher, String entryDate) {
this.id = id;
this.dayId = dayId;
this.subjectAndGroup = subjectAndGroup;
this.type = type;
this.description = description;
this.teacher = teacher;
this.entryDate = entryDate;
}
@Generated(hash = 945526930)
public Exam() {
}
public Long getId() {
return id;
}
public Exam setId(Long id) {
this.id = id;
return this;
}
public Long getDayId() {
return this.dayId;
}
public Exam setDayId(Long dayId) {
this.dayId = dayId;
return this;
}
public String getSubjectAndGroup() {
return subjectAndGroup;
}
public Exam setSubjectAndGroup(String subjectAndGroup) {
this.subjectAndGroup = subjectAndGroup;
return this;
}
public String getType() {
return type;
}
public Exam setType(String type) {
this.type = type;
return this;
}
public String getDescription() {
return description;
}
public Exam setDescription(String description) {
this.description = description;
return this;
}
public String getTeacher() {
return teacher;
}
public Exam setTeacher(String teacher) {
this.teacher = teacher;
return this;
}
public String getEntryDate() {
return entryDate;
}
public Exam setEntryDate(String entryDate) {
this.entryDate = entryDate;
return this;
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 128553479)
public void delete() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.delete(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 1942392019)
public void refresh() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.refresh(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 713229351)
public void update() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.update(this);
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 1730563422)
public void __setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
myDao = daoSession != null ? daoSession.getExamDao() : null;
}
}

View File

@ -10,8 +10,6 @@ import org.greenrobot.greendao.annotation.Property;
import java.io.Serializable;
import io.github.wulkanowy.R;
@Entity(
nameInDb = "Grades",
active = true
@ -21,72 +19,44 @@ public class Grade implements Serializable {
@Id(autoincrement = true)
protected Long id;
@Property(nameInDb = "SUBJECT_ID")
@Property(nameInDb = "semester_id")
private Long semesterId;
@Property(nameInDb = "subject_id")
private Long subjectId;
@Property(nameInDb = "USER_ID")
private Long userId;
@Property(nameInDb = "SUBJECT")
@Property(nameInDb = "subject")
private String subject = "";
@Property(nameInDb = "VALUE")
@Property(nameInDb = "value")
protected String value = "";
@Property(nameInDb = "COLOR")
private String color = "";
@Property(nameInDb = "SYMBOL")
private String symbol = "";
@Property(nameInDb = "DESCRIPTION")
private String description = "";
@Property(nameInDb = "WEIGHT")
@Property(nameInDb = "weight")
private String weight = "";
@Property(nameInDb = "DATE")
@Property(nameInDb = "date")
private String date = "";
@Property(nameInDb = "TEACHER")
@Property(nameInDb = "symbol")
private String symbol = "";
@Property(nameInDb = "color")
private String color = "";
@Property(nameInDb = "description")
private String description = "";
@Property(nameInDb = "teacher")
private String teacher = "";
@Property(nameInDb = "SEMESTER")
private String semester = "";
@Property(nameInDb = "IS_NEW")
@Property(nameInDb = "is_new")
private boolean isNew = false;
@Property(nameInDb = "READ")
@Property(nameInDb = "read")
private boolean read = true;
private static final long serialVersionUID = 42L;
@Generated(hash = 568899968)
public Grade(Long id, Long subjectId, Long userId, String subject, String value,
String color, String symbol, String description, String weight,
String date, String teacher, String semester, boolean isNew,
boolean read) {
this.id = id;
this.subjectId = subjectId;
this.userId = userId;
this.subject = subject;
this.value = value;
this.color = color;
this.symbol = symbol;
this.description = description;
this.weight = weight;
this.date = date;
this.teacher = teacher;
this.semester = semester;
this.isNew = isNew;
this.read = read;
}
@Generated(hash = 2042976393)
public Grade() {
}
/**
* Used to resolve relations
*/
@ -99,29 +69,27 @@ public class Grade implements Serializable {
@Generated(hash = 681281562)
private transient GradeDao myDao;
public int getValueColor() {
@Generated(hash = 2042976393)
public Grade() {
}
String replacedString = value.replaceAll("[^0-9]", "");
if (!"".equals(replacedString)) {
switch (Integer.parseInt(replacedString)) {
case 6:
return R.color.six_grade;
case 5:
return R.color.five_grade;
case 4:
return R.color.four_grade;
case 3:
return R.color.three_grade;
case 2:
return R.color.two_grade;
case 1:
return R.color.one_grade;
default:
return R.color.default_grade;
}
}
return R.color.default_grade;
@Generated(hash = 619853992)
public Grade(Long id, Long semesterId, Long subjectId, String subject, String value,
String weight, String date, String symbol, String color, String description,
String teacher, boolean isNew, boolean read) {
this.id = id;
this.semesterId = semesterId;
this.subjectId = subjectId;
this.subject = subject;
this.value = value;
this.weight = weight;
this.date = date;
this.symbol = symbol;
this.color = color;
this.description = description;
this.teacher = teacher;
this.isNew = isNew;
this.read = read;
}
@Override
@ -133,6 +101,7 @@ public class Grade implements Serializable {
Grade grade = (Grade) o;
return new EqualsBuilder()
.append(semesterId, grade.semesterId)
.append(subject, grade.subject)
.append(value, grade.value)
.append(color, grade.color)
@ -141,13 +110,13 @@ public class Grade implements Serializable {
.append(weight, grade.weight)
.append(date, grade.date)
.append(teacher, grade.teacher)
.append(semester, grade.semester)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(semesterId)
.append(subject)
.append(value)
.append(color)
@ -156,48 +125,19 @@ public class Grade implements Serializable {
.append(weight)
.append(date)
.append(teacher)
.append(semester)
.toHashCode();
}
public Long getId() {
return id;
return this.id;
}
public Grade setId(Long id) {
public void setId(Long id) {
this.id = id;
return this;
}
public Long getSubjectId() {
return subjectId;
}
public Grade setSubjectId(Long subjectId) {
this.subjectId = subjectId;
return this;
}
public Long getUserId() {
return userId;
}
public Grade setUserId(Long userId) {
this.userId = userId;
return this;
}
public String getSubject() {
return subject;
}
public Grade setSubject(String subject) {
this.subject = subject;
return this;
}
public String getValue() {
return value;
return this.value;
}
public Grade setValue(String value) {
@ -205,8 +145,26 @@ public class Grade implements Serializable {
return this;
}
public Long getSemesterId() {
return this.semesterId;
}
public Grade setSemesterId(Long semesterId) {
this.semesterId = semesterId;
return this;
}
public String getSubject() {
return this.subject;
}
public Grade setSubject(String subject) {
this.subject = subject;
return this;
}
public String getColor() {
return color;
return this.color;
}
public Grade setColor(String color) {
@ -215,7 +173,7 @@ public class Grade implements Serializable {
}
public String getSymbol() {
return symbol;
return this.symbol;
}
public Grade setSymbol(String symbol) {
@ -224,7 +182,7 @@ public class Grade implements Serializable {
}
public String getDescription() {
return description;
return this.description;
}
public Grade setDescription(String description) {
@ -233,7 +191,7 @@ public class Grade implements Serializable {
}
public String getWeight() {
return weight;
return this.weight;
}
public Grade setWeight(String weight) {
@ -242,7 +200,7 @@ public class Grade implements Serializable {
}
public String getDate() {
return date;
return this.date;
}
public Grade setDate(String date) {
@ -251,7 +209,7 @@ public class Grade implements Serializable {
}
public String getTeacher() {
return teacher;
return this.teacher;
}
public Grade setTeacher(String teacher) {
@ -259,22 +217,12 @@ public class Grade implements Serializable {
return this;
}
public String getSemester() {
return semester;
}
public Grade setSemester(String semester) {
this.semester = semester;
return this;
}
public boolean getIsNew() {
return this.isNew;
}
public Grade setIsNew(boolean isNew) {
public void setIsNew(boolean isNew) {
this.isNew = isNew;
return this;
}
public boolean getRead() {
@ -286,6 +234,17 @@ public class Grade implements Serializable {
return this;
}
public Long getSubjectId() {
return this.subjectId;
}
public void setSubjectId(Long subjectId) {
this.subjectId = subjectId;
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
* Entity must attached to an entity context.
@ -298,6 +257,7 @@ public class Grade implements Serializable {
myDao.delete(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
* Entity must attached to an entity context.
@ -310,6 +270,7 @@ public class Grade implements Serializable {
myDao.refresh(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
* Entity must attached to an entity context.
@ -322,6 +283,7 @@ public class Grade implements Serializable {
myDao.update(this);
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 1187286414)
public void __setDaoSession(DaoSession daoSession) {

View File

@ -0,0 +1,208 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;
import java.util.List;
@Entity(
nameInDb = "Semesters",
active = true
)
public class Semester {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "diary_id")
private Long diaryId;
@Property(nameInDb = "current")
private boolean current;
@Property(nameInDb = "name")
private String name;
@Property(nameInDb = "value")
private String value;
@ToMany(referencedJoinProperty = "semesterId")
private List<Subject> subjectList;
@ToMany(referencedJoinProperty = "semesterId")
private List<Grade> gradeList;
/**
* Used to resolve relations
*/
@Generated(hash = 2040040024)
private transient DaoSession daoSession;
/**
* Used for active entity operations.
*/
@Generated(hash = 282930393)
private transient SemesterDao myDao;
@Generated(hash = 1661077309)
public Semester(Long id, Long diaryId, boolean current, String name, String value) {
this.id = id;
this.diaryId = diaryId;
this.current = current;
this.name = name;
this.value = value;
}
@Generated(hash = 58335877)
public Semester() {
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Long getDiaryId() {
return this.diaryId;
}
public Semester setDiaryId(Long diaryId) {
this.diaryId = diaryId;
return this;
}
public String getName() {
return this.name;
}
public Semester setName(String name) {
this.name = name;
return this;
}
public String getValue() {
return this.value;
}
public Semester setValue(String value) {
this.value = value;
return this;
}
public boolean getCurrent() {
return this.current;
}
public Semester setCurrent(boolean current) {
this.current = current;
return this;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 723353662)
public List<Subject> getSubjectList() {
if (subjectList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
SubjectDao targetDao = daoSession.getSubjectDao();
List<Subject> subjectListNew = targetDao._querySemester_SubjectList(id);
synchronized (this) {
if (subjectList == null) {
subjectList = subjectListNew;
}
}
}
return subjectList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 594294258)
public synchronized void resetSubjectList() {
subjectList = null;
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 128553479)
public void delete() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.delete(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 1942392019)
public void refresh() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.refresh(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 713229351)
public void update() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.update(this);
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 390330007)
public List<Grade> getGradeList() {
if (gradeList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
GradeDao targetDao = daoSession.getGradeDao();
List<Grade> gradeListNew = targetDao._querySemester_GradeList(id);
synchronized (this) {
if (gradeList == null) {
gradeList = gradeListNew;
}
}
}
return gradeList;
}
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
@Generated(hash = 1939990047)
public synchronized void resetGradeList() {
gradeList = null;
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 676204164)
public void __setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
myDao = daoSession != null ? daoSession.getSemesterDao() : null;
}
}

View File

@ -0,0 +1,178 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;
import java.util.List;
@Entity(
nameInDb = "Students",
active = true
)
public class Student {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "symbol_id")
private Long symbolId;
@Property(nameInDb = "current")
private boolean current;
@Property(nameInDb = "real_id")
private String realId;
@Property(nameInDb = "name")
private String name;
@ToMany(referencedJoinProperty = "studentId")
private List<Diary> diaryList;
/**
* Used to resolve relations
*/
@Generated(hash = 2040040024)
private transient DaoSession daoSession;
/**
* Used for active entity operations.
*/
@Generated(hash = 1943931642)
private transient StudentDao myDao;
@Generated(hash = 1334215952)
public Student(Long id, Long symbolId, boolean current, String realId, String name) {
this.id = id;
this.symbolId = symbolId;
this.current = current;
this.realId = realId;
this.name = name;
}
@Generated(hash = 1556870573)
public Student() {
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Long getSymbolId() {
return this.symbolId;
}
public Student setSymbolId(Long symbolId) {
this.symbolId = symbolId;
return this;
}
public String getRealId() {
return this.realId;
}
public Student setRealId(String realId) {
this.realId = realId;
return this;
}
public String getName() {
return this.name;
}
public Student setName(String name) {
this.name = name;
return this;
}
public boolean getCurrent() {
return this.current;
}
public Student setCurrent(boolean current) {
this.current = current;
return this;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 508305571)
public List<Diary> getDiaryList() {
if (diaryList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
DiaryDao targetDao = daoSession.getDiaryDao();
List<Diary> diaryListNew = targetDao._queryStudent_DiaryList(id);
synchronized (this) {
if (diaryList == null) {
diaryList = diaryListNew;
}
}
}
return diaryList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1078514341)
public synchronized void resetDiaryList() {
diaryList = null;
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 128553479)
public void delete() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.delete(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 1942392019)
public void refresh() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.refresh(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 713229351)
public void update() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.update(this);
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 1701634981)
public void __setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
myDao = daoSession != null ? daoSession.getStudentDao() : null;
}
}

View File

@ -18,21 +18,18 @@ public class Subject {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "USER_ID")
private Long userId;
@Property(nameInDb = "semester_id")
private Long semesterId;
@Property(nameInDb = "NAME")
@Property(nameInDb = "name")
private String name;
@Property(nameInDb = "PREDICTED_RATING")
@Property(nameInDb = "predicted_rating")
private String predictedRating;
@Property(nameInDb = "FINAL_RATING")
@Property(nameInDb = "final_rating")
private String finalRating;
@Property(nameInDb = "SEMESTER")
private String semester;
@ToMany(referencedJoinProperty = "subjectId")
private List<Grade> gradeList;
@ -48,15 +45,14 @@ public class Subject {
@Generated(hash = 1644932788)
private transient SubjectDao myDao;
@Generated(hash = 396325764)
public Subject(Long id, Long userId, String name, String predictedRating,
String finalRating, String semester) {
@Generated(hash = 1817932538)
public Subject(Long id, Long semesterId, String name, String predictedRating,
String finalRating) {
this.id = id;
this.userId = userId;
this.semesterId = semesterId;
this.name = name;
this.predictedRating = predictedRating;
this.finalRating = finalRating;
this.semester = semester;
}
@Generated(hash = 1617906264)
@ -64,25 +60,24 @@ public class Subject {
}
public Long getId() {
return id;
return this.id;
}
public Subject setId(Long id) {
public void setId(Long id) {
this.id = id;
return this;
}
public Long getUserId() {
return userId;
public Long getSemesterId() {
return this.semesterId;
}
public Subject setUserId(Long userId) {
this.userId = userId;
public Subject setSemesterId(Long semesterId) {
this.semesterId = semesterId;
return this;
}
public String getName() {
return name;
return this.name;
}
public Subject setName(String name) {
@ -91,7 +86,7 @@ public class Subject {
}
public String getPredictedRating() {
return predictedRating;
return this.predictedRating;
}
public Subject setPredictedRating(String predictedRating) {
@ -100,7 +95,7 @@ public class Subject {
}
public String getFinalRating() {
return finalRating;
return this.finalRating;
}
public Subject setFinalRating(String finalRating) {
@ -108,45 +103,6 @@ public class Subject {
return this;
}
public String getSemester() {
return semester;
}
public Subject setSemester(String semester) {
this.semester = semester;
return this;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1358847893)
public List<Grade> getGradeList() {
if (gradeList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
GradeDao targetDao = daoSession.getGradeDao();
List<Grade> gradeListNew = targetDao._querySubject_GradeList(id);
synchronized (this) {
if (gradeList == null) {
gradeList = gradeListNew;
}
}
}
return gradeList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1939990047)
public synchronized void resetGradeList() {
gradeList = null;
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
* Entity must attached to an entity context.
@ -183,6 +139,34 @@ public class Subject {
myDao.update(this);
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 1358847893)
public List<Grade> getGradeList() {
if (gradeList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
GradeDao targetDao = daoSession.getGradeDao();
List<Grade> gradeListNew = targetDao._querySubject_GradeList(id);
synchronized (this) {
if (gradeList == null) {
gradeList = gradeListNew;
}
}
}
return gradeList;
}
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
@Generated(hash = 1939990047)
public synchronized void resetGradeList() {
gradeList = null;
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 937984622)
public void __setDaoSession(DaoSession daoSession) {

View File

@ -0,0 +1,191 @@
package io.github.wulkanowy.data.db.dao.entities;
import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;
import java.util.List;
@Entity(
nameInDb = "Symbols",
active = true
)
public class Symbol {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "user_id")
private Long userId;
@Property(nameInDb = "host")
private String host;
@Property(nameInDb = "school_id")
private String schoolId;
@Property(nameInDb = "symbol")
private String symbol;
@Property(nameInDb = "type")
private String type;
@ToMany(referencedJoinProperty = "symbolId")
private List<Student> studentList;
/**
* Used to resolve relations
*/
@Generated(hash = 2040040024)
private transient DaoSession daoSession;
/**
* Used for active entity operations.
*/
@Generated(hash = 684907977)
private transient SymbolDao myDao;
@Generated(hash = 242774339)
public Symbol(Long id, Long userId, String host, String schoolId, String symbol,
String type) {
this.id = id;
this.userId = userId;
this.host = host;
this.schoolId = schoolId;
this.symbol = symbol;
this.type = type;
}
@Generated(hash = 460475327)
public Symbol() {
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUserId() {
return this.userId;
}
public Symbol setUserId(Long userId) {
this.userId = userId;
return this;
}
public String getHost() {
return this.host;
}
public Symbol setHost(String host) {
this.host = host;
return this;
}
public String getSchoolId() {
return this.schoolId;
}
public Symbol setSchoolId(String schoolId) {
this.schoolId = schoolId;
return this;
}
public String getSymbol() {
return this.symbol;
}
public Symbol setSymbol(String symbol) {
this.symbol = symbol;
return this;
}
public String getType() {
return this.type;
}
public Symbol setType(String type) {
this.type = type;
return this;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
*/
@Generated(hash = 604366458)
public List<Student> getStudentList() {
if (studentList == null) {
final DaoSession daoSession = this.daoSession;
if (daoSession == null) {
throw new DaoException("Entity is detached from DAO context");
}
StudentDao targetDao = daoSession.getStudentDao();
List<Student> studentListNew = targetDao._querySymbol_StudentList(id);
synchronized (this) {
if (studentList == null) {
studentList = studentListNew;
}
}
}
return studentList;
}
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1628625923)
public synchronized void resetStudentList() {
studentList = null;
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 128553479)
public void delete() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.delete(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 1942392019)
public void refresh() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.refresh(this);
}
/**
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
* Entity must attached to an entity context.
*/
@Generated(hash = 713229351)
public void update() {
if (myDao == null) {
throw new DaoException("Entity is detached from DAO context");
}
myDao.update(this);
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 632145708)
public void __setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;
myDao = daoSession != null ? daoSession.getSymbolDao() : null;
}
}

View File

@ -16,58 +16,58 @@ import java.io.Serializable;
)
public class TimetableLesson implements Serializable {
private static final long serialVersionUID = 42L;
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "DAY_ID")
@Property(nameInDb = "day_id")
private Long dayId;
@Property(nameInDb = "NUMBER_OF_LESSON")
@Property(nameInDb = "number")
private String number;
@Property(nameInDb = "SUBJECT_NAME")
@Property(nameInDb = "subject")
private String subject = "";
@Property(nameInDb = "TEACHER")
@Property(nameInDb = "teacher")
private String teacher = "";
@Property(nameInDb = "ROOM")
@Property(nameInDb = "room")
private String room = "";
@Property(nameInDb = "DESCRIPTION")
@Property(nameInDb = "description")
private String description = "";
@Property(nameInDb = "GROUP_NAME")
private String groupName = "";
@Property(nameInDb = "group")
private String group = "";
@Property(nameInDb = "START_TIME")
@Property(nameInDb = "start_time")
private String startTime = "";
@Property(nameInDb = "END_TIME")
@Property(nameInDb = "end_time")
private String endTime = "";
@Property(nameInDb = "DATE")
@Property(nameInDb = "date")
private String date = "";
@Property(nameInDb = "IS_EMPTY")
private boolean isEmpty = false;
@Property(nameInDb = "empty")
private boolean empty = false;
@Property(nameInDb = "IS_DIVISION_INTO_GROUP")
private boolean isDivisionIntoGroups = false;
@Property(nameInDb = "division_into_groups")
private boolean divisionIntoGroups = false;
@Property(nameInDb = "IS_PLANNING")
private boolean isPlanning = false;
@Property(nameInDb = "planning")
private boolean planning = false;
@Property(nameInDb = "IS_REALIZED")
private boolean isRealized = false;
@Property(nameInDb = "realized")
private boolean realized = false;
@Property(nameInDb = "IS_MOVED_CANCELED")
private boolean isMovedOrCanceled = false;
@Property(nameInDb = "moved_canceled")
private boolean movedOrCanceled = false;
@Property(nameInDb = "IS_NEW_MOVED_IN_CANCELED")
private boolean isNewMovedInOrChanged = false;
private static final long serialVersionUID = 42L;
@Property(nameInDb = "new_moved_in_canceled")
private boolean newMovedInOrChanged = false;
/**
* Used to resolve relations
@ -81,12 +81,12 @@ public class TimetableLesson implements Serializable {
@Generated(hash = 1119360138)
private transient TimetableLessonDao myDao;
@Generated(hash = 627457324)
@Generated(hash = 1955911128)
public TimetableLesson(Long id, Long dayId, String number, String subject,
String teacher, String room, String description, String groupName,
String startTime, String endTime, String date, boolean isEmpty,
boolean isDivisionIntoGroups, boolean isPlanning, boolean isRealized,
boolean isMovedOrCanceled, boolean isNewMovedInOrChanged) {
String teacher, String room, String description, String group,
String startTime, String endTime, String date, boolean empty,
boolean divisionIntoGroups, boolean planning, boolean realized,
boolean movedOrCanceled, boolean newMovedInOrChanged) {
this.id = id;
this.dayId = dayId;
this.number = number;
@ -94,16 +94,16 @@ public class TimetableLesson implements Serializable {
this.teacher = teacher;
this.room = room;
this.description = description;
this.groupName = groupName;
this.group = group;
this.startTime = startTime;
this.endTime = endTime;
this.date = date;
this.isEmpty = isEmpty;
this.isDivisionIntoGroups = isDivisionIntoGroups;
this.isPlanning = isPlanning;
this.isRealized = isRealized;
this.isMovedOrCanceled = isMovedOrCanceled;
this.isNewMovedInOrChanged = isNewMovedInOrChanged;
this.empty = empty;
this.divisionIntoGroups = divisionIntoGroups;
this.planning = planning;
this.realized = realized;
this.movedOrCanceled = movedOrCanceled;
this.newMovedInOrChanged = newMovedInOrChanged;
}
@Generated(hash = 1878030142)
@ -122,8 +122,9 @@ public class TimetableLesson implements Serializable {
return this.dayId;
}
public void setDayId(Long dayId) {
public TimetableLesson setDayId(Long dayId) {
this.dayId = dayId;
return this;
}
public String getNumber() {
@ -171,12 +172,12 @@ public class TimetableLesson implements Serializable {
return this;
}
public String getGroupName() {
return this.groupName;
public String getGroup() {
return this.group;
}
public TimetableLesson setGroupName(String groupName) {
this.groupName = groupName;
public TimetableLesson setGroup(String group) {
this.group = group;
return this;
}
@ -207,57 +208,57 @@ public class TimetableLesson implements Serializable {
return this;
}
public boolean getIsEmpty() {
return this.isEmpty;
public boolean getEmpty() {
return this.empty;
}
public TimetableLesson setEmpty(boolean isEmpty) {
this.isEmpty = isEmpty;
public TimetableLesson setEmpty(boolean empty) {
this.empty = empty;
return this;
}
public boolean getIsDivisionIntoGroups() {
return this.isDivisionIntoGroups;
public boolean getDivisionIntoGroups() {
return this.divisionIntoGroups;
}
public TimetableLesson setDivisionIntoGroups(boolean isDivisionIntoGroups) {
this.isDivisionIntoGroups = isDivisionIntoGroups;
public TimetableLesson setDivisionIntoGroups(boolean divisionIntoGroups) {
this.divisionIntoGroups = divisionIntoGroups;
return this;
}
public boolean getIsPlanning() {
return this.isPlanning;
public boolean getPlanning() {
return this.planning;
}
public TimetableLesson setPlanning(boolean isPlanning) {
this.isPlanning = isPlanning;
public TimetableLesson setPlanning(boolean planning) {
this.planning = planning;
return this;
}
public boolean getIsRealized() {
return this.isRealized;
public boolean getRealized() {
return this.realized;
}
public TimetableLesson setRealized(boolean isRealized) {
this.isRealized = isRealized;
public TimetableLesson setRealized(boolean realized) {
this.realized = realized;
return this;
}
public boolean getIsMovedOrCanceled() {
return this.isMovedOrCanceled;
public boolean getMovedOrCanceled() {
return this.movedOrCanceled;
}
public TimetableLesson setMovedOrCanceled(boolean isMovedOrCanceled) {
this.isMovedOrCanceled = isMovedOrCanceled;
public TimetableLesson setMovedOrCanceled(boolean movedOrCanceled) {
this.movedOrCanceled = movedOrCanceled;
return this;
}
public boolean getIsNewMovedInOrChanged() {
return this.isNewMovedInOrChanged;
public boolean getNewMovedInOrChanged() {
return this.newMovedInOrChanged;
}
public TimetableLesson setNewMovedInOrChanged(boolean isNewMovedInOrChanged) {
this.isNewMovedInOrChanged = isNewMovedInOrChanged;
public TimetableLesson setNewMovedInOrChanged(boolean newMovedInOrChanged) {
this.newMovedInOrChanged = newMovedInOrChanged;
return this;
}
@ -297,30 +298,6 @@ public class TimetableLesson implements Serializable {
myDao.update(this);
}
public void setIsEmpty(boolean isEmpty) {
this.isEmpty = isEmpty;
}
public void setIsDivisionIntoGroups(boolean isDivisionIntoGroups) {
this.isDivisionIntoGroups = isDivisionIntoGroups;
}
public void setIsPlanning(boolean isPlanning) {
this.isPlanning = isPlanning;
}
public void setIsRealized(boolean isRealized) {
this.isRealized = isRealized;
}
public void setIsMovedOrCanceled(boolean isMovedOrCanceled) {
this.isMovedOrCanceled = isMovedOrCanceled;
}
public void setIsNewMovedInOrChanged(boolean isNewMovedInOrChanged) {
this.isNewMovedInOrChanged = isNewMovedInOrChanged;
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 1885258429)
public void __setDaoSession(DaoSession daoSession) {

View File

@ -13,44 +13,52 @@ import java.util.List;
@Entity(
nameInDb = "Weeks",
active = true,
indexes ={@Index(value = "userId,startDayDate", unique = true)}
indexes = {@Index(value = "diaryId,startDayDate", unique = true)}
)
public class Week {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "USER_ID")
private Long userId;
@Property(nameInDb = "diary_id")
private Long diaryId;
@Property(nameInDb = "START_DATE")
@Property(nameInDb = "start_day_date")
private String startDayDate = "";
@Property(nameInDb = "IS_ATTENDANCE_SYNCED")
private boolean isAttendanceSynced = false;
@Property(nameInDb = "attendance_synced")
private boolean attendanceSynced = false;
@Property(nameInDb = "IS_TIMETABLE_SYNCED")
private boolean isTimetableSynced = false;
@Property(nameInDb = "timetable_synced")
private boolean timetableSynced = false;
@Property(nameInDb = "exams_synced")
private boolean examsSynced = false;
@ToMany(referencedJoinProperty = "weekId")
private List<Day> dayList;
/** Used to resolve relations */
/**
* Used to resolve relations
*/
@Generated(hash = 2040040024)
private transient DaoSession daoSession;
/** Used for active entity operations. */
/**
* Used for active entity operations.
*/
@Generated(hash = 1019310398)
private transient WeekDao myDao;
@Generated(hash = 1745118398)
public Week(Long id, Long userId, String startDayDate, boolean isAttendanceSynced,
boolean isTimetableSynced) {
@Generated(hash = 23357599)
public Week(Long id, Long diaryId, String startDayDate, boolean attendanceSynced,
boolean timetableSynced, boolean examsSynced) {
this.id = id;
this.userId = userId;
this.diaryId = diaryId;
this.startDayDate = startDayDate;
this.isAttendanceSynced = isAttendanceSynced;
this.isTimetableSynced = isTimetableSynced;
this.attendanceSynced = attendanceSynced;
this.timetableSynced = timetableSynced;
this.examsSynced = examsSynced;
}
@Generated(hash = 2135529658)
@ -66,12 +74,12 @@ public class Week {
return this;
}
public Long getUserId() {
return userId;
public Long getDiaryId() {
return diaryId;
}
public Week setUserId(Long userId) {
this.userId = userId;
public Week setDiaryId(Long diaryId) {
this.diaryId = diaryId;
return this;
}
@ -84,20 +92,31 @@ public class Week {
return this;
}
public boolean getIsAttendanceSynced() {
return this.isAttendanceSynced;
public boolean getAttendanceSynced() {
return this.attendanceSynced;
}
public void setIsAttendanceSynced(boolean isAttendanceSynced) {
this.isAttendanceSynced = isAttendanceSynced;
public Week setAttendanceSynced(boolean attendanceSynced) {
this.attendanceSynced = attendanceSynced;
return this;
}
public boolean getIsTimetableSynced() {
return this.isTimetableSynced;
public boolean getTimetableSynced() {
return this.timetableSynced;
}
public void setIsTimetableSynced(boolean isTimetableSynced) {
this.isTimetableSynced = isTimetableSynced;
public Week setTimetableSynced(boolean timetableSynced) {
this.timetableSynced = timetableSynced;
return this;
}
public Week setExamsSynced(boolean examsSynced) {
this.examsSynced = examsSynced;
return this;
}
public boolean getExamsSynced() {
return examsSynced;
}
/**
@ -122,7 +141,9 @@ public class Week {
return dayList;
}
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
/**
* Resets a to-many relationship, making the next get call to query for a fresh result.
*/
@Generated(hash = 1010399236)
public synchronized void resetDayList() {
dayList = null;

View File

@ -100,7 +100,7 @@ public class Migration23 implements DbHelper.Migration {
private void insertDiaries(Database db, List<Diary> list) {
for (Diary diary : list) {
db.execSQL("INSERT INTO Diaries(STUDENT_ID, NAME, VALUE, IS_CURRENT) VALUES(" +
"\"" + diary.getStudentId() + "\"," +
"\"" + diary.getId() + "\"," +
"\"" + diary.getName() + "\"," +
"\"" + diary.getId() + "\"," +
"\"" + (diary.isCurrent() ? "1" : "0") + "\"" +

View File

@ -0,0 +1,20 @@
package io.github.wulkanowy.data.db.dao.migrations;
import org.greenrobot.greendao.database.Database;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.data.db.dao.DbHelper;
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
public class Migration26 implements DbHelper.Migration {
@Override
public Integer getVersion() {
return 26;
}
@Override
public void runMigration(final Database db, final SharedPrefContract sharedPref, final Vulcan vulcan) throws Exception {
throw new Exception("No migrations");
}
}

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();
}
@ -62,27 +62,27 @@ public class AppResources implements ResourcesContract {
public String getAttendanceLessonDescription(AttendanceLesson lesson) {
int id = R.string.attendance_present;
if (lesson.getIsAbsenceForSchoolReasons()) {
if (lesson.getAbsenceForSchoolReasons()) {
id = R.string.attendance_absence_for_school_reasons;
}
if (lesson.getIsAbsenceExcused()) {
if (lesson.getAbsenceExcused()) {
id = R.string.attendance_absence_excused;
}
if (lesson.getIsAbsenceUnexcused()) {
if (lesson.getAbsenceUnexcused()) {
id = R.string.attendance_absence_unexcused;
}
if (lesson.getIsExemption()) {
if (lesson.getExemption()) {
id = R.string.attendance_exemption;
}
if (lesson.getIsExcusedLateness()) {
if (lesson.getExcusedLateness()) {
id = R.string.attendance_excused_lateness;
}
if (lesson.getIsUnexcusedLateness()) {
if (lesson.getUnexcusedLateness()) {
id = R.string.attendance_unexcused_lateness;
}

View File

@ -1,13 +1,26 @@
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);
boolean getTimetableWidgetState();
int getStartupTab();
boolean isShowGradesSummary();
boolean isShowAttendancePresent();
int getServicesInterval();
boolean isMobileDisable();

View File

@ -1,5 +1,6 @@
package io.github.wulkanowy.data.db.shared;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
@ -12,16 +13,18 @@ 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";
private static final String SHARED_KEY_TIMETABLE_WIDGET_STATE = "TIMETABLE_WIDGET_STATE";
private final SharedPreferences appSharedPref;
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);
}
@ -31,14 +34,40 @@ 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();
}
@SuppressLint("ApplySharedPref")
@Override
public void setTimetableWidgetState(boolean nextDay) {
appSharedPref.edit().putBoolean(SHARED_KEY_TIMETABLE_WIDGET_STATE, nextDay).commit();
}
@Override
public boolean getTimetableWidgetState() {
return appSharedPref.getBoolean(SHARED_KEY_TIMETABLE_WIDGET_STATE, false);
}
@Override
public int getStartupTab() {
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_START_TAB, "2"));
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_START_TAB, "0"));
}
@Override
public boolean isShowGradesSummary() {
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_GRADES_SUMMARY, false);
}
@Override
public boolean isShowAttendancePresent() {
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_ATTENDANCE_PRESENT, false);
}
@Override

View File

@ -0,0 +1,155 @@
package io.github.wulkanowy.data.sync;
import android.content.Context;
import java.io.IOException;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.VulcanException;
import io.github.wulkanowy.data.db.dao.entities.Account;
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
import io.github.wulkanowy.data.db.dao.entities.Diary;
import io.github.wulkanowy.data.db.dao.entities.DiaryDao;
import io.github.wulkanowy.data.db.dao.entities.Semester;
import io.github.wulkanowy.data.db.dao.entities.Student;
import io.github.wulkanowy.data.db.dao.entities.StudentDao;
import io.github.wulkanowy.data.db.dao.entities.Symbol;
import io.github.wulkanowy.data.db.dao.entities.SymbolDao;
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
import io.github.wulkanowy.di.annotations.ApplicationContext;
import io.github.wulkanowy.utils.DataObjectConverter;
import io.github.wulkanowy.utils.LogUtils;
import io.github.wulkanowy.utils.security.CryptoException;
import io.github.wulkanowy.utils.security.Scrambler;
@Singleton
public class AccountSync {
private final DaoSession daoSession;
private final SharedPrefContract sharedPref;
private final Vulcan vulcan;
private final Context context;
@Inject
AccountSync(DaoSession daoSession, SharedPrefContract sharedPref,
Vulcan vulcan, @ApplicationContext Context context) {
this.daoSession = daoSession;
this.sharedPref = sharedPref;
this.vulcan = vulcan;
this.context = context;
}
public void registerUser(String email, String password, String symbol)
throws VulcanException, IOException, CryptoException {
vulcan.setCredentials(email, password, symbol, null, null, null);
daoSession.getDatabase().beginTransaction();
try {
Account account = insertAccount(email, password);
Symbol symbolEntity = insertSymbol(account);
insertStudents(symbolEntity);
insertDiaries(symbolEntity);
insertSemesters();
sharedPref.setCurrentUserId(account.getId());
daoSession.getDatabase().setTransactionSuccessful();
} finally {
daoSession.getDatabase().endTransaction();
}
}
private Account insertAccount(String email, String password) throws CryptoException {
LogUtils.debug("Register account: " + email);
Account account = new Account()
.setEmail(email)
.setPassword(Scrambler.encrypt(email, password, context));
daoSession.getAccountDao().insert(account);
return account;
}
private Symbol insertSymbol(Account account) throws VulcanException, IOException {
LogUtils.debug("Register symbol: " + vulcan.getSymbol());
Symbol symbol = new Symbol()
.setUserId(account.getId())
.setSchoolId(vulcan.getStudentAndParent().getSchoolID())
.setSymbol(vulcan.getSymbol());
daoSession.getSymbolDao().insert(symbol);
return symbol;
}
private void insertStudents(Symbol symbol) throws VulcanException, IOException {
List<Student> studentList = DataObjectConverter.studentsToStudentEntities(
vulcan.getStudentAndParent().getStudents(),
symbol.getId()
);
LogUtils.debug("Register students: " + studentList.size());
daoSession.getStudentDao().insertInTx(studentList);
}
private void insertDiaries(Symbol symbolEntity) throws VulcanException, IOException {
List<Diary> diaryList = DataObjectConverter.diariesToDiaryEntities(
vulcan.getStudentAndParent().getDiaries(),
daoSession.getStudentDao().queryBuilder().where(
StudentDao.Properties.SymbolId.eq(symbolEntity.getId()),
StudentDao.Properties.Current.eq(true)
).unique().getId());
LogUtils.debug("Register diaries: " + diaryList.size());
daoSession.getDiaryDao().insertInTx(diaryList);
}
private void insertSemesters() throws VulcanException, IOException {
List<Semester> semesterList = DataObjectConverter.semestersToSemesterEntities(
vulcan.getStudentAndParent().getSemesters(),
daoSession.getDiaryDao().queryBuilder().where(
DiaryDao.Properties.Current.eq(true)
).unique().getId());
LogUtils.debug("Register semesters: " + semesterList.size());
daoSession.getSemesterDao().insertInTx(semesterList);
}
public void initLastUser() throws IOException, CryptoException {
long userId = sharedPref.getCurrentUserId();
if (userId == 0) {
throw new IOException("Can't find saved user");
}
LogUtils.debug("Initialization current user id=" + userId);
Account account = daoSession.getAccountDao().load(userId);
Symbol symbol = daoSession.getSymbolDao().queryBuilder().where(
SymbolDao.Properties.UserId.eq(account.getId())).unique();
Student student = daoSession.getStudentDao().queryBuilder().where(
StudentDao.Properties.SymbolId.eq(symbol.getId()),
StudentDao.Properties.Current.eq(true)
).unique();
Diary diary = daoSession.getDiaryDao().queryBuilder().where(
DiaryDao.Properties.StudentId.eq(student.getId()),
DiaryDao.Properties.Current.eq(true)
).unique();
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;
@ -18,37 +18,27 @@ import io.github.wulkanowy.data.db.dao.entities.Day;
import io.github.wulkanowy.data.db.dao.entities.DayDao;
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;
import io.github.wulkanowy.utils.DataObjectConverter;
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;
private final SharedPrefContract sharedPref;
private final Vulcan vulcan;
private long userId;
private long diaryId;
@Inject
AttendanceSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
AttendanceSync(DaoSession daoSession, Vulcan vulcan) {
this.daoSession = daoSession;
this.sharedPref = sharedPref;
this.vulcan = vulcan;
}
@Override
public void syncAttendance() throws IOException, ParseException, VulcanException {
syncAttendance(null);
}
@Override
public void syncAttendance(String date) throws IOException, ParseException, VulcanException {
this.userId = sharedPref.getCurrentUserId();
public void syncAttendance(long diaryId, String date) throws IOException, ParseException, VulcanException {
this.diaryId = diaryId;
io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.generic.Day> weekApi = getWeekFromApi(getNormalizedDate(date));
Week weekDb = getWeekFromDb(weekApi.getStartDayDate());
@ -72,22 +62,22 @@ public class AttendanceSync implements AttendanceSyncContract {
}
private Week getWeekFromDb(String date) {
return daoSession.getWeekDao()
.queryBuilder()
.where(WeekDao.Properties.UserId.eq(userId), WeekDao.Properties.StartDayDate.eq(date))
.unique();
return daoSession.getWeekDao().queryBuilder().where(
WeekDao.Properties.DiaryId.eq(diaryId),
WeekDao.Properties.StartDayDate.eq(date)
).unique();
}
private Long updateWeekInDb(Week dbWeekEntity, io.github.wulkanowy.api.generic.Week fromApi) {
if (dbWeekEntity != null) {
dbWeekEntity.setIsAttendanceSynced(true);
dbWeekEntity.setAttendanceSynced(true);
dbWeekEntity.update();
return dbWeekEntity.getId();
}
Week apiWeekEntity = DataObjectConverter.weekToWeekEntity(fromApi).setUserId(userId);
apiWeekEntity.setIsAttendanceSynced(true);
Week apiWeekEntity = DataObjectConverter.weekToWeekEntity(fromApi).setDiaryId(diaryId);
apiWeekEntity.setAttendanceSynced(true);
return daoSession.getWeekDao().insert(apiWeekEntity);
}
@ -97,7 +87,7 @@ public class AttendanceSync implements AttendanceSyncContract {
for (io.github.wulkanowy.api.generic.Day dayFromApi : dayListFromApi) {
Day dbDayEntity = getDayFromDb(dayFromApi.getDate());
Day dbDayEntity = getDayFromDb(dayFromApi.getDate(), weekId);
Day apiDayEntity = DataObjectConverter.dayToDayEntity(dayFromApi);
@ -109,11 +99,12 @@ public class AttendanceSync implements AttendanceSyncContract {
return updatedLessonList;
}
private Day getDayFromDb(String date) {
return daoSession.getDayDao()
.queryBuilder()
.where(DayDao.Properties.UserId.eq(userId), DayDao.Properties.Date.eq(date))
.unique();
private Day getDayFromDb(String date, long weekId) {
return daoSession.getDayDao().queryBuilder()
.where(
DayDao.Properties.WeekId.eq(weekId),
DayDao.Properties.Date.eq(date)
).unique();
}
private long updateDay(Day dbDayEntity, Day apiDayEntity, long weekId) {
@ -121,7 +112,6 @@ public class AttendanceSync implements AttendanceSyncContract {
return dbDayEntity.getId();
}
apiDayEntity.setUserId(userId);
apiDayEntity.setWeekId(weekId);
return daoSession.getDayDao().insert(apiDayEntity);

View File

@ -0,0 +1,141 @@
package io.github.wulkanowy.data.sync;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.VulcanException;
import io.github.wulkanowy.api.exams.ExamDay;
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
import io.github.wulkanowy.data.db.dao.entities.Day;
import io.github.wulkanowy.data.db.dao.entities.DayDao;
import io.github.wulkanowy.data.db.dao.entities.Exam;
import io.github.wulkanowy.data.db.dao.entities.ExamDao;
import io.github.wulkanowy.data.db.dao.entities.Week;
import io.github.wulkanowy.data.db.dao.entities.WeekDao;
import io.github.wulkanowy.utils.DataObjectConverter;
import io.github.wulkanowy.utils.LogUtils;
import io.github.wulkanowy.utils.TimeUtils;
public class ExamsSync {
private final DaoSession daoSession;
private final Vulcan vulcan;
private long diaryId;
@Inject
ExamsSync(DaoSession daoSession, Vulcan vulcan) {
this.daoSession = daoSession;
this.vulcan = vulcan;
}
public void syncExams(long diaryId, String date) throws IOException, VulcanException,
ParseException {
this.diaryId = diaryId;
io.github.wulkanowy.api.generic.Week<ExamDay> weekApi = getWeekFromApi(getNormalizedDate(date));
Week weekDb = getWeekFromDb(weekApi.getStartDayDate());
long weekId = updateWeekInDb(weekDb, weekApi);
List<Exam> examList = getPreparedExams(weekApi.getDays(), weekId);
daoSession.getExamDao().saveInTx(examList);
LogUtils.debug("Synchronization exams (amount = " + examList.size() + ")");
}
private Week getWeekFromDb(String date) {
return daoSession.getWeekDao().queryBuilder().where(
WeekDao.Properties.DiaryId.eq(diaryId),
WeekDao.Properties.StartDayDate.eq(date)
).unique();
}
private io.github.wulkanowy.api.generic.Week<ExamDay> getWeekFromApi(String date)
throws VulcanException, IOException, ParseException {
return vulcan.getExamsList().getWeek(date, true);
}
private Long updateWeekInDb(Week weekDb, io.github.wulkanowy.api.generic.Week weekApi) {
if (weekDb != null) {
weekDb.setExamsSynced(true);
weekDb.update();
return weekDb.getId();
}
Week weekApiEntity = DataObjectConverter.weekToWeekEntity(weekApi).setDiaryId(diaryId);
weekApiEntity.setExamsSynced(true);
return daoSession.getWeekDao().insert(weekApiEntity);
}
private String getNormalizedDate(String date) throws ParseException {
return null != date ? String.valueOf(TimeUtils.getNetTicks(date)) : "";
}
private Day getDayFromDb(String date, long weekId) {
return daoSession.getDayDao().queryBuilder().where(
DayDao.Properties.WeekId.eq(weekId),
DayDao.Properties.Date.eq(date)
).unique();
}
private List<Exam> getPreparedExams(List<ExamDay> dayListFromApi,
long weekId) {
List<Exam> preparedExamList = new ArrayList<>();
for (ExamDay dayFromApi : dayListFromApi) {
Day dayDb = getDayFromDb(dayFromApi.getDate(), weekId);
Day dayApiEntity = DataObjectConverter.dayToDayEntity(dayFromApi);
long dayId = updateDayInDb(dayDb, dayApiEntity, weekId);
prepareExam(dayFromApi.getExamList(), preparedExamList, dayId);
}
return preparedExamList;
}
private long updateDayInDb(Day dayDb, Day dayApi, long weekId) {
dayApi.setWeekId(weekId);
if (null != dayDb) {
return dayDb.getId();
}
return daoSession.getDayDao().insert(dayApi);
}
private void prepareExam(List<io.github.wulkanowy.api.exams.Exam> examList,
List<Exam> preparedExams, long dayId) {
List<Exam> examsApiEntity = DataObjectConverter.examsToExamsEntity(examList);
for (Exam examApi : examsApiEntity) {
Exam examDb = getExamFromDb(examApi, dayId);
examApi.setDayId(dayId);
if (examDb != null) {
examApi.setId(examDb.getId());
}
preparedExams.add(examApi);
}
}
private Exam getExamFromDb(Exam examApi, long dayId) {
return daoSession.getExamDao().queryBuilder()
.where(ExamDao.Properties.DayId.eq(dayId),
ExamDao.Properties.EntryDate.eq(examApi.getEntryDate()),
ExamDao.Properties.SubjectAndGroup.eq(examApi.getSubjectAndGroup()),
ExamDao.Properties.Teacher.eq(examApi.getTeacher()))
.unique();
}
}

View File

@ -0,0 +1,82 @@
package io.github.wulkanowy.data.sync;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.VulcanException;
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.utils.DataObjectConverter;
import io.github.wulkanowy.utils.EntitiesCompare;
import io.github.wulkanowy.utils.LogUtils;
@Singleton
public class GradeSync {
private final DaoSession daoSession;
private final Vulcan vulcan;
private long semesterId;
@Inject
GradeSync(DaoSession daoSession, Vulcan vulcan) {
this.daoSession = daoSession;
this.vulcan = vulcan;
}
public void sync(long semesterId) throws IOException, VulcanException, ParseException {
this.semesterId = semesterId;
Semester semester = daoSession.getSemesterDao().load(semesterId);
resetSemesterRelations(semester);
List<Grade> lastList = getUpdatedList(getComparedList(semester));
daoSession.getGradeDao().deleteInTx(semester.getGradeList());
daoSession.getGradeDao().insertInTx(lastList);
LogUtils.debug("Synchronization grades (amount = " + lastList.size() + ")");
}
private void resetSemesterRelations(Semester semester) {
semester.resetSubjectList();
semester.resetGradeList();
}
private List<Grade> getUpdatedList(List<Grade> comparedList) {
List<Grade> updatedList = new ArrayList<>();
for (Grade grade : comparedList) {
grade.setSemesterId(semesterId);
grade.setSubjectId(getSubjectId(grade.getSubject()));
updatedList.add(grade);
}
return updatedList;
}
private List<Grade> getComparedList(Semester semester) throws IOException, VulcanException, ParseException {
List<Grade> gradesFromNet = DataObjectConverter.gradesToGradeEntities(
vulcan.getGradesList().getAll(semester.getValue()), semesterId);
List<Grade> gradesFromDb = semester.getGradeList();
return EntitiesCompare.compareGradeList(gradesFromNet, gradesFromDb);
}
private Long getSubjectId(String subjectName) {
return daoSession.getSubjectDao().queryBuilder().where(
SubjectDao.Properties.Name.eq(subjectName),
SubjectDao.Properties.SemesterId.eq(semesterId)
).build().uniqueOrThrow().getId();
}
}

View File

@ -1,7 +1,6 @@
package io.github.wulkanowy.data.sync.subjects;
package io.github.wulkanowy.data.sync;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@ -10,38 +9,33 @@ import javax.inject.Singleton;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.VulcanException;
import io.github.wulkanowy.data.db.dao.entities.Account;
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.db.shared.SharedPrefContract;
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;
private final Vulcan vulcan;
private final SharedPrefContract sharedPref;
private Long userId;
private long semesterId;
@Inject
SubjectSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
SubjectSync(DaoSession daoSession, Vulcan vulcan) {
this.daoSession = daoSession;
this.sharedPref = sharedPref;
this.vulcan = vulcan;
}
@Override
public void sync() throws VulcanException, IOException, ParseException {
public void sync(long semesterId) throws VulcanException, IOException {
this.semesterId = semesterId;
userId = sharedPref.getCurrentUserId();
Semester semester = daoSession.getSemesterDao().load(semesterId);
List<Subject> lastList = getUpdatedList(getSubjectsFromNet());
List<Subject> lastList = getUpdatedList(getSubjectsFromNet(semester));
daoSession.getSubjectDao().deleteInTx(getSubjectsFromDb());
daoSession.getSubjectDao().insertInTx(lastList);
@ -49,21 +43,22 @@ public class SubjectSync implements SyncContract {
LogUtils.debug("Synchronization subjects (amount = " + lastList.size() + ")");
}
private List<Subject> getSubjectsFromNet() throws VulcanException, IOException {
return DataObjectConverter.subjectsToSubjectEntities(vulcan.getSubjectsList().getAll());
private List<Subject> getSubjectsFromNet(Semester semester) throws VulcanException, IOException {
return DataObjectConverter.subjectsToSubjectEntities(
vulcan.getSubjectsList().getAll(semester.getValue()), semesterId);
}
private List<Subject> getSubjectsFromDb() {
Account account = daoSession.getAccountDao().load(userId);
account.resetSubjectList();
return account.getSubjectList();
Semester semester = daoSession.getSemesterDao().load(semesterId);
semester.resetSubjectList();
return semester.getSubjectList();
}
private List<Subject> getUpdatedList(List<Subject> subjectsFromNet) {
List<Subject> updatedList = new ArrayList<>();
for (Subject subject : subjectsFromNet) {
subject.setUserId(userId);
subject.setSemesterId(semesterId);
updatedList.add(subject);
}
return updatedList;

View File

@ -3,9 +3,38 @@ 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() throws VulcanException, IOException, ParseException;
void registerUser(String email, String password, String symbol) throws VulcanException,
IOException, CryptoException;
void initLastUser() throws IOException, CryptoException;
void syncGrades(int semesterName) throws VulcanException, IOException, ParseException;
void syncGrades() throws VulcanException, IOException, ParseException;
void syncSubjects(int semesterName) 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 syncExams() throws VulcanException, IOException, ParseException;
void syncExams(long diaryId, String date) throws VulcanException, IOException, ParseException;
void syncAll() throws VulcanException, IOException, ParseException;
}

View File

@ -0,0 +1,124 @@
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 ExamsSync examsSync;
private final DbContract database;
@Inject
SyncRepository(GradeSync gradeSync, SubjectSync subjectSync, AttendanceSync attendanceSync,
TimetableSync timetableSync, AccountSync accountSync, ExamsSync examsSync,
DbContract database) {
this.gradeSync = gradeSync;
this.subjectSync = subjectSync;
this.attendanceSync = attendanceSync;
this.timetableSync = timetableSync;
this.accountSync = accountSync;
this.examsSync = examsSync;
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(int semesterName) throws VulcanException, IOException, ParseException {
gradeSync.sync(semesterName);
}
@Override
public void syncGrades() throws VulcanException, IOException, ParseException {
gradeSync.sync(database.getCurrentSemesterId());
}
@Override
public void syncSubjects(int semesterName) throws VulcanException, IOException {
subjectSync.sync(semesterName);
}
@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 syncExams() throws VulcanException, IOException, ParseException {
examsSync.syncExams(database.getCurrentDiaryId(), null);
}
@Override
public void syncExams(long diaryId, String date) throws VulcanException, IOException, ParseException {
if (diaryId != 0) {
examsSync.syncExams(diaryId, date);
} else {
examsSync.syncExams(database.getCurrentDiaryId(), date);
}
}
@Override
public void syncAll() throws VulcanException, IOException, ParseException {
syncSubjects();
syncGrades();
syncAttendance();
syncTimetable();
syncExams();
}
}

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;
@ -18,39 +18,29 @@ import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
import io.github.wulkanowy.data.db.dao.entities.TimetableLessonDao;
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;
import io.github.wulkanowy.utils.DataObjectConverter;
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;
private final SharedPrefContract sharedPref;
private final Vulcan vulcan;
private long userId;
private long diaryId;
@Inject
TimetableSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
TimetableSync(DaoSession daoSession, Vulcan vulcan) {
this.daoSession = daoSession;
this.sharedPref = sharedPref;
this.vulcan = vulcan;
}
@Override
public void syncTimetable() throws IOException, ParseException, VulcanException {
syncTimetable(null);
}
public void syncTimetable(long diaryId, String date) throws IOException, ParseException, VulcanException {
this.diaryId = diaryId;
@Override
public void syncTimetable(String date) throws IOException, ParseException, VulcanException {
this.userId = sharedPref.getCurrentUserId();
io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.generic.Day> weekApi = getWeekFromApi(getNormalizedDate(date));
io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.timetable.TimetableDay> weekApi = getWeekFromApi(getNormalizedDate(date));
Week weekDb = getWeekFromDb(weekApi.getStartDayDate());
long weekId = updateWeekInDb(weekDb, weekApi);
@ -66,40 +56,40 @@ public class TimetableSync implements TimetableSyncContract {
return null != date ? String.valueOf(TimeUtils.getNetTicks(date)) : "";
}
private io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.generic.Day> getWeekFromApi(String date)
throws IOException, VulcanException, ParseException {
private io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.timetable.TimetableDay> getWeekFromApi(String date)
throws IOException, ParseException, VulcanException {
return vulcan.getTimetable().getWeekTable(date);
}
private Week getWeekFromDb(String date) {
return daoSession.getWeekDao()
.queryBuilder()
.where(WeekDao.Properties.UserId.eq(userId), WeekDao.Properties.StartDayDate.eq(date))
.unique();
return daoSession.getWeekDao().queryBuilder().where(
WeekDao.Properties.DiaryId.eq(diaryId),
WeekDao.Properties.StartDayDate.eq(date)
).unique();
}
private Long updateWeekInDb(Week dbEntity, io.github.wulkanowy.api.generic.Week fromApi) {
if (dbEntity != null) {
dbEntity.setIsTimetableSynced(true);
dbEntity.setTimetableSynced(true);
dbEntity.update();
return dbEntity.getId();
}
Week apiEntity = DataObjectConverter.weekToWeekEntity(fromApi).setUserId(userId);
apiEntity.setIsTimetableSynced(true);
Week apiEntity = DataObjectConverter.weekToWeekEntity(fromApi).setDiaryId(diaryId);
apiEntity.setTimetableSynced(true);
return daoSession.getWeekDao().insert(apiEntity);
}
private List<TimetableLesson> updateDays(List<io.github.wulkanowy.api.generic.Day> dayListFromApi, long weekId) {
private List<TimetableLesson> updateDays(List<io.github.wulkanowy.api.timetable.TimetableDay> dayListFromApi, long weekId) {
List<TimetableLesson> updatedLessonList = new ArrayList<>();
for (io.github.wulkanowy.api.generic.Day dayFromApi : dayListFromApi) {
for (io.github.wulkanowy.api.timetable.TimetableDay dayFromApi : dayListFromApi) {
Day dbDayEntity = getDayFromDb(dayFromApi.getDate());
Day dbDayEntity = getDayFromDb(dayFromApi.getDate(), weekId);
Day apiDayEntity = DataObjectConverter.dayToDayEntity(dayFromApi);
Day apiDayEntity = DataObjectConverter.timetableDayToDayEntity(dayFromApi);
long dayId = updateDay(dbDayEntity, apiDayEntity, weekId);
@ -109,15 +99,14 @@ public class TimetableSync implements TimetableSyncContract {
return updatedLessonList;
}
private Day getDayFromDb(String date) {
return daoSession.getDayDao()
.queryBuilder()
.where(DayDao.Properties.UserId.eq(userId), DayDao.Properties.Date.eq(date))
.unique();
private Day getDayFromDb(String date, long weekId) {
return daoSession.getDayDao().queryBuilder().where(
DayDao.Properties.WeekId.eq(weekId),
DayDao.Properties.Date.eq(date)
).unique();
}
private long updateDay(Day dayFromDb, Day apiDayEntity, long weekId) {
apiDayEntity.setUserId(userId);
apiDayEntity.setWeekId(weekId);
if (null != dayFromDb) {

View File

@ -1,91 +0,0 @@
package io.github.wulkanowy.data.sync.account;
import android.content.Context;
import java.io.IOException;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.VulcanException;
import io.github.wulkanowy.data.db.dao.entities.Account;
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
import io.github.wulkanowy.data.db.dao.entities.Diary;
import io.github.wulkanowy.data.db.dao.entities.DiaryDao;
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
import io.github.wulkanowy.di.annotations.ApplicationContext;
import io.github.wulkanowy.utils.DataObjectConverter;
import io.github.wulkanowy.utils.LogUtils;
import io.github.wulkanowy.utils.security.CryptoException;
import io.github.wulkanowy.utils.security.Scrambler;
@Singleton
public class AccountSync implements AccountSyncContract {
private final DaoSession daoSession;
private final SharedPrefContract sharedPref;
private final Vulcan vulcan;
private final Context context;
@Inject
AccountSync(DaoSession daoSession, SharedPrefContract sharedPref,
Vulcan vulcan, @ApplicationContext Context context) {
this.daoSession = daoSession;
this.sharedPref = sharedPref;
this.vulcan = vulcan;
this.context = context;
}
@Override
public void registerUser(String email, String password, String symbol)
throws VulcanException, IOException, CryptoException {
LogUtils.debug("Register new user email=" + email);
vulcan.setCredentials(email, password, symbol, null, null, null);
Account account = new Account()
.setName(vulcan.getBasicInformation().getPersonalData().getFirstAndLastName())
.setEmail(email)
.setPassword(Scrambler.encrypt(email, password, context))
.setSymbol(vulcan.getSymbol())
.setSchoolId(vulcan.getStudentAndParent().getSchoolID())
.setRealId(vulcan.getStudentAndParent().getStudentID());
List<Diary> diaryList = DataObjectConverter.diariesToDiaryEntities(
vulcan.getStudentAndParent().getDiaries());
daoSession.getAccountDao().insert(account);
daoSession.getDiaryDao().insertInTx(diaryList);
sharedPref.setCurrentUserId(account.getId());
}
@Override
public void initLastUser() throws IOException, CryptoException {
long userId = sharedPref.getCurrentUserId();
if (userId == 0) {
throw new IOException("Can't find saved user");
}
LogUtils.debug("Initialization current user id=" + userId);
Account account = daoSession.getAccountDao().load(userId);
vulcan.setCredentials(account.getEmail(),
Scrambler.decrypt(account.getEmail(), account.getPassword()),
account.getSymbol(),
account.getSchoolId(),
account.getRealId(),
daoSession.getDiaryDao().queryBuilder()
.where(DiaryDao.Properties.IsCurrent.eq(true)).unique().getValue()
);
}
}

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(String date) throws IOException, ParseException, VulcanException;
void syncAttendance() throws IOException, ParseException, VulcanException;
}

View File

@ -1,91 +0,0 @@
package io.github.wulkanowy.data.sync.grades;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.github.wulkanowy.api.Vulcan;
import io.github.wulkanowy.api.VulcanException;
import io.github.wulkanowy.data.db.dao.entities.Account;
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.SubjectDao;
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
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 {
private final DaoSession daoSession;
private final Vulcan vulcan;
private final SharedPrefContract sharedPref;
private Long userId;
@Inject
GradeSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
this.daoSession = daoSession;
this.sharedPref = sharedPref;
this.vulcan = vulcan;
}
@Override
public void sync() throws IOException, VulcanException, ParseException {
userId = sharedPref.getCurrentUserId();
Account account = daoSession.getAccountDao().load(userId);
resetAccountRelations(account);
List<Grade> lastList = getUpdatedList(getComparedList(account));
daoSession.getGradeDao().deleteInTx(account.getGradeList());
daoSession.getGradeDao().insertInTx(lastList);
LogUtils.debug("Synchronization grades (amount = " + lastList.size() + ")");
}
private void resetAccountRelations(Account account) {
account.resetSubjectList();
account.resetGradeList();
}
private List<Grade> getUpdatedList(List<Grade> comparedList) {
List<Grade> updatedList = new ArrayList<>();
for (Grade grade : comparedList) {
grade.setUserId(userId);
grade.setSubjectId(getSubjectId(grade.getSubject()));
updatedList.add(grade);
}
return updatedList;
}
private List<Grade> getComparedList(Account account) throws IOException, VulcanException,
ParseException {
List<Grade> gradesFromNet = DataObjectConverter
.gradesToGradeEntities(vulcan.getGradesList().getAll());
List<Grade> gradesFromDb = account.getGradeList();
return EntitiesCompare.compareGradeList(gradesFromNet, gradesFromDb);
}
private Long getSubjectId(String subjectName) {
return daoSession.getSubjectDao().queryBuilder()
.where(SubjectDao.Properties.Name.eq(subjectName),
SubjectDao.Properties.UserId.eq(userId))
.build()
.uniqueOrThrow()
.getId();
}
}

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(String date) throws VulcanException, IOException, ParseException;
void syncTimetable() 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

@ -9,7 +9,9 @@ import io.github.wulkanowy.WulkanowyApp;
import io.github.wulkanowy.data.RepositoryContract;
import io.github.wulkanowy.di.annotations.ApplicationContext;
import io.github.wulkanowy.di.modules.ApplicationModule;
import io.github.wulkanowy.services.SyncJob;
import io.github.wulkanowy.services.jobs.SyncJob;
import io.github.wulkanowy.ui.widgets.TimetableWidgetFactory;
import io.github.wulkanowy.ui.widgets.TimetableWidgetProvider;
@Singleton
@Component(modules = ApplicationModule.class)
@ -23,4 +25,8 @@ public interface ApplicationComponent {
void inject(WulkanowyApp wulkanowyApp);
void inject(SyncJob syncJob);
void inject(TimetableWidgetFactory timetableWidgetFactory);
void inject(TimetableWidgetProvider timetableWidgetProvider);
}

View File

@ -5,7 +5,8 @@ import io.github.wulkanowy.di.annotations.PerFragment;
import io.github.wulkanowy.di.modules.FragmentModule;
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
import io.github.wulkanowy.ui.main.attendance.AttendanceTabFragment;
import io.github.wulkanowy.ui.main.dashboard.DashboardFragment;
import io.github.wulkanowy.ui.main.exams.ExamsFragment;
import io.github.wulkanowy.ui.main.exams.ExamsTabFragment;
import io.github.wulkanowy.ui.main.grades.GradesFragment;
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
import io.github.wulkanowy.ui.main.timetable.TimetableTabFragment;
@ -20,7 +21,9 @@ public interface FragmentComponent {
void inject(AttendanceTabFragment attendanceTabFragment);
void inject(DashboardFragment dashboardFragment);
void inject(ExamsFragment examsFragment);
void inject(ExamsTabFragment examsTabFragment);
void inject(TimetableFragment timetableFragment);

View File

@ -8,10 +8,10 @@ import dagger.Module;
import dagger.Provides;
import io.github.wulkanowy.di.annotations.ActivityContext;
import io.github.wulkanowy.di.annotations.PerActivity;
import io.github.wulkanowy.ui.base.BasePagerAdapter;
import io.github.wulkanowy.ui.login.LoginContract;
import io.github.wulkanowy.ui.login.LoginPresenter;
import io.github.wulkanowy.ui.main.MainContract;
import io.github.wulkanowy.ui.main.MainPagerAdapter;
import io.github.wulkanowy.ui.main.MainPresenter;
import io.github.wulkanowy.ui.splash.SplashContract;
import io.github.wulkanowy.ui.splash.SplashPresenter;
@ -58,7 +58,7 @@ public class ActivityModule {
}
@Provides
MainPagerAdapter provideMainPagerAdapter() {
return new MainPagerAdapter(activity.getSupportFragmentManager());
BasePagerAdapter provideMainPagerAdapter() {
return new BasePagerAdapter(activity.getSupportFragmentManager());
}
}

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

@ -6,20 +6,22 @@ import dagger.Module;
import dagger.Provides;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import io.github.wulkanowy.di.annotations.PerFragment;
import io.github.wulkanowy.ui.base.BasePagerAdapter;
import io.github.wulkanowy.ui.main.attendance.AttendanceContract;
import io.github.wulkanowy.ui.main.attendance.AttendanceHeaderItem;
import io.github.wulkanowy.ui.main.attendance.AttendancePagerAdapter;
import io.github.wulkanowy.ui.main.attendance.AttendancePresenter;
import io.github.wulkanowy.ui.main.attendance.AttendanceTabContract;
import io.github.wulkanowy.ui.main.attendance.AttendanceTabPresenter;
import io.github.wulkanowy.ui.main.dashboard.DashboardContract;
import io.github.wulkanowy.ui.main.dashboard.DashboardPresenter;
import io.github.wulkanowy.ui.main.exams.ExamsContract;
import io.github.wulkanowy.ui.main.exams.ExamsPresenter;
import io.github.wulkanowy.ui.main.exams.ExamsSubItem;
import io.github.wulkanowy.ui.main.exams.ExamsTabContract;
import io.github.wulkanowy.ui.main.exams.ExamsTabPresenter;
import io.github.wulkanowy.ui.main.grades.GradeHeaderItem;
import io.github.wulkanowy.ui.main.grades.GradesContract;
import io.github.wulkanowy.ui.main.grades.GradesPresenter;
import io.github.wulkanowy.ui.main.timetable.TimetableContract;
import io.github.wulkanowy.ui.main.timetable.TimetableHeaderItem;
import io.github.wulkanowy.ui.main.timetable.TimetablePagerAdapter;
import io.github.wulkanowy.ui.main.timetable.TimetablePresenter;
import io.github.wulkanowy.ui.main.timetable.TimetableTabContract;
import io.github.wulkanowy.ui.main.timetable.TimetableTabPresenter;
@ -47,8 +49,8 @@ public class FragmentModule {
@PerFragment
@Provides
DashboardContract.Presenter provideDashboardPresenter(DashboardPresenter dashboardPresenter) {
return dashboardPresenter;
ExamsContract.Presenter provideDashboardPresenter(ExamsPresenter examsPresenter) {
return examsPresenter;
}
@PerFragment
@ -58,8 +60,8 @@ public class FragmentModule {
}
@Provides
AttendancePagerAdapter provideAttendancePagerAdapter() {
return new AttendancePagerAdapter(fragment.getChildFragmentManager());
BasePagerAdapter provideBasePagerAdapter() {
return new BasePagerAdapter(fragment.getChildFragmentManager());
}
@Provides
@ -67,6 +69,21 @@ public class FragmentModule {
return new FlexibleAdapter<>(null);
}
@Provides
FlexibleAdapter<TimetableHeaderItem> provideTimetableTabAdapter() {
return new FlexibleAdapter<>(null);
}
@Provides
FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
return new FlexibleAdapter<>(null);
}
@Provides
FlexibleAdapter<ExamsSubItem> provideExamAdapter() {
return new FlexibleAdapter<>(null);
}
@PerFragment
@Provides
TimetableContract.Presenter provideTimetablePresenter(TimetablePresenter timetablePresenter) {
@ -80,17 +97,7 @@ public class FragmentModule {
}
@Provides
TimetablePagerAdapter provideTimetablePagerAdapter() {
return new TimetablePagerAdapter(fragment.getChildFragmentManager());
}
@Provides
FlexibleAdapter<TimetableHeaderItem> provideTimetableTabAdapter() {
return new FlexibleAdapter<>(null);
}
@Provides
FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
return new FlexibleAdapter<>(null);
ExamsTabContract.Presenter provideExamsTabPresenter(ExamsTabPresenter examsTabPresenter) {
return examsTabPresenter;
}
}

View File

@ -1,4 +1,4 @@
package io.github.wulkanowy.services;
package io.github.wulkanowy.services.jobs;
import android.app.PendingIntent;
import android.content.Context;
@ -24,13 +24,12 @@ import io.github.wulkanowy.R;
import io.github.wulkanowy.WulkanowyApp;
import io.github.wulkanowy.data.RepositoryContract;
import io.github.wulkanowy.data.db.dao.entities.Grade;
import io.github.wulkanowy.services.notifies.GradeNotify;
import io.github.wulkanowy.ui.main.MainActivity;
import io.github.wulkanowy.utils.LogUtils;
public class SyncJob extends SimpleJobService {
public static final String EXTRA_INTENT_KEY = "cardId";
public static final String JOB_TAG = "SyncJob";
private List<Grade> gradeList = new ArrayList<>();
@ -66,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(repository.getDbRepo().getCurrentSemesterName());
if (!gradeList.isEmpty() && repository.isNotifyEnable()) {
if (!gradeList.isEmpty() && repository.getSharedRepo().isNotifyEnable()) {
showNotification();
}
return JobService.RESULT_SUCCESS;
@ -94,8 +93,9 @@ public class SyncJob extends SimpleJobService {
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setColor(getResources().getColor(R.color.colorPrimary))
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0,
MainActivity.getStartIntent(getApplicationContext()).putExtra(EXTRA_INTENT_KEY, 0)
, 0
MainActivity.getStartIntent(getApplicationContext())
.putExtra(MainActivity.EXTRA_CARD_ID_KEY, 0)
, PendingIntent.FLAG_UPDATE_CURRENT
))
.build());
}

View File

@ -1,4 +1,4 @@
package io.github.wulkanowy.services;
package io.github.wulkanowy.services.notifies;
import android.annotation.TargetApi;
import android.app.Notification;
@ -8,11 +8,11 @@ import android.content.Context;
import io.github.wulkanowy.R;
class GradeNotify extends NotificationService {
public class GradeNotify extends NotificationService {
private static final String CHANNEL_ID = "Grade_Notify";
GradeNotify(Context context) {
public GradeNotify(Context context) {
super(context);
}

View File

@ -1,4 +1,4 @@
package io.github.wulkanowy.services;
package io.github.wulkanowy.services.notifies;
import android.annotation.TargetApi;
@ -21,11 +21,11 @@ public class NotificationService {
this.context = context;
}
void notify(Notification notification) {
public void notify(Notification notification) {
getManager().notify(new Random().nextInt(1000), notification);
}
NotificationCompat.Builder notificationBuilder() {
public NotificationCompat.Builder notificationBuilder() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createChannel();
}

View File

@ -0,0 +1,14 @@
package io.github.wulkanowy.services.widgets;
import android.content.Intent;
import android.widget.RemoteViewsService;
import io.github.wulkanowy.ui.widgets.TimetableWidgetFactory;
public class TimetableWidgetServices extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new TimetableWidgetFactory(getApplicationContext());
}
}

View File

@ -0,0 +1,47 @@
package io.github.wulkanowy.ui.base;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class BasePagerAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragmentList = new ArrayList<>();
private List<String> titleList = new ArrayList<>();
public BasePagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
public void addFragment(@NonNull Fragment fragment, @NonNull String title) {
fragmentList.add(fragment);
titleList.add(title);
}
public void addFragment(@NonNull Fragment fragment) {
fragmentList.add(fragment);
}
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
@Override
public CharSequence getPageTitle(int position) {
if (!titleList.isEmpty()) {
return titleList.get(position);
}
return null;
}
}

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

@ -5,6 +5,7 @@ import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
@ -16,10 +17,10 @@ import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.github.wulkanowy.R;
import io.github.wulkanowy.services.SyncJob;
import io.github.wulkanowy.ui.base.BaseActivity;
import io.github.wulkanowy.ui.base.BasePagerAdapter;
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
import io.github.wulkanowy.ui.main.dashboard.DashboardFragment;
import io.github.wulkanowy.ui.main.exams.ExamsFragment;
import io.github.wulkanowy.ui.main.grades.GradesFragment;
import io.github.wulkanowy.ui.main.settings.SettingsFragment;
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
@ -27,6 +28,8 @@ import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
public class MainActivity extends BaseActivity implements MainContract.View,
AHBottomNavigation.OnTabSelectedListener, OnFragmentIsReadyListener {
public static final String EXTRA_CARD_ID_KEY = "cardId";
@BindView(R.id.main_activity_nav)
AHBottomNavigation bottomNavigation;
@ -37,7 +40,7 @@ public class MainActivity extends BaseActivity implements MainContract.View,
View progressBar;
@Inject
MainPagerAdapter pagerAdapter;
BasePagerAdapter pagerAdapter;
@Inject
MainContract.Presenter presenter;
@ -50,11 +53,12 @@ public class MainActivity extends BaseActivity implements MainContract.View,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
getActivityComponent().inject(this);
setButterKnife(ButterKnife.bind(this));
presenter.onStart(this, getIntent().getIntExtra(SyncJob.EXTRA_INTENT_KEY, -1));
presenter.onStart(this, getIntent().getIntExtra(EXTRA_CARD_ID_KEY, -1));
}
@Override
@ -104,8 +108,8 @@ public class MainActivity extends BaseActivity implements MainContract.View,
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.attendance_text),
R.drawable.ic_menu_attendance_24dp));
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.dashboard_text),
R.drawable.ic_menu_dashboard_24dp));
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.exams_text),
R.drawable.ic_menu_exams_24dp));
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.timetable_text),
R.drawable.ic_menu_timetable_24dp));
@ -126,7 +130,7 @@ public class MainActivity extends BaseActivity implements MainContract.View,
public void initiationViewPager(int tabPosition) {
pagerAdapter.addFragment(new GradesFragment());
pagerAdapter.addFragment(new AttendanceFragment());
pagerAdapter.addFragment(new DashboardFragment());
pagerAdapter.addFragment(new ExamsFragment());
pagerAdapter.addFragment(new TimetableFragment());
pagerAdapter.addFragment(new SettingsFragment());

View File

@ -1,31 +0,0 @@
package io.github.wulkanowy.ui.main;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class MainPagerAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragmentList = new ArrayList<>();
public MainPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
void addFragment(Fragment fragment) {
fragmentList.add(fragment);
}
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
}

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

@ -1,37 +0,0 @@
package io.github.wulkanowy.ui.main;
import android.support.v4.app.Fragment;
import java.util.ArrayList;
import java.util.List;
public class TabsData {
private List<Fragment> fragments = new ArrayList<>();
private List<String> titles = new ArrayList<>();
public Fragment getFragment(int index) {
return fragments.get(index);
}
public void addFragment(Fragment fragment) {
if (fragment != null) {
fragments.add(fragment);
}
}
public int getFragmentsCount() {
return fragments.size();
}
public String getTitle(int index) {
return titles.get(index);
}
public void addTitle(String title) {
if (title != null) {
titles.add(title);
}
}
}

View File

@ -3,7 +3,6 @@ package io.github.wulkanowy.ui.main.attendance;
import io.github.wulkanowy.di.annotations.PerActivity;
import io.github.wulkanowy.ui.base.BaseContract;
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
import io.github.wulkanowy.ui.main.TabsData;
public interface AttendanceContract {
@ -13,11 +12,13 @@ public interface AttendanceContract {
void scrollViewPagerToPosition(int position);
void setTabDataToAdapter(TabsData tabsData);
void setTabDataToAdapter(String date);
void setAdapterWithTabLayout();
boolean isMenuVisible();
void setThemeForTab(int position);
}
@PerActivity

View File

@ -77,7 +77,7 @@ public class AttendanceDialogFragment extends DialogFragment {
description.setText(lesson.getDescription());
if (lesson.getIsAbsenceUnexcused()) {
if (lesson.getAbsenceUnexcused()) {
description.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
}

View File

@ -17,8 +17,8 @@ import butterknife.ButterKnife;
import io.github.wulkanowy.R;
import io.github.wulkanowy.di.component.FragmentComponent;
import io.github.wulkanowy.ui.base.BaseFragment;
import io.github.wulkanowy.ui.base.BasePagerAdapter;
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
import io.github.wulkanowy.ui.main.TabsData;
public class AttendanceFragment extends BaseFragment implements AttendanceContract.View {
@ -31,7 +31,7 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
TabLayout tabLayout;
@Inject
AttendancePagerAdapter pagerAdapter;
BasePagerAdapter pagerAdapter;
@Inject
AttendanceContract.Presenter presenter;
@ -65,8 +65,8 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
}
@Override
public void setTabDataToAdapter(TabsData tabsData) {
pagerAdapter.setTabsData(tabsData);
public void setTabDataToAdapter(String date) {
pagerAdapter.addFragment(AttendanceTabFragment.newInstance(date), date);
}
@Override
@ -80,6 +80,14 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
viewPager.setCurrentItem(position, false);
}
@Override
public void setThemeForTab(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if (tab != null) {
tab.setCustomView(R.layout.current_week_tab);
}
}
@Override
public void setActivityTitle() {
setTitle(getString(R.string.attendance_text));

View File

@ -141,7 +141,7 @@ public class AttendanceHeaderItem
private int countNotPresentHours(List<AttendanceSubItem> subItems) {
int i = 0;
for (AttendanceSubItem subItem : subItems) {
if (subItem.getLesson().getIsAbsenceUnexcused()) {
if (subItem.getLesson().getAbsenceUnexcused()) {
i++;
}
}
@ -150,8 +150,8 @@ public class AttendanceHeaderItem
private boolean isSubItemsHasChanges(List<AttendanceSubItem> subItems) {
for (AttendanceSubItem subItem : subItems) {
if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson()
.getIsUnexcusedLateness()) {
if (subItem.getLesson().getAbsenceUnexcused() || subItem.getLesson()
.getUnexcusedLateness()) {
return true;
}
}

View File

@ -1,38 +0,0 @@
package io.github.wulkanowy.ui.main.attendance;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import io.github.wulkanowy.ui.main.TabsData;
public class AttendancePagerAdapter extends FragmentStatePagerAdapter {
private TabsData tabsData;
public AttendancePagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
void setTabsData(TabsData tabsData) {
this.tabsData = tabsData;
}
@Override
public Fragment getItem(int position) {
return tabsData.getFragment(position);
}
@Override
public int getCount() {
return tabsData.getFragmentsCount();
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return tabsData.getTitle(position);
}
}

View File

@ -8,7 +8,6 @@ import javax.inject.Inject;
import io.github.wulkanowy.data.RepositoryContract;
import io.github.wulkanowy.ui.base.BasePresenter;
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
import io.github.wulkanowy.ui.main.TabsData;
import io.github.wulkanowy.utils.TimeUtils;
import io.github.wulkanowy.utils.async.AbstractTask;
import io.github.wulkanowy.utils.async.AsyncListeners;
@ -20,8 +19,6 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
private List<String> dates = new ArrayList<>();
private TabsData tabsData = new TabsData();
private OnFragmentIsReadyListener listener;
private int positionToScroll = 0;
@ -69,8 +66,7 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
@Override
public void onDoInBackgroundLoading() throws Exception {
for (String date : dates) {
tabsData.addTitle(date);
tabsData.addFragment(AttendanceTabFragment.newInstance(date));
getView().setTabDataToAdapter(date);
}
}
@ -83,8 +79,8 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
@Override
public void onEndLoadingAsync(boolean result, Exception exception) {
if (result) {
getView().setTabDataToAdapter(tabsData);
getView().setAdapterWithTabLayout();
getView().setThemeForTab(positionToScroll);
getView().scrollViewPagerToPosition(positionToScroll);
listener.onFragmentIsReady();
}

View File

@ -102,7 +102,7 @@ class AttendanceSubItem
lessonName.setText(lesson.getSubject());
lessonNumber.setText((String.valueOf(lesson.getNumber())));
lessonDescription.setText(lesson.getDescription());
alert.setVisibility(lesson.getIsAbsenceUnexcused() || lesson.getIsUnexcusedLateness()
alert.setVisibility(lesson.getAbsenceUnexcused() || lesson.getUnexcusedLateness()
? View.VISIBLE : View.INVISIBLE);
}

View File

@ -85,20 +85,22 @@ 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);
boolean isShowPresent = getRepository().getSharedRepo().isShowAttendancePresent();
if (week == null || !week.getIsAttendanceSynced()) {
if (week == null || !week.getAttendanceSynced()) {
syncData();
week = getRepository().getWeek(date);
week = getRepository().getDbRepo().getWeek(date);
}
week.resetDayList();
List<Day> dayList = week.getDayList();
headerItems = new ArrayList<>();
@ -118,10 +120,18 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
List<AttendanceSubItem> subItems = new ArrayList<>();
for (AttendanceLesson lesson : lessonList) {
lesson.setDescription(getRepository().getAttendanceLessonDescription(lesson));
if (!isShowPresent && lesson.getPresence()) {
continue;
}
lesson.setDescription(getRepository().getResRepo().getAttendanceLessonDescription(lesson));
subItems.add(new AttendanceSubItem(headerItem, lesson));
}
if (!isShowPresent && subItems.isEmpty()) {
continue;
}
headerItem.setSubItems(subItems);
headerItem.setExpanded(false);
headerItems.add(headerItem);
@ -155,7 +165,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

@ -1,48 +0,0 @@
package io.github.wulkanowy.ui.main.dashboard;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import javax.inject.Inject;
import butterknife.ButterKnife;
import io.github.wulkanowy.R;
import io.github.wulkanowy.di.component.FragmentComponent;
import io.github.wulkanowy.ui.base.BaseFragment;
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
public class DashboardFragment extends BaseFragment implements DashboardContract.View {
@Inject
DashboardContract.Presenter presenter;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_board, container, false);
FragmentComponent component = getFragmentComponent();
if (component != null) {
component.inject(this);
setButterKnife(ButterKnife.bind(this, view));
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
}
return view;
}
@Override
public void setMenuVisibility(boolean menuVisible) {
super.setMenuVisibility(menuVisible);
if (presenter != null) {
presenter.onFragmentVisible(menuVisible);
}
}
@Override
public void setActivityTitle() {
setTitle(getString(R.string.dashboard_text));
}
}

Some files were not shown because too many files have changed in this diff Show More