Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
ce00c7025a | |||
5c558ae1f9 | |||
0708d84b98 | |||
b22d95392b | |||
78d57ca746 | |||
0aa8c5605d | |||
cb6afb137f | |||
c72e7748e2 | |||
5c9f10fa50 | |||
cdd3d6a53b | |||
8431661d54 | |||
3dabb11473 | |||
63b4ed42ca | |||
2bb2341d0f | |||
797e233809 | |||
64b964ca18 | |||
c9bdac6a66 | |||
83b4f359bc | |||
a094d4f0d9 | |||
3aca34340d | |||
a0313827ce | |||
3799fa910b | |||
828e76821b | |||
e050982de2 | |||
69fc4bf874 | |||
c3803b1c96 | |||
e274949257 | |||
bc4b150858 | |||
e187493e01 |
@ -7,7 +7,7 @@ references:
|
|||||||
|
|
||||||
container_config: &container_config
|
container_config: &container_config
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/android:api-27-alpha
|
- image: circleci/android:api-26-alpha
|
||||||
working_directory: *workspace_root
|
working_directory: *workspace_root
|
||||||
environment:
|
environment:
|
||||||
environment:
|
environment:
|
||||||
@ -126,6 +126,9 @@ jobs:
|
|||||||
name: Launch emulator
|
name: Launch emulator
|
||||||
command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on
|
command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on
|
||||||
background: true
|
background: true
|
||||||
|
- run:
|
||||||
|
name: Change circle-android script file permissions
|
||||||
|
command: sudo chmod +rx /bin/circle-android
|
||||||
- run:
|
- run:
|
||||||
name: Wait emulator
|
name: Wait emulator
|
||||||
command: |
|
command: |
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -32,6 +32,8 @@ local.properties
|
|||||||
.idea/tasks.xml
|
.idea/tasks.xml
|
||||||
.idea/vcs.xml
|
.idea/vcs.xml
|
||||||
.idea/workspace.xml
|
.idea/workspace.xml
|
||||||
|
.idea/caches/
|
||||||
|
.idea/codeStyles/
|
||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
# OS-specific files
|
# OS-specific files
|
||||||
|
@ -12,7 +12,7 @@ build:
|
|||||||
script:
|
script:
|
||||||
- ./gradlew --no-daemon --stacktrace dependencies || true
|
- ./gradlew --no-daemon --stacktrace dependencies || true
|
||||||
- ./gradlew --no-daemon --stacktrace assembleDebug
|
- ./gradlew --no-daemon --stacktrace assembleDebug
|
||||||
- mv app/build/outputs/apk/app-debug.apk .
|
- mv app/build/outputs/apk/debug/app-debug.apk .
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "${CI_PROJECT_NAME}_${CI_BUILD_REF_NAME}-${CI_BUILD_ID}"
|
name: "${CI_PROJECT_NAME}_${CI_BUILD_REF_NAME}-${CI_BUILD_ID}"
|
||||||
paths:
|
paths:
|
||||||
@ -26,7 +26,7 @@ tests:
|
|||||||
- .gradle
|
- .gradle
|
||||||
policy: pull
|
policy: pull
|
||||||
script:
|
script:
|
||||||
- ./gradlew --no-daemon --stacktrace test
|
- ./gradlew --no-daemon --stacktrace -x fabricGenerateResourcesRelease test
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- app/build/reports/tests
|
- app/build/reports/tests
|
||||||
@ -39,7 +39,7 @@ lint:
|
|||||||
- .gradle
|
- .gradle
|
||||||
policy: pull
|
policy: pull
|
||||||
script:
|
script:
|
||||||
- ./gradlew --no-daemon --stacktrace lint
|
- ./gradlew --no-daemon --stacktrace -x fabricGenerateResourcesRelease lint
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- app/build/reports
|
- app/build/reports
|
||||||
|
11
README.md
11
README.md
@ -1,12 +1,13 @@
|
|||||||
# Wulkanowy
|
# Wulkanowy
|
||||||
|
|
||||||
[](https://codecov.io/gh/wulkanowy/wulkanowy)
|
[](https://circleci.com/gh/wulkanowy/wulkanowy)
|
||||||
[](https://www.versioneye.com/user/projects/5969ff0b0fb24f004f8c711b)
|
|
||||||
[](https://circleci.com/gh/wulkanowy/wulkanowy)
|
|
||||||
[](https://www.bitrise.io/app/daeff1893f3c8128)
|
[](https://www.bitrise.io/app/daeff1893f3c8128)
|
||||||
|
[](https://codecov.io/gh/wulkanowy/wulkanowy)
|
||||||
[](https://bettercodehub.com/)
|
[](https://bettercodehub.com/)
|
||||||
|
[](https://scrutinizer-ci.com/g/wulkanowy/wulkanowy/?branch=master)
|
||||||
|
[](https://snyk.io/test/github/wulkanowy/wulkanowy?targetFile=app%2Fbuild.gradle)
|
||||||
[](https://bintray.com/wulkanowy/wulkanowy/api)
|
[](https://bintray.com/wulkanowy/wulkanowy/api)
|
||||||
|
|
||||||
[Pobierz wersję rozwojową](https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/master/artifacts/app-release-bitrise-signed.apk)
|
[Pobierz wersję rozwojową](https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/master/artifacts/app-debug-bitrise-signed.apk)
|
||||||
|
|
||||||
Wulkanowy to projekt aplikacji na androida ułatwiającej używanie dziennika VULCANa.
|
Androidowy klient dziennika VULCAN UONET+.
|
||||||
|
@ -5,7 +5,7 @@ sonarqube {
|
|||||||
//noinspection GroovyAssignabilityCheck
|
//noinspection GroovyAssignabilityCheck
|
||||||
properties {
|
properties {
|
||||||
def files = fileTree("${rootProject.projectDir}/api/build/libs/").filter { it.isFile() }.files.name
|
def files = fileTree("${rootProject.projectDir}/api/build/libs/").filter { it.isFile() }.files.name
|
||||||
def libraries = project.android.sdkDirectory.getPath() + "/platforms/android-27/android.jar," +
|
def libraries = project.android.sdkDirectory.getPath() + "/platforms/android-26/android.jar," +
|
||||||
"${project.rootDir}/api/build/libs/" + files[0]
|
"${project.rootDir}/api/build/libs/" + files[0]
|
||||||
|
|
||||||
property "sonar.projectName", GROUP_ID + ":app"
|
property "sonar.projectName", GROUP_ID + ":app"
|
||||||
|
@ -28,12 +28,12 @@ jacocoTestReport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.jsoup:jsoup:1.10.3'
|
implementation "org.jsoup:jsoup:$jsoup"
|
||||||
implementation 'org.apache.commons:commons-lang3:3.7'
|
implementation "org.apache.commons:commons-lang3:$apacheLang"
|
||||||
implementation 'com.google.code.gson:gson:2.8.2'
|
implementation "com.google.code.gson:gson:$gson"
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation "junit:junit:$junit"
|
||||||
testImplementation 'org.mockito:mockito-core:2.13.0'
|
testImplementation "org.mockito:mockito-core:$mockito"
|
||||||
}
|
}
|
||||||
|
|
||||||
version = PUBLISH_VERSION
|
version = PUBLISH_VERSION
|
||||||
|
@ -5,44 +5,102 @@ import org.jsoup.Jsoup;
|
|||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.api.login.Login;
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
private String protocol;
|
private String protocol = "https";
|
||||||
|
|
||||||
private String host;
|
private String host = "vulcan.net.pl";
|
||||||
|
|
||||||
private String symbol;
|
private String email;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private String symbol = "Default";
|
||||||
|
|
||||||
|
private Login login;
|
||||||
|
|
||||||
|
private Date lastSuccessRequest = new Date();
|
||||||
|
|
||||||
private Cookies cookies = new Cookies();
|
private Cookies cookies = new Cookies();
|
||||||
|
|
||||||
Client(String protocol, String host, String symbol) {
|
Client(String email, String password, String symbol) {
|
||||||
this.protocol = protocol;
|
this.email = email;
|
||||||
this.host = host;
|
this.password = password;
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
|
|
||||||
|
setFullEndpointInfo(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getHost() {
|
private void setFullEndpointInfo(String info) {
|
||||||
return host;
|
String[] creds = info.split("\\\\");
|
||||||
|
|
||||||
|
email = info;
|
||||||
|
|
||||||
|
if (creds.length > 2) {
|
||||||
|
String[] url = creds[0].split("://");
|
||||||
|
|
||||||
|
protocol = url[0];
|
||||||
|
host = url[1];
|
||||||
|
email = creds[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void login() throws IOException, VulcanException {
|
||||||
|
if (isLoggedIn()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.symbol = getLogin().login(email, password, symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLoggedIn() {
|
||||||
|
return getCookies().size() > 0 &&
|
||||||
|
29 > TimeUnit.MILLISECONDS.toMinutes(new Date().getTime() - lastSuccessRequest.getTime());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Login getLogin() {
|
||||||
|
if (null != login) {
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
|
login = new Login(this);
|
||||||
|
|
||||||
|
return login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSymbol() {
|
||||||
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSymbol(String symbol) {
|
public void setSymbol(String symbol) {
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> getCookies() {
|
private Map<String, String> getCookies() {
|
||||||
return cookies.getItems();
|
return cookies.getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFilledUrl(String url) {
|
String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getFilledUrl(String url) {
|
||||||
return url
|
return url
|
||||||
.replace("{schema}", protocol)
|
.replace("{schema}", protocol)
|
||||||
.replace("{host}", host.replace(":", "%253A"))
|
.replace("{host}", host.replace(":", "%253A"))
|
||||||
.replace("{symbol}", symbol == null ? "Default" : symbol);
|
.replace("{symbol}", symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
Document getPageByUrl(String url) throws IOException {
|
Document getPageByUrl(String url) throws IOException, VulcanException {
|
||||||
|
login();
|
||||||
|
|
||||||
Connection.Response response = Jsoup.connect(getFilledUrl(url))
|
Connection.Response response = Jsoup.connect(getFilledUrl(url))
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.cookies(getCookies())
|
.cookies(getCookies())
|
||||||
@ -50,10 +108,14 @@ public class Client {
|
|||||||
|
|
||||||
this.cookies.addItems(response.cookies());
|
this.cookies.addItems(response.cookies());
|
||||||
|
|
||||||
return response.parse();
|
Document doc = checkForErrors(response.parse());
|
||||||
|
|
||||||
|
lastSuccessRequest = new Date();
|
||||||
|
|
||||||
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Document postPageByUrl(String url, String[][] params) throws IOException {
|
public Document postPageByUrl(String url, String[][] params) throws IOException, VulcanException {
|
||||||
Connection connection = Jsoup.connect(getFilledUrl(url));
|
Connection connection = Jsoup.connect(getFilledUrl(url));
|
||||||
|
|
||||||
for (String[] data : params) {
|
for (String[] data : params) {
|
||||||
@ -68,10 +130,12 @@ public class Client {
|
|||||||
|
|
||||||
this.cookies.addItems(response.cookies());
|
this.cookies.addItems(response.cookies());
|
||||||
|
|
||||||
return response.parse();
|
return checkForErrors(response.parse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJsonStringByUrl(String url) throws IOException {
|
public String getJsonStringByUrl(String url) throws IOException, VulcanException {
|
||||||
|
login();
|
||||||
|
|
||||||
Connection.Response response = Jsoup.connect(getFilledUrl(url))
|
Connection.Response response = Jsoup.connect(getFilledUrl(url))
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.ignoreContentType(true)
|
.ignoreContentType(true)
|
||||||
@ -83,7 +147,9 @@ public class Client {
|
|||||||
return response.body();
|
return response.body();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String postJsonStringByUrl(String url, String[][] params) throws IOException {
|
public String postJsonStringByUrl(String url, String[][] params) throws IOException, VulcanException {
|
||||||
|
login();
|
||||||
|
|
||||||
Connection connection = Jsoup.connect(getFilledUrl(url));
|
Connection connection = Jsoup.connect(getFilledUrl(url));
|
||||||
|
|
||||||
for (String[] data : params) {
|
for (String[] data : params) {
|
||||||
@ -101,4 +167,18 @@ public class Client {
|
|||||||
|
|
||||||
return response.body();
|
return response.body();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Document checkForErrors(Document doc) throws VulcanException {
|
||||||
|
String title = doc.select("title").text();
|
||||||
|
if ("Przerwa techniczna".equals(title)) {
|
||||||
|
throw new VulcanOfflineException(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singIn = doc.select(".loginButton").text();
|
||||||
|
if ("Zaloguj się".equals(singIn)) {
|
||||||
|
throw new NotLoggedInErrorException(singIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,15 @@ package io.github.wulkanowy.api;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Cookies {
|
class Cookies {
|
||||||
|
|
||||||
private Map<String, String> jar = new HashMap<>();
|
private Map<String, String> jar = new HashMap<>();
|
||||||
|
|
||||||
public Map<String, String> getItems() {
|
Map<String, String> getItems() {
|
||||||
return jar;
|
return jar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cookies setItems(Map<String, String> items) {
|
void addItems(Map<String, String> items) {
|
||||||
this.jar = items;
|
jar.putAll(items);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cookies addItems(Map<String, String> items) {
|
|
||||||
this.jar.putAll(items);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package io.github.wulkanowy.api;
|
||||||
|
|
||||||
|
public class NotLoggedInErrorException extends VulcanException {
|
||||||
|
|
||||||
|
public NotLoggedInErrorException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -6,19 +6,17 @@ import org.jsoup.nodes.Element;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
|
|
||||||
public interface SnP {
|
public interface SnP {
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
void storeContextCookies() throws IOException, NotLoggedInErrorException;
|
StudentAndParent storeContextCookies() throws IOException, VulcanException;
|
||||||
|
|
||||||
String getRowDataChildValue(Element e, int index);
|
String getRowDataChildValue(Element e, int index);
|
||||||
|
|
||||||
Document getSnPPageDocument(String url) throws IOException;
|
Document getSnPPageDocument(String url) throws IOException, VulcanException;
|
||||||
|
|
||||||
List<Semester> getSemesters() throws IOException;
|
List<Semester> getSemesters() throws IOException, VulcanException;
|
||||||
|
|
||||||
List<Semester> getSemesters(Document gradesPage);
|
List<Semester> getSemesters(Document gradesPage);
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
|
|
||||||
public class StudentAndParent implements SnP {
|
public class StudentAndParent implements SnP {
|
||||||
|
|
||||||
private static final String START_PAGE_URL = "{schema}://uonetplus.{host}/{symbol}/Start.mvc/Index";
|
private static final String START_PAGE_URL = "{schema}://uonetplus.{host}/{symbol}/Start.mvc/Index";
|
||||||
@ -22,12 +20,8 @@ public class StudentAndParent implements SnP {
|
|||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
StudentAndParent(Client client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
StudentAndParent(Client client, String id) {
|
StudentAndParent(Client client, String id) {
|
||||||
this(client);
|
this.client = client;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +33,12 @@ public class StudentAndParent implements SnP {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeContextCookies() throws IOException, NotLoggedInErrorException {
|
public StudentAndParent storeContextCookies() throws IOException, VulcanException {
|
||||||
client.getPageByUrl(getSnpHomePageUrl());
|
client.getPageByUrl(getSnpHomePageUrl());
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getSnpHomePageUrl() throws IOException, NotLoggedInErrorException {
|
String getSnpHomePageUrl() throws IOException, VulcanException {
|
||||||
if (null != getId()) {
|
if (null != getId()) {
|
||||||
return getBaseUrl();
|
return getBaseUrl();
|
||||||
}
|
}
|
||||||
@ -53,7 +48,7 @@ public class StudentAndParent implements SnP {
|
|||||||
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
|
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
|
||||||
|
|
||||||
if (null == studentTileLink) {
|
if (null == studentTileLink) {
|
||||||
throw new NotLoggedInErrorException();
|
throw new NotLoggedInErrorException("You are probably not logged in. Force login");
|
||||||
}
|
}
|
||||||
|
|
||||||
String snpPageUrl = studentTileLink.attr("href");
|
String snpPageUrl = studentTileLink.attr("href");
|
||||||
@ -67,7 +62,7 @@ public class StudentAndParent implements SnP {
|
|||||||
String[] path = snpPageUrl.split(client.getHost())[1].split("/");
|
String[] path = snpPageUrl.split(client.getHost())[1].split("/");
|
||||||
|
|
||||||
if (5 != path.length) {
|
if (5 != path.length) {
|
||||||
throw new NotLoggedInErrorException();
|
throw new NotLoggedInErrorException("You are probably not logged in");
|
||||||
}
|
}
|
||||||
|
|
||||||
return path[2];
|
return path[2];
|
||||||
@ -77,11 +72,11 @@ public class StudentAndParent implements SnP {
|
|||||||
return e.select(".daneWiersz .wartosc").get(index - 1).text();
|
return e.select(".daneWiersz .wartosc").get(index - 1).text();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Document getSnPPageDocument(String url) throws IOException {
|
public Document getSnPPageDocument(String url) throws IOException, VulcanException {
|
||||||
return client.getPageByUrl(getBaseUrl() + url);
|
return client.getPageByUrl(getBaseUrl() + url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Semester> getSemesters() throws IOException {
|
public List<Semester> getSemesters() throws IOException, VulcanException {
|
||||||
return getSemesters(getSnPPageDocument(GRADES_PAGE_URL));
|
return getSemesters(getSnPPageDocument(GRADES_PAGE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,12 +7,6 @@ import io.github.wulkanowy.api.attendance.AttendanceTable;
|
|||||||
import io.github.wulkanowy.api.exams.ExamsWeek;
|
import io.github.wulkanowy.api.exams.ExamsWeek;
|
||||||
import io.github.wulkanowy.api.grades.GradesList;
|
import io.github.wulkanowy.api.grades.GradesList;
|
||||||
import io.github.wulkanowy.api.grades.SubjectsList;
|
import io.github.wulkanowy.api.grades.SubjectsList;
|
||||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
|
||||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
|
||||||
import io.github.wulkanowy.api.login.Login;
|
|
||||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
|
||||||
import io.github.wulkanowy.api.messages.Messages;
|
import io.github.wulkanowy.api.messages.Messages;
|
||||||
import io.github.wulkanowy.api.notes.AchievementsList;
|
import io.github.wulkanowy.api.notes.AchievementsList;
|
||||||
import io.github.wulkanowy.api.notes.NotesList;
|
import io.github.wulkanowy.api.notes.NotesList;
|
||||||
@ -26,171 +20,92 @@ public class Vulcan {
|
|||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String symbol;
|
|
||||||
|
|
||||||
private SnP snp;
|
private SnP snp;
|
||||||
|
|
||||||
private String protocolSchema = "https";
|
|
||||||
|
|
||||||
private String logHost = "vulcan.net.pl";
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
private Login login;
|
public void setCredentials(String email, String password, String symbol, String id) {
|
||||||
|
client = new Client(email, password, symbol);
|
||||||
public void setClient(Client client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLogin(Login login) {
|
|
||||||
this.login = login;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void login(String email, String password, String symbol)
|
|
||||||
throws BadCredentialsException, AccountPermissionException,
|
|
||||||
LoginErrorException, IOException, VulcanOfflineException {
|
|
||||||
|
|
||||||
setFullEndpointInfo(email);
|
|
||||||
login = getLogin();
|
|
||||||
|
|
||||||
this.symbol = login.login(this.email, password, symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vulcan login(String email, String password, String symbol, String id)
|
|
||||||
throws BadCredentialsException, AccountPermissionException,
|
|
||||||
LoginErrorException, IOException, VulcanOfflineException {
|
|
||||||
login(email, password, symbol);
|
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getProtocolSchema() {
|
public Client getClient() throws NotLoggedInErrorException {
|
||||||
return protocolSchema;
|
if (null == client) {
|
||||||
|
throw new NotLoggedInErrorException("Use setCredentials() method first");
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLogHost() {
|
|
||||||
return logHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSymbol() {
|
|
||||||
return symbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setFullEndpointInfo(String email) {
|
|
||||||
String[] creds = email.split("\\\\");
|
|
||||||
|
|
||||||
this.email = email;
|
|
||||||
|
|
||||||
if (creds.length >= 2) {
|
|
||||||
String[] url = creds[0].split("://");
|
|
||||||
|
|
||||||
this.protocolSchema = url[0];
|
|
||||||
this.logHost = url[1];
|
|
||||||
this.email = creds[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Client getClient() {
|
|
||||||
if (null != client) {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
client = new Client(getProtocolSchema(), getLogHost(), symbol);
|
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Login getLogin() {
|
public String getSymbol() throws NotLoggedInErrorException {
|
||||||
if (null != login) {
|
return getClient().getSymbol();
|
||||||
return login;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
login = new Login(getClient());
|
public SnP getStudentAndParent() throws IOException, VulcanException {
|
||||||
|
if (null != this.snp) {
|
||||||
return login;
|
return this.snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SnP getStudentAndParent() throws IOException, NotLoggedInErrorException {
|
this.snp = new StudentAndParent(getClient(), id).storeContextCookies();
|
||||||
if (0 == getClient().getCookies().size()) {
|
|
||||||
throw new NotLoggedInErrorException();
|
return this.snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != snp) {
|
public String getId() throws IOException, VulcanException {
|
||||||
return snp;
|
return getStudentAndParent().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
snp = createSnp(getClient(), id);
|
public AttendanceTable getAttendanceTable() throws IOException, VulcanException {
|
||||||
|
|
||||||
snp.storeContextCookies();
|
|
||||||
|
|
||||||
return snp;
|
|
||||||
}
|
|
||||||
|
|
||||||
SnP createSnp(Client client, String id) {
|
|
||||||
if (null == id) {
|
|
||||||
return new StudentAndParent(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new StudentAndParent(client, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AttendanceStatistics getAttendanceStatistics() throws IOException, NotLoggedInErrorException {
|
|
||||||
return new AttendanceStatistics(getStudentAndParent());
|
|
||||||
}
|
|
||||||
|
|
||||||
public AttendanceTable getAttendanceTable() throws IOException, NotLoggedInErrorException {
|
|
||||||
return new AttendanceTable(getStudentAndParent());
|
return new AttendanceTable(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExamsWeek getExamsList() throws IOException, NotLoggedInErrorException {
|
public AttendanceStatistics getAttendanceStatistics() throws IOException, VulcanException {
|
||||||
|
return new AttendanceStatistics(getStudentAndParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExamsWeek getExamsList() throws IOException, VulcanException {
|
||||||
return new ExamsWeek(getStudentAndParent());
|
return new ExamsWeek(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public GradesList getGradesList() throws IOException, NotLoggedInErrorException {
|
public GradesList getGradesList() throws IOException, VulcanException {
|
||||||
return new GradesList(getStudentAndParent());
|
return new GradesList(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubjectsList getSubjectsList() throws IOException, NotLoggedInErrorException {
|
public SubjectsList getSubjectsList() throws IOException, VulcanException {
|
||||||
return new SubjectsList(getStudentAndParent());
|
return new SubjectsList(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AchievementsList getAchievementsList() throws IOException, NotLoggedInErrorException {
|
public AchievementsList getAchievementsList() throws IOException, VulcanException {
|
||||||
return new AchievementsList(getStudentAndParent());
|
return new AchievementsList(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotesList getNotesList() throws IOException, NotLoggedInErrorException {
|
public NotesList getNotesList() throws IOException, VulcanException {
|
||||||
return new NotesList(getStudentAndParent());
|
return new NotesList(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SchoolInfo getSchoolInfo() throws IOException, NotLoggedInErrorException {
|
public SchoolInfo getSchoolInfo() throws IOException, VulcanException {
|
||||||
return new SchoolInfo(getStudentAndParent());
|
return new SchoolInfo(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TeachersInfo getTeachersInfo() throws IOException, NotLoggedInErrorException {
|
public TeachersInfo getTeachersInfo() throws IOException, VulcanException {
|
||||||
return new TeachersInfo(getStudentAndParent());
|
return new TeachersInfo(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timetable getTimetable() throws IOException, NotLoggedInErrorException {
|
public Timetable getTimetable() throws IOException, VulcanException {
|
||||||
return new Timetable(getStudentAndParent());
|
return new Timetable(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicInformation getBasicInformation() throws IOException, NotLoggedInErrorException {
|
public BasicInformation getBasicInformation() throws IOException, VulcanException {
|
||||||
return new BasicInformation(getStudentAndParent());
|
return new BasicInformation(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public FamilyInformation getFamilyInformation() throws IOException, NotLoggedInErrorException {
|
public FamilyInformation getFamilyInformation() throws IOException, VulcanException {
|
||||||
return new FamilyInformation(getStudentAndParent());
|
return new FamilyInformation(getStudentAndParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Messages getMessages() {
|
public Messages getMessages() throws VulcanException {
|
||||||
return new Messages(getClient());
|
return new Messages(getClient());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package io.github.wulkanowy.api;
|
||||||
|
|
||||||
|
public abstract class VulcanException extends Exception {
|
||||||
|
|
||||||
|
protected VulcanException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package io.github.wulkanowy.api;
|
||||||
|
|
||||||
|
public class VulcanOfflineException extends VulcanException {
|
||||||
|
|
||||||
|
VulcanOfflineException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
import io.github.wulkanowy.api.generic.Month;
|
import io.github.wulkanowy.api.generic.Month;
|
||||||
import io.github.wulkanowy.api.generic.Subject;
|
import io.github.wulkanowy.api.generic.Subject;
|
||||||
|
|
||||||
@ -22,15 +23,15 @@ public class AttendanceStatistics {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Types getTypesTable() throws IOException {
|
public Types getTypesTable() throws IOException, VulcanException {
|
||||||
return getTypesTable("");
|
return getTypesTable("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Types getTypesTable(String tick) throws IOException {
|
public Types getTypesTable(String tick) throws IOException, VulcanException {
|
||||||
return getTypesTable(tick, -1);
|
return getTypesTable(tick, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Subject> getSubjectList() throws IOException {
|
public List<Subject> getSubjectList() throws IOException, VulcanException {
|
||||||
Element mainContainer = snp.getSnPPageDocument(attendancePageUrl)
|
Element mainContainer = snp.getSnPPageDocument(attendancePageUrl)
|
||||||
.select(".mainContainer #idPrzedmiot").first();
|
.select(".mainContainer #idPrzedmiot").first();
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ public class AttendanceStatistics {
|
|||||||
return subjectList;
|
return subjectList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Types getTypesTable(String tick, Integer subjectId) throws IOException {
|
public Types getTypesTable(String tick, Integer subjectId) throws IOException, VulcanException {
|
||||||
Element mainContainer = snp.getSnPPageDocument((attendancePageUrl
|
Element mainContainer = snp.getSnPPageDocument((attendancePageUrl
|
||||||
+ "?data={tick}&idPrzedmiot={subject}")
|
+ "?data={tick}&idPrzedmiot={subject}")
|
||||||
.replace("{tick}", tick)
|
.replace("{tick}", tick)
|
||||||
|
@ -4,37 +4,52 @@ import org.jsoup.nodes.Element;
|
|||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
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.Day;
|
||||||
import io.github.wulkanowy.api.generic.Lesson;
|
import io.github.wulkanowy.api.generic.Lesson;
|
||||||
import io.github.wulkanowy.api.generic.Week;
|
import io.github.wulkanowy.api.generic.Week;
|
||||||
|
|
||||||
public class AttendanceTable {
|
public class AttendanceTable {
|
||||||
|
|
||||||
private SnP snp;
|
private final static String ATTENDANCE_PAGE_URL = "Frekwencja.mvc?data=";
|
||||||
|
|
||||||
private String attendancePageUrl = "Frekwencja.mvc?data=";
|
private SnP snp;
|
||||||
|
|
||||||
public AttendanceTable(SnP snp) {
|
public AttendanceTable(SnP snp) {
|
||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Week<Day> getWeekTable() throws IOException {
|
public Week<Day> getWeekTable() throws IOException, ParseException, VulcanException {
|
||||||
return getWeekTable("");
|
return getWeekTable("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Week<Day> getWeekTable(String tick) throws IOException {
|
public Week<Day> getWeekTable(String tick) throws IOException, ParseException, VulcanException {
|
||||||
Element table = snp.getSnPPageDocument(attendancePageUrl + tick)
|
Element table = snp.getSnPPageDocument(ATTENDANCE_PAGE_URL + tick)
|
||||||
|
|
||||||
.select(".mainContainer .presentData").first();
|
.select(".mainContainer .presentData").first();
|
||||||
|
|
||||||
Elements headerCells = table.select("thead th");
|
Elements headerCells = table.select("thead th");
|
||||||
List<Day> days = new ArrayList<>();
|
List<Day> days = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 1; i < headerCells.size(); i++) {
|
for (int i = 1; i < headerCells.size(); i++) {
|
||||||
days.add(new Day().setDate(headerCells.get(i).html().split("<br>")[1]));
|
String[] dayHeaderCell = headerCells.get(i).html().split("<br>");
|
||||||
|
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
|
||||||
|
Date d = sdf.parse(dayHeaderCell[1].trim());
|
||||||
|
sdf.applyPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
|
Day day = new Day();
|
||||||
|
day.setDayName(dayHeaderCell[0]);
|
||||||
|
day.setDate(sdf.format(d));
|
||||||
|
days.add(day);
|
||||||
}
|
}
|
||||||
|
|
||||||
Elements hoursInDays = table.select("tbody tr");
|
Elements hoursInDays = table.select("tbody tr");
|
||||||
@ -46,26 +61,29 @@ public class AttendanceTable {
|
|||||||
// fill hours in day
|
// fill hours in day
|
||||||
int size = hours.size();
|
int size = hours.size();
|
||||||
for (int i = 1; i < size; i++) {
|
for (int i = 1; i < size; i++) {
|
||||||
days.get(i - 1).setLesson(getNewLesson(hours.get(i)));
|
Lesson lesson = new Lesson();
|
||||||
}
|
lesson.setDate(days.get(i - 1).getDate());
|
||||||
}
|
lesson.setNumber(hours.get(0).text());
|
||||||
|
|
||||||
String[] dayDescription = headerCells.get(1).html().split("<br>");
|
addLessonDetails(lesson, hours.get(i));
|
||||||
|
|
||||||
|
days.get(i - 1).setLesson(lesson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new Week<Day>()
|
return new Week<Day>()
|
||||||
.setStartDayDate(dayDescription[1])
|
.setStartDayDate(days.get(0).getDate())
|
||||||
.setDays(days);
|
.setDays(days);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Lesson getNewLesson(Element cell) {
|
private void addLessonDetails(Lesson lesson, Element cell) {
|
||||||
Lesson lesson = new Lesson();
|
|
||||||
lesson.setSubject(cell.select("span").text());
|
lesson.setSubject(cell.select("span").text());
|
||||||
|
|
||||||
if (LessonTypes.CLASS_NOT_EXIST.equals(cell.attr("class"))) {
|
if (LessonTypes.CLASS_NOT_EXIST.equals(cell.attr("class"))) {
|
||||||
lesson.setNotExist(true);
|
lesson.setNotExist(true);
|
||||||
lesson.setEmpty(true);
|
lesson.setEmpty(true);
|
||||||
|
|
||||||
return lesson;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cell.select("div").attr("class")) {
|
switch (cell.select("div").attr("class")) {
|
||||||
@ -95,7 +113,5 @@ public class AttendanceTable {
|
|||||||
lesson.setEmpty(true);
|
lesson.setEmpty(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return lesson;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
import io.github.wulkanowy.api.generic.Week;
|
import io.github.wulkanowy.api.generic.Week;
|
||||||
|
|
||||||
public class ExamsWeek {
|
public class ExamsWeek {
|
||||||
@ -21,11 +22,11 @@ public class ExamsWeek {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Week<ExamDay> getCurrent() throws IOException {
|
public Week<ExamDay> getCurrent() throws IOException, VulcanException {
|
||||||
return getWeek("", true);
|
return getWeek("", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Week<ExamDay> getWeek(String tick, final boolean onlyNotEmpty) throws IOException {
|
public Week<ExamDay> getWeek(String tick, final boolean onlyNotEmpty) throws IOException, VulcanException {
|
||||||
Document examsPage = snp.getSnPPageDocument(EXAMS_PAGE_URL + tick);
|
Document examsPage = snp.getSnPPageDocument(EXAMS_PAGE_URL + tick);
|
||||||
Elements examsDays = examsPage.select(".mainContainer > div:not(.navigation)");
|
Elements examsDays = examsPage.select(".mainContainer > div:not(.navigation)");
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import io.github.wulkanowy.api.Semester;
|
import io.github.wulkanowy.api.Semester;
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class GradesList {
|
public class GradesList {
|
||||||
|
|
||||||
@ -33,11 +34,11 @@ public class GradesList {
|
|||||||
return GRADES_PAGE_URL;
|
return GRADES_PAGE_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Grade> getAll() throws IOException, ParseException {
|
public List<Grade> getAll() throws IOException, ParseException, VulcanException {
|
||||||
return getAll("");
|
return getAll("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Grade> getAll(String semester) throws IOException, ParseException {
|
public List<Grade> getAll(String semester) throws IOException, ParseException, VulcanException {
|
||||||
Document gradesPage = snp.getSnPPageDocument(getGradesPageUrl() + semester);
|
Document gradesPage = snp.getSnPPageDocument(getGradesPageUrl() + semester);
|
||||||
Elements gradesRows = gradesPage.select(".ocenySzczegoly-table > tbody > tr");
|
Elements gradesRows = gradesPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||||
Semester currentSemester = snp.getCurrentSemester(snp.getSemesters(gradesPage));
|
Semester currentSemester = snp.getCurrentSemester(snp.getSemesters(gradesPage));
|
||||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class SubjectsList {
|
public class SubjectsList {
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ public class SubjectsList {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Subject> getAll() throws IOException {
|
public List<Subject> getAll() throws IOException, VulcanException {
|
||||||
Document subjectPage = snp.getSnPPageDocument(SUBJECTS_PAGE_URL);
|
Document subjectPage = snp.getSnPPageDocument(SUBJECTS_PAGE_URL);
|
||||||
|
|
||||||
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");
|
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
package io.github.wulkanowy.api.login;
|
package io.github.wulkanowy.api.login;
|
||||||
|
|
||||||
public class AccountPermissionException extends Exception {
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
|
public class AccountPermissionException extends VulcanException {
|
||||||
|
|
||||||
|
AccountPermissionException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
package io.github.wulkanowy.api.login;
|
package io.github.wulkanowy.api.login;
|
||||||
|
|
||||||
public class BadCredentialsException extends Exception {
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
|
public class BadCredentialsException extends VulcanException {
|
||||||
|
|
||||||
|
BadCredentialsException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ package io.github.wulkanowy.api.login;
|
|||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.parser.Parser;
|
import org.jsoup.parser.Parser;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Client;
|
import io.github.wulkanowy.api.Client;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class Login {
|
public class Login {
|
||||||
|
|
||||||
@ -27,16 +29,13 @@ public class Login {
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String login(String email, String password, String symbol)
|
public String login(String email, String password, String symbol) throws VulcanException, IOException {
|
||||||
throws BadCredentialsException, LoginErrorException,
|
|
||||||
AccountPermissionException, IOException, VulcanOfflineException {
|
|
||||||
String certificate = sendCredentials(email, password, symbol);
|
String certificate = sendCredentials(email, password, symbol);
|
||||||
|
|
||||||
return sendCertificate(certificate, symbol);
|
return sendCertificate(certificate, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sendCredentials(String email, String password, String symbol)
|
String sendCredentials(String email, String password, String symbol) throws IOException, VulcanException {
|
||||||
throws IOException, BadCredentialsException {
|
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
|
|
||||||
Document html = client.postPageByUrl(LOGIN_PAGE_URL, new String[][]{
|
Document html = client.postPageByUrl(LOGIN_PAGE_URL, new String[][]{
|
||||||
@ -44,33 +43,29 @@ public class Login {
|
|||||||
{"Password", password}
|
{"Password", password}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (null != html.select(".ErrorMessage").first()) {
|
Element errorMessage = html.select(".ErrorMessage").first();
|
||||||
throw new BadCredentialsException();
|
if (null != errorMessage) {
|
||||||
|
throw new BadCredentialsException(errorMessage.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
return html.select("input[name=wresult]").attr("value");
|
return html.select("input[name=wresult]").attr("value");
|
||||||
}
|
}
|
||||||
|
|
||||||
String sendCertificate(String certificate, String defaultSymbol)
|
String sendCertificate(String certificate, String defaultSymbol) throws IOException, VulcanException {
|
||||||
throws IOException, LoginErrorException, AccountPermissionException, VulcanOfflineException {
|
|
||||||
this.symbol = findSymbol(defaultSymbol, certificate);
|
this.symbol = findSymbol(defaultSymbol, certificate);
|
||||||
client.setSymbol(this.symbol);
|
client.setSymbol(this.symbol);
|
||||||
|
|
||||||
Document html = client.postPageByUrl(LOGIN_ENDPOINT_PAGE_URL, new String[][]{
|
String title = client.postPageByUrl(LOGIN_ENDPOINT_PAGE_URL, new String[][]{
|
||||||
{"wa", "wsignin1.0"},
|
{"wa", "wsignin1.0"},
|
||||||
{"wresult", certificate}
|
{"wresult", certificate}
|
||||||
});
|
}).select("title").text();
|
||||||
|
|
||||||
if (html.getElementsByTag("title").text().equals("Logowanie")) {
|
if ("Logowanie".equals(title)) {
|
||||||
throw new AccountPermissionException();
|
throw new AccountPermissionException("No account access. Try another symbol");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (html.getElementsByTag("title").text().equals("Przerwa techniczna")) {
|
if (!"Uonet+".equals(title)) {
|
||||||
throw new VulcanOfflineException();
|
throw new LoginErrorException("Could not log in, unknown error");
|
||||||
}
|
|
||||||
|
|
||||||
if (!html.select("title").text().equals("Uonet+")) {
|
|
||||||
throw new LoginErrorException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.symbol;
|
return this.symbol;
|
||||||
@ -85,7 +80,8 @@ public class Login {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String findSymbolInCertificate(String certificate) {
|
String findSymbolInCertificate(String certificate) {
|
||||||
Elements els = Jsoup.parse(certificate.replaceAll(":", ""), "", Parser.xmlParser())
|
Elements els = Jsoup
|
||||||
|
.parse(certificate.replaceAll(":", ""), "", Parser.xmlParser())
|
||||||
.select("[AttributeName=\"UserInstance\"] samlAttributeValue");
|
.select("[AttributeName=\"UserInstance\"] samlAttributeValue");
|
||||||
|
|
||||||
if (els.isEmpty()) {
|
if (els.isEmpty()) {
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
package io.github.wulkanowy.api.login;
|
package io.github.wulkanowy.api.login;
|
||||||
|
|
||||||
public class LoginErrorException extends NotLoggedInErrorException {
|
import io.github.wulkanowy.api.NotLoggedInErrorException;
|
||||||
|
|
||||||
|
class LoginErrorException extends NotLoggedInErrorException {
|
||||||
|
|
||||||
|
LoginErrorException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
package io.github.wulkanowy.api.login;
|
|
||||||
|
|
||||||
public class NotLoggedInErrorException extends Exception {
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
package io.github.wulkanowy.api.login;
|
|
||||||
|
|
||||||
public class VulcanOfflineException extends Exception {
|
|
||||||
}
|
|
@ -1,4 +1,10 @@
|
|||||||
package io.github.wulkanowy.api.messages;
|
package io.github.wulkanowy.api.messages;
|
||||||
|
|
||||||
class BadRequestException extends Exception {
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
|
class BadRequestException extends VulcanException {
|
||||||
|
|
||||||
|
BadRequestException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ import java.io.IOException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Client;
|
import io.github.wulkanowy.api.Client;
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.NotLoggedInErrorException;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class Messages {
|
public class Messages {
|
||||||
|
|
||||||
@ -37,19 +38,19 @@ public class Messages {
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Message> getReceived() throws IOException, NotLoggedInErrorException, BadRequestException {
|
public List<Message> getReceived() throws IOException, VulcanException {
|
||||||
return getMessages(RECEIVED_URL);
|
return getMessages(RECEIVED_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Message> getSent() throws IOException, NotLoggedInErrorException, BadRequestException {
|
public List<Message> getSent() throws IOException, VulcanException {
|
||||||
return getMessages(SENT_URL);
|
return getMessages(SENT_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Message> getDeleted() throws IOException, NotLoggedInErrorException, BadRequestException {
|
public List<Message> getDeleted() throws IOException, VulcanException {
|
||||||
return getMessages(DELETED_URL);
|
return getMessages(DELETED_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Message> getMessages(String url) throws IOException, NotLoggedInErrorException, BadRequestException {
|
private List<Message> getMessages(String url) throws IOException, VulcanException {
|
||||||
String res = client.getJsonStringByUrl(url);
|
String res = client.getJsonStringByUrl(url);
|
||||||
|
|
||||||
List<Message> messages;
|
List<Message> messages;
|
||||||
@ -58,16 +59,16 @@ public class Messages {
|
|||||||
messages = new Gson().fromJson(res, MessagesContainer.class).data;
|
messages = new Gson().fromJson(res, MessagesContainer.class).data;
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
if (res.contains(ERROR_TITLE)) {
|
if (res.contains(ERROR_TITLE)) {
|
||||||
throw new BadRequestException();
|
throw new BadRequestException(ERROR_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotLoggedInErrorException();
|
throw new NotLoggedInErrorException("You are probably not logged in");
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message getMessage(int id, int folder) throws IOException, BadRequestException, NotLoggedInErrorException {
|
public Message getMessage(int id, int folder) throws IOException, VulcanException {
|
||||||
String res = client.postJsonStringByUrl(MESSAGE_URL, new String[][]{
|
String res = client.postJsonStringByUrl(MESSAGE_URL, new String[][]{
|
||||||
{"idWiadomosc", String.valueOf(id)},
|
{"idWiadomosc", String.valueOf(id)},
|
||||||
{"Folder", String.valueOf(folder)}
|
{"Folder", String.valueOf(folder)}
|
||||||
@ -79,10 +80,10 @@ public class Messages {
|
|||||||
message = new Gson().fromJson(res, MessageContainer.class).data;
|
message = new Gson().fromJson(res, MessageContainer.class).data;
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
if (res.contains(ERROR_TITLE)) {
|
if (res.contains(ERROR_TITLE)) {
|
||||||
throw new BadRequestException();
|
throw new BadRequestException(ERROR_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotLoggedInErrorException();
|
throw new NotLoggedInErrorException("You are probably not logged in. Force login");
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class AchievementsList {
|
public class AchievementsList {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class AchievementsList {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAllAchievements() throws IOException {
|
public List<String> getAllAchievements() throws IOException, VulcanException {
|
||||||
Element pageFragment = snp.getSnPPageDocument(NOTES_PAGE_URL)
|
Element pageFragment = snp.getSnPPageDocument(NOTES_PAGE_URL)
|
||||||
.select(".mainContainer > div").get(1);
|
.select(".mainContainer > div").get(1);
|
||||||
Elements items = pageFragment.select("article");
|
Elements items = pageFragment.select("article");
|
||||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class NotesList {
|
public class NotesList {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class NotesList {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Note> getAllNotes() throws IOException {
|
public List<Note> getAllNotes() throws IOException, VulcanException {
|
||||||
Element pageFragment = snp.getSnPPageDocument(NOTES_PAGE_URL)
|
Element pageFragment = snp.getSnPPageDocument(NOTES_PAGE_URL)
|
||||||
.select(".mainContainer > div").get(0);
|
.select(".mainContainer > div").get(0);
|
||||||
Elements items = pageFragment.select("article");
|
Elements items = pageFragment.select("article");
|
||||||
|
@ -5,6 +5,7 @@ import org.jsoup.nodes.Element;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class SchoolInfo {
|
public class SchoolInfo {
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ public class SchoolInfo {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SchoolData getSchoolData() throws IOException {
|
public SchoolData getSchoolData() throws IOException, VulcanException {
|
||||||
Element e = snp.getSnPPageDocument(SCHOOL_PAGE_URL)
|
Element e = snp.getSnPPageDocument(SCHOOL_PAGE_URL)
|
||||||
.select(".mainContainer > article").get(0);
|
.select(".mainContainer > article").get(0);
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class TeachersInfo {
|
public class TeachersInfo {
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ public class TeachersInfo {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TeachersData getTeachersData() throws IOException {
|
public TeachersData getTeachersData() throws IOException, VulcanException {
|
||||||
Document doc = snp.getSnPPageDocument(SCHOOL_PAGE_URL);
|
Document doc = snp.getSnPPageDocument(SCHOOL_PAGE_URL);
|
||||||
Elements rows = doc.select(".mainContainer > table tbody tr");
|
Elements rows = doc.select(".mainContainer > table tbody tr");
|
||||||
String description = doc.select(".mainContainer > p").first().text();
|
String description = doc.select(".mainContainer > p").first().text();
|
||||||
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
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.Day;
|
||||||
import io.github.wulkanowy.api.generic.Lesson;
|
import io.github.wulkanowy.api.generic.Lesson;
|
||||||
import io.github.wulkanowy.api.generic.Week;
|
import io.github.wulkanowy.api.generic.Week;
|
||||||
@ -27,11 +28,11 @@ public class Timetable {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Week<Day> getWeekTable() throws IOException, ParseException {
|
public Week<Day> getWeekTable() throws IOException, ParseException, VulcanException {
|
||||||
return getWeekTable("");
|
return getWeekTable("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Week<Day> getWeekTable(final String tick) throws IOException, ParseException {
|
public Week<Day> getWeekTable(final String tick) throws IOException, ParseException, VulcanException {
|
||||||
Element table = snp.getSnPPageDocument(TIMETABLE_PAGE_URL + tick)
|
Element table = snp.getSnPPageDocument(TIMETABLE_PAGE_URL + tick)
|
||||||
.select(".mainContainer .presentData").first();
|
.select(".mainContainer .presentData").first();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import org.jsoup.nodes.Element;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class BasicInformation {
|
public class BasicInformation {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class BasicInformation {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Document getStudentDataPageDocument() throws IOException {
|
public Document getStudentDataPageDocument() throws IOException, VulcanException {
|
||||||
if (null == studentDataPageDocument) {
|
if (null == studentDataPageDocument) {
|
||||||
studentDataPageDocument = snp.getSnPPageDocument(STUDENT_DATA_PAGE_URL);
|
studentDataPageDocument = snp.getSnPPageDocument(STUDENT_DATA_PAGE_URL);
|
||||||
}
|
}
|
||||||
@ -29,7 +30,7 @@ public class BasicInformation {
|
|||||||
return studentDataPageDocument;
|
return studentDataPageDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PersonalData getPersonalData() throws IOException {
|
public PersonalData getPersonalData() throws IOException, VulcanException {
|
||||||
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(0);
|
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(0);
|
||||||
|
|
||||||
String name = snp.getRowDataChildValue(e, 1);
|
String name = snp.getRowDataChildValue(e, 1);
|
||||||
@ -48,7 +49,7 @@ public class BasicInformation {
|
|||||||
.setParentsNames(snp.getRowDataChildValue(e, 7));
|
.setParentsNames(snp.getRowDataChildValue(e, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddressData getAddressData() throws IOException {
|
public AddressData getAddressData() throws IOException, VulcanException {
|
||||||
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(1);
|
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(1);
|
||||||
|
|
||||||
return new AddressData()
|
return new AddressData()
|
||||||
@ -58,7 +59,7 @@ public class BasicInformation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContactDetails getContactDetails() throws IOException {
|
public ContactDetails getContactDetails() throws IOException, VulcanException {
|
||||||
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(2);
|
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(2);
|
||||||
|
|
||||||
return new ContactDetails()
|
return new ContactDetails()
|
||||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.SnP;
|
import io.github.wulkanowy.api.SnP;
|
||||||
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class FamilyInformation {
|
public class FamilyInformation {
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ public class FamilyInformation {
|
|||||||
this.snp = snp;
|
this.snp = snp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FamilyMember> getFamilyMembers() throws IOException {
|
public List<FamilyMember> getFamilyMembers() throws IOException, VulcanException {
|
||||||
Elements membersElements = snp.getSnPPageDocument(STUDENT_DATA_PAGE_URL)
|
Elements membersElements = snp.getSnPPageDocument(STUDENT_DATA_PAGE_URL)
|
||||||
.select(".mainContainer > article:nth-of-type(n+4)");
|
.select(".mainContainer > article:nth-of-type(n+4)");
|
||||||
|
|
||||||
|
80
api/src/test/java/io/github/wulkanowy/api/ClientTest.java
Normal file
80
api/src/test/java/io/github/wulkanowy/api/ClientTest.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package io.github.wulkanowy.api;
|
||||||
|
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.api.login.Login;
|
||||||
|
|
||||||
|
public class ClientTest {
|
||||||
|
|
||||||
|
private String getFixtureAsString(String fixtureFileName) {
|
||||||
|
return FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setFullEndpointInfoTest() throws Exception {
|
||||||
|
Client client = new Client("http://fakelog.net\\\\admin", "pass", "Default");
|
||||||
|
|
||||||
|
Assert.assertEquals("fakelog.net", client.getHost());
|
||||||
|
Assert.assertEquals("Default", client.getSymbol());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkForNoErrorsTest() throws Exception {
|
||||||
|
Client client = new Client("", "", "");
|
||||||
|
|
||||||
|
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-success.html"));
|
||||||
|
|
||||||
|
Assert.assertEquals(doc, client.checkForErrors(doc));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = VulcanOfflineException.class)
|
||||||
|
public void checkForErrorsOffline() throws Exception {
|
||||||
|
Client client = new Client("", "", "");
|
||||||
|
|
||||||
|
Document doc = Jsoup.parse(getFixtureAsString("login/PrzerwaTechniczna.html"));
|
||||||
|
|
||||||
|
client.checkForErrors(doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = NotLoggedInErrorException.class)
|
||||||
|
public void checkForErrors() throws Exception {
|
||||||
|
Client client = new Client("", "", "");
|
||||||
|
|
||||||
|
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-notLoggedIn.html"));
|
||||||
|
|
||||||
|
client.checkForErrors(doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getClientTest() throws Exception {
|
||||||
|
Client client = new Client("", "", "");
|
||||||
|
|
||||||
|
Assert.assertThat(client.getLogin(), CoreMatchers.instanceOf(Login.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getClientTwiceTest() throws Exception {
|
||||||
|
Client client = new Client("", "", "");
|
||||||
|
|
||||||
|
Assert.assertEquals(client.getLogin(), client.getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getFilledUrlTest() throws Exception {
|
||||||
|
Client client = new Client("http://fakelog.cf\\\\admin", "", "symbol123");
|
||||||
|
|
||||||
|
Assert.assertEquals("http://uonetplus.fakelog.cf/symbol123/LoginEndpoint.aspx",
|
||||||
|
client.getFilledUrl("{schema}://uonetplus.{host}/{symbol}/LoginEndpoint.aspx"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSymbolTest() throws Exception {
|
||||||
|
Client client = new Client("", "", "symbol4321");
|
||||||
|
|
||||||
|
Assert.assertEquals("symbol4321", client.getSymbol());
|
||||||
|
}
|
||||||
|
}
|
@ -10,8 +10,6 @@ import org.mockito.Mockito;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
|
|
||||||
public class StudentAndParentTest {
|
public class StudentAndParentTest {
|
||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
@ -45,7 +43,7 @@ public class StudentAndParentTest {
|
|||||||
|
|
||||||
Mockito.when(client.getHost()).thenReturn("vulcan.net.pl");
|
Mockito.when(client.getHost()).thenReturn("vulcan.net.pl");
|
||||||
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(startPageDocument);
|
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(startPageDocument);
|
||||||
StudentAndParent snp = new StudentAndParent(client);
|
StudentAndParent snp = new StudentAndParent(client, null);
|
||||||
|
|
||||||
Assert.assertEquals("https://uonetplus-opiekun.vulcan.net.pl/symbol/534213/Start/Index/",
|
Assert.assertEquals("https://uonetplus-opiekun.vulcan.net.pl/symbol/534213/Start/Index/",
|
||||||
snp.getSnpHomePageUrl());
|
snp.getSnpHomePageUrl());
|
||||||
@ -58,7 +56,7 @@ public class StudentAndParentTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(wrongPageDocument);
|
Mockito.when(client.getPageByUrl(Mockito.anyString())).thenReturn(wrongPageDocument);
|
||||||
StudentAndParent snp = new StudentAndParent(client);
|
StudentAndParent snp = new StudentAndParent(client, null);
|
||||||
|
|
||||||
snp.getSnpHomePageUrl();
|
snp.getSnpHomePageUrl();
|
||||||
}
|
}
|
||||||
|
@ -1,86 +1,31 @@
|
|||||||
package io.github.wulkanowy.api;
|
package io.github.wulkanowy.api;
|
||||||
|
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.Login;
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
|
|
||||||
public class VulcanTest {
|
public class VulcanTest {
|
||||||
|
|
||||||
private Vulcan vulcan;
|
@Test(expected = NotLoggedInErrorException.class)
|
||||||
|
public void getClientWithoutLoginTest() throws Exception {
|
||||||
|
Vulcan vulcan = new Vulcan();
|
||||||
|
|
||||||
@Before
|
vulcan.getClient();
|
||||||
public void setUp() throws Exception {
|
|
||||||
vulcan = new Vulcan();
|
|
||||||
vulcan.setClient(Mockito.mock(Client.class));
|
|
||||||
vulcan.setLogin(Mockito.mock(Login.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setFullEndpointInfoTest() throws Exception {
|
public void getClientTest() throws Exception {
|
||||||
vulcan.login("http://fakelog.net\\\\admin", "pass", "Default", "123");
|
Vulcan vulcan = new Vulcan();
|
||||||
|
vulcan.setCredentials("email", "password", "symbol", null);
|
||||||
|
|
||||||
Assert.assertEquals("http", vulcan.getProtocolSchema());
|
Assert.assertThat(vulcan.getClient(), CoreMatchers.instanceOf(Client.class));
|
||||||
Assert.assertEquals("fakelog.net", vulcan.getLogHost());
|
|
||||||
Assert.assertEquals("admin", vulcan.getEmail());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getClientTwiceTest() throws Exception {
|
public void getClientTwiceTest() throws Exception {
|
||||||
Vulcan vulcan = new Vulcan();
|
Vulcan vulcan = new Vulcan();
|
||||||
Assert.assertTrue(vulcan.getClient().equals(vulcan.getClient()));
|
vulcan.setCredentials("email", "password", "symbol", null);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
Assert.assertEquals(vulcan.getClient(), vulcan.getClient());
|
||||||
public void getLoginTwiceTest() throws Exception {
|
|
||||||
Vulcan vulcan = new Vulcan();
|
|
||||||
Assert.assertTrue(vulcan.getLogin().equals(vulcan.getLogin()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = NotLoggedInErrorException.class)
|
|
||||||
public void getStudentAndParentNotLoggedInTest() throws Exception {
|
|
||||||
vulcan.getStudentAndParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getStudentAndParentTwiceTest() throws Exception {
|
|
||||||
Client client = Mockito.mock(Client.class);
|
|
||||||
Map<String, String> cookies = new HashMap<>();
|
|
||||||
cookies.put("test", "test");
|
|
||||||
Mockito.when(client.getCookies()).thenReturn(cookies);
|
|
||||||
|
|
||||||
SnP snp = Mockito.mock(StudentAndParent.class);
|
|
||||||
Mockito.doNothing().when(snp).storeContextCookies();
|
|
||||||
|
|
||||||
Vulcan vulcan = Mockito.mock(Vulcan.class);
|
|
||||||
Mockito.when(vulcan.getClient()).thenReturn(client);
|
|
||||||
Mockito.when(vulcan.getStudentAndParent()).thenCallRealMethod();
|
|
||||||
Mockito.when(vulcan.createSnp(Mockito.any(Client.class), Mockito.any())).thenReturn(snp);
|
|
||||||
|
|
||||||
vulcan.getStudentAndParent();
|
|
||||||
vulcan.getStudentAndParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createSnPTest() throws Exception {
|
|
||||||
vulcan.login("wulkanowy@wulkanowy.io", "wulkanowy123", "wulkan");
|
|
||||||
|
|
||||||
SnP snp1 = vulcan.createSnp(Mockito.mock(Client.class), null);
|
|
||||||
Assert.assertEquals(null, snp1.getId());
|
|
||||||
|
|
||||||
SnP snp2 = vulcan.createSnp(Mockito.mock(Client.class), "wulkan");
|
|
||||||
Assert.assertEquals("wulkan", snp2.getId());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = NotLoggedInErrorException.class)
|
|
||||||
public void getAttendanceExceptionText() throws Exception {
|
|
||||||
vulcan.getAttendanceTable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ public class AttendanceTableTest extends StudentAndParentTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getWeekStartByDate() throws Exception {
|
public void getWeekStartByDate() throws Exception {
|
||||||
Assert.assertEquals("31.08.2015", excellent.getWeekTable().getStartDayDate());
|
Assert.assertEquals("2015-08-31", excellent.getWeekTable().getStartDayDate());
|
||||||
Assert.assertEquals("05.09.2016", full.getWeekTable().getStartDayDate());
|
Assert.assertEquals("2016-09-05", full.getWeekTable().getStartDayDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -38,13 +38,13 @@ public class AttendanceTableTest extends StudentAndParentTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDayDate() throws Exception {
|
public void getDayDate() throws Exception {
|
||||||
Assert.assertEquals("31.08.2015", excellent.getWeekTable().getDay(0).getDate());
|
Assert.assertEquals("2015-08-31", excellent.getWeekTable().getDay(0).getDate());
|
||||||
Assert.assertEquals("02.09.2015", excellent.getWeekTable().getDay(2).getDate());
|
Assert.assertEquals("2015-09-02", excellent.getWeekTable().getDay(2).getDate());
|
||||||
Assert.assertEquals("04.09.2015", excellent.getWeekTable().getDay(4).getDate());
|
Assert.assertEquals("2015-09-04", excellent.getWeekTable().getDay(4).getDate());
|
||||||
|
|
||||||
Assert.assertEquals("05.09.2016", full.getWeekTable().getDay(0).getDate());
|
Assert.assertEquals("2016-09-05", full.getWeekTable().getDay(0).getDate());
|
||||||
Assert.assertEquals("07.09.2016", full.getWeekTable().getDay(2).getDate());
|
Assert.assertEquals("2016-09-07", full.getWeekTable().getDay(2).getDate());
|
||||||
Assert.assertEquals("09.09.2016", full.getWeekTable().getDay(4).getDate());
|
Assert.assertEquals("2016-09-09", full.getWeekTable().getDay(4).getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package io.github.wulkanowy.api.login;
|
package io.github.wulkanowy.api.login;
|
||||||
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@ -79,13 +78,6 @@ public class LoginTest {
|
|||||||
login.sendCertificate(getFixtureAsString("cert.xml"), "demo123");
|
login.sendCertificate(getFixtureAsString("cert.xml"), "demo123");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = VulcanOfflineException.class)
|
|
||||||
public void sendCertificateVulcanOfflineTest() throws Exception {
|
|
||||||
Login login = new Login(getClient("PrzerwaTechniczna.html"));
|
|
||||||
|
|
||||||
login.sendCertificate(getFixtureAsString("cert.xml"), "demo123");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findSymbolInCertificateTest() throws Exception {
|
public void findSymbolInCertificateTest() throws Exception {
|
||||||
Login login = new Login(getClient("Logowanie-certyfikat.html"));
|
Login login = new Login(getClient("Logowanie-certyfikat.html"));
|
||||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import io.github.wulkanowy.api.Client;
|
import io.github.wulkanowy.api.Client;
|
||||||
import io.github.wulkanowy.api.FixtureHelper;
|
import io.github.wulkanowy.api.FixtureHelper;
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.NotLoggedInErrorException;
|
||||||
|
|
||||||
public class MessagesTest {
|
public class MessagesTest {
|
||||||
|
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<title>Dziennik UONET+</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="MainPage_InfoPage">
|
||||||
|
<div class="startScreen">
|
||||||
|
<div class="topBar">
|
||||||
|
<div class="loginBox">
|
||||||
|
<div>
|
||||||
|
<a href="/LoginEndpoint.aspx" class="loginButton"></a>
|
||||||
|
<a href="/LoginEndpoint.aspx" class="loginButton">Zaloguj się</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="bottomBar"><span>Uonet+ wersja 17.09.0007.26300</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -21,15 +21,15 @@ apply from: '../jacoco.gradle'
|
|||||||
apply from: '../android-sonarqube.gradle'
|
apply from: '../android-sonarqube.gradle'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 27
|
compileSdkVersion 26
|
||||||
buildToolsVersion "27.0.3"
|
buildToolsVersion '27.0.3'
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "io.github.wulkanowy"
|
applicationId "io.github.wulkanowy"
|
||||||
testApplicationId "io.github.tests.wulkanowy"
|
testApplicationId "io.github.tests.wulkanowy"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 27
|
targetSdkVersion 26
|
||||||
versionCode 1
|
versionCode 6
|
||||||
versionName "0.1.0"
|
versionName "0.3.0"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
manifestPlaceholders = [
|
manifestPlaceholders = [
|
||||||
@ -43,6 +43,8 @@ android {
|
|||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
debug {
|
debug {
|
||||||
|
applicationIdSuffix ".dev"
|
||||||
|
versionNameSuffix "-dev"
|
||||||
testCoverageEnabled = true
|
testCoverageEnabled = true
|
||||||
ext.enableCrashlytics = false
|
ext.enableCrashlytics = false
|
||||||
}
|
}
|
||||||
@ -60,47 +62,46 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
greendao {
|
greendao {
|
||||||
schemaVersion 20
|
schemaVersion 22
|
||||||
generateTests = true
|
generateTests = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':api')
|
implementation project(':api')
|
||||||
implementation 'com.android.support:appcompat-v7:27.1.0'
|
implementation "com.android.support:support-v4:$supportVersion"
|
||||||
implementation 'com.android.support:design:27.1.0'
|
implementation "com.android.support:design:$supportVersion"
|
||||||
implementation 'com.android.support:support-v4:27.1.0'
|
implementation "com.android.support:cardview-v7:$supportVersion"
|
||||||
implementation 'com.android.support:recyclerview-v7:27.1.0'
|
implementation "com.android.support:customtabs:$supportVersion"
|
||||||
implementation 'com.android.support:cardview-v7:27.1.0'
|
implementation "com.android.support:preference-v14:$supportVersion"
|
||||||
implementation 'com.android.support:customtabs:27.1.0'
|
implementation "com.firebase:firebase-jobdispatcher:$firebaseJob"
|
||||||
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
|
implementation "org.apache.commons:commons-lang3:$apacheLang"
|
||||||
implementation 'org.apache.commons:commons-lang3:3.7'
|
implementation "org.apache.commons:commons-collections4:$apacheCollections"
|
||||||
implementation 'eu.davidea:flexible-adapter:5.0.0-rc4'
|
implementation "eu.davidea:flexible-adapter:$flexibleAdapter"
|
||||||
implementation 'eu.davidea:flexible-adapter-ui:1.0.0-b1'
|
implementation "eu.davidea:flexible-adapter-ui:$flexibleUi"
|
||||||
implementation 'org.apache.commons:commons-collections4:4.1'
|
implementation "org.greenrobot:greendao:$greenDao"
|
||||||
implementation 'org.greenrobot:greendao:3.2.2'
|
implementation "com.github.yuweiguocn:GreenDaoUpgradeHelper:$greenDaoHelper"
|
||||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
implementation "com.jakewharton:butterknife:$butterknife"
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation "com.google.dagger:dagger-android-support:$dagger2"
|
||||||
implementation 'com.google.dagger:dagger-android:2.14.1'
|
implementation "com.aurelhubert:ahbottomnavigation:$ahbottom"
|
||||||
implementation 'com.google.dagger:dagger-android-support:2.14.1'
|
implementation "com.jakewharton.threetenabp:threetenabp:$threeTenABP"
|
||||||
implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
|
|
||||||
|
|
||||||
implementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
|
implementation("com.crashlytics.sdk.android:crashlytics:$crashlyticsSdk@aar") {
|
||||||
transitive = true
|
transitive = true
|
||||||
}
|
}
|
||||||
implementation('com.crashlytics.sdk.android:answers:1.4.1@aar') {
|
implementation("com.crashlytics.sdk.android:answers:$crashlyticsAnswers@aar") {
|
||||||
transitive = true
|
transitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-android-processor:2.14.1'
|
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger2"
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1'
|
annotationProcessor "com.google.dagger:dagger-compiler:$dagger2"
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife"
|
||||||
|
|
||||||
debugImplementation 'com.amitshekhar.android:debug-db:1.0.1'
|
debugImplementation "com.amitshekhar.android:debug-db:$debugDb"
|
||||||
debugImplementation 'net.zetetic:android-database-sqlcipher:3.5.9'
|
debugImplementation "net.zetetic:android-database-sqlcipher:$sqlcipher"
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation "junit:junit:$junit"
|
||||||
testImplementation 'org.mockito:mockito-core:2.13.0'
|
testImplementation "org.mockito:mockito-core:$mockito"
|
||||||
|
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.1'
|
androidTestImplementation "com.android.support.test:runner:$testRunner"
|
||||||
androidTestImplementation 'org.mockito:mockito-android:2.13.0'
|
androidTestImplementation "org.mockito:mockito-android:$mockito"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package io.github.wulkanowy.data.db.dao.entities;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLessonDao;
|
||||||
|
|
||||||
|
public class AttendanceLessonTest extends AbstractDaoTestLongPk<AttendanceLessonDao, AttendanceLesson> {
|
||||||
|
|
||||||
|
public AttendanceLessonTest() {
|
||||||
|
super(AttendanceLessonDao.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,15 +2,18 @@ package io.github.wulkanowy.data.db.dao.entities;
|
|||||||
|
|
||||||
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
import org.greenrobot.greendao.test.AbstractDaoTestLongPk;
|
||||||
|
|
||||||
public class LessonTest extends AbstractDaoTestLongPk<LessonDao, Lesson> {
|
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.TimetableLessonDao;
|
||||||
|
|
||||||
public LessonTest() {
|
public class TimetableLessonTest extends AbstractDaoTestLongPk<TimetableLessonDao, TimetableLesson> {
|
||||||
super(LessonDao.class);
|
|
||||||
|
public TimetableLessonTest() {
|
||||||
|
super(TimetableLessonDao.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Lesson createEntity(Long key) {
|
protected TimetableLesson createEntity(Long key) {
|
||||||
Lesson entity = new Lesson();
|
TimetableLesson entity = new TimetableLesson();
|
||||||
entity.setId(key);
|
entity.setId(key);
|
||||||
entity.setIsEmpty(false);
|
entity.setIsEmpty(false);
|
||||||
entity.setIsDivisionIntoGroups(false);
|
entity.setIsDivisionIntoGroups(false);
|
3
app/src/debug/res/values-pl/strings.xml
Normal file
3
app/src/debug/res/values-pl/strings.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">Wulkanowy DEV</string>
|
||||||
|
</resources>
|
3
app/src/debug/res/values/strings.xml
Normal file
3
app/src/debug/res/values/strings.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">Wulkanowy DEV</string>
|
||||||
|
</resources>
|
@ -4,6 +4,7 @@ import android.app.Application;
|
|||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.core.CrashlyticsCore;
|
import com.crashlytics.android.core.CrashlyticsCore;
|
||||||
|
import com.jakewharton.threetenabp.AndroidThreeTen;
|
||||||
|
|
||||||
import org.greenrobot.greendao.query.QueryBuilder;
|
import org.greenrobot.greendao.query.QueryBuilder;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import io.github.wulkanowy.data.RepositoryContract;
|
|||||||
import io.github.wulkanowy.di.component.ApplicationComponent;
|
import io.github.wulkanowy.di.component.ApplicationComponent;
|
||||||
import io.github.wulkanowy.di.component.DaggerApplicationComponent;
|
import io.github.wulkanowy.di.component.DaggerApplicationComponent;
|
||||||
import io.github.wulkanowy.di.modules.ApplicationModule;
|
import io.github.wulkanowy.di.modules.ApplicationModule;
|
||||||
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
|
|
||||||
public class WulkanowyApp extends Application {
|
public class WulkanowyApp extends Application {
|
||||||
|
|
||||||
@ -27,6 +29,8 @@ public class WulkanowyApp extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
AndroidThreeTen.init(this);
|
||||||
|
|
||||||
applicationComponent = DaggerApplicationComponent
|
applicationComponent = DaggerApplicationComponent
|
||||||
.builder()
|
.builder()
|
||||||
.applicationModule(new ApplicationModule(this))
|
.applicationModule(new ApplicationModule(this))
|
||||||
@ -37,6 +41,17 @@ public class WulkanowyApp extends Application {
|
|||||||
enableDebugLog();
|
enableDebugLog();
|
||||||
}
|
}
|
||||||
initializeFabric();
|
initializeFabric();
|
||||||
|
initializeUserSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeUserSession() {
|
||||||
|
if (repository.getCurrentUserId() != 0) {
|
||||||
|
try {
|
||||||
|
repository.initLastUser();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.error("An error occurred when the application was started", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableDebugLog() {
|
private void enableDebugLog() {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package io.github.wulkanowy.data;
|
package io.github.wulkanowy.data;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -8,11 +7,9 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Account;
|
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.DaoSession;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
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.GradeDao;
|
||||||
@ -21,7 +18,8 @@ import io.github.wulkanowy.data.db.dao.entities.WeekDao;
|
|||||||
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
import io.github.wulkanowy.data.sync.SyncContract;
|
import io.github.wulkanowy.data.sync.SyncContract;
|
||||||
import io.github.wulkanowy.data.sync.login.LoginSyncContract;
|
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.sync.timetable.TimetableSyncContract;
|
||||||
import io.github.wulkanowy.di.annotations.SyncGrades;
|
import io.github.wulkanowy.di.annotations.SyncGrades;
|
||||||
import io.github.wulkanowy.di.annotations.SyncSubjects;
|
import io.github.wulkanowy.di.annotations.SyncSubjects;
|
||||||
@ -36,7 +34,9 @@ public class Repository implements RepositoryContract {
|
|||||||
|
|
||||||
private final DaoSession daoSession;
|
private final DaoSession daoSession;
|
||||||
|
|
||||||
private final LoginSyncContract loginSync;
|
private final AccountSyncContract accountSync;
|
||||||
|
|
||||||
|
private final AttendanceSyncContract attendanceSync;
|
||||||
|
|
||||||
private final TimetableSyncContract timetableSync;
|
private final TimetableSyncContract timetableSync;
|
||||||
|
|
||||||
@ -48,14 +48,16 @@ public class Repository implements RepositoryContract {
|
|||||||
Repository(SharedPrefContract sharedPref,
|
Repository(SharedPrefContract sharedPref,
|
||||||
ResourcesContract resources,
|
ResourcesContract resources,
|
||||||
DaoSession daoSession,
|
DaoSession daoSession,
|
||||||
LoginSyncContract loginSync,
|
AccountSyncContract accountSync,
|
||||||
|
AttendanceSyncContract attendanceSync,
|
||||||
TimetableSyncContract timetableSync,
|
TimetableSyncContract timetableSync,
|
||||||
@SyncGrades SyncContract gradeSync,
|
@SyncGrades SyncContract gradeSync,
|
||||||
@SyncSubjects SyncContract subjectSync) {
|
@SyncSubjects SyncContract subjectSync) {
|
||||||
this.sharedPref = sharedPref;
|
this.sharedPref = sharedPref;
|
||||||
this.resources = resources;
|
this.resources = resources;
|
||||||
this.daoSession = daoSession;
|
this.daoSession = daoSession;
|
||||||
this.loginSync = loginSync;
|
this.accountSync = accountSync;
|
||||||
|
this.attendanceSync = attendanceSync;
|
||||||
this.timetableSync = timetableSync;
|
this.timetableSync = timetableSync;
|
||||||
this.gradeSync = gradeSync;
|
this.gradeSync = gradeSync;
|
||||||
this.subjectSync = subjectSync;
|
this.subjectSync = subjectSync;
|
||||||
@ -66,6 +68,31 @@ public class Repository implements RepositoryContract {
|
|||||||
return sharedPref.getCurrentUserId();
|
return sharedPref.getCurrentUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStartupTab() {
|
||||||
|
return sharedPref.getStartupTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getServicesInterval() {
|
||||||
|
return sharedPref.getServicesInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServicesEnable() {
|
||||||
|
return sharedPref.isServicesEnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNotifyEnable() {
|
||||||
|
return sharedPref.isNotifyEnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMobileDisable() {
|
||||||
|
return sharedPref.isMobileDisable();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSymbolsKeysArray() {
|
public String[] getSymbolsKeysArray() {
|
||||||
return resources.getSymbolsKeysArray();
|
return resources.getSymbolsKeysArray();
|
||||||
@ -82,42 +109,56 @@ public class Repository implements RepositoryContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loginUser(String email, String password, String symbol)
|
public String getAttendanceLessonDescription(AttendanceLesson lesson) {
|
||||||
throws NotLoggedInErrorException, AccountPermissionException, IOException,
|
return resources.getAttendanceLessonDescription(lesson);
|
||||||
CryptoException, VulcanOfflineException, BadCredentialsException {
|
|
||||||
loginSync.loginUser(email, password, symbol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loginCurrentUser() throws NotLoggedInErrorException, AccountPermissionException,
|
public void registerUser(String email, String password, String symbol) throws VulcanException,
|
||||||
IOException, CryptoException, VulcanOfflineException, BadCredentialsException {
|
IOException, CryptoException {
|
||||||
loginSync.loginCurrentUser();
|
accountSync.registerUser(email, password, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncGrades() throws NotLoggedInErrorException, IOException, ParseException {
|
public void initLastUser() throws VulcanException, IOException, CryptoException {
|
||||||
|
accountSync.initLastUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void syncGrades() throws VulcanException, IOException, ParseException {
|
||||||
gradeSync.sync();
|
gradeSync.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncSubjects() throws NotLoggedInErrorException, IOException, ParseException {
|
public void syncSubjects() throws VulcanException, IOException, ParseException {
|
||||||
subjectSync.sync();
|
subjectSync.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncTimetable() throws NotLoggedInErrorException, IOException, ParseException {
|
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();
|
timetableSync.syncTimetable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncTimetable(String date) throws NotLoggedInErrorException, IOException, ParseException {
|
public void syncTimetable(String date) throws VulcanException, IOException, ParseException {
|
||||||
timetableSync.syncTimetable(date);
|
timetableSync.syncTimetable(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncAll() throws NotLoggedInErrorException, IOException, ParseException {
|
public void syncAll() throws VulcanException, IOException, ParseException {
|
||||||
syncSubjects();
|
syncSubjects();
|
||||||
syncGrades();
|
syncGrades();
|
||||||
|
syncAttendance();
|
||||||
syncTimetable();
|
syncTimetable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,25 +6,36 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Account;
|
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.Grade;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
||||||
import io.github.wulkanowy.data.sync.login.LoginSyncContract;
|
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.sync.timetable.TimetableSyncContract;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public interface RepositoryContract extends ResourcesContract, LoginSyncContract,
|
public interface RepositoryContract extends ResourcesContract, AccountSyncContract,
|
||||||
TimetableSyncContract {
|
AttendanceSyncContract, TimetableSyncContract {
|
||||||
|
|
||||||
long getCurrentUserId();
|
long getCurrentUserId();
|
||||||
|
|
||||||
void syncGrades() throws NotLoggedInErrorException, IOException, ParseException;
|
int getStartupTab();
|
||||||
|
|
||||||
void syncSubjects() throws NotLoggedInErrorException, IOException, ParseException;
|
boolean isServicesEnable();
|
||||||
|
|
||||||
void syncAll() throws NotLoggedInErrorException, IOException, ParseException;
|
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();
|
Account getCurrentUser();
|
||||||
|
|
||||||
|
@ -1,19 +1,61 @@
|
|||||||
package io.github.wulkanowy.data.db.dao;
|
package io.github.wulkanowy.data.db.dao;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import com.github.yuweiguocn.library.greendao.MigrationHelper;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.database.StandardDatabase;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.BuildConfig;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AccountDao;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
|
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.GradeDao;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.SubjectDao;
|
||||||
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||||
import io.github.wulkanowy.di.annotations.DatabaseInfo;
|
import io.github.wulkanowy.di.annotations.DatabaseInfo;
|
||||||
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DbHelper extends DaoMaster.DevOpenHelper {
|
public class DbHelper extends DaoMaster.OpenHelper {
|
||||||
|
|
||||||
|
private SharedPrefContract sharedPref;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DbHelper(@ApplicationContext Context context, @DatabaseInfo String dbName) {
|
DbHelper(@ApplicationContext Context context, @DatabaseInfo String dbName,
|
||||||
|
SharedPrefContract sharedPref) {
|
||||||
super(context, dbName);
|
super(context, dbName);
|
||||||
|
this.sharedPref = sharedPref;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void onUpgrade(Database db, int oldVersion, int newVersion) {
|
||||||
|
MigrationHelper.DEBUG = BuildConfig.DEBUG;
|
||||||
|
MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {
|
||||||
|
@Override
|
||||||
|
public void onCreateAllTables(Database db, boolean ifNotExists) {
|
||||||
|
DaoMaster.createAllTables(db, ifNotExists);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onDropAllTables(Database db, boolean ifExists) {
|
||||||
|
DaoMaster.dropAllTables(db, ifExists);
|
||||||
|
}
|
||||||
|
}, AccountDao.class, SubjectDao.class, GradeDao.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,254 @@
|
|||||||
|
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.Index;
|
||||||
|
import org.greenrobot.greendao.annotation.Property;
|
||||||
|
import org.greenrobot.greendao.annotation.Transient;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
nameInDb = "AttendanceLessons",
|
||||||
|
active = true,
|
||||||
|
indexes = {@Index(value = "dayId,date,number", unique = true)}
|
||||||
|
)
|
||||||
|
public class AttendanceLesson implements Serializable {
|
||||||
|
|
||||||
|
@Id(autoincrement = true)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Property(nameInDb = "DAY_ID")
|
||||||
|
private Long dayId;
|
||||||
|
|
||||||
|
@Property(nameInDb = "DATE")
|
||||||
|
private String date = "";
|
||||||
|
|
||||||
|
@Property(nameInDb = "NUMBER_OF_LESSON")
|
||||||
|
private int number = 0;
|
||||||
|
|
||||||
|
@Property(nameInDb = "SUBJECT_NAME")
|
||||||
|
private String subject = "";
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_PRESENCE")
|
||||||
|
private boolean isPresence = false;
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_ABSENCE_UNEXCUSED")
|
||||||
|
private boolean isAbsenceUnexcused = false;
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_ABSENCE_EXCUSED")
|
||||||
|
private boolean isAbsenceExcused = false;
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_UNEXCUSED_LATENESS")
|
||||||
|
private boolean isUnexcusedLateness = false;
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_ABSENCE_FOR_SCHOOL_REASONS")
|
||||||
|
private boolean isAbsenceForSchoolReasons = false;
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_EXCUSED_LATENESS")
|
||||||
|
private boolean isExcusedLateness = false;
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_EXEMPTION")
|
||||||
|
private boolean isExemption = false;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private String description = "";
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 42L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to resolve relations
|
||||||
|
*/
|
||||||
|
@Generated(hash = 2040040024)
|
||||||
|
private transient DaoSession daoSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for active entity operations.
|
||||||
|
*/
|
||||||
|
@Generated(hash = 1936953859)
|
||||||
|
private transient AttendanceLessonDao myDao;
|
||||||
|
|
||||||
|
@Generated(hash = 1428129046)
|
||||||
|
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) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated(hash = 921806575)
|
||||||
|
public AttendanceLesson() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDayId() {
|
||||||
|
return this.dayId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDayId(Long dayId) {
|
||||||
|
this.dayId = dayId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDate() {
|
||||||
|
return this.date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setDate(String date) {
|
||||||
|
this.date = date;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumber() {
|
||||||
|
return this.number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setNumber(int number) {
|
||||||
|
this.number = number;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubject() {
|
||||||
|
return this.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setSubject(String subject) {
|
||||||
|
this.subject = subject;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsPresence() {
|
||||||
|
return this.isPresence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setIsPresence(boolean isPresence) {
|
||||||
|
this.isPresence = isPresence;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsAbsenceUnexcused() {
|
||||||
|
return this.isAbsenceUnexcused;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setIsAbsenceUnexcused(boolean isAbsenceUnexcused) {
|
||||||
|
this.isAbsenceUnexcused = isAbsenceUnexcused;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsAbsenceExcused() {
|
||||||
|
return this.isAbsenceExcused;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setIsAbsenceExcused(boolean isAbsenceExcused) {
|
||||||
|
this.isAbsenceExcused = isAbsenceExcused;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsUnexcusedLateness() {
|
||||||
|
return this.isUnexcusedLateness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setIsUnexcusedLateness(boolean isUnexcusedLateness) {
|
||||||
|
this.isUnexcusedLateness = isUnexcusedLateness;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsAbsenceForSchoolReasons() {
|
||||||
|
return this.isAbsenceForSchoolReasons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setIsAbsenceForSchoolReasons(boolean isAbsenceForSchoolReasons) {
|
||||||
|
this.isAbsenceForSchoolReasons = isAbsenceForSchoolReasons;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsExcusedLateness() {
|
||||||
|
return this.isExcusedLateness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setIsExcusedLateness(boolean isExcusedLateness) {
|
||||||
|
this.isExcusedLateness = isExcusedLateness;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsExemption() {
|
||||||
|
return this.isExemption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setIsExemption(boolean isExemption) {
|
||||||
|
this.isExemption = isExemption;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttendanceLesson setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
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 = 1157101112)
|
||||||
|
public void __setDaoSession(DaoSession daoSession) {
|
||||||
|
this.daoSession = daoSession;
|
||||||
|
myDao = daoSession != null ? daoSession.getAttendanceLessonDao() : null;
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import org.greenrobot.greendao.annotation.Entity;
|
|||||||
import org.greenrobot.greendao.annotation.Generated;
|
import org.greenrobot.greendao.annotation.Generated;
|
||||||
import org.greenrobot.greendao.annotation.Id;
|
import org.greenrobot.greendao.annotation.Id;
|
||||||
import org.greenrobot.greendao.annotation.Index;
|
import org.greenrobot.greendao.annotation.Index;
|
||||||
|
import org.greenrobot.greendao.annotation.OrderBy;
|
||||||
import org.greenrobot.greendao.annotation.Property;
|
import org.greenrobot.greendao.annotation.Property;
|
||||||
import org.greenrobot.greendao.annotation.ToMany;
|
import org.greenrobot.greendao.annotation.ToMany;
|
||||||
|
|
||||||
@ -39,7 +40,11 @@ public class Day {
|
|||||||
private String freeDayName = "";
|
private String freeDayName = "";
|
||||||
|
|
||||||
@ToMany(referencedJoinProperty = "dayId")
|
@ToMany(referencedJoinProperty = "dayId")
|
||||||
private List<Lesson> lessons;
|
private List<TimetableLesson> timetableLessons;
|
||||||
|
|
||||||
|
@ToMany(referencedJoinProperty = "dayId")
|
||||||
|
@OrderBy("number ASC")
|
||||||
|
private List<AttendanceLesson> attendanceLessons;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to resolve relations
|
* Used to resolve relations
|
||||||
@ -113,12 +118,12 @@ public class Day {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFreeDay() {
|
public boolean getIsFreeDay() {
|
||||||
return isFreeDay;
|
return this.isFreeDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Day setFreeDay(boolean freeDay) {
|
public Day setIsFreeDay(boolean isFreeDay) {
|
||||||
isFreeDay = freeDay;
|
this.isFreeDay = isFreeDay;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,42 +136,62 @@ public class Day {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsFreeDay() {
|
/**
|
||||||
return this.isFreeDay;
|
* 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 = 218588195)
|
||||||
|
public List<TimetableLesson> getTimetableLessons() {
|
||||||
|
if (timetableLessons == null) {
|
||||||
|
final DaoSession daoSession = this.daoSession;
|
||||||
|
if (daoSession == null) {
|
||||||
|
throw new DaoException("Entity is detached from DAO context");
|
||||||
|
}
|
||||||
|
TimetableLessonDao targetDao = daoSession.getTimetableLessonDao();
|
||||||
|
List<TimetableLesson> timetableLessonsNew = targetDao
|
||||||
|
._queryDay_TimetableLessons(id);
|
||||||
|
synchronized (this) {
|
||||||
|
if (timetableLessons == null) {
|
||||||
|
timetableLessons = timetableLessonsNew;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return timetableLessons;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsFreeDay(boolean isFreeDay) {
|
/** Resets a to-many relationship, making the next get call to query for a fresh result. */
|
||||||
this.isFreeDay = isFreeDay;
|
@Generated(hash = 1687683740)
|
||||||
|
public synchronized void resetTimetableLessons() {
|
||||||
|
timetableLessons = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To-many relationship, resolved on first access (and after reset).
|
* To-many relationship, resolved on first access (and after reset).
|
||||||
* Changes to to-many relations are not persisted, make changes to the target entity.
|
* Changes to to-many relations are not persisted, make changes to the target entity.
|
||||||
*/
|
*/
|
||||||
@Generated(hash = 1552857303)
|
@Generated(hash = 1166820581)
|
||||||
public List<Lesson> getLessons() {
|
public List<AttendanceLesson> getAttendanceLessons() {
|
||||||
if (lessons == null) {
|
if (attendanceLessons == null) {
|
||||||
final DaoSession daoSession = this.daoSession;
|
final DaoSession daoSession = this.daoSession;
|
||||||
if (daoSession == null) {
|
if (daoSession == null) {
|
||||||
throw new DaoException("Entity is detached from DAO context");
|
throw new DaoException("Entity is detached from DAO context");
|
||||||
}
|
}
|
||||||
LessonDao targetDao = daoSession.getLessonDao();
|
AttendanceLessonDao targetDao = daoSession.getAttendanceLessonDao();
|
||||||
List<Lesson> lessonsNew = targetDao._queryDay_Lessons(id);
|
List<AttendanceLesson> attendanceLessonsNew = targetDao
|
||||||
|
._queryDay_AttendanceLessons(id);
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (lessons == null) {
|
if (attendanceLessons == null) {
|
||||||
lessons = lessonsNew;
|
attendanceLessons = attendanceLessonsNew;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lessons;
|
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() {
|
||||||
@Generated(hash = 1769801440)
|
attendanceLessons = null;
|
||||||
public synchronized void resetLessons() {
|
|
||||||
lessons = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,11 +10,11 @@ import org.greenrobot.greendao.annotation.Property;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
nameInDb = "Lessons",
|
nameInDb = "TimetableLessons",
|
||||||
active = true,
|
active = true,
|
||||||
indexes = {@Index(value = "dayId,date,startTime,endTime", unique = true)}
|
indexes = {@Index(value = "dayId,date,startTime,endTime", unique = true)}
|
||||||
)
|
)
|
||||||
public class Lesson implements Serializable {
|
public class TimetableLesson implements Serializable {
|
||||||
|
|
||||||
@Id(autoincrement = true)
|
@Id(autoincrement = true)
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -78,13 +78,14 @@ public class Lesson implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* Used for active entity operations.
|
* Used for active entity operations.
|
||||||
*/
|
*/
|
||||||
@Generated(hash = 610143130)
|
@Generated(hash = 1119360138)
|
||||||
private transient LessonDao myDao;
|
private transient TimetableLessonDao myDao;
|
||||||
|
|
||||||
@Generated(hash = 140778287)
|
@Generated(hash = 627457324)
|
||||||
public Lesson(Long id, Long dayId, String number, String subject, String teacher, String room,
|
public TimetableLesson(Long id, Long dayId, String number, String subject,
|
||||||
String description, String groupName, String startTime, String endTime, String date,
|
String teacher, String room, String description, String groupName,
|
||||||
boolean isEmpty, boolean isDivisionIntoGroups, boolean isPlanning, boolean isRealized,
|
String startTime, String endTime, String date, boolean isEmpty,
|
||||||
|
boolean isDivisionIntoGroups, boolean isPlanning, boolean isRealized,
|
||||||
boolean isMovedOrCanceled, boolean isNewMovedInOrChanged) {
|
boolean isMovedOrCanceled, boolean isNewMovedInOrChanged) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.dayId = dayId;
|
this.dayId = dayId;
|
||||||
@ -105,8 +106,8 @@ public class Lesson implements Serializable {
|
|||||||
this.isNewMovedInOrChanged = isNewMovedInOrChanged;
|
this.isNewMovedInOrChanged = isNewMovedInOrChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Generated(hash = 1669664117)
|
@Generated(hash = 1878030142)
|
||||||
public Lesson() {
|
public TimetableLesson() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -126,186 +127,138 @@ public class Lesson implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getNumber() {
|
public String getNumber() {
|
||||||
return number;
|
return this.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setNumber(String number) {
|
public TimetableLesson setNumber(String number) {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubject() {
|
public String getSubject() {
|
||||||
return subject;
|
return this.subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setSubject(String subject) {
|
public TimetableLesson setSubject(String subject) {
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTeacher() {
|
public String getTeacher() {
|
||||||
return teacher;
|
return this.teacher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setTeacher(String teacher) {
|
public TimetableLesson setTeacher(String teacher) {
|
||||||
this.teacher = teacher;
|
this.teacher = teacher;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoom() {
|
public String getRoom() {
|
||||||
return room;
|
return this.room;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setRoom(String room) {
|
public TimetableLesson setRoom(String room) {
|
||||||
this.room = room;
|
this.room = room;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setDescription(String description) {
|
public TimetableLesson setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupName() {
|
public String getGroupName() {
|
||||||
return groupName;
|
return this.groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setGroupName(String groupName) {
|
public TimetableLesson setGroupName(String groupName) {
|
||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStartTime() {
|
public String getStartTime() {
|
||||||
return startTime;
|
return this.startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setStartTime(String startTime) {
|
public TimetableLesson setStartTime(String startTime) {
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEndTime() {
|
public String getEndTime() {
|
||||||
return endTime;
|
return this.endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setEndTime(String endTime) {
|
public TimetableLesson setEndTime(String endTime) {
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDate() {
|
public String getDate() {
|
||||||
return date;
|
return this.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lesson setDate(String date) {
|
public TimetableLesson setDate(String date) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return isEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lesson setEmpty(boolean empty) {
|
|
||||||
isEmpty = empty;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDivisionIntoGroups() {
|
|
||||||
return isDivisionIntoGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lesson setDivisionIntoGroups(boolean divisionIntoGroups) {
|
|
||||||
isDivisionIntoGroups = divisionIntoGroups;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPlanning() {
|
|
||||||
return isPlanning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lesson setPlanning(boolean planning) {
|
|
||||||
isPlanning = planning;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRealized() {
|
|
||||||
return isRealized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lesson setRealized(boolean realized) {
|
|
||||||
isRealized = realized;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMovedOrCanceled() {
|
|
||||||
return isMovedOrCanceled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lesson setMovedOrCanceled(boolean movedOrCanceled) {
|
|
||||||
isMovedOrCanceled = movedOrCanceled;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNewMovedInOrChanged() {
|
|
||||||
return isNewMovedInOrChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lesson setNewMovedInOrChanged(boolean newMovedInOrChanged) {
|
|
||||||
isNewMovedInOrChanged = newMovedInOrChanged;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getIsEmpty() {
|
public boolean getIsEmpty() {
|
||||||
return this.isEmpty;
|
return this.isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsEmpty(boolean isEmpty) {
|
public TimetableLesson setEmpty(boolean isEmpty) {
|
||||||
this.isEmpty = isEmpty;
|
this.isEmpty = isEmpty;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsDivisionIntoGroups() {
|
public boolean getIsDivisionIntoGroups() {
|
||||||
return this.isDivisionIntoGroups;
|
return this.isDivisionIntoGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsDivisionIntoGroups(boolean isDivisionIntoGroups) {
|
public TimetableLesson setDivisionIntoGroups(boolean isDivisionIntoGroups) {
|
||||||
this.isDivisionIntoGroups = isDivisionIntoGroups;
|
this.isDivisionIntoGroups = isDivisionIntoGroups;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsPlanning() {
|
public boolean getIsPlanning() {
|
||||||
return this.isPlanning;
|
return this.isPlanning;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsPlanning(boolean isPlanning) {
|
public TimetableLesson setPlanning(boolean isPlanning) {
|
||||||
this.isPlanning = isPlanning;
|
this.isPlanning = isPlanning;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsRealized() {
|
public boolean getIsRealized() {
|
||||||
return this.isRealized;
|
return this.isRealized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsRealized(boolean isRealized) {
|
public TimetableLesson setRealized(boolean isRealized) {
|
||||||
this.isRealized = isRealized;
|
this.isRealized = isRealized;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsMovedOrCanceled() {
|
public boolean getIsMovedOrCanceled() {
|
||||||
return this.isMovedOrCanceled;
|
return this.isMovedOrCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsMovedOrCanceled(boolean isMovedOrCanceled) {
|
public TimetableLesson setMovedOrCanceled(boolean isMovedOrCanceled) {
|
||||||
this.isMovedOrCanceled = isMovedOrCanceled;
|
this.isMovedOrCanceled = isMovedOrCanceled;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsNewMovedInOrChanged() {
|
public boolean getIsNewMovedInOrChanged() {
|
||||||
return this.isNewMovedInOrChanged;
|
return this.isNewMovedInOrChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsNewMovedInOrChanged(boolean isNewMovedInOrChanged) {
|
public TimetableLesson setNewMovedInOrChanged(boolean isNewMovedInOrChanged) {
|
||||||
this.isNewMovedInOrChanged = isNewMovedInOrChanged;
|
this.isNewMovedInOrChanged = isNewMovedInOrChanged;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -344,10 +297,34 @@ public class Lesson implements Serializable {
|
|||||||
myDao.update(this);
|
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. */
|
/** called by internal mechanisms, do not call yourself. */
|
||||||
@Generated(hash = 2078826279)
|
@Generated(hash = 1885258429)
|
||||||
public void __setDaoSession(DaoSession daoSession) {
|
public void __setDaoSession(DaoSession daoSession) {
|
||||||
this.daoSession = daoSession;
|
this.daoSession = daoSession;
|
||||||
myDao = daoSession != null ? daoSession.getLessonDao() : null;
|
myDao = daoSession != null ? daoSession.getTimetableLessonDao() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,6 +26,12 @@ public class Week {
|
|||||||
@Property(nameInDb = "START_DATE")
|
@Property(nameInDb = "START_DATE")
|
||||||
private String startDayDate = "";
|
private String startDayDate = "";
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_ATTENDANCE_SYNCED")
|
||||||
|
private boolean isAttendanceSynced = false;
|
||||||
|
|
||||||
|
@Property(nameInDb = "IS_TIMETABLE_SYNCED")
|
||||||
|
private boolean isTimetableSynced = false;
|
||||||
|
|
||||||
@ToMany(referencedJoinProperty = "weekId")
|
@ToMany(referencedJoinProperty = "weekId")
|
||||||
private List<Day> dayList;
|
private List<Day> dayList;
|
||||||
|
|
||||||
@ -37,11 +43,14 @@ public class Week {
|
|||||||
@Generated(hash = 1019310398)
|
@Generated(hash = 1019310398)
|
||||||
private transient WeekDao myDao;
|
private transient WeekDao myDao;
|
||||||
|
|
||||||
@Generated(hash = 36829814)
|
@Generated(hash = 1745118398)
|
||||||
public Week(Long id, Long userId, String startDayDate) {
|
public Week(Long id, Long userId, String startDayDate, boolean isAttendanceSynced,
|
||||||
|
boolean isTimetableSynced) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.startDayDate = startDayDate;
|
this.startDayDate = startDayDate;
|
||||||
|
this.isAttendanceSynced = isAttendanceSynced;
|
||||||
|
this.isTimetableSynced = isTimetableSynced;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Generated(hash = 2135529658)
|
@Generated(hash = 2135529658)
|
||||||
@ -75,6 +84,22 @@ public class Week {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getIsAttendanceSynced() {
|
||||||
|
return this.isAttendanceSynced;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsAttendanceSynced(boolean isAttendanceSynced) {
|
||||||
|
this.isAttendanceSynced = isAttendanceSynced;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsTimetableSynced() {
|
||||||
|
return this.isTimetableSynced;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsTimetableSynced(boolean isTimetableSynced) {
|
||||||
|
this.isTimetableSynced = isTimetableSynced;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To-many relationship, resolved on first access (and after reset).
|
* To-many relationship, resolved on first access (and after reset).
|
||||||
* Changes to to-many relations are not persisted, make changes to the target entity.
|
* Changes to to-many relations are not persisted, make changes to the target entity.
|
||||||
|
@ -3,6 +3,8 @@ package io.github.wulkanowy.data.db.resources;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@ -11,8 +13,8 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.NotLoggedInErrorException;
|
||||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||||
import io.github.wulkanowy.utils.AppConstant;
|
import io.github.wulkanowy.utils.AppConstant;
|
||||||
import io.github.wulkanowy.utils.LogUtils;
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
@ -41,6 +43,7 @@ public class AppResources implements ResourcesContract {
|
|||||||
@Override
|
@Override
|
||||||
public String getErrorLoginMessage(Exception exception) {
|
public String getErrorLoginMessage(Exception exception) {
|
||||||
LogUtils.error(AppConstant.APP_NAME + " encountered a error", exception);
|
LogUtils.error(AppConstant.APP_NAME + " encountered a error", exception);
|
||||||
|
Crashlytics.logException(exception);
|
||||||
|
|
||||||
if (exception instanceof CryptoException) {
|
if (exception instanceof CryptoException) {
|
||||||
return resources.getString(R.string.encrypt_failed_text);
|
return resources.getString(R.string.encrypt_failed_text);
|
||||||
@ -50,10 +53,39 @@ public class AppResources implements ResourcesContract {
|
|||||||
return resources.getString(R.string.generic_timeout_error);
|
return resources.getString(R.string.generic_timeout_error);
|
||||||
} else if (exception instanceof NotLoggedInErrorException || exception instanceof IOException) {
|
} else if (exception instanceof NotLoggedInErrorException || exception instanceof IOException) {
|
||||||
return resources.getString(R.string.login_denied_text);
|
return resources.getString(R.string.login_denied_text);
|
||||||
} else if (exception instanceof VulcanOfflineException) {
|
|
||||||
return resources.getString(R.string.error_host_offline);
|
|
||||||
} else {
|
} else {
|
||||||
return exception.getMessage();
|
return exception.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAttendanceLessonDescription(AttendanceLesson lesson) {
|
||||||
|
int id = R.string.attendance_present;
|
||||||
|
|
||||||
|
if (lesson.getIsAbsenceForSchoolReasons()) {
|
||||||
|
id = R.string.attendance_absence_for_school_reasons;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lesson.getIsAbsenceExcused()) {
|
||||||
|
id = R.string.attendance_absence_excused;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lesson.getIsAbsenceUnexcused()) {
|
||||||
|
id = R.string.attendance_absence_unexcused;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lesson.getIsExemption()) {
|
||||||
|
id = R.string.attendance_exemption;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lesson.getIsExcusedLateness()) {
|
||||||
|
id = R.string.attendance_excused_lateness;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lesson.getIsUnexcusedLateness()) {
|
||||||
|
id = R.string.attendance_unexcused_lateness;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources.getString(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.wulkanowy.data.db.resources;
|
package io.github.wulkanowy.data.db.resources;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
|
|
||||||
public interface ResourcesContract {
|
public interface ResourcesContract {
|
||||||
|
|
||||||
String[] getSymbolsKeysArray();
|
String[] getSymbolsKeysArray();
|
||||||
@ -7,4 +9,6 @@ public interface ResourcesContract {
|
|||||||
String[] getSymbolsValuesArray();
|
String[] getSymbolsValuesArray();
|
||||||
|
|
||||||
String getErrorLoginMessage(Exception e);
|
String getErrorLoginMessage(Exception e);
|
||||||
|
|
||||||
|
String getAttendanceLessonDescription(AttendanceLesson lesson);
|
||||||
}
|
}
|
||||||
|
@ -2,32 +2,62 @@ package io.github.wulkanowy.data.db.shared;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||||
import io.github.wulkanowy.di.annotations.SharedPreferencesInfo;
|
import io.github.wulkanowy.di.annotations.SharedPreferencesInfo;
|
||||||
|
import io.github.wulkanowy.ui.main.settings.SettingsFragment;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class SharedPref implements SharedPrefContract {
|
public class SharedPref implements SharedPrefContract {
|
||||||
|
|
||||||
private static final String SHARED_KEY_USER_ID = "USER_ID";
|
private static final String SHARED_KEY_USER_ID = "USER_ID";
|
||||||
|
|
||||||
private final SharedPreferences sharedPreferences;
|
private final SharedPreferences appSharedPref;
|
||||||
|
|
||||||
|
private final SharedPreferences settingsSharedPref;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SharedPref(@ApplicationContext Context context, @SharedPreferencesInfo String sharedName) {
|
SharedPref(@ApplicationContext Context context, @SharedPreferencesInfo String sharedName) {
|
||||||
sharedPreferences = context.getSharedPreferences(sharedName, Context.MODE_PRIVATE);
|
appSharedPref = context.getSharedPreferences(sharedName, Context.MODE_PRIVATE);
|
||||||
|
settingsSharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentUserId() {
|
public long getCurrentUserId() {
|
||||||
return sharedPreferences.getLong(SHARED_KEY_USER_ID, 0);
|
return appSharedPref.getLong(SHARED_KEY_USER_ID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCurrentUserId(long userId) {
|
public void setCurrentUserId(long userId) {
|
||||||
sharedPreferences.edit().putLong(SHARED_KEY_USER_ID, userId).apply();
|
appSharedPref.edit().putLong(SHARED_KEY_USER_ID, userId).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStartupTab() {
|
||||||
|
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_START_TAB, "2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getServicesInterval() {
|
||||||
|
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_SERVICES_INTERVAL, "60"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServicesEnable() {
|
||||||
|
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_SERVICES_ENABLE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNotifyEnable() {
|
||||||
|
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_NOTIFY_ENABLE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMobileDisable() {
|
||||||
|
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_SERVICES_MOBILE_DISABLED, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,4 +5,14 @@ public interface SharedPrefContract {
|
|||||||
long getCurrentUserId();
|
long getCurrentUserId();
|
||||||
|
|
||||||
void setCurrentUserId(long userId);
|
void setCurrentUserId(long userId);
|
||||||
|
|
||||||
|
int getStartupTab();
|
||||||
|
|
||||||
|
int getServicesInterval();
|
||||||
|
|
||||||
|
boolean isMobileDisable();
|
||||||
|
|
||||||
|
boolean isServicesEnable();
|
||||||
|
|
||||||
|
boolean isNotifyEnable();
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package io.github.wulkanowy.data.sync;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public interface SyncContract {
|
public interface SyncContract {
|
||||||
|
|
||||||
void sync() throws NotLoggedInErrorException, IOException, ParseException;
|
void sync() throws VulcanException, IOException, ParseException;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.data.sync.login;
|
package io.github.wulkanowy.data.sync.account;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
@ -8,10 +8,7 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Vulcan;
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Account;
|
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.DaoSession;
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
@ -21,7 +18,7 @@ import io.github.wulkanowy.utils.security.CryptoException;
|
|||||||
import io.github.wulkanowy.utils.security.Scrambler;
|
import io.github.wulkanowy.utils.security.Scrambler;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class LoginSync implements LoginSyncContract {
|
public class AccountSync implements AccountSyncContract {
|
||||||
|
|
||||||
private final DaoSession daoSession;
|
private final DaoSession daoSession;
|
||||||
|
|
||||||
@ -32,7 +29,7 @@ public class LoginSync implements LoginSyncContract {
|
|||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
LoginSync(DaoSession daoSession, SharedPrefContract sharedPref,
|
AccountSync(DaoSession daoSession, SharedPrefContract sharedPref,
|
||||||
Vulcan vulcan, @ApplicationContext Context context) {
|
Vulcan vulcan, @ApplicationContext Context context) {
|
||||||
this.daoSession = daoSession;
|
this.daoSession = daoSession;
|
||||||
this.sharedPref = sharedPref;
|
this.sharedPref = sharedPref;
|
||||||
@ -41,13 +38,12 @@ public class LoginSync implements LoginSyncContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loginUser(String email, String password, String symbol)
|
public void registerUser(String email, String password, String symbol)
|
||||||
throws NotLoggedInErrorException, AccountPermissionException, IOException,
|
throws VulcanException, IOException, CryptoException {
|
||||||
CryptoException, VulcanOfflineException, BadCredentialsException {
|
|
||||||
|
|
||||||
LogUtils.debug("Login new user email=" + email);
|
LogUtils.debug("Register new user email=" + email);
|
||||||
|
|
||||||
vulcan.login(email, password, symbol);
|
vulcan.setCredentials(email, password, symbol, null);
|
||||||
|
|
||||||
Account account = new Account()
|
Account account = new Account()
|
||||||
.setName(vulcan.getBasicInformation().getPersonalData().getFirstAndLastName())
|
.setName(vulcan.getBasicInformation().getPersonalData().getFirstAndLastName())
|
||||||
@ -56,24 +52,25 @@ public class LoginSync implements LoginSyncContract {
|
|||||||
.setSymbol(vulcan.getSymbol())
|
.setSymbol(vulcan.getSymbol())
|
||||||
.setSnpId(vulcan.getStudentAndParent().getId());
|
.setSnpId(vulcan.getStudentAndParent().getId());
|
||||||
|
|
||||||
sharedPref.setCurrentUserId(daoSession.getAccountDao().insert(account));
|
daoSession.getAccountDao().insert(account);
|
||||||
|
|
||||||
|
sharedPref.setCurrentUserId(account.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loginCurrentUser() throws NotLoggedInErrorException, AccountPermissionException,
|
public void initLastUser() throws VulcanException, IOException, CryptoException {
|
||||||
IOException, CryptoException, VulcanOfflineException, BadCredentialsException {
|
|
||||||
|
|
||||||
long userId = sharedPref.getCurrentUserId();
|
long userId = sharedPref.getCurrentUserId();
|
||||||
|
|
||||||
if (userId == 0) {
|
if (userId == 0) {
|
||||||
throw new IOException("Can't find logged user");
|
throw new IOException("Can't find saved user");
|
||||||
}
|
}
|
||||||
|
|
||||||
LogUtils.debug("Login current user id=" + userId);
|
LogUtils.debug("Initialization current user id=" + userId);
|
||||||
|
|
||||||
Account account = daoSession.getAccountDao().load(userId);
|
Account account = daoSession.getAccountDao().load(userId);
|
||||||
|
|
||||||
vulcan.login(account.getEmail(),
|
vulcan.setCredentials(account.getEmail(),
|
||||||
Scrambler.decrypt(account.getEmail(), account.getPassword()),
|
Scrambler.decrypt(account.getEmail(), account.getPassword()),
|
||||||
account.getSymbol(),
|
account.getSymbol(),
|
||||||
account.getSnpId());
|
account.getSnpId());
|
@ -0,0 +1,16 @@
|
|||||||
|
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;
|
||||||
|
}
|
@ -0,0 +1,156 @@
|
|||||||
|
package io.github.wulkanowy.data.sync.attendance;
|
||||||
|
|
||||||
|
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.api.generic.Lesson;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLessonDao;
|
||||||
|
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.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 {
|
||||||
|
|
||||||
|
private final DaoSession daoSession;
|
||||||
|
|
||||||
|
private final SharedPrefContract sharedPref;
|
||||||
|
|
||||||
|
private final Vulcan vulcan;
|
||||||
|
|
||||||
|
private long userId;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AttendanceSync(DaoSession daoSession, SharedPrefContract sharedPref, 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();
|
||||||
|
|
||||||
|
io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.generic.Day> weekApi = getWeekFromApi(getNormalizedDate(date));
|
||||||
|
Week weekDb = getWeekFromDb(weekApi.getStartDayDate());
|
||||||
|
|
||||||
|
long weekId = updateWeekInDb(weekDb, weekApi);
|
||||||
|
|
||||||
|
List<AttendanceLesson> lessonList = updateDays(weekApi.getDays(), weekId);
|
||||||
|
|
||||||
|
daoSession.getAttendanceLessonDao().saveInTx(lessonList);
|
||||||
|
|
||||||
|
LogUtils.debug("Synchronization attendance lessons (amount = " + lessonList.size() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNormalizedDate(String date) throws ParseException {
|
||||||
|
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, ParseException, VulcanException {
|
||||||
|
return vulcan.getAttendanceTable().getWeekTable(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Week getWeekFromDb(String date) {
|
||||||
|
return daoSession.getWeekDao()
|
||||||
|
.queryBuilder()
|
||||||
|
.where(WeekDao.Properties.UserId.eq(userId), 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.update();
|
||||||
|
|
||||||
|
return dbWeekEntity.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
Week apiWeekEntity = DataObjectConverter.weekToWeekEntity(fromApi).setUserId(userId);
|
||||||
|
apiWeekEntity.setIsAttendanceSynced(true);
|
||||||
|
|
||||||
|
return daoSession.getWeekDao().insert(apiWeekEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<AttendanceLesson> updateDays(List<io.github.wulkanowy.api.generic.Day> dayListFromApi, long weekId) {
|
||||||
|
List<AttendanceLesson> updatedLessonList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (io.github.wulkanowy.api.generic.Day dayFromApi : dayListFromApi) {
|
||||||
|
|
||||||
|
Day dbDayEntity = getDayFromDb(dayFromApi.getDate());
|
||||||
|
|
||||||
|
Day apiDayEntity = DataObjectConverter.dayToDayEntity(dayFromApi);
|
||||||
|
|
||||||
|
long dayId = updateDay(dbDayEntity, apiDayEntity, weekId);
|
||||||
|
|
||||||
|
updateLessons(dayFromApi.getLessons(), updatedLessonList, dayId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedLessonList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Day getDayFromDb(String date) {
|
||||||
|
return daoSession.getDayDao()
|
||||||
|
.queryBuilder()
|
||||||
|
.where(DayDao.Properties.UserId.eq(userId), DayDao.Properties.Date.eq(date))
|
||||||
|
.unique();
|
||||||
|
}
|
||||||
|
|
||||||
|
private long updateDay(Day dbDayEntity, Day apiDayEntity, long weekId) {
|
||||||
|
if (null != dbDayEntity) {
|
||||||
|
return dbDayEntity.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
apiDayEntity.setUserId(userId);
|
||||||
|
apiDayEntity.setWeekId(weekId);
|
||||||
|
|
||||||
|
return daoSession.getDayDao().insert(apiDayEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLessons(List<Lesson> lessons, List<AttendanceLesson> updatedLessons, long dayId) {
|
||||||
|
List<AttendanceLesson> lessonsFromApiEntities = DataObjectConverter
|
||||||
|
.lessonsToAttendanceLessonsEntities(lessons);
|
||||||
|
|
||||||
|
for (AttendanceLesson apiLessonEntity : lessonsFromApiEntities) {
|
||||||
|
AttendanceLesson lessonFromDb = getLessonFromDb(apiLessonEntity, dayId);
|
||||||
|
|
||||||
|
apiLessonEntity.setDayId(dayId);
|
||||||
|
|
||||||
|
if (lessonFromDb != null) {
|
||||||
|
apiLessonEntity.setId(lessonFromDb.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"".equals(apiLessonEntity.getSubject())) {
|
||||||
|
updatedLessons.add(apiLessonEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AttendanceLesson getLessonFromDb(AttendanceLesson apiEntity, long dayId) {
|
||||||
|
return daoSession.getAttendanceLessonDao().queryBuilder()
|
||||||
|
.where(AttendanceLessonDao.Properties.DayId.eq(dayId),
|
||||||
|
AttendanceLessonDao.Properties.Date.eq(apiEntity.getDate()),
|
||||||
|
AttendanceLessonDao.Properties.Number.eq(apiEntity.getNumber()))
|
||||||
|
.unique();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
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;
|
||||||
|
}
|
@ -9,7 +9,7 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Vulcan;
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Account;
|
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.DaoSession;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
||||||
@ -29,6 +29,8 @@ public class GradeSync implements SyncContract {
|
|||||||
|
|
||||||
private final SharedPrefContract sharedPref;
|
private final SharedPrefContract sharedPref;
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GradeSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
|
GradeSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
|
||||||
this.daoSession = daoSession;
|
this.daoSession = daoSession;
|
||||||
@ -37,36 +39,53 @@ public class GradeSync implements SyncContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sync() throws IOException, NotLoggedInErrorException, ParseException {
|
public void sync() throws IOException, VulcanException, ParseException {
|
||||||
|
|
||||||
long userId = sharedPref.getCurrentUserId();
|
userId = sharedPref.getCurrentUserId();
|
||||||
|
|
||||||
Account account = daoSession.getAccountDao().load(userId);
|
Account account = daoSession.getAccountDao().load(userId);
|
||||||
account.resetGradeList();
|
resetAccountRelations(account);
|
||||||
account.resetSubjectList();
|
|
||||||
|
|
||||||
List<Grade> gradesFromNet = DataObjectConverter
|
List<Grade> lastList = getUpdatedList(getComparedList(account));
|
||||||
.gradesToGradeEntities(vulcan.getGradesList().getAll());
|
|
||||||
List<Grade> gradesFromDb = account.getGradeList();
|
|
||||||
|
|
||||||
List<Grade> updatedGrades = EntitiesCompare.compareGradeList(gradesFromNet, gradesFromDb);
|
|
||||||
|
|
||||||
daoSession.getGradeDao().deleteInTx(gradesFromDb);
|
|
||||||
|
|
||||||
List<Grade> lastList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Grade grade : updatedGrades) {
|
|
||||||
grade.setUserId(userId);
|
|
||||||
grade.setSubjectId(daoSession.getSubjectDao().queryBuilder()
|
|
||||||
.where(SubjectDao.Properties.Name.eq(grade.getSubject()),
|
|
||||||
SubjectDao.Properties.UserId.eq(userId))
|
|
||||||
.build()
|
|
||||||
.uniqueOrThrow().getId());
|
|
||||||
lastList.add(grade);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
daoSession.getGradeDao().deleteInTx(account.getGradeList());
|
||||||
daoSession.getGradeDao().insertInTx(lastList);
|
daoSession.getGradeDao().insertInTx(lastList);
|
||||||
|
|
||||||
LogUtils.debug("Synchronization grades (amount = " + lastList.size() + ")");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
package io.github.wulkanowy.data.sync.login;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
|
||||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
|
||||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
|
||||||
import io.github.wulkanowy.utils.security.CryptoException;
|
|
||||||
|
|
||||||
public interface LoginSyncContract {
|
|
||||||
|
|
||||||
void loginUser(String email, String password, String symbol)
|
|
||||||
throws NotLoggedInErrorException, AccountPermissionException, IOException,
|
|
||||||
CryptoException, VulcanOfflineException, BadCredentialsException;
|
|
||||||
|
|
||||||
void loginCurrentUser() throws NotLoggedInErrorException, AccountPermissionException, IOException,
|
|
||||||
CryptoException, VulcanOfflineException, BadCredentialsException;
|
|
||||||
}
|
|
@ -9,10 +9,10 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Vulcan;
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
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.DaoSession;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.SubjectDao;
|
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
import io.github.wulkanowy.data.sync.SyncContract;
|
import io.github.wulkanowy.data.sync.SyncContract;
|
||||||
import io.github.wulkanowy.utils.DataObjectConverter;
|
import io.github.wulkanowy.utils.DataObjectConverter;
|
||||||
@ -21,41 +21,51 @@ import io.github.wulkanowy.utils.LogUtils;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class SubjectSync implements SyncContract {
|
public class SubjectSync implements SyncContract {
|
||||||
|
|
||||||
private final SubjectDao subjectDao;
|
private final DaoSession daoSession;
|
||||||
|
|
||||||
private final Vulcan vulcan;
|
private final Vulcan vulcan;
|
||||||
|
|
||||||
private final SharedPrefContract sharedPref;
|
private final SharedPrefContract sharedPref;
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SubjectSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
|
SubjectSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
|
||||||
this.subjectDao = daoSession.getSubjectDao();
|
this.daoSession = daoSession;
|
||||||
this.sharedPref = sharedPref;
|
this.sharedPref = sharedPref;
|
||||||
this.vulcan = vulcan;
|
this.vulcan = vulcan;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sync() throws NotLoggedInErrorException, IOException, ParseException {
|
public void sync() throws VulcanException, IOException, ParseException {
|
||||||
|
|
||||||
long userId = sharedPref.getCurrentUserId();
|
userId = sharedPref.getCurrentUserId();
|
||||||
|
|
||||||
List<Subject> subjectsFromNet = DataObjectConverter
|
List<Subject> lastList = getUpdatedList(getSubjectsFromNet());
|
||||||
.subjectsToSubjectEntities(vulcan.getSubjectsList().getAll());
|
|
||||||
|
|
||||||
subjectDao.deleteInTx(subjectDao.queryBuilder()
|
daoSession.getSubjectDao().deleteInTx(getSubjectsFromDb());
|
||||||
.where(SubjectDao.Properties.UserId.eq(userId))
|
daoSession.getSubjectDao().insertInTx(lastList);
|
||||||
.build()
|
|
||||||
.list());
|
|
||||||
|
|
||||||
List<Subject> lastList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Subject subject : subjectsFromNet) {
|
|
||||||
subject.setUserId(userId);
|
|
||||||
lastList.add(subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
subjectDao.insertInTx(lastList);
|
|
||||||
|
|
||||||
LogUtils.debug("Synchronization subjects (amount = " + lastList.size() + ")");
|
LogUtils.debug("Synchronization subjects (amount = " + lastList.size() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Subject> getSubjectsFromNet() throws VulcanException, IOException {
|
||||||
|
return DataObjectConverter.subjectsToSubjectEntities(vulcan.getSubjectsList().getAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Subject> getSubjectsFromDb() {
|
||||||
|
Account account = daoSession.getAccountDao().load(userId);
|
||||||
|
account.resetSubjectList();
|
||||||
|
return account.getSubjectList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Subject> getUpdatedList(List<Subject> subjectsFromNet) {
|
||||||
|
List<Subject> updatedList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Subject subject : subjectsFromNet) {
|
||||||
|
subject.setUserId(userId);
|
||||||
|
updatedList.add(subject);
|
||||||
|
}
|
||||||
|
return updatedList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,13 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Vulcan;
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
import io.github.wulkanowy.api.generic.Lesson;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
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.Day;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DayDao;
|
import io.github.wulkanowy.data.db.dao.entities.DayDao;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Lesson;
|
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.LessonDao;
|
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.Week;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.WeekDao;
|
import io.github.wulkanowy.data.db.dao.entities.WeekDao;
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
@ -27,9 +28,11 @@ public class TimetableSync implements TimetableSyncContract {
|
|||||||
|
|
||||||
private final DaoSession daoSession;
|
private final DaoSession daoSession;
|
||||||
|
|
||||||
|
private final SharedPrefContract sharedPref;
|
||||||
|
|
||||||
private final Vulcan vulcan;
|
private final Vulcan vulcan;
|
||||||
|
|
||||||
private final SharedPrefContract sharedPref;
|
private long userId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
TimetableSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
|
TimetableSync(DaoSession daoSession, SharedPrefContract sharedPref, Vulcan vulcan) {
|
||||||
@ -39,82 +42,121 @@ public class TimetableSync implements TimetableSyncContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncTimetable(String date) throws NotLoggedInErrorException, IOException, ParseException {
|
public void syncTimetable() throws IOException, ParseException, VulcanException {
|
||||||
long userId = sharedPref.getCurrentUserId();
|
syncTimetable(null);
|
||||||
|
|
||||||
io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.generic.Day> weekFromNet =
|
|
||||||
date == null ? vulcan.getTimetable().getWeekTable()
|
|
||||||
: vulcan.getTimetable().getWeekTable(String.valueOf(TimeUtils.getNetTicks(date)));
|
|
||||||
|
|
||||||
Week weekFromDb = daoSession.getWeekDao().queryBuilder()
|
|
||||||
.where(WeekDao.Properties.UserId.eq(userId),
|
|
||||||
WeekDao.Properties.StartDayDate.eq(weekFromNet.getStartDayDate()))
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
Long weekId;
|
|
||||||
|
|
||||||
if (weekFromDb == null) {
|
|
||||||
Week weekFromNetEntity = DataObjectConverter.weekToWeekEntity(weekFromNet).setUserId(userId);
|
|
||||||
weekId = daoSession.getWeekDao().insert(weekFromNetEntity);
|
|
||||||
} else {
|
|
||||||
weekId = weekFromDb.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<io.github.wulkanowy.api.generic.Day> dayListFromNet = weekFromNet.getDays();
|
|
||||||
|
|
||||||
List<Lesson> updatedLessonList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (io.github.wulkanowy.api.generic.Day dayFromNet : dayListFromNet) {
|
|
||||||
Day dayFromNetEntity = DataObjectConverter.dayToDayEntity(dayFromNet);
|
|
||||||
|
|
||||||
Day dayFromDb = daoSession.getDayDao().queryBuilder()
|
|
||||||
.where(DayDao.Properties.UserId.eq(userId),
|
|
||||||
DayDao.Properties.WeekId.eq(weekId),
|
|
||||||
DayDao.Properties.Date.eq(dayFromNetEntity.getDate()))
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
dayFromNetEntity.setUserId(userId);
|
|
||||||
dayFromNetEntity.setWeekId(weekId);
|
|
||||||
|
|
||||||
Long dayId;
|
|
||||||
|
|
||||||
if (dayFromDb != null) {
|
|
||||||
dayFromNetEntity.setId(dayFromDb.getId());
|
|
||||||
daoSession.getDayDao().save(dayFromNetEntity);
|
|
||||||
dayId = dayFromNetEntity.getId();
|
|
||||||
} else {
|
|
||||||
dayId = daoSession.getDayDao().insert(dayFromNetEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Lesson> lessonListFromNetEntities = DataObjectConverter
|
|
||||||
.lessonsToLessonsEntities(dayFromNet.getLessons());
|
|
||||||
|
|
||||||
for (Lesson lessonFromNetEntity : lessonListFromNetEntities) {
|
|
||||||
Lesson lessonFromDb = daoSession.getLessonDao().queryBuilder()
|
|
||||||
.where(LessonDao.Properties.DayId.eq(dayId),
|
|
||||||
LessonDao.Properties.Date.eq(lessonFromNetEntity.getDate()),
|
|
||||||
LessonDao.Properties.StartTime.eq(lessonFromNetEntity.getStartTime()),
|
|
||||||
LessonDao.Properties.EndTime.eq(lessonFromNetEntity.getEndTime()))
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
if (lessonFromDb != null) {
|
|
||||||
lessonFromNetEntity.setId(lessonFromDb.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
lessonFromNetEntity.setDayId(dayFromNetEntity.getId());
|
|
||||||
|
|
||||||
if (!"".equals(lessonFromNetEntity.getSubject())) {
|
|
||||||
updatedLessonList.add(lessonFromNetEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
daoSession.getLessonDao().saveInTx(updatedLessonList);
|
|
||||||
|
|
||||||
LogUtils.debug("Synchronization lessons (amount = " + updatedLessonList.size() + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncTimetable() throws NotLoggedInErrorException, IOException, ParseException {
|
public void syncTimetable(String date) throws IOException, ParseException, VulcanException {
|
||||||
syncTimetable(null);
|
this.userId = sharedPref.getCurrentUserId();
|
||||||
|
|
||||||
|
io.github.wulkanowy.api.generic.Week<io.github.wulkanowy.api.generic.Day> weekApi = getWeekFromApi(getNormalizedDate(date));
|
||||||
|
Week weekDb = getWeekFromDb(weekApi.getStartDayDate());
|
||||||
|
|
||||||
|
long weekId = updateWeekInDb(weekDb, weekApi);
|
||||||
|
|
||||||
|
List<TimetableLesson> lessonList = updateDays(weekApi.getDays(), weekId);
|
||||||
|
|
||||||
|
daoSession.getTimetableLessonDao().saveInTx(lessonList);
|
||||||
|
|
||||||
|
LogUtils.debug("Synchronization timetable lessons (amount = " + lessonList.size() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNormalizedDate(String date) throws ParseException {
|
||||||
|
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 {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long updateWeekInDb(Week dbEntity, io.github.wulkanowy.api.generic.Week fromApi) {
|
||||||
|
if (dbEntity != null) {
|
||||||
|
dbEntity.setIsTimetableSynced(true);
|
||||||
|
dbEntity.update();
|
||||||
|
|
||||||
|
return dbEntity.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
Week apiEntity = DataObjectConverter.weekToWeekEntity(fromApi).setUserId(userId);
|
||||||
|
apiEntity.setIsTimetableSynced(true);
|
||||||
|
|
||||||
|
return daoSession.getWeekDao().insert(apiEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TimetableLesson> updateDays(List<io.github.wulkanowy.api.generic.Day> dayListFromApi, long weekId) {
|
||||||
|
List<TimetableLesson> updatedLessonList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (io.github.wulkanowy.api.generic.Day dayFromApi : dayListFromApi) {
|
||||||
|
|
||||||
|
Day dbDayEntity = getDayFromDb(dayFromApi.getDate());
|
||||||
|
|
||||||
|
Day apiDayEntity = DataObjectConverter.dayToDayEntity(dayFromApi);
|
||||||
|
|
||||||
|
long dayId = updateDay(dbDayEntity, apiDayEntity, weekId);
|
||||||
|
|
||||||
|
updateLessons(dayFromApi.getLessons(), updatedLessonList, dayId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedLessonList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Day getDayFromDb(String date) {
|
||||||
|
return daoSession.getDayDao()
|
||||||
|
.queryBuilder()
|
||||||
|
.where(DayDao.Properties.UserId.eq(userId), DayDao.Properties.Date.eq(date))
|
||||||
|
.unique();
|
||||||
|
}
|
||||||
|
|
||||||
|
private long updateDay(Day dayFromDb, Day apiDayEntity, long weekId) {
|
||||||
|
apiDayEntity.setUserId(userId);
|
||||||
|
apiDayEntity.setWeekId(weekId);
|
||||||
|
|
||||||
|
if (null != dayFromDb) {
|
||||||
|
apiDayEntity.setId(dayFromDb.getId());
|
||||||
|
|
||||||
|
daoSession.getDayDao().save(apiDayEntity);
|
||||||
|
dayFromDb.refresh();
|
||||||
|
|
||||||
|
return dayFromDb.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return daoSession.getDayDao().insert(apiDayEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLessons(List<Lesson> lessons, List<TimetableLesson> updatedLessons, long dayId) {
|
||||||
|
List<TimetableLesson> lessonsFromApiEntities = DataObjectConverter
|
||||||
|
.lessonsToTimetableLessonsEntities(lessons);
|
||||||
|
|
||||||
|
for (TimetableLesson apiLessonEntity : lessonsFromApiEntities) {
|
||||||
|
TimetableLesson lessonFromDb = getLessonFromDb(apiLessonEntity, dayId);
|
||||||
|
|
||||||
|
apiLessonEntity.setDayId(dayId);
|
||||||
|
|
||||||
|
if (lessonFromDb != null) {
|
||||||
|
apiLessonEntity.setId(lessonFromDb.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"".equals(apiLessonEntity.getSubject())) {
|
||||||
|
updatedLessons.add(apiLessonEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimetableLesson getLessonFromDb(TimetableLesson apiEntity, long dayId) {
|
||||||
|
return daoSession.getTimetableLessonDao().queryBuilder()
|
||||||
|
.where(TimetableLessonDao.Properties.DayId.eq(dayId),
|
||||||
|
TimetableLessonDao.Properties.Date.eq(apiEntity.getDate()),
|
||||||
|
TimetableLessonDao.Properties.StartTime.eq(apiEntity.getStartTime()),
|
||||||
|
TimetableLessonDao.Properties.EndTime.eq(apiEntity.getEndTime()))
|
||||||
|
.unique();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ package io.github.wulkanowy.data.sync.timetable;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public interface TimetableSyncContract {
|
public interface TimetableSyncContract {
|
||||||
|
|
||||||
void syncTimetable(String date) throws NotLoggedInErrorException, IOException, ParseException;
|
void syncTimetable(String date) throws VulcanException, IOException, ParseException;
|
||||||
|
|
||||||
void syncTimetable() throws NotLoggedInErrorException, IOException, ParseException;
|
void syncTimetable() throws VulcanException, IOException, ParseException;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import dagger.Component;
|
|||||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
import io.github.wulkanowy.di.annotations.PerFragment;
|
||||||
import io.github.wulkanowy.di.modules.FragmentModule;
|
import io.github.wulkanowy.di.modules.FragmentModule;
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
|
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.dashboard.DashboardFragment;
|
||||||
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
||||||
@ -17,6 +18,8 @@ public interface FragmentComponent {
|
|||||||
|
|
||||||
void inject(AttendanceFragment attendanceFragment);
|
void inject(AttendanceFragment attendanceFragment);
|
||||||
|
|
||||||
|
void inject(AttendanceTabFragment attendanceTabFragment);
|
||||||
|
|
||||||
void inject(DashboardFragment dashboardFragment);
|
void inject(DashboardFragment dashboardFragment);
|
||||||
|
|
||||||
void inject(TimetableFragment timetableFragment);
|
void inject(TimetableFragment timetableFragment);
|
||||||
|
@ -21,9 +21,11 @@ import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
|||||||
import io.github.wulkanowy.data.db.shared.SharedPref;
|
import io.github.wulkanowy.data.db.shared.SharedPref;
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
import io.github.wulkanowy.data.sync.SyncContract;
|
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.grades.GradeSync;
|
||||||
import io.github.wulkanowy.data.sync.login.LoginSync;
|
|
||||||
import io.github.wulkanowy.data.sync.login.LoginSyncContract;
|
|
||||||
import io.github.wulkanowy.data.sync.subjects.SubjectSync;
|
import io.github.wulkanowy.data.sync.subjects.SubjectSync;
|
||||||
import io.github.wulkanowy.data.sync.timetable.TimetableSync;
|
import io.github.wulkanowy.data.sync.timetable.TimetableSync;
|
||||||
import io.github.wulkanowy.data.sync.timetable.TimetableSyncContract;
|
import io.github.wulkanowy.data.sync.timetable.TimetableSyncContract;
|
||||||
@ -98,8 +100,8 @@ public class ApplicationModule {
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
LoginSyncContract provideLoginSync(LoginSync loginSync) {
|
AccountSyncContract provideLoginSync(AccountSync accountSync) {
|
||||||
return loginSync;
|
return accountSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SyncGrades
|
@SyncGrades
|
||||||
@ -122,6 +124,12 @@ public class ApplicationModule {
|
|||||||
return timetableSync;
|
return timetableSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
AttendanceSyncContract provideAttendanceSync(AttendanceSync attendanceSync) {
|
||||||
|
return attendanceSync;
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
FirebaseJobDispatcher provideDispatcher() {
|
FirebaseJobDispatcher provideDispatcher() {
|
||||||
return new FirebaseJobDispatcher(new GooglePlayDriver(application));
|
return new FirebaseJobDispatcher(new GooglePlayDriver(application));
|
||||||
|
@ -7,7 +7,11 @@ import dagger.Provides;
|
|||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
import io.github.wulkanowy.di.annotations.PerFragment;
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceContract;
|
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.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.DashboardContract;
|
||||||
import io.github.wulkanowy.ui.main.dashboard.DashboardPresenter;
|
import io.github.wulkanowy.ui.main.dashboard.DashboardPresenter;
|
||||||
import io.github.wulkanowy.ui.main.grades.GradeHeaderItem;
|
import io.github.wulkanowy.ui.main.grades.GradeHeaderItem;
|
||||||
@ -47,6 +51,22 @@ public class FragmentModule {
|
|||||||
return dashboardPresenter;
|
return dashboardPresenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@Provides
|
||||||
|
AttendanceTabContract.Presenter provideAttendanceTabPresenter(AttendanceTabPresenter timetableTabPresenter) {
|
||||||
|
return timetableTabPresenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
AttendancePagerAdapter provideAttendancePagerAdapter() {
|
||||||
|
return new AttendancePagerAdapter(fragment.getChildFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
FlexibleAdapter<AttendanceHeaderItem> provideAttendanceTabAdapter() {
|
||||||
|
return new FlexibleAdapter<>(null);
|
||||||
|
}
|
||||||
|
|
||||||
@PerFragment
|
@PerFragment
|
||||||
@Provides
|
@Provides
|
||||||
TimetableContract.Presenter provideTimetablePresenter(TimetablePresenter timetablePresenter) {
|
TimetableContract.Presenter provideTimetablePresenter(TimetablePresenter timetablePresenter) {
|
||||||
@ -65,12 +85,12 @@ public class FragmentModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
|
FlexibleAdapter<TimetableHeaderItem> provideTimetableTabAdapter() {
|
||||||
return new FlexibleAdapter<>(null);
|
return new FlexibleAdapter<>(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
FlexibleAdapter<TimetableHeaderItem> provideTimetableTabAdapter() {
|
FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
|
||||||
return new FlexibleAdapter<>(null);
|
return new FlexibleAdapter<>(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package io.github.wulkanowy.services;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.R;
|
||||||
|
|
||||||
|
class GradeNotify extends NotificationService {
|
||||||
|
|
||||||
|
private static final String CHANNEL_ID = "Grade_Notify";
|
||||||
|
|
||||||
|
GradeNotify(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@TargetApi(26)
|
||||||
|
void createChannel() {
|
||||||
|
String channelName = getString(R.string.notify_grade_channel);
|
||||||
|
|
||||||
|
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, channelName,
|
||||||
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
|
notificationChannel.enableLights(true);
|
||||||
|
notificationChannel.enableVibration(true);
|
||||||
|
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
|
||||||
|
getManager().createNotificationChannel(notificationChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getChannelId() {
|
||||||
|
return CHANNEL_ID;
|
||||||
|
}
|
||||||
|
}
|
@ -3,29 +3,22 @@ package io.github.wulkanowy.services;
|
|||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
class NotificationService {
|
public class NotificationService {
|
||||||
|
|
||||||
private static final String CHANNEL_ID = "Wulkanowy_New_Grade_Channel";
|
|
||||||
|
|
||||||
private static final String CHANNEL_NAME = "New Grade Channel";
|
|
||||||
|
|
||||||
private NotificationManager manager;
|
private NotificationManager manager;
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
NotificationService(Context context) {
|
public NotificationService(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
createChannel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void notify(Notification notification) {
|
void notify(Notification notification) {
|
||||||
@ -33,23 +26,32 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NotificationCompat.Builder notificationBuilder() {
|
NotificationCompat.Builder notificationBuilder() {
|
||||||
return new NotificationCompat.Builder(context, CHANNEL_ID);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
createChannel();
|
||||||
|
}
|
||||||
|
return new NotificationCompat.Builder(context, getChannelId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(26)
|
public void cancelAll() {
|
||||||
private void createChannel() {
|
getManager().cancelAll();
|
||||||
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME,
|
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
|
||||||
notificationChannel.enableLights(true);
|
|
||||||
notificationChannel.enableVibration(true);
|
|
||||||
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
|
|
||||||
getManager().createNotificationChannel(notificationChannel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private NotificationManager getManager() {
|
NotificationManager getManager() {
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
}
|
}
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getString(@StringRes int stringId) {
|
||||||
|
return context.getString(stringId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(26)
|
||||||
|
void createChannel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
String getChannelId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import android.app.PendingIntent;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.firebase.jobdispatcher.Constraint;
|
import com.firebase.jobdispatcher.Constraint;
|
||||||
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
|
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
|
||||||
import com.firebase.jobdispatcher.GooglePlayDriver;
|
import com.firebase.jobdispatcher.GooglePlayDriver;
|
||||||
@ -14,6 +15,7 @@ import com.firebase.jobdispatcher.RetryStrategy;
|
|||||||
import com.firebase.jobdispatcher.SimpleJobService;
|
import com.firebase.jobdispatcher.SimpleJobService;
|
||||||
import com.firebase.jobdispatcher.Trigger;
|
import com.firebase.jobdispatcher.Trigger;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -27,32 +29,34 @@ import io.github.wulkanowy.utils.LogUtils;
|
|||||||
|
|
||||||
public class SyncJob extends SimpleJobService {
|
public class SyncJob extends SimpleJobService {
|
||||||
|
|
||||||
private static final int DEFAULT_INTERVAL_START = 60 * 50;
|
|
||||||
|
|
||||||
private static final int DEFAULT_INTERVAL_END = DEFAULT_INTERVAL_START + (60 * 40);
|
|
||||||
|
|
||||||
public static final String EXTRA_INTENT_KEY = "cardId";
|
public static final String EXTRA_INTENT_KEY = "cardId";
|
||||||
|
|
||||||
private List<Grade> gradeList;
|
public static final String JOB_TAG = "SyncJob";
|
||||||
|
|
||||||
|
private List<Grade> gradeList = new ArrayList<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RepositoryContract repository;
|
RepositoryContract repository;
|
||||||
|
|
||||||
public static void start(Context context) {
|
public static void start(Context context, int interval, boolean useOnlyWifi) {
|
||||||
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
|
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
|
||||||
|
|
||||||
dispatcher.mustSchedule(dispatcher.newJobBuilder()
|
dispatcher.mustSchedule(dispatcher.newJobBuilder()
|
||||||
.setLifetime(Lifetime.FOREVER)
|
.setLifetime(Lifetime.FOREVER)
|
||||||
.setService(SyncJob.class)
|
.setService(SyncJob.class)
|
||||||
.setTag("SyncJob")
|
.setTag(JOB_TAG)
|
||||||
.setRecurring(true)
|
.setRecurring(true)
|
||||||
.setTrigger(Trigger.executionWindow(DEFAULT_INTERVAL_START, DEFAULT_INTERVAL_END))
|
.setTrigger(Trigger.executionWindow(interval * 60, (interval + 10) * 60))
|
||||||
.setConstraints(Constraint.ON_ANY_NETWORK)
|
.setConstraints(useOnlyWifi ? Constraint.ON_UNMETERED_NETWORK : Constraint.ON_ANY_NETWORK)
|
||||||
.setReplaceCurrent(false)
|
.setReplaceCurrent(false)
|
||||||
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
|
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void stop(Context context) {
|
||||||
|
new FirebaseJobDispatcher(new GooglePlayDriver(context)).cancel(JOB_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
@ -62,28 +66,29 @@ public class SyncJob extends SimpleJobService {
|
|||||||
@Override
|
@Override
|
||||||
public int onRunJob(JobParameters job) {
|
public int onRunJob(JobParameters job) {
|
||||||
try {
|
try {
|
||||||
repository.loginCurrentUser();
|
repository.initLastUser();
|
||||||
repository.syncAll();
|
repository.syncAll();
|
||||||
|
|
||||||
gradeList = repository.getNewGrades();
|
gradeList = repository.getNewGrades();
|
||||||
|
|
||||||
if (!gradeList.isEmpty()) {
|
if (!gradeList.isEmpty() && repository.isNotifyEnable()) {
|
||||||
showNotification();
|
showNotification();
|
||||||
}
|
}
|
||||||
return JobService.RESULT_SUCCESS;
|
return JobService.RESULT_SUCCESS;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
LogUtils.error("During background synchronization an error occurred", e);
|
LogUtils.error("During background synchronization an error occurred", e);
|
||||||
return JobService.RESULT_FAIL_RETRY;
|
return JobService.RESULT_FAIL_RETRY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showNotification() {
|
private void showNotification() {
|
||||||
NotificationService service = new NotificationService(getApplicationContext());
|
GradeNotify gradeNotify = new GradeNotify(getApplicationContext());
|
||||||
|
|
||||||
service.notify(service.notificationBuilder()
|
gradeNotify.notify(gradeNotify.notificationBuilder()
|
||||||
.setContentTitle(getStringTitle())
|
.setContentTitle(getStringTitle())
|
||||||
.setContentText(getStringContent())
|
.setContentText(getStringContent())
|
||||||
.setSmallIcon(R.drawable.ic_stat_notify)
|
.setSmallIcon(R.drawable.ic_notify_grade)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
@ -25,6 +25,10 @@ public class BasePresenter<V extends BaseContract.View> implements BaseContract.
|
|||||||
view = null;
|
view = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isViewAttached() {
|
||||||
|
return view != null;
|
||||||
|
}
|
||||||
|
|
||||||
public final RepositoryContract getRepository() {
|
public final RepositoryContract getRepository() {
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.design.widget.TextInputLayout;
|
import android.support.design.widget.TextInputLayout;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
@ -97,14 +98,12 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
|||||||
|
|
||||||
@OnClick(R.id.login_activity_create_text)
|
@OnClick(R.id.login_activity_create_text)
|
||||||
void onCreateAccountButtonClick() {
|
void onCreateAccountButtonClick() {
|
||||||
CommonUtils.openInternalBrowserViewer(getApplicationContext(),
|
CommonUtils.openInternalBrowserViewer(this, AppConstant.VULCAN_CREATE_ACCOUNT_URL);
|
||||||
AppConstant.VULCAN_CREATE_ACCOUNT_URL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.login_activity_forgot_text)
|
@OnClick(R.id.login_activity_forgot_text)
|
||||||
void onForgotPasswordButtonClick() {
|
void onForgotPasswordButtonClick() {
|
||||||
CommonUtils.openInternalBrowserViewer(getApplicationContext(),
|
CommonUtils.openInternalBrowserViewer(this, AppConstant.VULCAN_FORGOT_PASS_URL);
|
||||||
AppConstant.VULCAN_FORGOT_PASS_URL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -211,6 +210,18 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showActionBar(boolean show) {
|
||||||
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
if (show) {
|
||||||
|
actionBar.show();
|
||||||
|
} else {
|
||||||
|
actionBar.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -33,6 +33,8 @@ public interface LoginContract {
|
|||||||
|
|
||||||
void hideSoftInput();
|
void hideSoftInput();
|
||||||
|
|
||||||
|
void showActionBar(boolean show);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
@PerActivity
|
||||||
@ -42,6 +44,8 @@ public interface LoginContract {
|
|||||||
|
|
||||||
void onStartAsync();
|
void onStartAsync();
|
||||||
|
|
||||||
|
void onDoInBackground(int stepNumber) throws Exception;
|
||||||
|
|
||||||
void onLoginProgress(int step);
|
void onLoginProgress(int step);
|
||||||
|
|
||||||
void onEndAsync(boolean success, Exception exception);
|
void onEndAsync(boolean success, Exception exception);
|
||||||
|
@ -17,35 +17,32 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
|
|
||||||
private LoginTask loginAsync;
|
private LoginTask loginAsync;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private String symbol;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
LoginPresenter(RepositoryContract repository) {
|
LoginPresenter(RepositoryContract repository) {
|
||||||
super(repository);
|
super(repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
if (loginAsync != null) {
|
|
||||||
loginAsync.cancel(true);
|
|
||||||
loginAsync = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attemptLogin(String email, String password, String symbol) {
|
public void attemptLogin(String email, String password, String symbol) {
|
||||||
getView().resetViewErrors();
|
getView().resetViewErrors();
|
||||||
|
|
||||||
|
this.email = email;
|
||||||
|
this.password = password;
|
||||||
|
this.symbol = getNormalizedSymbol(symbol);
|
||||||
|
|
||||||
if (!isAllFieldCorrect(password, email)) {
|
if (!isAllFieldCorrect(password, email)) {
|
||||||
getView().showSoftInput();
|
getView().showSoftInput();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getView().isNetworkConnected()) {
|
if (getView().isNetworkConnected()) {
|
||||||
// Dopóki używamy AsyncTask presenter będzie musiał "wiedzieć" o AsyncTaskach
|
loginAsync = new LoginTask(this);
|
||||||
loginAsync = new LoginTask(this,
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
getNormalizedSymbol(symbol));
|
|
||||||
loginAsync.execute();
|
loginAsync.execute();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -57,8 +54,23 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartAsync() {
|
public void onStartAsync() {
|
||||||
|
if (isViewAttached()) {
|
||||||
|
getView().showActionBar(false);
|
||||||
getView().showLoginProgress(true);
|
getView().showLoginProgress(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDoInBackground(int stepNumber) throws Exception {
|
||||||
|
switch (stepNumber) {
|
||||||
|
case 1:
|
||||||
|
getRepository().registerUser(email, password, symbol);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
getRepository().syncAll();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoginProgress(int step) {
|
public void onLoginProgress(int step) {
|
||||||
@ -73,25 +85,28 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
public void onEndAsync(boolean success, Exception exception) {
|
public void onEndAsync(boolean success, Exception exception) {
|
||||||
if (success) {
|
if (success) {
|
||||||
getView().openMainActivity();
|
getView().openMainActivity();
|
||||||
|
return;
|
||||||
} else if (exception instanceof BadCredentialsException) {
|
} else if (exception instanceof BadCredentialsException) {
|
||||||
getView().setErrorPassIncorrect();
|
getView().setErrorPassIncorrect();
|
||||||
getView().showSoftInput();
|
getView().showSoftInput();
|
||||||
getView().showLoginProgress(false);
|
|
||||||
} else if (exception instanceof AccountPermissionException) {
|
} else if (exception instanceof AccountPermissionException) {
|
||||||
getView().setErrorSymbolRequired();
|
getView().setErrorSymbolRequired();
|
||||||
getView().showSoftInput();
|
getView().showSoftInput();
|
||||||
getView().showLoginProgress(false);
|
|
||||||
} else {
|
} else {
|
||||||
getView().onError(getRepository().getErrorLoginMessage(exception));
|
getView().onError(getRepository().getErrorLoginMessage(exception));
|
||||||
getView().showLoginProgress(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getView().showActionBar(true);
|
||||||
|
getView().showLoginProgress(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCanceledAsync() {
|
public void onCanceledAsync() {
|
||||||
|
if (isViewAttached()) {
|
||||||
|
getView().showActionBar(true);
|
||||||
getView().showLoginProgress(false);
|
getView().showLoginProgress(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isEmailValid(String email) {
|
private boolean isEmailValid(String email) {
|
||||||
return email.contains("@") || email.contains("\\\\");
|
return email.contains("@") || email.contains("\\\\");
|
||||||
@ -140,4 +155,13 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
}
|
}
|
||||||
return correct;
|
return correct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
if (loginAsync != null) {
|
||||||
|
loginAsync.cancel(true);
|
||||||
|
loginAsync = null;
|
||||||
|
}
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,12 @@ import android.os.AsyncTask;
|
|||||||
|
|
||||||
public class LoginTask extends AsyncTask<Void, Integer, Boolean> {
|
public class LoginTask extends AsyncTask<Void, Integer, Boolean> {
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
private String symbol;
|
|
||||||
|
|
||||||
private LoginContract.Presenter presenter;
|
private LoginContract.Presenter presenter;
|
||||||
|
|
||||||
private Exception exception;
|
private Exception exception;
|
||||||
|
|
||||||
LoginTask(LoginContract.Presenter presenter, String email, String password, String symbol) {
|
LoginTask(LoginContract.Presenter presenter) {
|
||||||
this.presenter = presenter;
|
this.presenter = presenter;
|
||||||
this.email = email;
|
|
||||||
this.password = password;
|
|
||||||
this.symbol = symbol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,10 +21,10 @@ public class LoginTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
protected Boolean doInBackground(Void... params) {
|
protected Boolean doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
publishProgress(1);
|
publishProgress(1);
|
||||||
presenter.getRepository().loginUser(email, password, symbol);
|
presenter.onDoInBackground(1);
|
||||||
|
|
||||||
publishProgress(2);
|
publishProgress(2);
|
||||||
presenter.getRepository().syncAll();
|
presenter.onDoInBackground(2);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
return false;
|
return false;
|
||||||
|
@ -18,15 +18,15 @@ import butterknife.ButterKnife;
|
|||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.services.SyncJob;
|
import io.github.wulkanowy.services.SyncJob;
|
||||||
import io.github.wulkanowy.ui.base.BaseActivity;
|
import io.github.wulkanowy.ui.base.BaseActivity;
|
||||||
|
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
|
||||||
import io.github.wulkanowy.ui.main.dashboard.DashboardFragment;
|
import io.github.wulkanowy.ui.main.dashboard.DashboardFragment;
|
||||||
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.settings.SettingsFragment;
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity implements MainContract.View,
|
public class MainActivity extends BaseActivity implements MainContract.View,
|
||||||
AHBottomNavigation.OnTabSelectedListener, OnFragmentIsReadyListener {
|
AHBottomNavigation.OnTabSelectedListener, OnFragmentIsReadyListener {
|
||||||
|
|
||||||
private int initTabPosition = 0;
|
|
||||||
|
|
||||||
@BindView(R.id.main_activity_nav)
|
@BindView(R.id.main_activity_nav)
|
||||||
AHBottomNavigation bottomNavigation;
|
AHBottomNavigation bottomNavigation;
|
||||||
|
|
||||||
@ -51,15 +51,10 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
initTabPosition = getIntent().getIntExtra(SyncJob.EXTRA_INTENT_KEY, initTabPosition);
|
|
||||||
|
|
||||||
getActivityComponent().inject(this);
|
getActivityComponent().inject(this);
|
||||||
setButterKnife(ButterKnife.bind(this));
|
setButterKnife(ButterKnife.bind(this));
|
||||||
|
|
||||||
presenter.onStart(this);
|
presenter.onStart(this, getIntent().getIntExtra(SyncJob.EXTRA_INTENT_KEY, -1));
|
||||||
|
|
||||||
initiationViewPager();
|
|
||||||
initiationBottomNav();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,48 +96,44 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
|||||||
presenter.onFragmentIsReady();
|
presenter.onFragmentIsReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initiationBottomNav() {
|
@Override
|
||||||
bottomNavigation.addItem(new AHBottomNavigationItem(
|
public void initiationBottomNav(int tabPosition) {
|
||||||
getString(R.string.grades_text),
|
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.grades_text),
|
||||||
getResources().getDrawable(R.drawable.ic_menu_grade_26dp)
|
R.drawable.ic_menu_grade_26dp));
|
||||||
));
|
|
||||||
bottomNavigation.addItem(new AHBottomNavigationItem(
|
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.attendance_text),
|
||||||
getString(R.string.attendance_text),
|
R.drawable.ic_menu_attendance_24dp));
|
||||||
getResources().getDrawable(R.drawable.ic_menu_attendance_24dp)
|
|
||||||
));
|
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.dashboard_text),
|
||||||
bottomNavigation.addItem(new AHBottomNavigationItem(
|
R.drawable.ic_menu_dashboard_24dp));
|
||||||
getString(R.string.dashboard_text),
|
|
||||||
getResources().getDrawable(R.drawable.ic_menu_dashboard_24dp)
|
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.timetable_text),
|
||||||
));
|
R.drawable.ic_menu_timetable_24dp));
|
||||||
bottomNavigation.addItem(new AHBottomNavigationItem(
|
|
||||||
getString(R.string.lessonplan_text),
|
bottomNavigation.addItem(new AHBottomNavigationItem(getString(R.string.settings_text),
|
||||||
getResources().getDrawable(R.drawable.ic_menu_timetable_24dp)
|
R.drawable.ic_menu_other_24dp));
|
||||||
));
|
|
||||||
bottomNavigation.addItem(new AHBottomNavigationItem(
|
|
||||||
getString(R.string.settings_text),
|
|
||||||
getResources().getDrawable(R.drawable.ic_menu_other_24dp)
|
|
||||||
));
|
|
||||||
|
|
||||||
bottomNavigation.setAccentColor(getResources().getColor(R.color.colorPrimary));
|
bottomNavigation.setAccentColor(getResources().getColor(R.color.colorPrimary));
|
||||||
bottomNavigation.setInactiveColor(Color.BLACK);
|
bottomNavigation.setInactiveColor(Color.BLACK);
|
||||||
bottomNavigation.setBackgroundColor(getResources().getColor(R.color.colorBackgroundBottomNav));
|
bottomNavigation.setBackgroundColor(getResources().getColor(R.color.colorBackgroundBottomNav));
|
||||||
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
|
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
|
||||||
bottomNavigation.setOnTabSelectedListener(this);
|
bottomNavigation.setOnTabSelectedListener(this);
|
||||||
bottomNavigation.setCurrentItem(initTabPosition);
|
bottomNavigation.setCurrentItem(tabPosition);
|
||||||
bottomNavigation.setBehaviorTranslationEnabled(false);
|
bottomNavigation.setBehaviorTranslationEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initiationViewPager() {
|
@Override
|
||||||
|
public void initiationViewPager(int tabPosition) {
|
||||||
pagerAdapter.addFragment(new GradesFragment());
|
pagerAdapter.addFragment(new GradesFragment());
|
||||||
pagerAdapter.addFragment(new DashboardFragment());
|
pagerAdapter.addFragment(new AttendanceFragment());
|
||||||
pagerAdapter.addFragment(new DashboardFragment());
|
pagerAdapter.addFragment(new DashboardFragment());
|
||||||
pagerAdapter.addFragment(new TimetableFragment());
|
pagerAdapter.addFragment(new TimetableFragment());
|
||||||
pagerAdapter.addFragment(new DashboardFragment());
|
pagerAdapter.addFragment(new SettingsFragment());
|
||||||
|
|
||||||
viewPager.setPagingEnabled(false);
|
viewPager.setPagingEnabled(false);
|
||||||
viewPager.setAdapter(pagerAdapter);
|
viewPager.setAdapter(pagerAdapter);
|
||||||
viewPager.setOffscreenPageLimit(4);
|
viewPager.setOffscreenPageLimit(4);
|
||||||
viewPager.setCurrentItem(initTabPosition, false);
|
viewPager.setCurrentItem(tabPosition, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,11 +14,17 @@ public interface MainContract {
|
|||||||
void showActionBar();
|
void showActionBar();
|
||||||
|
|
||||||
void hideActionBar();
|
void hideActionBar();
|
||||||
|
|
||||||
|
void initiationViewPager(int tabPosition);
|
||||||
|
|
||||||
|
void initiationBottomNav(int tabPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
@PerActivity
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
|
void onStart(View view, int tabPositionIntent);
|
||||||
|
|
||||||
void onTabSelected(int position, boolean wasSelected);
|
void onTabSelected(int position, boolean wasSelected);
|
||||||
|
|
||||||
void onFragmentIsReady();
|
void onFragmentIsReady();
|
||||||
|
@ -17,10 +17,21 @@ public class MainPresenter extends BasePresenter<MainContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(MainContract.View view) {
|
public void onStart(MainContract.View view, int tabPositionIntent) {
|
||||||
super.onStart(view);
|
super.onStart(view);
|
||||||
getView().showProgressBar(true);
|
getView().showProgressBar(true);
|
||||||
getView().hideActionBar();
|
getView().hideActionBar();
|
||||||
|
|
||||||
|
int tabPosition;
|
||||||
|
|
||||||
|
if (tabPositionIntent != -1) {
|
||||||
|
tabPosition = tabPositionIntent;
|
||||||
|
} else {
|
||||||
|
tabPosition = getRepository().getStartupTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
getView().initiationBottomNav(tabPosition);
|
||||||
|
getView().initiationViewPager(tabPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,11 +43,11 @@ public class MainPresenter extends BasePresenter<MainContract.View>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFragmentIsReady() {
|
public void onFragmentIsReady() {
|
||||||
if (fragmentCount < 5) {
|
if (fragmentCount < 4) {
|
||||||
fragmentCount++;
|
fragmentCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fragmentCount == 5) {
|
if (fragmentCount == 4) {
|
||||||
getView().showActionBar();
|
getView().showActionBar();
|
||||||
getView().showProgressBar(false);
|
getView().showProgressBar(false);
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class TabsData {
|
public class TabsData {
|
||||||
|
|
||||||
private List<Fragment> fragments = new ArrayList<>();
|
private List<Fragment> fragments = new ArrayList<>();
|
||||||
|
|
||||||
private List<String> titles = new ArrayList<>();
|
private List<String> titles = new ArrayList<>();
|
||||||
|
|
||||||
Fragment getFragment(int index) {
|
public Fragment getFragment(int index) {
|
||||||
return fragments.get(index);
|
return fragments.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addFragment(Fragment fragment) {
|
public void addFragment(Fragment fragment) {
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
fragments.add(fragment);
|
fragments.add(fragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getFragmentsCount() {
|
public int getFragmentsCount() {
|
||||||
return fragments.size();
|
return fragments.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getTitle(int index) {
|
public String getTitle(int index) {
|
||||||
return titles.get(index);
|
return titles.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTitle(String title) {
|
public void addTitle(String title) {
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
titles.add(title);
|
titles.add(title);
|
||||||
}
|
}
|
@ -1,8 +1,9 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||||
import io.github.wulkanowy.ui.base.BaseContract;
|
import io.github.wulkanowy.ui.base.BaseContract;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
import io.github.wulkanowy.ui.main.TabsData;
|
||||||
|
|
||||||
public interface AttendanceContract {
|
public interface AttendanceContract {
|
||||||
|
|
||||||
@ -10,14 +11,22 @@ public interface AttendanceContract {
|
|||||||
|
|
||||||
void setActivityTitle();
|
void setActivityTitle();
|
||||||
|
|
||||||
|
void scrollViewPagerToPosition(int position);
|
||||||
|
|
||||||
|
void setTabDataToAdapter(TabsData tabsData);
|
||||||
|
|
||||||
|
void setAdapterWithTabLayout();
|
||||||
|
|
||||||
boolean isMenuVisible();
|
boolean isMenuVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerFragment
|
@PerActivity
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
|
void onFragmentActivated(boolean isVisible);
|
||||||
|
|
||||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
void onStart(View view, OnFragmentIsReadyListener listener);
|
||||||
|
|
||||||
void onFragmentVisible(boolean isVisible);
|
void setRestoredPosition(int position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,91 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
import io.github.wulkanowy.R;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
|
|
||||||
|
public class AttendanceDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
private static final String ARGUMENT_KEY = "Item";
|
||||||
|
|
||||||
|
private AttendanceLesson lesson;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_dialog_subject_value)
|
||||||
|
TextView subject;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_dialog_date_value)
|
||||||
|
TextView date;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_dialog_number_value)
|
||||||
|
TextView number;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_dialog_description_value)
|
||||||
|
TextView description;
|
||||||
|
|
||||||
|
public AttendanceDialogFragment() {
|
||||||
|
//empty constructor for fragment
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AttendanceDialogFragment newInstance(AttendanceLesson lesson) {
|
||||||
|
AttendanceDialogFragment dialogFragment = new AttendanceDialogFragment();
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putSerializable(ARGUMENT_KEY, lesson);
|
||||||
|
|
||||||
|
dialogFragment.setArguments(bundle);
|
||||||
|
|
||||||
|
return dialogFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (getArguments() != null) {
|
||||||
|
lesson = (AttendanceLesson) getArguments().getSerializable(ARGUMENT_KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.attendance_dialog, container, false);
|
||||||
|
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
|
if (!lesson.getSubject().isEmpty()) {
|
||||||
|
subject.setText(lesson.getSubject());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lesson.getDate().isEmpty()) {
|
||||||
|
date.setText(lesson.getDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != lesson.getNumber()) {
|
||||||
|
number.setText(String.valueOf(lesson.getNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
|
description.setText(lesson.getDescription());
|
||||||
|
|
||||||
|
if (lesson.getIsAbsenceUnexcused()) {
|
||||||
|
description.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
|
||||||
|
}
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.attendance_dialog_close)
|
||||||
|
void onClickCloseButton() {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
}
|
@ -2,30 +2,44 @@ package io.github.wulkanowy.ui.main.attendance;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.design.widget.TabLayout;
|
||||||
|
import android.support.v4.view.ViewPager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
import io.github.wulkanowy.ui.main.TabsData;
|
||||||
|
|
||||||
public class AttendanceFragment extends BaseFragment implements AttendanceContract.View {
|
public class AttendanceFragment extends BaseFragment implements AttendanceContract.View {
|
||||||
|
|
||||||
|
private static final String CURRENT_ITEM_KEY = "CurrentItem";
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_fragment_viewpager)
|
||||||
|
ViewPager viewPager;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_fragment_tab_layout)
|
||||||
|
TabLayout tabLayout;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AttendancePagerAdapter pagerAdapter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AttendanceContract.Presenter presenter;
|
AttendanceContract.Presenter presenter;
|
||||||
|
|
||||||
public AttendanceFragment() {
|
@Nullable
|
||||||
// empty constructor for fragment
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_attendance, container, false);
|
View view = inflater.inflate(R.layout.fragment_attendance, container, false);
|
||||||
|
|
||||||
FragmentComponent component = getFragmentComponent();
|
FragmentComponent component = getFragmentComponent();
|
||||||
@ -33,6 +47,10 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
|||||||
component.inject(this);
|
component.inject(this);
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
setButterKnife(ButterKnife.bind(this, view));
|
||||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
@ -42,18 +60,48 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
|||||||
public void setMenuVisibility(boolean menuVisible) {
|
public void setMenuVisibility(boolean menuVisible) {
|
||||||
super.setMenuVisibility(menuVisible);
|
super.setMenuVisibility(menuVisible);
|
||||||
if (presenter != null) {
|
if (presenter != null) {
|
||||||
presenter.onFragmentVisible(menuVisible);
|
presenter.onFragmentActivated(menuVisible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTabDataToAdapter(TabsData tabsData) {
|
||||||
|
pagerAdapter.setTabsData(tabsData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAdapterWithTabLayout() {
|
||||||
|
viewPager.setAdapter(pagerAdapter);
|
||||||
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scrollViewPagerToPosition(int position) {
|
||||||
|
viewPager.setCurrentItem(position, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setActivityTitle() {
|
public void setActivityTitle() {
|
||||||
setTitle(getString(R.string.dashboard_text));
|
setTitle(getString(R.string.attendance_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(String message) {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||||
|
message, Snackbar.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
|
||||||
presenter.onDestroy();
|
presenter.onDestroy();
|
||||||
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,161 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import butterknife.BindColor;
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
import eu.davidea.flexibleadapter.items.AbstractExpandableHeaderItem;
|
||||||
|
import eu.davidea.flexibleadapter.items.IFlexible;
|
||||||
|
import eu.davidea.viewholders.ExpandableViewHolder;
|
||||||
|
import io.github.wulkanowy.R;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.Day;
|
||||||
|
|
||||||
|
public class AttendanceHeaderItem
|
||||||
|
extends AbstractExpandableHeaderItem<AttendanceHeaderItem.HeaderViewHolder, AttendanceSubItem> {
|
||||||
|
|
||||||
|
private Day day;
|
||||||
|
|
||||||
|
AttendanceHeaderItem(Day day) {
|
||||||
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
AttendanceHeaderItem that = (AttendanceHeaderItem) o;
|
||||||
|
|
||||||
|
return new EqualsBuilder()
|
||||||
|
.append(day, that.day)
|
||||||
|
.isEquals();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return new HashCodeBuilder(17, 37)
|
||||||
|
.append(day)
|
||||||
|
.toHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutRes() {
|
||||||
|
return R.layout.attendance_header;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HeaderViewHolder createViewHolder(View view, FlexibleAdapter<IFlexible> adapter) {
|
||||||
|
return new HeaderViewHolder(view, adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, HeaderViewHolder holder,
|
||||||
|
int position, List<Object> payloads) {
|
||||||
|
holder.onBind(day, getSubItems());
|
||||||
|
}
|
||||||
|
|
||||||
|
static class HeaderViewHolder extends ExpandableViewHolder {
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_header_day)
|
||||||
|
TextView dayName;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_header_date)
|
||||||
|
TextView date;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_header_description)
|
||||||
|
TextView description;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_header_alert_image)
|
||||||
|
ImageView alert;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_header_free_name)
|
||||||
|
TextView freeName;
|
||||||
|
|
||||||
|
@BindColor(R.color.secondary_text)
|
||||||
|
int secondaryColor;
|
||||||
|
|
||||||
|
@BindColor(R.color.free_day)
|
||||||
|
int backgroundFreeDay;
|
||||||
|
|
||||||
|
@BindColor(android.R.color.black)
|
||||||
|
int black;
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
HeaderViewHolder(View view, FlexibleAdapter adapter) {
|
||||||
|
super(view, adapter);
|
||||||
|
view.setOnClickListener(this);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
context = view.getContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onBind(Day item, List<AttendanceSubItem> subItems) {
|
||||||
|
dayName.setText(StringUtils.capitalize(item.getDayName()));
|
||||||
|
date.setText(item.getDate());
|
||||||
|
|
||||||
|
int numberOfHours = countNotPresentHours(subItems);
|
||||||
|
description.setText((getContentView().getResources().getQuantityString(R.plurals.numberOfAbsences,
|
||||||
|
numberOfHours, numberOfHours)));
|
||||||
|
description.setVisibility(numberOfHours > 0 ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
alert.setVisibility(isSubItemsHasChanges(subItems) ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
freeName.setVisibility(subItems.isEmpty() ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
setInactiveHeader(item.getAttendanceLessons().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setInactiveHeader(boolean inactive) {
|
||||||
|
((FrameLayout) getContentView()).setForeground(inactive ? null : getSelectableDrawable());
|
||||||
|
dayName.setTextColor(inactive ? secondaryColor : black);
|
||||||
|
|
||||||
|
if (inactive) {
|
||||||
|
getContentView().setBackgroundColor(backgroundFreeDay);
|
||||||
|
} else {
|
||||||
|
getContentView().setBackgroundDrawable(context.getResources()
|
||||||
|
.getDrawable(R.drawable.ic_border));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable getSelectableDrawable() {
|
||||||
|
int[] attrs = new int[]{R.attr.selectableItemBackground};
|
||||||
|
TypedArray typedArray = context.obtainStyledAttributes(attrs);
|
||||||
|
Drawable drawable = typedArray.getDrawable(0);
|
||||||
|
typedArray.recycle();
|
||||||
|
return drawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countNotPresentHours(List<AttendanceSubItem> subItems) {
|
||||||
|
int i = 0;
|
||||||
|
for (AttendanceSubItem subItem : subItems) {
|
||||||
|
if (subItem.getLesson().getIsAbsenceUnexcused()) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSubItemsHasChanges(List<AttendanceSubItem> subItems) {
|
||||||
|
for (AttendanceSubItem subItem : subItems) {
|
||||||
|
if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson()
|
||||||
|
.getIsUnexcusedLateness()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,33 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter;
|
import io.github.wulkanowy.ui.base.BasePresenter;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
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;
|
||||||
|
|
||||||
public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
||||||
implements AttendanceContract.Presenter {
|
implements AttendanceContract.Presenter, AsyncListeners.OnFirstLoadingListener {
|
||||||
|
|
||||||
|
private AbstractTask loadingTask;
|
||||||
|
|
||||||
|
private List<String> dates = new ArrayList<>();
|
||||||
|
|
||||||
|
private TabsData tabsData = new TabsData();
|
||||||
|
|
||||||
private OnFragmentIsReadyListener listener;
|
private OnFragmentIsReadyListener listener;
|
||||||
|
|
||||||
|
private int positionToScroll = 0;
|
||||||
|
|
||||||
|
private boolean isFirstSight = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AttendancePresenter(RepositoryContract repository) {
|
AttendancePresenter(RepositoryContract repository) {
|
||||||
super(repository);
|
super(repository);
|
||||||
@ -25,13 +42,68 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
|||||||
getView().setActivityTitle();
|
getView().setActivityTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.listener.onFragmentIsReady();
|
if (dates.isEmpty()) {
|
||||||
|
dates = TimeUtils.getMondaysFromCurrentSchoolYear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (positionToScroll == 0) {
|
||||||
|
positionToScroll = dates.indexOf(TimeUtils.getDateOfCurrentMonday(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isFirstSight) {
|
||||||
|
isFirstSight = true;
|
||||||
|
|
||||||
|
loadingTask = new AbstractTask();
|
||||||
|
loadingTask.setOnFirstLoadingListener(this);
|
||||||
|
loadingTask.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFragmentVisible(boolean isVisible) {
|
public void onFragmentActivated(boolean isVisible) {
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
getView().setActivityTitle();
|
getView().setActivityTitle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDoInBackgroundLoading() throws Exception {
|
||||||
|
for (String date : dates) {
|
||||||
|
tabsData.addTitle(date);
|
||||||
|
tabsData.addFragment(AttendanceTabFragment.newInstance(date));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCanceledLoadingAsync() {
|
||||||
|
//do nothing
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEndLoadingAsync(boolean result, Exception exception) {
|
||||||
|
if (result) {
|
||||||
|
getView().setTabDataToAdapter(tabsData);
|
||||||
|
getView().setAdapterWithTabLayout();
|
||||||
|
getView().scrollViewPagerToPosition(positionToScroll);
|
||||||
|
listener.onFragmentIsReady();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRestoredPosition(int position) {
|
||||||
|
this.positionToScroll = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
isFirstSight = false;
|
||||||
|
|
||||||
|
if (loadingTask != null) {
|
||||||
|
loadingTask.cancel(true);
|
||||||
|
loadingTask = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,121 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
import eu.davidea.flexibleadapter.items.AbstractSectionableItem;
|
||||||
|
import eu.davidea.flexibleadapter.items.IFlexible;
|
||||||
|
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||||
|
import io.github.wulkanowy.R;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
|
|
||||||
|
class AttendanceSubItem
|
||||||
|
extends AbstractSectionableItem<AttendanceSubItem.SubItemViewHolder, AttendanceHeaderItem> {
|
||||||
|
|
||||||
|
private AttendanceLesson lesson;
|
||||||
|
|
||||||
|
AttendanceSubItem(AttendanceHeaderItem header, AttendanceLesson lesson) {
|
||||||
|
super(header);
|
||||||
|
this.lesson = lesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttendanceLesson getLesson() {
|
||||||
|
return lesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
AttendanceSubItem that = (AttendanceSubItem) o;
|
||||||
|
|
||||||
|
return new EqualsBuilder()
|
||||||
|
.append(lesson, that.lesson)
|
||||||
|
.isEquals();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return new HashCodeBuilder(17, 37)
|
||||||
|
.append(lesson)
|
||||||
|
.toHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutRes() {
|
||||||
|
return R.layout.attendance_subitem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SubItemViewHolder createViewHolder(View view, FlexibleAdapter<IFlexible> adapter) {
|
||||||
|
return new SubItemViewHolder(view, adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, SubItemViewHolder holder,
|
||||||
|
int position, List<Object> payloads) {
|
||||||
|
holder.onBind(lesson);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class SubItemViewHolder extends FlexibleViewHolder {
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_subItem_lesson)
|
||||||
|
TextView lessonName;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_subItem_number)
|
||||||
|
TextView lessonNumber;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_subItem_description)
|
||||||
|
TextView lessonDescription;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_subItem_alert_image)
|
||||||
|
ImageView alert;
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
private AttendanceLesson item;
|
||||||
|
|
||||||
|
SubItemViewHolder(View view, FlexibleAdapter adapter) {
|
||||||
|
super(view, adapter);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
context = view.getContext();
|
||||||
|
view.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onBind(AttendanceLesson lesson) {
|
||||||
|
item = lesson;
|
||||||
|
|
||||||
|
lessonName.setText(lesson.getSubject());
|
||||||
|
lessonNumber.setText((String.valueOf(lesson.getNumber())));
|
||||||
|
lessonDescription.setText(lesson.getDescription());
|
||||||
|
alert.setVisibility(lesson.getIsAbsenceUnexcused() || lesson.getIsUnexcusedLateness()
|
||||||
|
? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
super.onClick(view);
|
||||||
|
showDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showDialog() {
|
||||||
|
AttendanceDialogFragment dialogFragment = AttendanceDialogFragment.newInstance(item);
|
||||||
|
dialogFragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
|
||||||
|
dialogFragment.show(((FragmentActivity) context).getSupportFragmentManager(), item.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.ui.base.BaseContract;
|
||||||
|
|
||||||
|
public interface AttendanceTabContract {
|
||||||
|
|
||||||
|
interface View extends BaseContract.View {
|
||||||
|
|
||||||
|
void updateAdapterList(List<AttendanceHeaderItem> headerItems);
|
||||||
|
|
||||||
|
void onRefreshSuccess();
|
||||||
|
|
||||||
|
void hideRefreshingBar();
|
||||||
|
|
||||||
|
void showNoItem(boolean show);
|
||||||
|
|
||||||
|
void showProgressBar(boolean show);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Presenter extends BaseContract.Presenter<AttendanceTabContract.View> {
|
||||||
|
|
||||||
|
void onFragmentActivated(boolean isSelected);
|
||||||
|
|
||||||
|
void setArgumentDate(String date);
|
||||||
|
|
||||||
|
void onRefresh();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,146 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||||
|
import io.github.wulkanowy.R;
|
||||||
|
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||||
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
|
|
||||||
|
public class AttendanceTabFragment extends BaseFragment implements AttendanceTabContract.View,
|
||||||
|
SwipeRefreshLayout.OnRefreshListener {
|
||||||
|
|
||||||
|
private static final String ARGUMENT_KEY = "date";
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_tab_fragment_recycler)
|
||||||
|
RecyclerView recyclerView;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_tab_fragment_swipe_refresh)
|
||||||
|
SwipeRefreshLayout refreshLayout;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_tab_fragment_progress_bar)
|
||||||
|
View progressBar;
|
||||||
|
|
||||||
|
@BindView(R.id.attendance_tab_fragment_no_item_container)
|
||||||
|
View noItemView;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AttendanceTabContract.Presenter presenter;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FlexibleAdapter<AttendanceHeaderItem> adapter;
|
||||||
|
|
||||||
|
private boolean isFragmentVisible = false;
|
||||||
|
|
||||||
|
public static AttendanceTabFragment newInstance(String date) {
|
||||||
|
AttendanceTabFragment fragmentTab = new AttendanceTabFragment();
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString(ARGUMENT_KEY, date);
|
||||||
|
fragmentTab.setArguments(bundle);
|
||||||
|
|
||||||
|
return fragmentTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_attendance_tab, container, false);
|
||||||
|
|
||||||
|
FragmentComponent component = getFragmentComponent();
|
||||||
|
if (component != null) {
|
||||||
|
component.inject(this);
|
||||||
|
setButterKnife(ButterKnife.bind(this, view));
|
||||||
|
|
||||||
|
if (getArguments() != null) {
|
||||||
|
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||||
|
}
|
||||||
|
|
||||||
|
presenter.onStart(this);
|
||||||
|
presenter.onFragmentActivated(isFragmentVisible);
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUpOnViewCreated(View fragmentView) {
|
||||||
|
adapter.setAutoCollapseOnExpand(true);
|
||||||
|
adapter.setAutoScrollOnExpand(true);
|
||||||
|
adapter.expandItemsAtStartUp();
|
||||||
|
|
||||||
|
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||||
|
refreshLayout.setOnRefreshListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAdapterList(List<AttendanceHeaderItem> headerItems) {
|
||||||
|
adapter.updateDataSet(headerItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMenuVisibility(boolean menuVisible) {
|
||||||
|
super.setMenuVisibility(menuVisible);
|
||||||
|
isFragmentVisible = menuVisible;
|
||||||
|
if (presenter != null) {
|
||||||
|
presenter.onFragmentActivated(menuVisible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
presenter.onRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefreshSuccess() {
|
||||||
|
onError(R.string.timetable_refresh_success);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hideRefreshingBar() {
|
||||||
|
refreshLayout.setRefreshing(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showProgressBar(boolean show) {
|
||||||
|
progressBar.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showNoItem(boolean show) {
|
||||||
|
noItemView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(String message) {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||||
|
message, Snackbar.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
presenter.onDestroy();
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,178 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.Day;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
|
import io.github.wulkanowy.ui.base.BasePresenter;
|
||||||
|
import io.github.wulkanowy.utils.async.AbstractTask;
|
||||||
|
import io.github.wulkanowy.utils.async.AsyncListeners;
|
||||||
|
|
||||||
|
public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.View>
|
||||||
|
implements AttendanceTabContract.Presenter, AsyncListeners.OnRefreshListener,
|
||||||
|
AsyncListeners.OnFirstLoadingListener {
|
||||||
|
|
||||||
|
private AbstractTask refreshTask;
|
||||||
|
|
||||||
|
private AbstractTask loadingTask;
|
||||||
|
|
||||||
|
private List<AttendanceHeaderItem> headerItems = new ArrayList<>();
|
||||||
|
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
private boolean isFirstSight = false;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AttendanceTabPresenter(RepositoryContract repository) {
|
||||||
|
super(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart(AttendanceTabContract.View view) {
|
||||||
|
super.onStart(view);
|
||||||
|
getView().showProgressBar(true);
|
||||||
|
getView().showNoItem(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFragmentActivated(boolean isSelected) {
|
||||||
|
if (!isFirstSight && isSelected && isViewAttached()) {
|
||||||
|
isFirstSight = true;
|
||||||
|
|
||||||
|
loadingTask = new AbstractTask();
|
||||||
|
loadingTask.setOnFirstLoadingListener(this);
|
||||||
|
loadingTask.execute();
|
||||||
|
} else if (!isSelected) {
|
||||||
|
cancelAsyncTasks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
if (getView().isNetworkConnected()) {
|
||||||
|
refreshTask = new AbstractTask();
|
||||||
|
refreshTask.setOnRefreshListener(this);
|
||||||
|
refreshTask.execute();
|
||||||
|
} else {
|
||||||
|
getView().onNoNetworkError();
|
||||||
|
getView().hideRefreshingBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDoInBackgroundRefresh() throws Exception {
|
||||||
|
syncData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCanceledRefreshAsync() {
|
||||||
|
if (isViewAttached()) {
|
||||||
|
getView().hideRefreshingBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEndRefreshAsync(boolean result, Exception exception) {
|
||||||
|
if (result) {
|
||||||
|
loadingTask = new AbstractTask();
|
||||||
|
loadingTask.setOnFirstLoadingListener(this);
|
||||||
|
loadingTask.execute();
|
||||||
|
|
||||||
|
getView().onRefreshSuccess();
|
||||||
|
} else {
|
||||||
|
getView().onError(getRepository().getErrorLoginMessage(exception));
|
||||||
|
}
|
||||||
|
getView().hideRefreshingBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDoInBackgroundLoading() throws Exception {
|
||||||
|
Week week = getRepository().getWeek(date);
|
||||||
|
|
||||||
|
if (week == null || !week.getIsAttendanceSynced()) {
|
||||||
|
syncData();
|
||||||
|
week = getRepository().getWeek(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Day> dayList = week.getDayList();
|
||||||
|
|
||||||
|
headerItems = new ArrayList<>();
|
||||||
|
|
||||||
|
boolean isEmptyWeek = true;
|
||||||
|
|
||||||
|
for (Day day : dayList) {
|
||||||
|
day.resetAttendanceLessons();
|
||||||
|
AttendanceHeaderItem headerItem = new AttendanceHeaderItem(day);
|
||||||
|
|
||||||
|
if (isEmptyWeek) {
|
||||||
|
isEmptyWeek = day.getAttendanceLessons().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AttendanceLesson> lessonList = day.getAttendanceLessons();
|
||||||
|
|
||||||
|
List<AttendanceSubItem> subItems = new ArrayList<>();
|
||||||
|
|
||||||
|
for (AttendanceLesson lesson : lessonList) {
|
||||||
|
lesson.setDescription(getRepository().getAttendanceLessonDescription(lesson));
|
||||||
|
subItems.add(new AttendanceSubItem(headerItem, lesson));
|
||||||
|
}
|
||||||
|
|
||||||
|
headerItem.setSubItems(subItems);
|
||||||
|
headerItem.setExpanded(false);
|
||||||
|
headerItems.add(headerItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEmptyWeek) {
|
||||||
|
headerItems = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCanceledLoadingAsync() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEndLoadingAsync(boolean result, Exception exception) {
|
||||||
|
if (headerItems.isEmpty()) {
|
||||||
|
getView().showNoItem(true);
|
||||||
|
getView().updateAdapterList(null);
|
||||||
|
} else {
|
||||||
|
getView().updateAdapterList(headerItems);
|
||||||
|
getView().showNoItem(false);
|
||||||
|
}
|
||||||
|
getView().showProgressBar(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setArgumentDate(String date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncData() throws Exception {
|
||||||
|
getRepository().syncAttendance(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelAsyncTasks() {
|
||||||
|
if (refreshTask != null) {
|
||||||
|
refreshTask.cancel(true);
|
||||||
|
refreshTask = null;
|
||||||
|
}
|
||||||
|
if (loadingTask != null) {
|
||||||
|
loadingTask.cancel(true);
|
||||||
|
loadingTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
cancelAsyncTasks();
|
||||||
|
isFirstSight = false;
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
}
|
@ -91,15 +91,26 @@ public class GradeHeaderItem
|
|||||||
numberText.setText(resources.getQuantityString(R.plurals.numberOfGradesPlurals,
|
numberText.setText(resources.getQuantityString(R.plurals.numberOfGradesPlurals,
|
||||||
subItems.size(), subItems.size()));
|
subItems.size(), subItems.size()));
|
||||||
averageText.setText(getGradesAverageString(item));
|
averageText.setText(getGradesAverageString(item));
|
||||||
alertImage.setVisibility(isSubItemsRead(subItems) ? View.INVISIBLE : View.VISIBLE);
|
alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems)
|
||||||
alertImage.setTag(item.getName());
|
? View.INVISIBLE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSubItemsRead(List<GradesSubItem> subItems) {
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
super.onClick(view);
|
||||||
|
if (subjectName.getLineCount() == 1) {
|
||||||
|
subjectName.setMaxLines(3);
|
||||||
|
} else {
|
||||||
|
subjectName.setMaxLines(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
|
||||||
boolean isRead = true;
|
boolean isRead = true;
|
||||||
|
|
||||||
for (GradesSubItem item : subItems) {
|
for (GradesSubItem item : subItems) {
|
||||||
isRead = item.getGrade().getRead();
|
isRead = item.getGrade().getRead();
|
||||||
|
item.setSubjectAlertImage(alertImage);
|
||||||
}
|
}
|
||||||
return isRead;
|
return isRead;
|
||||||
}
|
}
|
||||||
|
@ -71,15 +71,16 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDoInBackgroundRefresh() throws Exception {
|
public void onDoInBackgroundRefresh() throws Exception {
|
||||||
getRepository().loginCurrentUser();
|
|
||||||
getRepository().syncSubjects();
|
getRepository().syncSubjects();
|
||||||
getRepository().syncGrades();
|
getRepository().syncGrades();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCanceledRefreshAsync() {
|
public void onCanceledRefreshAsync() {
|
||||||
|
if (isViewAttached()) {
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEndRefreshAsync(boolean success, Exception exception) {
|
public void onEndRefreshAsync(boolean success, Exception exception) {
|
||||||
@ -108,6 +109,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
headerItems = new ArrayList<>();
|
headerItems = new ArrayList<>();
|
||||||
|
|
||||||
for (Subject subject : subjectList) {
|
for (Subject subject : subjectList) {
|
||||||
|
subject.resetGradeList();
|
||||||
List<Grade> gradeList = subject.getGradeList();
|
List<Grade> gradeList = subject.getGradeList();
|
||||||
|
|
||||||
if (!gradeList.isEmpty()) {
|
if (!gradeList.isEmpty()) {
|
||||||
@ -138,13 +140,14 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
} else {
|
} else {
|
||||||
getView().updateAdapterList(headerItems);
|
getView().updateAdapterList(headerItems);
|
||||||
getView().showNoItem(false);
|
getView().showNoItem(false);
|
||||||
listener.onFragmentIsReady();
|
|
||||||
}
|
}
|
||||||
|
listener.onFragmentIsReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
isFirstSight = false;
|
||||||
|
|
||||||
if (refreshTask != null) {
|
if (refreshTask != null) {
|
||||||
refreshTask.cancel(true);
|
refreshTask.cancel(true);
|
||||||
refreshTask = null;
|
refreshTask = null;
|
||||||
@ -153,5 +156,6 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
loadingTask.cancel(true);
|
loadingTask.cancel(true);
|
||||||
loadingTask = null;
|
loadingTask = null;
|
||||||
}
|
}
|
||||||
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package io.github.wulkanowy.ui.main.grades;
|
package io.github.wulkanowy.ui.main.grades;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
@ -27,6 +26,8 @@ public class GradesSubItem
|
|||||||
|
|
||||||
private static int numberOfNotReadGrade;
|
private static int numberOfNotReadGrade;
|
||||||
|
|
||||||
|
private View subjectAlertImage;
|
||||||
|
|
||||||
GradesSubItem(GradeHeaderItem header, Grade grade) {
|
GradesSubItem(GradeHeaderItem header, Grade grade) {
|
||||||
super(header);
|
super(header);
|
||||||
this.grade = grade;
|
this.grade = grade;
|
||||||
@ -36,6 +37,10 @@ public class GradesSubItem
|
|||||||
return grade;
|
return grade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSubjectAlertImage(View subjectAlertImage) {
|
||||||
|
this.subjectAlertImage = subjectAlertImage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
@ -68,7 +73,7 @@ public class GradesSubItem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindViewHolder(FlexibleAdapter adapter, SubItemViewHolder holder, int position, List payloads) {
|
public void bindViewHolder(FlexibleAdapter adapter, SubItemViewHolder holder, int position, List payloads) {
|
||||||
holder.onBind(grade);
|
holder.onBind(grade, subjectAlertImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class SubItemViewHolder extends FlexibleViewHolder {
|
static class SubItemViewHolder extends FlexibleViewHolder {
|
||||||
@ -85,6 +90,8 @@ public class GradesSubItem
|
|||||||
@BindView(R.id.grade_subitem_alert_image)
|
@BindView(R.id.grade_subitem_alert_image)
|
||||||
View alert;
|
View alert;
|
||||||
|
|
||||||
|
private View subjectAlertImage;
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private Grade item;
|
private Grade item;
|
||||||
@ -96,8 +103,9 @@ public class GradesSubItem
|
|||||||
view.setOnClickListener(this);
|
view.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBind(Grade item) {
|
void onBind(Grade item, View subjectAlertImage) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
|
this.subjectAlertImage = subjectAlertImage;
|
||||||
|
|
||||||
value.setText(item.getValue());
|
value.setText(item.getValue());
|
||||||
value.setBackgroundResource(item.getValueColor());
|
value.setBackgroundResource(item.getValueColor());
|
||||||
@ -119,8 +127,7 @@ public class GradesSubItem
|
|||||||
numberOfNotReadGrade--;
|
numberOfNotReadGrade--;
|
||||||
|
|
||||||
if (numberOfNotReadGrade == 0) {
|
if (numberOfNotReadGrade == 0) {
|
||||||
((Activity) context).findViewById(R.id.grade_fragment_container)
|
subjectAlertImage.setVisibility(View.INVISIBLE);
|
||||||
.findViewWithTag(item.getSubject()).setVisibility(View.INVISIBLE);
|
|
||||||
}
|
}
|
||||||
item.setIsNew(false);
|
item.setIsNew(false);
|
||||||
item.setRead(true);
|
item.setRead(true);
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.settings;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.R;
|
||||||
|
import io.github.wulkanowy.services.SyncJob;
|
||||||
|
|
||||||
|
public class SettingsFragment extends PreferenceFragmentCompat
|
||||||
|
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
public static final String SHARED_KEY_START_TAB = "startup_tab";
|
||||||
|
|
||||||
|
public static final String SHARED_KEY_SERVICES_ENABLE = "services_enable";
|
||||||
|
|
||||||
|
public static final String SHARED_KEY_NOTIFY_ENABLE = "notify_enable";
|
||||||
|
|
||||||
|
public static final String SHARED_KEY_SERVICES_INTERVAL = "services_interval";
|
||||||
|
|
||||||
|
public static final String SHARED_KEY_SERVICES_MOBILE_DISABLED = "services_disable_mobile";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
if (key.equals(SHARED_KEY_SERVICES_ENABLE) || key.equals(SHARED_KEY_SERVICES_INTERVAL)
|
||||||
|
|| key.equals(SHARED_KEY_SERVICES_MOBILE_DISABLED)) {
|
||||||
|
launchServices(sharedPreferences.getBoolean(SHARED_KEY_SERVICES_ENABLE, true),
|
||||||
|
sharedPreferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchServices(boolean start, SharedPreferences sharedPref) {
|
||||||
|
if (start) {
|
||||||
|
int newInterval = Integer.parseInt(sharedPref.getString(SHARED_KEY_SERVICES_INTERVAL, "60"));
|
||||||
|
boolean useOnlyWifi = sharedPref.getBoolean(SHARED_KEY_SERVICES_MOBILE_DISABLED, false);
|
||||||
|
|
||||||
|
SyncJob.stop(getContext());
|
||||||
|
SyncJob.start(getContext(), newInterval, useOnlyWifi);
|
||||||
|
} else {
|
||||||
|
SyncJob.stop(getContext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMenuVisibility(boolean menuVisible) {
|
||||||
|
super.setMenuVisibility(menuVisible);
|
||||||
|
if (menuVisible) {
|
||||||
|
getActivity().setTitle(R.string.settings_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
getPreferenceScreen().getSharedPreferences()
|
||||||
|
.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
getPreferenceScreen().getSharedPreferences()
|
||||||
|
.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.main.timetable;
|
|||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||||
import io.github.wulkanowy.ui.base.BaseContract;
|
import io.github.wulkanowy.ui.base.BaseContract;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
import io.github.wulkanowy.ui.main.TabsData;
|
||||||
|
|
||||||
public interface TimetableContract {
|
public interface TimetableContract {
|
||||||
|
|
||||||
@ -16,20 +17,16 @@ public interface TimetableContract {
|
|||||||
|
|
||||||
void setAdapterWithTabLayout();
|
void setAdapterWithTabLayout();
|
||||||
|
|
||||||
void setChildFragmentSelected(int position, boolean selected);
|
|
||||||
|
|
||||||
boolean isMenuVisible();
|
boolean isMenuVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
@PerActivity
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void onFragmentVisible(boolean isVisible);
|
void onFragmentActivated(boolean isVisible);
|
||||||
|
|
||||||
void onTabSelected(int position);
|
|
||||||
|
|
||||||
void onTabUnselected(int position);
|
|
||||||
|
|
||||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
void onStart(View view, OnFragmentIsReadyListener listener);
|
||||||
|
|
||||||
|
void setRestoredPosition(int position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Lesson;
|
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||||
|
|
||||||
public class TimetableDialogFragment extends DialogFragment {
|
public class TimetableDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
private static final String ARGUMENT_KEY = "Item";
|
private static final String ARGUMENT_KEY = "Item";
|
||||||
|
|
||||||
private Lesson lesson;
|
private TimetableLesson lesson;
|
||||||
|
|
||||||
@BindView(R.id.timetable_dialog_lesson_value)
|
@BindView(R.id.timetable_dialog_lesson_value)
|
||||||
TextView lessonName;
|
TextView lessonName;
|
||||||
@ -54,7 +54,7 @@ public class TimetableDialogFragment extends DialogFragment {
|
|||||||
//empty constructor for fragment
|
//empty constructor for fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimetableDialogFragment newInstance(Lesson lesson) {
|
public static TimetableDialogFragment newInstance(TimetableLesson lesson) {
|
||||||
TimetableDialogFragment dialogFragment = new TimetableDialogFragment();
|
TimetableDialogFragment dialogFragment = new TimetableDialogFragment();
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
@ -69,7 +69,7 @@ public class TimetableDialogFragment extends DialogFragment {
|
|||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
lesson = (Lesson) getArguments().getSerializable(ARGUMENT_KEY);
|
lesson = (TimetableLesson) getArguments().getSerializable(ARGUMENT_KEY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,11 @@ import io.github.wulkanowy.R;
|
|||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
import io.github.wulkanowy.ui.main.TabsData;
|
||||||
|
|
||||||
public class TimetableFragment extends BaseFragment implements TimetableContract.View, TabLayout.OnTabSelectedListener {
|
public class TimetableFragment extends BaseFragment implements TimetableContract.View {
|
||||||
|
|
||||||
|
private static final String CURRENT_ITEM_KEY = "CurrentItem";
|
||||||
|
|
||||||
@BindView(R.id.timetable_fragment_viewpager)
|
@BindView(R.id.timetable_fragment_viewpager)
|
||||||
ViewPager viewPager;
|
ViewPager viewPager;
|
||||||
@ -43,6 +46,10 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
component.inject(this);
|
component.inject(this);
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
setButterKnife(ButterKnife.bind(this, view));
|
||||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@ -51,25 +58,10 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
public void setMenuVisibility(boolean menuVisible) {
|
public void setMenuVisibility(boolean menuVisible) {
|
||||||
super.setMenuVisibility(menuVisible);
|
super.setMenuVisibility(menuVisible);
|
||||||
if (presenter != null) {
|
if (presenter != null) {
|
||||||
presenter.onFragmentVisible(menuVisible);
|
presenter.onFragmentActivated(menuVisible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabSelected(TabLayout.Tab tab) {
|
|
||||||
presenter.onTabSelected(tab.getPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabUnselected(TabLayout.Tab tab) {
|
|
||||||
presenter.onTabUnselected(tab.getPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabReselected(TabLayout.Tab tab) {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTabDataToAdapter(TabsData tabsData) {
|
public void setTabDataToAdapter(TabsData tabsData) {
|
||||||
pagerAdapter.setTabsData(tabsData);
|
pagerAdapter.setTabsData(tabsData);
|
||||||
@ -78,14 +70,7 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
@Override
|
@Override
|
||||||
public void setAdapterWithTabLayout() {
|
public void setAdapterWithTabLayout() {
|
||||||
viewPager.setAdapter(pagerAdapter);
|
viewPager.setAdapter(pagerAdapter);
|
||||||
|
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
tabLayout.addOnTabSelectedListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setChildFragmentSelected(int position, boolean selected) {
|
|
||||||
((TimetableTabFragment) pagerAdapter.getItem(position)).setSelected(selected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -95,7 +80,7 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setActivityTitle() {
|
public void setActivityTitle() {
|
||||||
setTitle(getString(R.string.lessonplan_text));
|
setTitle(getString(R.string.timetable_text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -106,6 +91,12 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
presenter.onDestroy();
|
presenter.onDestroy();
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user