forked from github/wulkanowy-mirror
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
d4b172e022 | |||
b4c765b482 | |||
3f1fff6d96 | |||
b59008a90f | |||
74c0dda999 | |||
2288ceffb8 | |||
ffe8511e3f | |||
34205e4a8b | |||
ef648c7f8b | |||
3592946e6f | |||
859f8dc319 | |||
9c97962e89 | |||
a4445a8a97 | |||
3f54d13b6b | |||
5685e73e46 | |||
e9b357e92d | |||
62bc00cd68 | |||
54e6aee82e | |||
3000c077c4 | |||
7d5072b529 | |||
052d5e3911 | |||
0014b74c6b | |||
08dd316aee |
@ -199,24 +199,40 @@ jobs:
|
|||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
|
|
||||||
build_check_tests:
|
build-test-deploy:
|
||||||
jobs:
|
jobs:
|
||||||
- build
|
- build:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
- lint:
|
- lint:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
- app-test:
|
- app-test:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
- api-test:
|
- api-test:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
- instrumented:
|
- instrumented:
|
||||||
requires:
|
filters:
|
||||||
- build
|
tags:
|
||||||
|
only: /.*/
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
- sonarcube:
|
- sonarcube:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
- lint
|
- lint
|
||||||
@ -227,5 +243,7 @@ workflows:
|
|||||||
requires:
|
requires:
|
||||||
- instrumented
|
- instrumented
|
||||||
filters:
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /\d+\.\d+\.\d+/
|
||||||
branches:
|
branches:
|
||||||
only: master
|
ignore: /.*/
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
[](https://bettercodehub.com/)
|
[](https://bettercodehub.com/)
|
||||||
[](https://scrutinizer-ci.com/g/wulkanowy/wulkanowy/?branch=master)
|
[](https://scrutinizer-ci.com/g/wulkanowy/wulkanowy/?branch=master)
|
||||||
[](https://bintray.com/wulkanowy/wulkanowy/api)
|
[](https://bintray.com/wulkanowy/wulkanowy/api)
|
||||||
[](https://discord.gg/JMG2rhJ)
|
[](https://discord.gg/vccAQBr)
|
||||||
|
|
||||||
[Pobierz wersję beta](https://play.google.com/store/apps/details?id=io.github.wulkanowy&utm_source=vcs)
|
[Pobierz wersję beta](https://play.google.com/store/apps/details?id=io.github.wulkanowy&utm_source=vcs)
|
||||||
|
|
||||||
|
@ -58,13 +58,12 @@ public class Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cookies = new Cookies();
|
|
||||||
this.symbol = new Login(this).login(email, password, symbol);
|
this.symbol = new Login(this).login(email, password, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLoggedIn() {
|
private boolean isLoggedIn() {
|
||||||
return getCookies().size() > 0 && lastSuccessRequest != null &&
|
return getCookies().size() > 0 && lastSuccessRequest != null &&
|
||||||
29 > TimeUnit.MILLISECONDS.toMinutes(new Date().getTime() - lastSuccessRequest.getTime());
|
5 > TimeUnit.MILLISECONDS.toMinutes(new Date().getTime() - lastSuccessRequest.getTime());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +118,7 @@ public class Client {
|
|||||||
|
|
||||||
this.cookies.addItems(response.cookies());
|
this.cookies.addItems(response.cookies());
|
||||||
|
|
||||||
Document doc = checkForErrors(response.parse());
|
Document doc = checkForErrors(response.parse(), response.statusCode());
|
||||||
|
|
||||||
if (loginBefore) {
|
if (loginBefore) {
|
||||||
lastSuccessRequest = new Date();
|
lastSuccessRequest = new Date();
|
||||||
@ -143,7 +142,9 @@ public class Client {
|
|||||||
|
|
||||||
this.cookies.addItems(response.cookies());
|
this.cookies.addItems(response.cookies());
|
||||||
|
|
||||||
return checkForErrors(response.parse());
|
response.bufferUp(); // fixes cert parsing issues #109
|
||||||
|
|
||||||
|
return checkForErrors(response.parse(), response.statusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJsonStringByUrl(String url) throws IOException, VulcanException {
|
public String getJsonStringByUrl(String url) throws IOException, VulcanException {
|
||||||
@ -181,7 +182,7 @@ public class Client {
|
|||||||
return response.body();
|
return response.body();
|
||||||
}
|
}
|
||||||
|
|
||||||
Document checkForErrors(Document doc) throws VulcanException {
|
Document checkForErrors(Document doc, int code) throws VulcanException {
|
||||||
lastSuccessRequest = null;
|
lastSuccessRequest = null;
|
||||||
|
|
||||||
String title = doc.select("title").text();
|
String title = doc.select("title").text();
|
||||||
@ -195,7 +196,7 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("Błąd strony".equals(title)) {
|
if ("Błąd strony".equals(title)) {
|
||||||
throw new VulcanException("Nieznany błąd");
|
throw new NotLoggedInErrorException(title + " " + doc.selectFirst("p, body") + ", status: " + code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
|
@ -65,12 +65,12 @@ public class StudentAndParent implements SnP {
|
|||||||
return getBaseUrl();
|
return getBaseUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get url to uonetplus-opiekun.vulcan.net.pl
|
// get url to uonetplus-opiekun.fakelog.cf
|
||||||
Document startPage = client.getPageByUrl(START_PAGE_URL);
|
Document startPage = client.getPageByUrl(START_PAGE_URL);
|
||||||
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("You are probably not logged in. Force login");
|
throw new VulcanException("Na pewno używasz konta z dostępem do Witryny ucznia i rodzica?");
|
||||||
}
|
}
|
||||||
|
|
||||||
String snpPageUrl = studentTileLink.attr("href");
|
String snpPageUrl = studentTileLink.attr("href");
|
||||||
@ -84,7 +84,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("You are probably not logged in");
|
throw new NotLoggedInErrorException("You are probably not logged in " + snpPageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path[2];
|
return path[2];
|
||||||
|
@ -63,7 +63,7 @@ public class AttendanceTable {
|
|||||||
for (int i = 1; i < size; i++) {
|
for (int i = 1; i < size; i++) {
|
||||||
Lesson lesson = new Lesson();
|
Lesson lesson = new Lesson();
|
||||||
lesson.setDate(days.get(i - 1).getDate());
|
lesson.setDate(days.get(i - 1).getDate());
|
||||||
lesson.setNumber(hours.get(0).text());
|
lesson.setNumber(Integer.valueOf(hours.get(0).text()));
|
||||||
|
|
||||||
addLessonDetails(lesson, hours.get(i));
|
addLessonDetails(lesson, hours.get(i));
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.api.generic;
|
|||||||
|
|
||||||
public class Lesson {
|
public class Lesson {
|
||||||
|
|
||||||
private String number = "";
|
private int number = 0;
|
||||||
|
|
||||||
private String subject = "";
|
private String subject = "";
|
||||||
|
|
||||||
@ -48,12 +48,13 @@ public class Lesson {
|
|||||||
|
|
||||||
private boolean isExemption = false;
|
private boolean isExemption = false;
|
||||||
|
|
||||||
public String getNumber() {
|
public int getNumber() {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumber(String number) {
|
public Lesson setNumber(int number) {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubject() {
|
public String getSubject() {
|
||||||
|
@ -9,6 +9,7 @@ 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.NotLoggedInErrorException;
|
||||||
import io.github.wulkanowy.api.VulcanException;
|
import io.github.wulkanowy.api.VulcanException;
|
||||||
|
|
||||||
public class Login {
|
public class Login {
|
||||||
@ -27,6 +28,10 @@ public class Login {
|
|||||||
public String login(String email, String password, String symbol) throws VulcanException, IOException {
|
public String login(String email, String password, String symbol) throws VulcanException, IOException {
|
||||||
Document certDoc = sendCredentials(email, password);
|
Document certDoc = sendCredentials(email, password);
|
||||||
|
|
||||||
|
if ("Błąd".equals(certDoc.title())) {
|
||||||
|
throw new NotLoggedInErrorException(certDoc.selectFirst("body").text());
|
||||||
|
}
|
||||||
|
|
||||||
return sendCertificate(certDoc, symbol);
|
return sendCertificate(certDoc, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,29 +41,29 @@ public class Login {
|
|||||||
{"Password", password}
|
{"Password", password}
|
||||||
};
|
};
|
||||||
|
|
||||||
String nextUrl = LOGIN_PAGE_URL;
|
Document nextDoc = sendCredentialsData(credentials, LOGIN_PAGE_URL);
|
||||||
Document loginPage = client.getPageByUrl(nextUrl, false);
|
|
||||||
|
|
||||||
Element formFirst = loginPage.select("#form1").first();
|
Element errorMessage = nextDoc.selectFirst(".ErrorMessage, #ErrorTextLabel");
|
||||||
if (null != formFirst) { // on adfs login
|
|
||||||
Document formSecond = client.postPageByUrl(
|
|
||||||
formFirst.attr("abs:action"),
|
|
||||||
getFormStateParams(formFirst, "", "")
|
|
||||||
);
|
|
||||||
credentials = getFormStateParams(formSecond, email, password);
|
|
||||||
nextUrl = formSecond.select("#form1").first().attr("abs:action");
|
|
||||||
} else if (!"Logowanie".equals(loginPage.select("#h1Default").text())) {
|
|
||||||
throw new VulcanException("Expected login page, got page with title: " + loginPage.title());
|
|
||||||
}
|
|
||||||
|
|
||||||
Document html = client.postPageByUrl(nextUrl, credentials);
|
|
||||||
|
|
||||||
Element errorMessage = html.select(".ErrorMessage, #ErrorTextLabel").first();
|
|
||||||
if (null != errorMessage) {
|
if (null != errorMessage) {
|
||||||
throw new BadCredentialsException(errorMessage.text());
|
throw new BadCredentialsException(errorMessage.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
return html;
|
return nextDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document sendCredentialsData(String[][] credentials, String nextUrl) throws IOException, VulcanException {
|
||||||
|
Element formFirst = client.getPageByUrl(nextUrl, false).selectFirst("#form1");
|
||||||
|
|
||||||
|
if (null != formFirst) { // only on adfs login
|
||||||
|
Document formSecond = client.postPageByUrl(
|
||||||
|
formFirst.attr("abs:action"),
|
||||||
|
getFormStateParams(formFirst, "", "")
|
||||||
|
);
|
||||||
|
credentials = getFormStateParams(formSecond, credentials[0][1], credentials[1][1]);
|
||||||
|
nextUrl = formSecond.selectFirst("#form1").attr("abs:action");
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.postPageByUrl(nextUrl, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[][] getFormStateParams(Element form, String email, String password) {
|
private String[][] getFormStateParams(Element form, String email, String password) {
|
||||||
@ -77,13 +82,7 @@ public class Login {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String sendCertificate(Document doc, String defaultSymbol) throws IOException, VulcanException {
|
String sendCertificate(Document doc, String defaultSymbol) throws IOException, VulcanException {
|
||||||
String certificate = doc.select("input[name=wresult]").val();
|
client.setSymbol(findSymbol(defaultSymbol, doc.select("input[name=wresult]").val()));
|
||||||
|
|
||||||
if ("".equals(certificate)) {
|
|
||||||
throw new VulcanException("Expected certificate, got empty string. Page title: " + doc.title());
|
|
||||||
}
|
|
||||||
|
|
||||||
client.setSymbol(findSymbol(defaultSymbol, certificate));
|
|
||||||
|
|
||||||
Document targetDoc = sendCertData(doc);
|
Document targetDoc = sendCertData(doc);
|
||||||
String title = targetDoc.title();
|
String title = targetDoc.title();
|
||||||
@ -106,10 +105,6 @@ public class Login {
|
|||||||
private Document sendCertData(Document doc) throws IOException, VulcanException {
|
private Document sendCertData(Document doc) throws IOException, VulcanException {
|
||||||
String url = doc.select("form[name=hiddenform]").attr("action");
|
String url = doc.select("form[name=hiddenform]").attr("action");
|
||||||
|
|
||||||
if (!doc.title().equals("Working...")) {
|
|
||||||
throw new VulcanException("Expected certificate page, got page with title: " + doc.title());
|
|
||||||
}
|
|
||||||
|
|
||||||
return client.postPageByUrl(url.replaceFirst("Default", "{symbol}"), new String[][]{
|
return client.postPageByUrl(url.replaceFirst("Default", "{symbol}"), new String[][]{
|
||||||
{"wa", "wsignin1.0"},
|
{"wa", "wsignin1.0"},
|
||||||
{"wresult", doc.select("input[name=wresult]").val()},
|
{"wresult", doc.select("input[name=wresult]").val()},
|
||||||
@ -130,6 +125,10 @@ public class Login {
|
|||||||
.parse(certificate.replaceAll(":", ""), "", Parser.xmlParser())
|
.parse(certificate.replaceAll(":", ""), "", Parser.xmlParser())
|
||||||
.select("[AttributeName=\"UserInstance\"] samlAttributeValue");
|
.select("[AttributeName=\"UserInstance\"] samlAttributeValue");
|
||||||
|
|
||||||
|
if (instances.isEmpty()) { // on adfs login
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (instances.size() < 2) { // 1st index is always `Default`
|
if (instances.size() < 2) { // 1st index is always `Default`
|
||||||
throw new AccountPermissionException("First login detected, specify symbol");
|
throw new AccountPermissionException("First login detected, specify symbol");
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import io.github.wulkanowy.api.generic.Week;
|
|||||||
|
|
||||||
public class Timetable {
|
public class Timetable {
|
||||||
|
|
||||||
private static final String TIMETABLE_PAGE_URL = "Lekcja.mvc/PlanLekcji?data=";
|
private static final String TIMETABLE_PAGE_URL = "Lekcja.mvc/PlanZajec?data=";
|
||||||
|
|
||||||
private SnP snp;
|
private SnP snp;
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ public class Timetable {
|
|||||||
lesson.setStartTime(startEndEnd[0]);
|
lesson.setStartTime(startEndEnd[0]);
|
||||||
lesson.setEndTime(startEndEnd[1]);
|
lesson.setEndTime(startEndEnd[1]);
|
||||||
lesson.setDate(days.get(i - 2).getDate());
|
lesson.setDate(days.get(i - 2).getDate());
|
||||||
lesson.setNumber(hours.get(0).text());
|
lesson.setNumber(Integer.valueOf(hours.get(0).text()));
|
||||||
|
|
||||||
addLessonDetails(lesson, hours.get(i).select("div"));
|
addLessonDetails(lesson, hours.get(i).select("div"));
|
||||||
|
|
||||||
@ -98,8 +98,10 @@ public class Timetable {
|
|||||||
addLessonInfoFromElement(lesson, e.first());
|
addLessonInfoFromElement(lesson, e.first());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Element span = e.last().select("span").first();
|
Element span = e.last().selectFirst("span");
|
||||||
if (span.hasClass(LessonTypes.CLASS_MOVED_OR_CANCELED)) {
|
if (null == span) {
|
||||||
|
addLessonInfoFromElement(lesson, e.first());
|
||||||
|
} else if (span.hasClass(LessonTypes.CLASS_MOVED_OR_CANCELED)) {
|
||||||
lesson.setNewMovedInOrChanged(true);
|
lesson.setNewMovedInOrChanged(true);
|
||||||
lesson.setDescription("poprzednio: " + getLessonAndGroupInfoFromSpan(span)[0]);
|
lesson.setDescription("poprzednio: " + getLessonAndGroupInfoFromSpan(span)[0]);
|
||||||
addLessonInfoFromElement(lesson, e.first());
|
addLessonInfoFromElement(lesson, e.first());
|
||||||
@ -120,7 +122,9 @@ public class Timetable {
|
|||||||
Elements warn = e.select(".uwaga-panel");
|
Elements warn = e.select(".uwaga-panel");
|
||||||
|
|
||||||
if (!warn.isEmpty()) {
|
if (!warn.isEmpty()) {
|
||||||
e.select(".x-treelabel-rlz").last().text("(" + warn.text() + ")");
|
e.select("span").last()
|
||||||
|
.addClass("x-treelabel-rlz")
|
||||||
|
.text(warn.text());
|
||||||
e.remove(1);
|
e.remove(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class ClientTest {
|
|||||||
|
|
||||||
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-success.html"));
|
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-success.html"));
|
||||||
|
|
||||||
Assert.assertEquals(doc, client.checkForErrors(doc));
|
Assert.assertEquals(doc, client.checkForErrors(doc, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = VulcanOfflineException.class)
|
@Test(expected = VulcanOfflineException.class)
|
||||||
@ -34,7 +34,7 @@ public class ClientTest {
|
|||||||
|
|
||||||
Document doc = Jsoup.parse(getFixtureAsString("login/PrzerwaTechniczna.html"));
|
Document doc = Jsoup.parse(getFixtureAsString("login/PrzerwaTechniczna.html"));
|
||||||
|
|
||||||
client.checkForErrors(doc);
|
client.checkForErrors(doc, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NotLoggedInErrorException.class)
|
@Test(expected = NotLoggedInErrorException.class)
|
||||||
@ -43,7 +43,7 @@ public class ClientTest {
|
|||||||
|
|
||||||
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-notLoggedIn.html"));
|
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-notLoggedIn.html"));
|
||||||
|
|
||||||
client.checkForErrors(doc);
|
client.checkForErrors(doc, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -53,7 +53,7 @@ public class StudentAndParentTest {
|
|||||||
snp.getSnpHomePageUrl());
|
snp.getSnpHomePageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NotLoggedInErrorException.class)
|
@Test(expected = VulcanException.class)
|
||||||
public void getSnpPageUrlWithWrongPage() throws Exception {
|
public void getSnpPageUrlWithWrongPage() throws Exception {
|
||||||
Document wrongPageDocument = Jsoup.parse(
|
Document wrongPageDocument = Jsoup.parse(
|
||||||
FixtureHelper.getAsString(getClass().getResourceAsStream("OcenyWszystkie-semester.html"))
|
FixtureHelper.getAsString(getClass().getResourceAsStream("OcenyWszystkie-semester.html"))
|
||||||
|
@ -83,11 +83,11 @@ public class TimetableTest extends StudentAndParentTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getLessonNumberTest() throws Exception {
|
public void getLessonNumberTest() throws Exception {
|
||||||
Assert.assertEquals("2", std.getWeekTable().getDay(0).getLesson(1).getNumber());
|
Assert.assertEquals(2, std.getWeekTable().getDay(0).getLesson(1).getNumber());
|
||||||
Assert.assertEquals("5", std.getWeekTable().getDay(2).getLesson(4).getNumber());
|
Assert.assertEquals(5, std.getWeekTable().getDay(2).getLesson(4).getNumber());
|
||||||
Assert.assertEquals("0", full.getWeekTable().getDay(0).getLesson(0).getNumber());
|
Assert.assertEquals(0, full.getWeekTable().getDay(0).getLesson(0).getNumber());
|
||||||
Assert.assertEquals("13", full.getWeekTable().getDay(4).getLesson(13).getNumber());
|
Assert.assertEquals(13, full.getWeekTable().getDay(4).getLesson(13).getNumber());
|
||||||
Assert.assertEquals("3", holidays.getWeekTable().getDay(3).getLesson(3).getNumber());
|
Assert.assertEquals(3, holidays.getWeekTable().getDay(3).getLesson(3).getNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -105,6 +105,7 @@ public class TimetableTest extends StudentAndParentTestCase {
|
|||||||
Assert.assertEquals("Zajęcia techniczne", std.getWeekTable().getDay(2).getLesson(4).getSubject());
|
Assert.assertEquals("Zajęcia techniczne", std.getWeekTable().getDay(2).getLesson(4).getSubject());
|
||||||
Assert.assertEquals("Wychowanie fizyczne", std.getWeekTable().getDay(1).getLesson(1).getSubject());
|
Assert.assertEquals("Wychowanie fizyczne", std.getWeekTable().getDay(1).getLesson(1).getSubject());
|
||||||
Assert.assertEquals("Język angielski", full.getWeekTable().getDay(0).getLesson(1).getSubject());
|
Assert.assertEquals("Język angielski", full.getWeekTable().getDay(0).getLesson(1).getSubject());
|
||||||
|
Assert.assertEquals("Wychowanie fizyczne", full.getWeekTable().getDay(0).getLesson(9).getSubject());
|
||||||
Assert.assertEquals("Wychowanie do życia w rodzinie", full.getWeekTable().getDay(2).getLesson(0).getSubject());
|
Assert.assertEquals("Wychowanie do życia w rodzinie", full.getWeekTable().getDay(2).getLesson(0).getSubject());
|
||||||
Assert.assertEquals("Wychowanie fizyczne", full.getWeekTable().getDay(3).getLesson(1).getSubject());
|
Assert.assertEquals("Wychowanie fizyczne", full.getWeekTable().getDay(3).getLesson(1).getSubject());
|
||||||
Assert.assertEquals("Uroczyste zakończenie roku szkolnego", full.getWeekTable().getDay(4).getLesson(0).getSubject());
|
Assert.assertEquals("Uroczyste zakończenie roku szkolnego", full.getWeekTable().getDay(4).getLesson(0).getSubject());
|
||||||
@ -155,6 +156,7 @@ public class TimetableTest extends StudentAndParentTestCase {
|
|||||||
Assert.assertEquals("poprzednio: Wychowanie fizyczne", full.getWeekTable().getDay(4).getLesson(2).getDescription());
|
Assert.assertEquals("poprzednio: Wychowanie fizyczne", full.getWeekTable().getDay(4).getLesson(2).getDescription());
|
||||||
Assert.assertEquals("egzamin", full.getWeekTable().getDay(3).getLesson(0).getDescription());
|
Assert.assertEquals("egzamin", full.getWeekTable().getDay(3).getLesson(0).getDescription());
|
||||||
Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getDescription());
|
Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getDescription());
|
||||||
|
Assert.assertEquals("opis w uwadze bez klasy w spanie", full.getWeekTable().getDay(4).getLesson(4).getDescription());
|
||||||
Assert.assertEquals("", holidays.getWeekTable().getDay(3).getLesson(3).getDescription());
|
Assert.assertEquals("", holidays.getWeekTable().getDay(3).getLesson(3).getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +319,16 @@
|
|||||||
<span></span>
|
<span></span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td></td>
|
<td>
|
||||||
|
<div>
|
||||||
|
<span class="x-treelabel-ppl x-treelabel-inv">Język polski</span>
|
||||||
|
<span class="x-treelabel-ppl x-treelabel-inv"> </span>
|
||||||
|
<span class="x-treelabel-ppl x-treelabel-inv">16</span>
|
||||||
|
<span class="random-class">(oddział nieobecny)</span>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="uwaga-btn">Uwaga</button>
|
||||||
|
<div class="uwaga-panel">opis w uwadze bez klasy w spanie</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>5</td>
|
<td>5</td>
|
||||||
@ -461,7 +470,18 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>9</td>
|
<td>9</td>
|
||||||
<td>14:50 15:35</td>
|
<td>14:50 15:35</td>
|
||||||
<td></td>
|
<td>
|
||||||
|
<div>
|
||||||
|
<span class="x-treelabel-ppl x-treelabel-zas">Wychowanie fizyczne [zaw2]</span>
|
||||||
|
<span class="x-treelabel-ppl x-treelabel-zas"></span>
|
||||||
|
<span class="x-treelabel-ppl x-treelabel-zas"></span>
|
||||||
|
<span class="x-treelabel-ppl x-treelabel-zas">G3</span>
|
||||||
|
<span class="x-treelabel-rlz">(przeniesiona z lekcji 7, 01.12.2017)</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<!--<span>WTF</span>-->
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div>
|
<div>
|
||||||
<span class="x-treelabel-ppl x-treelabel-inv">Język niemiecki [J1]</span>
|
<span class="x-treelabel-ppl x-treelabel-inv">Język niemiecki [J1]</span>
|
||||||
|
@ -9,7 +9,7 @@ buildscript {
|
|||||||
classpath "org.greenrobot:greendao-gradle-plugin:$greenDaoGradle"
|
classpath "org.greenrobot:greendao-gradle-plugin:$greenDaoGradle"
|
||||||
classpath "io.fabric.tools:gradle:$fabricGradle"
|
classpath "io.fabric.tools:gradle:$fabricGradle"
|
||||||
classpath "com.google.gms:oss-licenses:0.9.2"
|
classpath "com.google.gms:oss-licenses:0.9.2"
|
||||||
classpath 'com.github.triplet.gradle:play-publisher:1.2.0'
|
classpath "com.github.triplet.gradle:play-publisher:$playPublisher"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +41,8 @@ android {
|
|||||||
testApplicationId "io.github.tests.wulkanowy"
|
testApplicationId "io.github.tests.wulkanowy"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 9
|
versionCode 13
|
||||||
versionName "0.4.1"
|
versionName "0.4.5"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
playAccountConfig = playAccountConfigs.defaultAccountConfig
|
playAccountConfig = playAccountConfigs.defaultAccountConfig
|
||||||
@ -91,7 +91,7 @@ play {
|
|||||||
}
|
}
|
||||||
|
|
||||||
greendao {
|
greendao {
|
||||||
schemaVersion 26
|
schemaVersion 28
|
||||||
generateTests = true
|
generateTests = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package io.github.wulkanowy;
|
package io.github.wulkanowy;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.core.CrashlyticsCore;
|
import com.crashlytics.android.core.CrashlyticsCore;
|
||||||
import com.jakewharton.threetenabp.AndroidThreeTen;
|
import com.jakewharton.threetenabp.AndroidThreeTen;
|
||||||
|
|
||||||
@ -10,18 +9,16 @@ import org.greenrobot.greendao.query.QueryBuilder;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjector;
|
||||||
|
import dagger.android.support.DaggerApplication;
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
import eu.davidea.flexibleadapter.utils.Log;
|
import eu.davidea.flexibleadapter.utils.Log;
|
||||||
import io.fabric.sdk.android.Fabric;
|
import io.fabric.sdk.android.Fabric;
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.di.component.ApplicationComponent;
|
import io.github.wulkanowy.di.DaggerAppComponent;
|
||||||
import io.github.wulkanowy.di.component.DaggerApplicationComponent;
|
|
||||||
import io.github.wulkanowy.di.modules.ApplicationModule;
|
|
||||||
import io.github.wulkanowy.utils.LogUtils;
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
|
|
||||||
public class WulkanowyApp extends Application {
|
public class WulkanowyApp extends DaggerApplication {
|
||||||
|
|
||||||
protected ApplicationComponent applicationComponent;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RepositoryContract repository;
|
RepositoryContract repository;
|
||||||
@ -31,12 +28,6 @@ public class WulkanowyApp extends Application {
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
AndroidThreeTen.init(this);
|
AndroidThreeTen.init(this);
|
||||||
|
|
||||||
applicationComponent = DaggerApplicationComponent
|
|
||||||
.builder()
|
|
||||||
.applicationModule(new ApplicationModule(this))
|
|
||||||
.build();
|
|
||||||
applicationComponent.inject(this);
|
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
enableDebugLog();
|
enableDebugLog();
|
||||||
}
|
}
|
||||||
@ -61,14 +52,18 @@ public class WulkanowyApp extends Application {
|
|||||||
|
|
||||||
private void initializeFabric() {
|
private void initializeFabric() {
|
||||||
Fabric.with(new Fabric.Builder(this)
|
Fabric.with(new Fabric.Builder(this)
|
||||||
.kits(new Crashlytics.Builder()
|
.kits(
|
||||||
|
new Crashlytics.Builder()
|
||||||
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
|
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
|
||||||
.build())
|
.build(),
|
||||||
|
new Answers()
|
||||||
|
)
|
||||||
.debuggable(BuildConfig.DEBUG)
|
.debuggable(BuildConfig.DEBUG)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationComponent getApplicationComponent() {
|
@Override
|
||||||
return applicationComponent;
|
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
|
||||||
|
return DaggerAppComponent.builder().create(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
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.Subject;
|
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.Symbol;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
|
|
||||||
public interface DbContract {
|
public interface DbContract {
|
||||||
@ -20,6 +21,8 @@ public interface DbContract {
|
|||||||
|
|
||||||
long getCurrentSymbolId();
|
long getCurrentSymbolId();
|
||||||
|
|
||||||
|
Symbol getCurrentSymbol();
|
||||||
|
|
||||||
long getCurrentDiaryId();
|
long getCurrentDiaryId();
|
||||||
|
|
||||||
long getSemesterId(int name);
|
long getSemesterId(int name);
|
||||||
|
@ -12,15 +12,16 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.api.Vulcan;
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
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.migrations.Migration23;
|
import io.github.wulkanowy.data.db.dao.migrations.Migration23;
|
||||||
import io.github.wulkanowy.data.db.dao.migrations.Migration26;
|
import io.github.wulkanowy.data.db.dao.migrations.Migration26;
|
||||||
|
import io.github.wulkanowy.data.db.dao.migrations.Migration27;
|
||||||
|
import io.github.wulkanowy.data.db.dao.migrations.Migration28;
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
|
||||||
import io.github.wulkanowy.di.annotations.DatabaseInfo;
|
|
||||||
import io.github.wulkanowy.utils.LogUtils;
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@ -31,7 +32,7 @@ public class DbHelper extends DaoMaster.OpenHelper {
|
|||||||
private final Vulcan vulcan;
|
private final Vulcan vulcan;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DbHelper(@ApplicationContext Context context, @DatabaseInfo String dbName,
|
DbHelper(Context context, @Named("dbName") String dbName,
|
||||||
SharedPrefContract sharedPref, Vulcan vulcan) {
|
SharedPrefContract sharedPref, Vulcan vulcan) {
|
||||||
super(context, dbName);
|
super(context, dbName);
|
||||||
this.sharedPref = sharedPref;
|
this.sharedPref = sharedPref;
|
||||||
@ -76,6 +77,8 @@ public class DbHelper extends DaoMaster.OpenHelper {
|
|||||||
List<Migration> migrations = new ArrayList<>();
|
List<Migration> migrations = new ArrayList<>();
|
||||||
migrations.add(new Migration23());
|
migrations.add(new Migration23());
|
||||||
migrations.add(new Migration26());
|
migrations.add(new Migration26());
|
||||||
|
migrations.add(new Migration27());
|
||||||
|
migrations.add(new Migration28());
|
||||||
|
|
||||||
// Sorting just to be safe, in case other people add migrations in the wrong order.
|
// Sorting just to be safe, in case other people add migrations in the wrong order.
|
||||||
Comparator<Migration> migrationComparator = new Comparator<Migration>() {
|
Comparator<Migration> migrationComparator = new Comparator<Migration>() {
|
||||||
|
@ -12,6 +12,7 @@ import io.github.wulkanowy.data.db.dao.entities.Semester;
|
|||||||
import io.github.wulkanowy.data.db.dao.entities.SemesterDao;
|
import io.github.wulkanowy.data.db.dao.entities.SemesterDao;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.StudentDao;
|
import io.github.wulkanowy.data.db.dao.entities.StudentDao;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.Symbol;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.SymbolDao;
|
import io.github.wulkanowy.data.db.dao.entities.SymbolDao;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.WeekDao;
|
import io.github.wulkanowy.data.db.dao.entities.WeekDao;
|
||||||
@ -57,10 +58,15 @@ public class DbRepository implements DbContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCurrentSymbolId() {
|
public Symbol getCurrentSymbol() {
|
||||||
return daoSession.getSymbolDao().queryBuilder().where(
|
return daoSession.getSymbolDao().queryBuilder().where(
|
||||||
SymbolDao.Properties.UserId.eq(sharedPref.getCurrentUserId())
|
SymbolDao.Properties.UserId.eq(sharedPref.getCurrentUserId())
|
||||||
).unique().getId();
|
).unique();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getCurrentSymbolId() {
|
||||||
|
return getCurrentSymbol().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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;
|
||||||
|
|
||||||
@ -35,9 +36,11 @@ public class Day {
|
|||||||
@Property(nameInDb = "free_day_name")
|
@Property(nameInDb = "free_day_name")
|
||||||
private String freeDayName = "";
|
private String freeDayName = "";
|
||||||
|
|
||||||
|
@OrderBy("number ASC")
|
||||||
@ToMany(referencedJoinProperty = "dayId")
|
@ToMany(referencedJoinProperty = "dayId")
|
||||||
private List<TimetableLesson> timetableLessons;
|
private List<TimetableLesson> timetableLessons;
|
||||||
|
|
||||||
|
@OrderBy("number ASC")
|
||||||
@ToMany(referencedJoinProperty = "dayId")
|
@ToMany(referencedJoinProperty = "dayId")
|
||||||
private List<AttendanceLesson> attendanceLessons;
|
private List<AttendanceLesson> attendanceLessons;
|
||||||
|
|
||||||
@ -50,9 +53,7 @@ public class Day {
|
|||||||
@Generated(hash = 2040040024)
|
@Generated(hash = 2040040024)
|
||||||
private transient DaoSession daoSession;
|
private transient DaoSession daoSession;
|
||||||
|
|
||||||
/**
|
/** Used for active entity operations. */
|
||||||
* Used for active entity operations.
|
|
||||||
*/
|
|
||||||
@Generated(hash = 312167767)
|
@Generated(hash = 312167767)
|
||||||
private transient DayDao myDao;
|
private transient DayDao myDao;
|
||||||
|
|
||||||
@ -185,6 +186,36 @@ public class Day {
|
|||||||
attendanceLessons = null;
|
attendanceLessons = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To-many relationship, resolved on first access (and after reset).
|
||||||
|
* Changes to to-many relations are not persisted, make changes to the target entity.
|
||||||
|
*/
|
||||||
|
@Generated(hash = 1231531946)
|
||||||
|
public List<Exam> getExams() {
|
||||||
|
if (exams == null) {
|
||||||
|
final DaoSession daoSession = this.daoSession;
|
||||||
|
if (daoSession == null) {
|
||||||
|
throw new DaoException("Entity is detached from DAO context");
|
||||||
|
}
|
||||||
|
ExamDao targetDao = daoSession.getExamDao();
|
||||||
|
List<Exam> examsNew = targetDao._queryDay_Exams(id);
|
||||||
|
synchronized (this) {
|
||||||
|
if (exams == null) {
|
||||||
|
exams = examsNew;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return exams;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets a to-many relationship, making the next get call to query for a fresh result.
|
||||||
|
*/
|
||||||
|
@Generated(hash = 841969952)
|
||||||
|
public synchronized void resetExams() {
|
||||||
|
exams = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
|
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
|
||||||
* Entity must attached to an entity context.
|
* Entity must attached to an entity context.
|
||||||
@ -221,40 +252,12 @@ public class Day {
|
|||||||
myDao.update(this);
|
myDao.update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* To-many relationship, resolved on first access (and after reset).
|
|
||||||
* Changes to to-many relations are not persisted, make changes to the target entity.
|
|
||||||
*/
|
|
||||||
@Generated(hash = 1231531946)
|
|
||||||
public List<Exam> getExams() {
|
|
||||||
if (exams == null) {
|
|
||||||
final DaoSession daoSession = this.daoSession;
|
|
||||||
if (daoSession == null) {
|
|
||||||
throw new DaoException("Entity is detached from DAO context");
|
|
||||||
}
|
|
||||||
ExamDao targetDao = daoSession.getExamDao();
|
|
||||||
List<Exam> examsNew = targetDao._queryDay_Exams(id);
|
|
||||||
synchronized (this) {
|
|
||||||
if (exams == null) {
|
|
||||||
exams = examsNew;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return exams;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets a to-many relationship, making the next get call to query for a fresh result.
|
|
||||||
*/
|
|
||||||
@Generated(hash = 841969952)
|
|
||||||
public synchronized void resetExams() {
|
|
||||||
exams = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** called by internal mechanisms, do not call yourself. */
|
/** called by internal mechanisms, do not call yourself. */
|
||||||
@Generated(hash = 1409317752)
|
@Generated(hash = 1409317752)
|
||||||
public void __setDaoSession(DaoSession daoSession) {
|
public void __setDaoSession(DaoSession daoSession) {
|
||||||
this.daoSession = daoSession;
|
this.daoSession = daoSession;
|
||||||
myDao = daoSession != null ? daoSession.getDayDao() : null;
|
myDao = daoSession != null ? daoSession.getDayDao() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,15 @@ import org.greenrobot.greendao.DaoException;
|
|||||||
import org.greenrobot.greendao.annotation.Entity;
|
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.Property;
|
import org.greenrobot.greendao.annotation.Property;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
nameInDb = "Exams",
|
nameInDb = "Exams",
|
||||||
active = true
|
active = true,
|
||||||
|
indexes = {@Index(value = "dayId,entryDate,subjectAndGroup,type,teacher", unique = true)}
|
||||||
)
|
)
|
||||||
|
|
||||||
public class Exam implements Serializable {
|
public class Exam implements Serializable {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.wulkanowy.data.db.dao.entities;
|
package io.github.wulkanowy.data.db.dao.entities;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||||
import org.greenrobot.greendao.DaoException;
|
import org.greenrobot.greendao.DaoException;
|
||||||
import org.greenrobot.greendao.annotation.Entity;
|
import org.greenrobot.greendao.annotation.Entity;
|
||||||
import org.greenrobot.greendao.annotation.Generated;
|
import org.greenrobot.greendao.annotation.Generated;
|
||||||
@ -12,7 +14,7 @@ import java.io.Serializable;
|
|||||||
@Entity(
|
@Entity(
|
||||||
nameInDb = "TimetableLessons",
|
nameInDb = "TimetableLessons",
|
||||||
active = true,
|
active = true,
|
||||||
indexes = {@Index(value = "dayId,date,startTime,endTime", unique = true)}
|
indexes = {@Index(value = "dayId,date,number,startTime,endTime", unique = true)}
|
||||||
)
|
)
|
||||||
public class TimetableLesson implements Serializable {
|
public class TimetableLesson implements Serializable {
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ public class TimetableLesson implements Serializable {
|
|||||||
private Long dayId;
|
private Long dayId;
|
||||||
|
|
||||||
@Property(nameInDb = "number")
|
@Property(nameInDb = "number")
|
||||||
private String number;
|
private int number = 0;
|
||||||
|
|
||||||
@Property(nameInDb = "subject")
|
@Property(nameInDb = "subject")
|
||||||
private String subject = "";
|
private String subject = "";
|
||||||
@ -75,18 +77,15 @@ public class TimetableLesson implements Serializable {
|
|||||||
@Generated(hash = 2040040024)
|
@Generated(hash = 2040040024)
|
||||||
private transient DaoSession daoSession;
|
private transient DaoSession daoSession;
|
||||||
|
|
||||||
/**
|
/** Used for active entity operations. */
|
||||||
* Used for active entity operations.
|
|
||||||
*/
|
|
||||||
@Generated(hash = 1119360138)
|
@Generated(hash = 1119360138)
|
||||||
private transient TimetableLessonDao myDao;
|
private transient TimetableLessonDao myDao;
|
||||||
|
|
||||||
@Generated(hash = 1955911128)
|
@Generated(hash = 1665905034)
|
||||||
public TimetableLesson(Long id, Long dayId, String number, String subject,
|
public TimetableLesson(Long id, Long dayId, int number, String subject, String teacher,
|
||||||
String teacher, String room, String description, String group,
|
String room, String description, String group, String startTime, String endTime,
|
||||||
String startTime, String endTime, String date, boolean empty,
|
String date, boolean empty, boolean divisionIntoGroups, boolean planning,
|
||||||
boolean divisionIntoGroups, boolean planning, boolean realized,
|
boolean realized, boolean movedOrCanceled, boolean newMovedInOrChanged) {
|
||||||
boolean movedOrCanceled, boolean newMovedInOrChanged) {
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.dayId = dayId;
|
this.dayId = dayId;
|
||||||
this.number = number;
|
this.number = number;
|
||||||
@ -127,11 +126,11 @@ public class TimetableLesson implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNumber() {
|
public int getNumber() {
|
||||||
return this.number;
|
return this.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimetableLesson setNumber(String number) {
|
public TimetableLesson setNumber(int number) {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -262,6 +261,32 @@ public class TimetableLesson implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
TimetableLesson lesson = (TimetableLesson) o;
|
||||||
|
|
||||||
|
return new EqualsBuilder()
|
||||||
|
.append(number, lesson.number)
|
||||||
|
.append(startTime, lesson.startTime)
|
||||||
|
.append(endTime, lesson.endTime)
|
||||||
|
.append(date, lesson.date)
|
||||||
|
.isEquals();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return new HashCodeBuilder(17, 37)
|
||||||
|
.append(number)
|
||||||
|
.append(startTime)
|
||||||
|
.append(endTime)
|
||||||
|
.append(date)
|
||||||
|
.toHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
|
* Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
|
||||||
* Entity must attached to an entity context.
|
* Entity must attached to an entity context.
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package io.github.wulkanowy.data.db.dao.migrations;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
|
import io.github.wulkanowy.data.db.dao.DbHelper;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.ExamDao;
|
||||||
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
|
|
||||||
|
public class Migration27 implements DbHelper.Migration {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getVersion() {
|
||||||
|
return 27;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runMigration(Database db, SharedPrefContract sharedPref, Vulcan vulcan) throws Exception {
|
||||||
|
ExamDao.dropTable(db, true);
|
||||||
|
ExamDao.createTable(db, true);
|
||||||
|
|
||||||
|
db.execSQL("UPDATE Weeks SET exams_synced = 0");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package io.github.wulkanowy.data.db.dao.migrations;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
|
import io.github.wulkanowy.data.db.dao.DbHelper;
|
||||||
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
|
|
||||||
|
public class Migration28 implements DbHelper.Migration {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getVersion() {
|
||||||
|
return 28;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runMigration(final Database db, final SharedPrefContract sharedPref, final Vulcan vulcan) throws Exception {
|
||||||
|
throw new Exception("No migrations");
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,6 @@ import javax.inject.Singleton;
|
|||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.api.NotLoggedInErrorException;
|
import io.github.wulkanowy.api.NotLoggedInErrorException;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
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;
|
||||||
import io.github.wulkanowy.utils.security.CryptoException;
|
import io.github.wulkanowy.utils.security.CryptoException;
|
||||||
@ -26,7 +25,7 @@ public class ResourcesRepository implements ResourcesContract {
|
|||||||
private Resources resources;
|
private Resources resources;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ResourcesRepository(@ApplicationContext Context context) {
|
ResourcesRepository(Context context) {
|
||||||
resources = context.getResources();
|
resources = context.getResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,9 @@ import android.content.SharedPreferences;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
|
||||||
import io.github.wulkanowy.di.annotations.SharedPreferencesInfo;
|
|
||||||
import io.github.wulkanowy.ui.main.settings.SettingsFragment;
|
import io.github.wulkanowy.ui.main.settings.SettingsFragment;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@ -24,7 +23,7 @@ public class SharedPrefRepository implements SharedPrefContract {
|
|||||||
private final SharedPreferences settingsSharedPref;
|
private final SharedPreferences settingsSharedPref;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SharedPrefRepository(@ApplicationContext Context context, @SharedPreferencesInfo String sharedName) {
|
SharedPrefRepository(Context context, @Named("sharedPrefName") String sharedName) {
|
||||||
appSharedPref = context.getSharedPreferences(sharedName, Context.MODE_PRIVATE);
|
appSharedPref = context.getSharedPreferences(sharedName, Context.MODE_PRIVATE);
|
||||||
settingsSharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
settingsSharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package io.github.wulkanowy.data.sync;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,6 +13,7 @@ import javax.inject.Singleton;
|
|||||||
import io.github.wulkanowy.api.Vulcan;
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
import io.github.wulkanowy.api.VulcanException;
|
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.DaoMaster;
|
||||||
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.Diary;
|
import io.github.wulkanowy.data.db.dao.entities.Diary;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DiaryDao;
|
import io.github.wulkanowy.data.db.dao.entities.DiaryDao;
|
||||||
@ -20,7 +23,6 @@ import io.github.wulkanowy.data.db.dao.entities.StudentDao;
|
|||||||
import io.github.wulkanowy.data.db.dao.entities.Symbol;
|
import io.github.wulkanowy.data.db.dao.entities.Symbol;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.SymbolDao;
|
import io.github.wulkanowy.data.db.dao.entities.SymbolDao;
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
|
||||||
import io.github.wulkanowy.utils.DataObjectConverter;
|
import io.github.wulkanowy.utils.DataObjectConverter;
|
||||||
import io.github.wulkanowy.utils.LogUtils;
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
import io.github.wulkanowy.utils.security.CryptoException;
|
import io.github.wulkanowy.utils.security.CryptoException;
|
||||||
@ -39,7 +41,7 @@ public class AccountSync {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AccountSync(DaoSession daoSession, SharedPrefContract sharedPref,
|
AccountSync(DaoSession daoSession, SharedPrefContract sharedPref,
|
||||||
Vulcan vulcan, @ApplicationContext Context context) {
|
Vulcan vulcan, Context context) {
|
||||||
this.daoSession = daoSession;
|
this.daoSession = daoSession;
|
||||||
this.sharedPref = sharedPref;
|
this.sharedPref = sharedPref;
|
||||||
this.vulcan = vulcan;
|
this.vulcan = vulcan;
|
||||||
@ -49,6 +51,8 @@ public class AccountSync {
|
|||||||
public void registerUser(String email, String password, String symbol)
|
public void registerUser(String email, String password, String symbol)
|
||||||
throws VulcanException, IOException, CryptoException {
|
throws VulcanException, IOException, CryptoException {
|
||||||
|
|
||||||
|
clearUserData();
|
||||||
|
|
||||||
vulcan.setCredentials(email, password, symbol, null, null, null);
|
vulcan.setCredentials(email, password, symbol, null, null, null);
|
||||||
|
|
||||||
daoSession.getDatabase().beginTransaction();
|
daoSession.getDatabase().beginTransaction();
|
||||||
@ -118,12 +122,12 @@ public class AccountSync {
|
|||||||
daoSession.getSemesterDao().insertInTx(semesterList);
|
daoSession.getSemesterDao().insertInTx(semesterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initLastUser() throws IOException, CryptoException {
|
public void initLastUser() throws CryptoException {
|
||||||
|
|
||||||
long userId = sharedPref.getCurrentUserId();
|
long userId = sharedPref.getCurrentUserId();
|
||||||
|
|
||||||
if (userId == 0) {
|
if (userId == 0) {
|
||||||
throw new IOException("Can't find saved user");
|
throw new NotRegisteredUserException("Can't find user id in SharedPreferences");
|
||||||
}
|
}
|
||||||
|
|
||||||
LogUtils.debug("Initialization current user id=" + userId);
|
LogUtils.debug("Initialization current user id=" + userId);
|
||||||
@ -152,4 +156,11 @@ public class AccountSync {
|
|||||||
diary.getValue()
|
diary.getValue()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clearUserData() {
|
||||||
|
Database database = daoSession.getDatabase();
|
||||||
|
DaoMaster.dropAllTables(database, true);
|
||||||
|
DaoMaster.createAllTables(database, true);
|
||||||
|
sharedPref.setCurrentUserId(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,7 @@ public class ExamsSync {
|
|||||||
.where(ExamDao.Properties.DayId.eq(dayId),
|
.where(ExamDao.Properties.DayId.eq(dayId),
|
||||||
ExamDao.Properties.EntryDate.eq(examApi.getEntryDate()),
|
ExamDao.Properties.EntryDate.eq(examApi.getEntryDate()),
|
||||||
ExamDao.Properties.SubjectAndGroup.eq(examApi.getSubjectAndGroup()),
|
ExamDao.Properties.SubjectAndGroup.eq(examApi.getSubjectAndGroup()),
|
||||||
|
ExamDao.Properties.Type.eq(examApi.getType()),
|
||||||
ExamDao.Properties.Teacher.eq(examApi.getTeacher()))
|
ExamDao.Properties.Teacher.eq(examApi.getTeacher()))
|
||||||
.unique();
|
.unique();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package io.github.wulkanowy.data.sync;
|
||||||
|
|
||||||
|
public class NotRegisteredUserException extends RuntimeException {
|
||||||
|
|
||||||
|
public NotRegisteredUserException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.wulkanowy.data.sync;
|
package io.github.wulkanowy.data.sync;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -125,6 +127,16 @@ public class TimetableSync {
|
|||||||
List<TimetableLesson> lessonsFromApiEntities = DataObjectConverter
|
List<TimetableLesson> lessonsFromApiEntities = DataObjectConverter
|
||||||
.lessonsToTimetableLessonsEntities(lessons);
|
.lessonsToTimetableLessonsEntities(lessons);
|
||||||
|
|
||||||
|
List<TimetableLesson> lessonsFromDbEntities = getLessonsFromDb(dayId);
|
||||||
|
|
||||||
|
if (!lessonsFromDbEntities.isEmpty()) {
|
||||||
|
List<TimetableLesson> lessonToRemove = new ArrayList<>(CollectionUtils.removeAll(lessonsFromDbEntities, lessonsFromApiEntities));
|
||||||
|
|
||||||
|
for (TimetableLesson timetableLesson : lessonToRemove) {
|
||||||
|
daoSession.getTimetableLessonDao().delete(timetableLesson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (TimetableLesson apiLessonEntity : lessonsFromApiEntities) {
|
for (TimetableLesson apiLessonEntity : lessonsFromApiEntities) {
|
||||||
TimetableLesson lessonFromDb = getLessonFromDb(apiLessonEntity, dayId);
|
TimetableLesson lessonFromDb = getLessonFromDb(apiLessonEntity, dayId);
|
||||||
|
|
||||||
@ -148,4 +160,8 @@ public class TimetableSync {
|
|||||||
TimetableLessonDao.Properties.EndTime.eq(apiEntity.getEndTime()))
|
TimetableLessonDao.Properties.EndTime.eq(apiEntity.getEndTime()))
|
||||||
.unique();
|
.unique();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<TimetableLesson> getLessonsFromDb(long dayId) {
|
||||||
|
return daoSession.getDayDao().load(dayId).getTimetableLessons();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
20
app/src/main/java/io/github/wulkanowy/di/AppComponent.java
Normal file
20
app/src/main/java/io/github/wulkanowy/di/AppComponent.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package io.github.wulkanowy.di;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Component;
|
||||||
|
import dagger.android.AndroidInjector;
|
||||||
|
import dagger.android.support.AndroidSupportInjectionModule;
|
||||||
|
import io.github.wulkanowy.WulkanowyApp;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Component(modules = {
|
||||||
|
AndroidSupportInjectionModule.class,
|
||||||
|
AppModule.class,
|
||||||
|
BuilderModule.class
|
||||||
|
})
|
||||||
|
public interface AppComponent extends AndroidInjector<WulkanowyApp> {
|
||||||
|
@Component.Builder
|
||||||
|
abstract class Builder extends AndroidInjector.Builder<WulkanowyApp> {
|
||||||
|
}
|
||||||
|
}
|
78
app/src/main/java/io/github/wulkanowy/di/AppModule.java
Normal file
78
app/src/main/java/io/github/wulkanowy/di/AppModule.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package io.github.wulkanowy.di;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import io.github.wulkanowy.WulkanowyApp;
|
||||||
|
import io.github.wulkanowy.api.Vulcan;
|
||||||
|
import io.github.wulkanowy.data.Repository;
|
||||||
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
|
import io.github.wulkanowy.data.db.dao.DbContract;
|
||||||
|
import io.github.wulkanowy.data.db.dao.DbHelper;
|
||||||
|
import io.github.wulkanowy.data.db.dao.DbRepository;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
||||||
|
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
||||||
|
import io.github.wulkanowy.data.db.resources.ResourcesRepository;
|
||||||
|
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||||
|
import io.github.wulkanowy.data.db.shared.SharedPrefRepository;
|
||||||
|
import io.github.wulkanowy.data.sync.SyncContract;
|
||||||
|
import io.github.wulkanowy.data.sync.SyncRepository;
|
||||||
|
import io.github.wulkanowy.utils.AppConstant;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class AppModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract Context provideContext(WulkanowyApp app);
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Binds
|
||||||
|
abstract RepositoryContract provideRepository(Repository repository);
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Binds
|
||||||
|
abstract DbContract provideDatabse(DbRepository dbRepository);
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Binds
|
||||||
|
abstract SharedPrefContract provideSharedPref(SharedPrefRepository sharedPrefRepository);
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Binds
|
||||||
|
abstract SyncContract provideSync(SyncRepository syncRepository);
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Binds
|
||||||
|
abstract ResourcesContract provideResources(ResourcesRepository resourcesRepository);
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
static DaoSession provideDaoSession(DbHelper dbHelper) {
|
||||||
|
return new DaoMaster(dbHelper.getWritableDb()).newSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
static Vulcan provideVulcan() {
|
||||||
|
return new Vulcan();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("dbName")
|
||||||
|
static String provideDbName() {
|
||||||
|
return AppConstant.DATABASE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("sharedPrefName")
|
||||||
|
static String provideSharedPrefName() {
|
||||||
|
return AppConstant.SHARED_PREFERENCES_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
app/src/main/java/io/github/wulkanowy/di/BuilderModule.java
Normal file
39
app/src/main/java/io/github/wulkanowy/di/BuilderModule.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package io.github.wulkanowy.di;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.android.ContributesAndroidInjector;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||||
|
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||||
|
import io.github.wulkanowy.services.widgets.TimetableWidgetServices;
|
||||||
|
import io.github.wulkanowy.ui.login.LoginActivity;
|
||||||
|
import io.github.wulkanowy.ui.login.LoginModule;
|
||||||
|
import io.github.wulkanowy.ui.main.MainActivity;
|
||||||
|
import io.github.wulkanowy.ui.main.MainModule;
|
||||||
|
import io.github.wulkanowy.ui.splash.SplashActivity;
|
||||||
|
import io.github.wulkanowy.ui.splash.SplashModule;
|
||||||
|
import io.github.wulkanowy.ui.widgets.TimetableWidgetProvider;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
abstract class BuilderModule {
|
||||||
|
|
||||||
|
@PerActivity
|
||||||
|
@ContributesAndroidInjector(modules = SplashModule.class)
|
||||||
|
abstract SplashActivity bindSplashActivity();
|
||||||
|
|
||||||
|
@PerActivity
|
||||||
|
@ContributesAndroidInjector(modules = LoginModule.class)
|
||||||
|
abstract LoginActivity bindLoginActivity();
|
||||||
|
|
||||||
|
@PerActivity
|
||||||
|
@ContributesAndroidInjector(modules = MainModule.class)
|
||||||
|
abstract MainActivity bindMainActivity();
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract SyncJob bindSyncJob();
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract TimetableWidgetServices bindTimetableWidgetServices();
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract TimetableWidgetProvider bindTimetableWidgetProvider();
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.annotations;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
@Qualifier
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface ActivityContext {
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.annotations;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
@Qualifier
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface ApplicationContext {
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.annotations;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
@Qualifier
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface SharedPreferencesInfo {
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.component;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
|
||||||
import io.github.wulkanowy.di.modules.ActivityModule;
|
|
||||||
import io.github.wulkanowy.ui.login.LoginActivity;
|
|
||||||
import io.github.wulkanowy.ui.main.MainActivity;
|
|
||||||
import io.github.wulkanowy.ui.splash.SplashActivity;
|
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
@Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
|
|
||||||
public interface ActivityComponent {
|
|
||||||
|
|
||||||
void inject(SplashActivity splashActivity);
|
|
||||||
|
|
||||||
void inject(LoginActivity loginActivity);
|
|
||||||
|
|
||||||
void inject(MainActivity mainActivity);
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.component;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
import io.github.wulkanowy.WulkanowyApp;
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
|
||||||
import io.github.wulkanowy.di.modules.ApplicationModule;
|
|
||||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
|
||||||
import io.github.wulkanowy.ui.widgets.TimetableWidgetFactory;
|
|
||||||
import io.github.wulkanowy.ui.widgets.TimetableWidgetProvider;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Component(modules = ApplicationModule.class)
|
|
||||||
public interface ApplicationComponent {
|
|
||||||
|
|
||||||
@ApplicationContext
|
|
||||||
Context getContext();
|
|
||||||
|
|
||||||
RepositoryContract getRepository();
|
|
||||||
|
|
||||||
void inject(WulkanowyApp wulkanowyApp);
|
|
||||||
|
|
||||||
void inject(SyncJob syncJob);
|
|
||||||
|
|
||||||
void inject(TimetableWidgetFactory timetableWidgetFactory);
|
|
||||||
|
|
||||||
void inject(TimetableWidgetProvider timetableWidgetProvider);
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.component;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
|
||||||
import io.github.wulkanowy.di.modules.FragmentModule;
|
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
|
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceTabFragment;
|
|
||||||
import io.github.wulkanowy.ui.main.exams.ExamsFragment;
|
|
||||||
import io.github.wulkanowy.ui.main.exams.ExamsTabFragment;
|
|
||||||
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableTabFragment;
|
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
@Component(dependencies = ApplicationComponent.class, modules = FragmentModule.class)
|
|
||||||
public interface FragmentComponent {
|
|
||||||
|
|
||||||
void inject(GradesFragment gradesFragment);
|
|
||||||
|
|
||||||
void inject(AttendanceFragment attendanceFragment);
|
|
||||||
|
|
||||||
void inject(AttendanceTabFragment attendanceTabFragment);
|
|
||||||
|
|
||||||
void inject(ExamsFragment examsFragment);
|
|
||||||
|
|
||||||
void inject(ExamsTabFragment examsTabFragment);
|
|
||||||
|
|
||||||
void inject(TimetableFragment timetableFragment);
|
|
||||||
|
|
||||||
void inject(TimetableTabFragment timetableTabFragment);
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.modules;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
import io.github.wulkanowy.di.annotations.ActivityContext;
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
|
||||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
|
||||||
import io.github.wulkanowy.ui.login.LoginContract;
|
|
||||||
import io.github.wulkanowy.ui.login.LoginPresenter;
|
|
||||||
import io.github.wulkanowy.ui.main.MainContract;
|
|
||||||
import io.github.wulkanowy.ui.main.MainPresenter;
|
|
||||||
import io.github.wulkanowy.ui.splash.SplashContract;
|
|
||||||
import io.github.wulkanowy.ui.splash.SplashPresenter;
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public class ActivityModule {
|
|
||||||
|
|
||||||
private AppCompatActivity activity;
|
|
||||||
|
|
||||||
public ActivityModule(AppCompatActivity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityContext
|
|
||||||
@Provides
|
|
||||||
Context provideContext() {
|
|
||||||
return activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
AppCompatActivity provideActivity() {
|
|
||||||
return activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
@Provides
|
|
||||||
SplashContract.Presenter provideSplashPresenter
|
|
||||||
(SplashPresenter splashPresenter) {
|
|
||||||
return splashPresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
@Provides
|
|
||||||
LoginContract.Presenter provideLoginPresenter
|
|
||||||
(LoginPresenter loginPresenter) {
|
|
||||||
return loginPresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
@Provides
|
|
||||||
MainContract.Presenter provideMainPresenter
|
|
||||||
(MainPresenter mainPresenter) {
|
|
||||||
return mainPresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
BasePagerAdapter provideMainPagerAdapter() {
|
|
||||||
return new BasePagerAdapter(activity.getSupportFragmentManager());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.modules;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
|
|
||||||
import com.firebase.jobdispatcher.GooglePlayDriver;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
import io.github.wulkanowy.api.Vulcan;
|
|
||||||
import io.github.wulkanowy.data.Repository;
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
|
||||||
import io.github.wulkanowy.data.db.dao.DbContract;
|
|
||||||
import io.github.wulkanowy.data.db.dao.DbHelper;
|
|
||||||
import io.github.wulkanowy.data.db.dao.DbRepository;
|
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
|
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
|
||||||
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
|
||||||
import io.github.wulkanowy.data.db.resources.ResourcesRepository;
|
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
|
||||||
import io.github.wulkanowy.data.db.shared.SharedPrefRepository;
|
|
||||||
import io.github.wulkanowy.data.sync.SyncContract;
|
|
||||||
import io.github.wulkanowy.data.sync.SyncRepository;
|
|
||||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
|
||||||
import io.github.wulkanowy.di.annotations.DatabaseInfo;
|
|
||||||
import io.github.wulkanowy.di.annotations.SharedPreferencesInfo;
|
|
||||||
import io.github.wulkanowy.utils.AppConstant;
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public class ApplicationModule {
|
|
||||||
|
|
||||||
private final Application application;
|
|
||||||
|
|
||||||
public ApplicationModule(Application application) {
|
|
||||||
this.application = application;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
Application provideApplication() {
|
|
||||||
return application;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApplicationContext
|
|
||||||
@Provides
|
|
||||||
Context provideAppContext() {
|
|
||||||
return application;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DatabaseInfo
|
|
||||||
@Provides
|
|
||||||
String provideDatabaseName() {
|
|
||||||
return AppConstant.DATABASE_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SharedPreferencesInfo
|
|
||||||
@Provides
|
|
||||||
String provideSharedPreferencesName() {
|
|
||||||
return AppConstant.SHARED_PREFERENCES_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
DaoSession provideDaoSession(DbHelper dbHelper) {
|
|
||||||
return new DaoMaster(dbHelper.getWritableDb()).newSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
Vulcan provideVulcan() {
|
|
||||||
return new Vulcan();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
RepositoryContract provideRepository(Repository repository) {
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
SharedPrefContract provideSharedPref(SharedPrefRepository sharedPrefRepository) {
|
|
||||||
return sharedPrefRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
ResourcesContract provideAppResources(ResourcesRepository resourcesRepository) {
|
|
||||||
return resourcesRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
DbContract provideDatabase(DbRepository dbRepository) {
|
|
||||||
return dbRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
SyncContract provideSync(SyncRepository syncRepository) {
|
|
||||||
return syncRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
FirebaseJobDispatcher provideDispatcher() {
|
|
||||||
return new FirebaseJobDispatcher(new GooglePlayDriver(application));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
package io.github.wulkanowy.di.modules;
|
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
|
||||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
|
||||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceContract;
|
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceHeaderItem;
|
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendancePresenter;
|
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceTabContract;
|
|
||||||
import io.github.wulkanowy.ui.main.attendance.AttendanceTabPresenter;
|
|
||||||
import io.github.wulkanowy.ui.main.exams.ExamsContract;
|
|
||||||
import io.github.wulkanowy.ui.main.exams.ExamsPresenter;
|
|
||||||
import io.github.wulkanowy.ui.main.exams.ExamsSubItem;
|
|
||||||
import io.github.wulkanowy.ui.main.exams.ExamsTabContract;
|
|
||||||
import io.github.wulkanowy.ui.main.exams.ExamsTabPresenter;
|
|
||||||
import io.github.wulkanowy.ui.main.grades.GradeHeaderItem;
|
|
||||||
import io.github.wulkanowy.ui.main.grades.GradesContract;
|
|
||||||
import io.github.wulkanowy.ui.main.grades.GradesPresenter;
|
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableContract;
|
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableHeaderItem;
|
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetablePresenter;
|
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableTabContract;
|
|
||||||
import io.github.wulkanowy.ui.main.timetable.TimetableTabPresenter;
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public class FragmentModule {
|
|
||||||
|
|
||||||
private final Fragment fragment;
|
|
||||||
|
|
||||||
public FragmentModule(Fragment fragment) {
|
|
||||||
this.fragment = fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
@Provides
|
|
||||||
GradesContract.Presenter provideGradesPresenter(GradesPresenter gradesPresenter) {
|
|
||||||
return gradesPresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
@Provides
|
|
||||||
AttendanceContract.Presenter provideAttendancePresenter(AttendancePresenter attendancePresenter) {
|
|
||||||
return attendancePresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
@Provides
|
|
||||||
ExamsContract.Presenter provideDashboardPresenter(ExamsPresenter examsPresenter) {
|
|
||||||
return examsPresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
@Provides
|
|
||||||
AttendanceTabContract.Presenter provideAttendanceTabPresenter(AttendanceTabPresenter timetableTabPresenter) {
|
|
||||||
return timetableTabPresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
BasePagerAdapter provideBasePagerAdapter() {
|
|
||||||
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
FlexibleAdapter<AttendanceHeaderItem> provideAttendanceTabAdapter() {
|
|
||||||
return new FlexibleAdapter<>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
FlexibleAdapter<TimetableHeaderItem> provideTimetableTabAdapter() {
|
|
||||||
return new FlexibleAdapter<>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
|
|
||||||
return new FlexibleAdapter<>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
FlexibleAdapter<ExamsSubItem> provideExamAdapter() {
|
|
||||||
return new FlexibleAdapter<>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
@Provides
|
|
||||||
TimetableContract.Presenter provideTimetablePresenter(TimetablePresenter timetablePresenter) {
|
|
||||||
return timetablePresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
@Provides
|
|
||||||
TimetableTabContract.Presenter provideTimetableTabPresenter(TimetableTabPresenter timetableTabPresenter) {
|
|
||||||
return timetableTabPresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
ExamsTabContract.Presenter provideExamsTabPresenter(ExamsTabPresenter examsTabPresenter) {
|
|
||||||
return examsTabPresenter;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.di.annotations;
|
package io.github.wulkanowy.di.scopes;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
@ -1,11 +1,11 @@
|
|||||||
package io.github.wulkanowy.di.annotations;
|
package io.github.wulkanowy.di.scopes;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
import javax.inject.Scope;
|
||||||
|
|
||||||
@Qualifier
|
@Scope
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface DatabaseInfo {
|
public @interface PerChildFragment {
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.di.annotations;
|
package io.github.wulkanowy.di.scopes;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
@ -20,10 +20,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjection;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.WulkanowyApp;
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
||||||
|
import io.github.wulkanowy.data.sync.NotRegisteredUserException;
|
||||||
import io.github.wulkanowy.services.notifies.GradeNotify;
|
import io.github.wulkanowy.services.notifies.GradeNotify;
|
||||||
import io.github.wulkanowy.ui.main.MainActivity;
|
import io.github.wulkanowy.ui.main.MainActivity;
|
||||||
import io.github.wulkanowy.utils.LogUtils;
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
@ -59,7 +60,7 @@ public class SyncJob extends SimpleJobService {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
((WulkanowyApp) getApplication()).getApplicationComponent().inject(this);
|
AndroidInjection.inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,9 +75,12 @@ public class SyncJob extends SimpleJobService {
|
|||||||
showNotification();
|
showNotification();
|
||||||
}
|
}
|
||||||
return JobService.RESULT_SUCCESS;
|
return JobService.RESULT_SUCCESS;
|
||||||
|
} catch (NotRegisteredUserException e) {
|
||||||
|
logError(e);
|
||||||
|
stop(getApplicationContext());
|
||||||
|
return JobService.RESULT_FAIL_NORETRY;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Crashlytics.logException(e);
|
logError(e);
|
||||||
LogUtils.error("During background synchronization an error occurred", e);
|
|
||||||
return JobService.RESULT_FAIL_RETRY;
|
return JobService.RESULT_FAIL_RETRY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,4 +120,9 @@ public class SyncJob extends SimpleJobService {
|
|||||||
gradeList.size(), gradeList.size());
|
gradeList.size(), gradeList.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logError(Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
LogUtils.error("During background synchronization an error occurred", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,20 @@ package io.github.wulkanowy.services.widgets;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.widget.RemoteViewsService;
|
import android.widget.RemoteViewsService;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjection;
|
||||||
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.ui.widgets.TimetableWidgetFactory;
|
import io.github.wulkanowy.ui.widgets.TimetableWidgetFactory;
|
||||||
|
|
||||||
public class TimetableWidgetServices extends RemoteViewsService {
|
public class TimetableWidgetServices extends RemoteViewsService {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RepositoryContract repository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteViewsFactory onGetViewFactory(Intent intent) {
|
public RemoteViewsFactory onGetViewFactory(Intent intent) {
|
||||||
return new TimetableWidgetFactory(getApplicationContext());
|
AndroidInjection.inject(this);
|
||||||
|
return new TimetableWidgetFactory(getApplicationContext(), repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,51 @@
|
|||||||
package io.github.wulkanowy.ui.base;
|
package io.github.wulkanowy.ui.base;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.AppCompatDelegate;
|
import android.support.v7.app.AppCompatDelegate;
|
||||||
import android.widget.Toast;
|
import android.view.View;
|
||||||
|
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
import dagger.android.support.DaggerAppCompatActivity;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.WulkanowyApp;
|
|
||||||
import io.github.wulkanowy.di.component.ActivityComponent;
|
|
||||||
import io.github.wulkanowy.di.component.DaggerActivityComponent;
|
|
||||||
import io.github.wulkanowy.di.modules.ActivityModule;
|
|
||||||
import io.github.wulkanowy.utils.NetworkUtils;
|
import io.github.wulkanowy.utils.NetworkUtils;
|
||||||
|
|
||||||
public abstract class BaseActivity extends AppCompatActivity implements BaseContract.View {
|
public abstract class BaseActivity extends DaggerAppCompatActivity implements BaseContract.View {
|
||||||
|
|
||||||
private ActivityComponent activityComponent;
|
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
activityComponent = DaggerActivityComponent.builder()
|
protected void injectViews() {
|
||||||
.activityModule(new ActivityModule(this))
|
unbinder = ButterKnife.bind(this);
|
||||||
.applicationComponent(((WulkanowyApp) getApplication()).getApplicationComponent())
|
}
|
||||||
.build();
|
|
||||||
|
@Override
|
||||||
|
public void showMessage(@NonNull String text) {
|
||||||
|
if (getMessageView() != null) {
|
||||||
|
Snackbar.make(getMessageView(), text, Snackbar.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showNoNetworkMessage() {
|
||||||
|
showMessage(getString(R.string.noInternet_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNetworkConnected() {
|
||||||
|
return NetworkUtils.isOnline(getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View getMessageView() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,32 +55,4 @@ public abstract class BaseActivity extends AppCompatActivity implements BaseCont
|
|||||||
unbinder.unbind();
|
unbinder.unbind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(int resId) {
|
|
||||||
onError(getString(resId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(String message) {
|
|
||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNoNetworkError() {
|
|
||||||
onError(R.string.noInternet_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNetworkConnected() {
|
|
||||||
return NetworkUtils.isOnline(getApplicationContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActivityComponent getActivityComponent() {
|
|
||||||
return activityComponent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setButterKnife(Unbinder unbinder) {
|
|
||||||
this.unbinder = unbinder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,22 @@
|
|||||||
package io.github.wulkanowy.ui.base;
|
package io.github.wulkanowy.ui.base;
|
||||||
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
|
||||||
|
|
||||||
public interface BaseContract {
|
public interface BaseContract {
|
||||||
|
|
||||||
interface View {
|
interface View {
|
||||||
|
|
||||||
void onError(@StringRes int resId);
|
void showMessage(@NonNull String text);
|
||||||
|
|
||||||
void onError(String message);
|
void showNoNetworkMessage();
|
||||||
|
|
||||||
void onNoNetworkError();
|
|
||||||
|
|
||||||
boolean isNetworkConnected();
|
boolean isNetworkConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
interface Presenter<V extends View> {
|
interface Presenter<V extends View> {
|
||||||
|
|
||||||
void onStart(V view);
|
void attachView(@NonNull V view);
|
||||||
|
|
||||||
void onDestroy();
|
void detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,56 +1,20 @@
|
|||||||
package io.github.wulkanowy.ui.base;
|
package io.github.wulkanowy.ui.base;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
import io.github.wulkanowy.R;
|
import dagger.android.support.DaggerFragment;
|
||||||
import io.github.wulkanowy.WulkanowyApp;
|
import io.github.wulkanowy.utils.NetworkUtils;
|
||||||
import io.github.wulkanowy.di.component.DaggerFragmentComponent;
|
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
|
||||||
import io.github.wulkanowy.di.modules.FragmentModule;
|
|
||||||
|
|
||||||
public abstract class BaseFragment extends Fragment implements BaseContract.View {
|
public abstract class BaseFragment extends DaggerFragment implements BaseContract.View {
|
||||||
|
|
||||||
private BaseActivity activity;
|
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
|
|
||||||
private FragmentComponent fragmentComponent;
|
protected void injectViews(@NonNull View view) {
|
||||||
|
unbinder = ButterKnife.bind(this, view);
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
if (context instanceof BaseActivity) {
|
|
||||||
activity = (BaseActivity) context;
|
|
||||||
}
|
|
||||||
|
|
||||||
fragmentComponent = DaggerFragmentComponent.builder()
|
|
||||||
.fragmentModule(new FragmentModule(this))
|
|
||||||
.applicationComponent(((WulkanowyApp) activity.getApplication()).getApplicationComponent())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setHasOptionsMenu(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
setUpOnViewCreated(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetach() {
|
|
||||||
activity = null;
|
|
||||||
super.onDetach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,44 +25,32 @@ public abstract class BaseFragment extends Fragment implements BaseContract.View
|
|||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setTitle(String title) {
|
||||||
public void onError(int resId) {
|
if (getActivity() != null) {
|
||||||
onError(getString(resId));
|
getActivity().setTitle(title);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(String message) {
|
|
||||||
if (activity != null) {
|
|
||||||
activity.onError(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNoNetworkError() {
|
public void showMessage(@NonNull String text) {
|
||||||
onError(R.string.noInternet_text);
|
if (getActivity() != null) {
|
||||||
|
((BaseActivity) getActivity()).showMessage(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showMessage(@StringRes int stringId) {
|
||||||
|
showMessage(getString(stringId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showNoNetworkMessage() {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
((BaseActivity) getActivity()).showNoNetworkMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNetworkConnected() {
|
public boolean isNetworkConnected() {
|
||||||
return activity != null && activity.isNetworkConnected();
|
return NetworkUtils.isOnline(getContext());
|
||||||
}
|
|
||||||
|
|
||||||
public void setButterKnife(Unbinder unbinder) {
|
|
||||||
this.unbinder = unbinder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
if (activity != null) {
|
|
||||||
activity.setTitle(title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FragmentComponent getFragmentComponent() {
|
|
||||||
return fragmentComponent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void setUpOnViewCreated(View fragmentView) {
|
|
||||||
// do something on view created
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.base;
|
package io.github.wulkanowy.ui.base;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
@ -16,12 +18,12 @@ public class BasePresenter<V extends BaseContract.View> implements BaseContract.
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(V view) {
|
public void attachView(@NonNull V view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
view = null;
|
view = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import android.animation.AnimatorListenerAdapter;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.TextInputLayout;
|
import android.support.design.widget.TextInputLayout;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -18,7 +18,6 @@ import android.widget.TextView;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import butterknife.OnEditorAction;
|
import butterknife.OnEditorAction;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
@ -64,14 +63,10 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_login);
|
setContentView(R.layout.activity_login);
|
||||||
|
injectViews();
|
||||||
|
|
||||||
setButterKnife(ButterKnife.bind(this));
|
presenter.attachView(this);
|
||||||
getActivityComponent().inject(this);
|
|
||||||
|
|
||||||
presenter.onStart(this);
|
|
||||||
|
|
||||||
setUpOnCreate();
|
setUpOnCreate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setUpOnCreate() {
|
protected void setUpOnCreate() {
|
||||||
@ -165,12 +160,6 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
|||||||
KeyboardUtils.hideSoftInput(this);
|
KeyboardUtils.hideSoftInput(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(String message) {
|
|
||||||
Snackbar.make(findViewById(R.id.login_activity_container), message,
|
|
||||||
Snackbar.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStepOneLoginProgress() {
|
public void setStepOneLoginProgress() {
|
||||||
onLoginProgressUpdate("1", getString(R.string.step_login));
|
onLoginProgressUpdate("1", getString(R.string.step_login));
|
||||||
@ -222,13 +211,19 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
protected View getMessageView() {
|
||||||
super.onDestroy();
|
return findViewById(R.id.login_activity_container);
|
||||||
presenter.onDestroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLoginProgressUpdate(String step, String message) {
|
private void onLoginProgressUpdate(String step, String message) {
|
||||||
loginProgressText.setText(String.format("%1$s/2 - %2$s...", step, message));
|
loginProgressText.setText(String.format("%1$s/2 - %2$s...", step, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
presenter.detachView();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package io.github.wulkanowy.ui.login;
|
package io.github.wulkanowy.ui.login;
|
||||||
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseContract;
|
import io.github.wulkanowy.ui.base.BaseContract;
|
||||||
|
|
||||||
public interface LoginContract {
|
public interface LoginContract {
|
||||||
@ -37,7 +35,6 @@ public interface LoginContract {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void attemptLogin(String email, String password, String symbol);
|
void attemptLogin(String email, String password, String symbol);
|
||||||
@ -51,7 +48,5 @@ public interface LoginContract {
|
|||||||
void onEndAsync(boolean success, Exception exception);
|
void onEndAsync(boolean success, Exception exception);
|
||||||
|
|
||||||
void onCanceledAsync();
|
void onCanceledAsync();
|
||||||
|
|
||||||
RepositoryContract getRepository();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package io.github.wulkanowy.ui.login;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class LoginModule {
|
||||||
|
|
||||||
|
@PerActivity
|
||||||
|
@Binds
|
||||||
|
abstract LoginContract.Presenter provideLoginPresenter(LoginPresenter loginPresenter);
|
||||||
|
}
|
@ -11,6 +11,7 @@ import io.github.wulkanowy.api.login.BadCredentialsException;
|
|||||||
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.utils.AppConstant;
|
import io.github.wulkanowy.utils.AppConstant;
|
||||||
|
import io.github.wulkanowy.utils.FabricUtils;
|
||||||
|
|
||||||
public class LoginPresenter extends BasePresenter<LoginContract.View>
|
public class LoginPresenter extends BasePresenter<LoginContract.View>
|
||||||
implements LoginContract.Presenter {
|
implements LoginContract.Presenter {
|
||||||
@ -46,7 +47,7 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
loginAsync.execute();
|
loginAsync.execute();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
getView().onNoNetworkError();
|
getView().showNoNetworkMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
getView().hideSoftInput();
|
getView().hideSoftInput();
|
||||||
@ -84,6 +85,7 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
@Override
|
@Override
|
||||||
public void onEndAsync(boolean success, Exception exception) {
|
public void onEndAsync(boolean success, Exception exception) {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
FabricUtils.logRegister(true, getRepository().getDbRepo().getCurrentSymbol().getSymbol());
|
||||||
getView().openMainActivity();
|
getView().openMainActivity();
|
||||||
return;
|
return;
|
||||||
} else if (exception instanceof BadCredentialsException) {
|
} else if (exception instanceof BadCredentialsException) {
|
||||||
@ -93,7 +95,8 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
getView().setErrorSymbolRequired();
|
getView().setErrorSymbolRequired();
|
||||||
getView().showSoftInput();
|
getView().showSoftInput();
|
||||||
} else {
|
} else {
|
||||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
FabricUtils.logRegister(false, symbol);
|
||||||
|
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||||
}
|
}
|
||||||
|
|
||||||
getView().showActionBar(true);
|
getView().showActionBar(true);
|
||||||
@ -157,11 +160,11 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
if (loginAsync != null) {
|
if (loginAsync != null) {
|
||||||
loginAsync.cancel(true);
|
loginAsync.cancel(true);
|
||||||
loginAsync = null;
|
loginAsync = null;
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -13,9 +14,9 @@ import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
|
|||||||
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager;
|
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||||
import io.github.wulkanowy.ui.base.BaseActivity;
|
import io.github.wulkanowy.ui.base.BaseActivity;
|
||||||
@ -40,6 +41,7 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
|||||||
@BindView(R.id.main_activity_progress_bar)
|
@BindView(R.id.main_activity_progress_bar)
|
||||||
View progressBar;
|
View progressBar;
|
||||||
|
|
||||||
|
@Named("Main")
|
||||||
@Inject
|
@Inject
|
||||||
BasePagerAdapter pagerAdapter;
|
BasePagerAdapter pagerAdapter;
|
||||||
|
|
||||||
@ -55,11 +57,9 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||||
|
injectViews();
|
||||||
|
|
||||||
getActivityComponent().inject(this);
|
presenter.attachView(this, getIntent().getIntExtra(EXTRA_CARD_ID_KEY, -1));
|
||||||
setButterKnife(ButterKnife.bind(this));
|
|
||||||
|
|
||||||
presenter.onStart(this, getIntent().getIntExtra(EXTRA_CARD_ID_KEY, -1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -146,9 +146,15 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
|||||||
SyncJob.start(getApplicationContext(), interval, useOnlyWifi);
|
SyncJob.start(getApplicationContext(), interval, useOnlyWifi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected View getMessageView() {
|
||||||
|
return findViewById(R.id.main_activity_view_pager);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
presenter.detachView();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
presenter.onDestroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main;
|
package io.github.wulkanowy.ui.main;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import io.github.wulkanowy.ui.base.BaseContract;
|
import io.github.wulkanowy.ui.base.BaseContract;
|
||||||
|
|
||||||
public interface MainContract {
|
public interface MainContract {
|
||||||
@ -22,10 +23,9 @@ public interface MainContract {
|
|||||||
void startSyncService(int interval, boolean useOnlyWifi);
|
void startSyncService(int interval, boolean useOnlyWifi);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void onStart(View view, int tabPositionIntent);
|
void attachView(@NonNull View view, int initTabId);
|
||||||
|
|
||||||
void onTabSelected(int position, boolean wasSelected);
|
void onTabSelected(int position, boolean wasSelected);
|
||||||
|
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package io.github.wulkanowy.ui.main;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import dagger.android.ContributesAndroidInjector;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||||
|
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||||
|
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.attendance.AttendanceModule;
|
||||||
|
import io.github.wulkanowy.ui.main.exams.ExamsFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.exams.ExamsModule;
|
||||||
|
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.grades.GradesModule;
|
||||||
|
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.timetable.TimetableModule;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class MainModule {
|
||||||
|
|
||||||
|
@PerActivity
|
||||||
|
@Binds
|
||||||
|
abstract MainContract.Presenter provideMainPresenter(MainPresenter mainPresenter);
|
||||||
|
|
||||||
|
@Named("Main")
|
||||||
|
@PerActivity
|
||||||
|
@Provides
|
||||||
|
static BasePagerAdapter provideAdapter(MainActivity activity) {
|
||||||
|
return new BasePagerAdapter(activity.getSupportFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@ContributesAndroidInjector(modules = GradesModule.class)
|
||||||
|
abstract GradesFragment bindsGradesFragment();
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@ContributesAndroidInjector(modules = TimetableModule.class)
|
||||||
|
abstract TimetableFragment bindTimetableFragment();
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@ContributesAndroidInjector(modules = ExamsModule.class)
|
||||||
|
abstract ExamsFragment bindExamsFragment();
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@ContributesAndroidInjector(modules = AttendanceModule.class)
|
||||||
|
abstract AttendanceFragment bindAttendanceFramgnet();
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package io.github.wulkanowy.ui.main;
|
package io.github.wulkanowy.ui.main;
|
||||||
|
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
@ -17,15 +19,15 @@ public class MainPresenter extends BasePresenter<MainContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(MainContract.View view, int tabPositionIntent) {
|
public void attachView(@NonNull MainContract.View view, int initTabId) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
getView().showProgressBar(true);
|
getView().showProgressBar(true);
|
||||||
getView().hideActionBar();
|
getView().hideActionBar();
|
||||||
|
|
||||||
int tabPosition;
|
int tabPosition;
|
||||||
|
|
||||||
if (tabPositionIntent != -1) {
|
if (initTabId != -1) {
|
||||||
tabPosition = tabPositionIntent;
|
tabPosition = initTabId;
|
||||||
} else {
|
} else {
|
||||||
tabPosition = getRepository().getSharedRepo().getStartupTab();
|
tabPosition = getRepository().getSharedRepo().getStartupTab();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -21,12 +22,11 @@ public interface AttendanceContract {
|
|||||||
void setThemeForTab(int position);
|
void setThemeForTab(int position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void onFragmentActivated(boolean isVisible);
|
void onFragmentActivated(boolean isVisible);
|
||||||
|
|
||||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||||
|
|
||||||
void setRestoredPosition(int position);
|
void setRestoredPosition(int position);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ 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.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -11,14 +10,14 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
import io.github.wulkanowy.ui.main.attendance.tab.AttendanceTabFragment;
|
||||||
|
|
||||||
public class AttendanceFragment extends BaseFragment implements AttendanceContract.View {
|
public class AttendanceFragment extends BaseFragment implements AttendanceContract.View {
|
||||||
|
|
||||||
@ -31,6 +30,7 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
|||||||
TabLayout tabLayout;
|
TabLayout tabLayout;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("Attendance")
|
||||||
BasePagerAdapter pagerAdapter;
|
BasePagerAdapter pagerAdapter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -41,18 +41,13 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
@Nullable 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);
|
||||||
|
injectViews(view);
|
||||||
|
|
||||||
FragmentComponent component = getFragmentComponent();
|
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||||
if (component != null) {
|
|
||||||
component.inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
|
||||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,14 +88,6 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
|||||||
setTitle(getString(R.string.attendance_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
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
||||||
@ -109,7 +96,7 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
presenter.onDestroy();
|
presenter.detachView();
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import dagger.android.ContributesAndroidInjector;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||||
|
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||||
|
import io.github.wulkanowy.ui.main.attendance.tab.AttendanceTabFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.attendance.tab.AttendanceTabModule;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class AttendanceModule {
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@Binds
|
||||||
|
abstract AttendanceContract.Presenter provideAttendancePresenter(AttendancePresenter attendancePresenter);
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@Named("Attendance")
|
||||||
|
@Provides
|
||||||
|
static BasePagerAdapter providePagerAdapter(AttendanceFragment fragment) {
|
||||||
|
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@ContributesAndroidInjector(modules = AttendanceTabModule.class)
|
||||||
|
abstract AttendanceTabFragment bindAttendanceTabFragment();
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -31,8 +33,8 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(AttendanceContract.View view, OnFragmentIsReadyListener listener) {
|
public void attachView(@NonNull AttendanceContract.View view, OnFragmentIsReadyListener listener) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
||||||
if (getView().isMenuVisible()) {
|
if (getView().isMenuVisible()) {
|
||||||
@ -64,7 +66,7 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDoInBackgroundLoading() throws Exception {
|
public void onDoInBackgroundLoading() {
|
||||||
for (String date : dates) {
|
for (String date : dates) {
|
||||||
getView().setTabDataToAdapter(date);
|
getView().setTabDataToAdapter(date);
|
||||||
}
|
}
|
||||||
@ -92,14 +94,13 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
isFirstSight = false;
|
isFirstSight = false;
|
||||||
|
|
||||||
if (loadingTask != null) {
|
if (loadingTask != null) {
|
||||||
loadingTask.cancel(true);
|
loadingTask.cancel(true);
|
||||||
loadingTask = null;
|
loadingTask = null;
|
||||||
}
|
}
|
||||||
|
super.detachView();
|
||||||
super.onDestroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
@ -20,6 +20,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
|||||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||||
|
import io.github.wulkanowy.ui.main.attendance.AttendanceDialogFragment;
|
||||||
|
|
||||||
class AttendanceSubItem
|
class AttendanceSubItem
|
||||||
extends AbstractSectionableItem<AttendanceSubItem.SubItemViewHolder, AttendanceHeaderItem> {
|
extends AbstractSectionableItem<AttendanceSubItem.SubItemViewHolder, AttendanceHeaderItem> {
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,9 +1,8 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||||
|
|
||||||
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.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -15,11 +14,9 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
|
|
||||||
public class AttendanceTabFragment extends BaseFragment implements AttendanceTabContract.View,
|
public class AttendanceTabFragment extends BaseFragment implements AttendanceTabContract.View,
|
||||||
@ -61,34 +58,28 @@ public class AttendanceTabFragment extends BaseFragment implements AttendanceTab
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_attendance_tab, container, false);
|
View view = inflater.inflate(R.layout.fragment_attendance_tab, container, false);
|
||||||
|
injectViews(view);
|
||||||
FragmentComponent component = getFragmentComponent();
|
|
||||||
if (component != null) {
|
|
||||||
component.inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
presenter.onStart(this);
|
presenter.attachView(this);
|
||||||
presenter.onFragmentActivated(isFragmentVisible);
|
presenter.onFragmentActivated(isFragmentVisible);
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUpOnViewCreated(View fragmentView) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
adapter.setAutoCollapseOnExpand(true);
|
adapter.setAutoCollapseOnExpand(true);
|
||||||
adapter.setAutoScrollOnExpand(true);
|
adapter.setAutoScrollOnExpand(true);
|
||||||
adapter.expandItemsAtStartUp();
|
adapter.expandItemsAtStartUp();
|
||||||
|
|
||||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||||
refreshLayout.setOnRefreshListener(this);
|
refreshLayout.setOnRefreshListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -112,7 +103,7 @@ public class AttendanceTabFragment extends BaseFragment implements AttendanceTab
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshSuccess() {
|
public void onRefreshSuccess() {
|
||||||
onError(R.string.sync_completed);
|
showMessage(R.string.sync_completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -130,17 +121,9 @@ public class AttendanceTabFragment extends BaseFragment implements AttendanceTab
|
|||||||
noItemView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
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
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
presenter.onDestroy();
|
presenter.detachView();
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class AttendanceTabModule {
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@Binds
|
||||||
|
abstract AttendanceTabContract.Presenter provideAttendanceTabPresenter(AttendanceTabPresenter attendanceTabPresenter);
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@Provides
|
||||||
|
static FlexibleAdapter<AttendanceHeaderItem> provideAdapter() {
|
||||||
|
return new FlexibleAdapter<>(null);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
package io.github.wulkanowy.ui.main.attendance;
|
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -10,6 +12,7 @@ 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.Day;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter;
|
import io.github.wulkanowy.ui.base.BasePresenter;
|
||||||
|
import io.github.wulkanowy.utils.FabricUtils;
|
||||||
import io.github.wulkanowy.utils.async.AbstractTask;
|
import io.github.wulkanowy.utils.async.AbstractTask;
|
||||||
import io.github.wulkanowy.utils.async.AsyncListeners;
|
import io.github.wulkanowy.utils.async.AsyncListeners;
|
||||||
|
|
||||||
@ -33,8 +36,9 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(AttendanceTabContract.View view) {
|
public void attachView(@NonNull AttendanceTabContract.View view) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
|
|
||||||
getView().showProgressBar(true);
|
getView().showProgressBar(true);
|
||||||
getView().showNoItem(false);
|
getView().showNoItem(false);
|
||||||
}
|
}
|
||||||
@ -59,7 +63,7 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
|||||||
refreshTask.setOnRefreshListener(this);
|
refreshTask.setOnRefreshListener(this);
|
||||||
refreshTask.execute();
|
refreshTask.execute();
|
||||||
} else {
|
} else {
|
||||||
getView().onNoNetworkError();
|
getView().showNoNetworkMessage();
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,9 +89,11 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
|||||||
|
|
||||||
getView().onRefreshSuccess();
|
getView().onRefreshSuccess();
|
||||||
} else {
|
} else {
|
||||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||||
}
|
}
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
|
|
||||||
|
FabricUtils.logRefresh("Attendance", result, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -180,9 +186,9 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
cancelAsyncTasks();
|
cancelAsyncTasks();
|
||||||
isFirstSight = false;
|
isFirstSight = false;
|
||||||
super.onDestroy();
|
super.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.exams;
|
package io.github.wulkanowy.ui.main.exams;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -21,10 +22,9 @@ public interface ExamsContract {
|
|||||||
void setThemeForTab(int position);
|
void setThemeForTab(int position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||||
|
|
||||||
void onFragmentActivated(boolean isVisible);
|
void onFragmentActivated(boolean isVisible);
|
||||||
|
|
||||||
|
@ -10,14 +10,15 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.BindView;
|
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.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
import io.github.wulkanowy.ui.main.exams.tab.ExamsTabFragment;
|
||||||
|
|
||||||
public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
|||||||
TabLayout tabLayout;
|
TabLayout tabLayout;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("Exams")
|
||||||
BasePagerAdapter pagerAdapter;
|
BasePagerAdapter pagerAdapter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -39,17 +41,13 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_exams, container, false);
|
View view = inflater.inflate(R.layout.fragment_exams, container, false);
|
||||||
|
injectViews(view);
|
||||||
|
|
||||||
FragmentComponent component = getFragmentComponent();
|
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||||
if (component != null) {
|
|
||||||
component.inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
|
||||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,14 +59,6 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public void setActivityTitle() {
|
public void setActivityTitle() {
|
||||||
setTitle(getString(R.string.exams_text));
|
setTitle(getString(R.string.exams_text));
|
||||||
@ -107,6 +97,6 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
presenter.onDestroy();
|
presenter.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.exams;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import dagger.android.ContributesAndroidInjector;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||||
|
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||||
|
import io.github.wulkanowy.ui.main.exams.tab.ExamsTabFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.exams.tab.ExamsTabModule;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class ExamsModule {
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@Binds
|
||||||
|
abstract ExamsContract.Presenter provideExamsPresneter(ExamsPresenter examsPresenter);
|
||||||
|
|
||||||
|
@Named("Exams")
|
||||||
|
@PerFragment
|
||||||
|
@Provides
|
||||||
|
static BasePagerAdapter providePagerAdapter(ExamsFragment fragment) {
|
||||||
|
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@ContributesAndroidInjector(modules = ExamsTabModule.class)
|
||||||
|
abstract ExamsTabFragment bindExamsTabFragment();
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.exams;
|
package io.github.wulkanowy.ui.main.exams;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -31,8 +33,8 @@ public class ExamsPresenter extends BasePresenter<ExamsContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(ExamsContract.View view, OnFragmentIsReadyListener listener) {
|
public void attachView(@NonNull ExamsContract.View view, OnFragmentIsReadyListener listener) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
||||||
if (getView().isMenuVisible()) {
|
if (getView().isMenuVisible()) {
|
||||||
@ -69,7 +71,7 @@ public class ExamsPresenter extends BasePresenter<ExamsContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDoInBackgroundLoading() throws Exception {
|
public void onDoInBackgroundLoading() {
|
||||||
for (String date : dates) {
|
for (String date : dates) {
|
||||||
getView().setTabDataToAdapter(date);
|
getView().setTabDataToAdapter(date);
|
||||||
}
|
}
|
||||||
@ -91,13 +93,13 @@ public class ExamsPresenter extends BasePresenter<ExamsContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
isFirstSight = false;
|
isFirstSight = false;
|
||||||
|
|
||||||
if (loadingTask != null) {
|
if (loadingTask != null) {
|
||||||
loadingTask.cancel(true);
|
loadingTask.cancel(true);
|
||||||
loadingTask = null;
|
loadingTask = null;
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.exams;
|
package io.github.wulkanowy.ui.main.exams.tab;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -22,7 +22,7 @@ public class ExamsHeaderItem extends AbstractHeaderItem<ExamsHeaderItem.HeaderVi
|
|||||||
|
|
||||||
private Day day;
|
private Day day;
|
||||||
|
|
||||||
public ExamsHeaderItem(Day day) {
|
ExamsHeaderItem(Day day) {
|
||||||
this.day = day;
|
this.day = day;
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.exams;
|
package io.github.wulkanowy.ui.main.exams.tab;
|
||||||
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
@ -18,6 +18,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
|||||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Exam;
|
import io.github.wulkanowy.data.db.dao.entities.Exam;
|
||||||
|
import io.github.wulkanowy.ui.main.exams.ExamsDialogFragment;
|
||||||
|
|
||||||
public class ExamsSubItem
|
public class ExamsSubItem
|
||||||
extends AbstractSectionableItem<ExamsSubItem.SubItemViewHolder, ExamsHeaderItem> {
|
extends AbstractSectionableItem<ExamsSubItem.SubItemViewHolder, ExamsHeaderItem> {
|
@ -1,8 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.exams;
|
package io.github.wulkanowy.ui.main.exams.tab;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseContract;
|
import io.github.wulkanowy.ui.base.BaseContract;
|
||||||
|
|
||||||
public interface ExamsTabContract {
|
public interface ExamsTabContract {
|
||||||
@ -20,7 +19,6 @@ public interface ExamsTabContract {
|
|||||||
void updateAdapterList(List<ExamsSubItem> headerItems);
|
void updateAdapterList(List<ExamsSubItem> headerItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void onFragmentActivated(boolean isSelected);
|
void onFragmentActivated(boolean isSelected);
|
@ -1,8 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.exams;
|
package io.github.wulkanowy.ui.main.exams.tab;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -14,11 +13,9 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
|
|
||||||
public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.View,
|
public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.View,
|
||||||
@ -60,26 +57,21 @@ public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.V
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_exams_tab, container, false);
|
View view = inflater.inflate(R.layout.fragment_exams_tab, container, false);
|
||||||
|
injectViews(view);
|
||||||
FragmentComponent component = getFragmentComponent();
|
|
||||||
if (component != null) {
|
|
||||||
component.inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||||
}
|
}
|
||||||
presenter.onStart(this);
|
presenter.attachView(this);
|
||||||
presenter.onFragmentActivated(isFragmentVisible);
|
presenter.onFragmentActivated(isFragmentVisible);
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUpOnViewCreated(View fragmentView) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
adapter.setDisplayHeadersAtStartUp(true);
|
adapter.setDisplayHeadersAtStartUp(true);
|
||||||
|
|
||||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||||
@ -107,7 +99,7 @@ public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.V
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshSuccess() {
|
public void onRefreshSuccess() {
|
||||||
onError(R.string.sync_completed);
|
showMessage(R.string.sync_completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -125,17 +117,10 @@ public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.V
|
|||||||
progressBar.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
progressBar.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
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
|
presenter.detachView();
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
presenter.onDestroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.exams.tab;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class ExamsTabModule {
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@Binds
|
||||||
|
abstract ExamsTabContract.Presenter provideExamsTabPresenter(ExamsTabPresenter examsTabPresenter);
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@Provides
|
||||||
|
static FlexibleAdapter<ExamsSubItem> provideAdapter() {
|
||||||
|
return new FlexibleAdapter<>(null);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
package io.github.wulkanowy.ui.main.exams;
|
package io.github.wulkanowy.ui.main.exams.tab;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -10,6 +12,7 @@ import io.github.wulkanowy.data.db.dao.entities.Day;
|
|||||||
import io.github.wulkanowy.data.db.dao.entities.Exam;
|
import io.github.wulkanowy.data.db.dao.entities.Exam;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter;
|
import io.github.wulkanowy.ui.base.BasePresenter;
|
||||||
|
import io.github.wulkanowy.utils.FabricUtils;
|
||||||
import io.github.wulkanowy.utils.async.AbstractTask;
|
import io.github.wulkanowy.utils.async.AbstractTask;
|
||||||
import io.github.wulkanowy.utils.async.AsyncListeners;
|
import io.github.wulkanowy.utils.async.AsyncListeners;
|
||||||
|
|
||||||
@ -28,13 +31,13 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
|||||||
private boolean isFirstSight = false;
|
private boolean isFirstSight = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ExamsTabPresenter(RepositoryContract repository) {
|
ExamsTabPresenter(RepositoryContract repository) {
|
||||||
super(repository);
|
super(repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(ExamsTabContract.View view) {
|
public void attachView(@NonNull ExamsTabContract.View view) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
getView().showProgressBar(true);
|
getView().showProgressBar(true);
|
||||||
getView().showNoItem(false);
|
getView().showNoItem(false);
|
||||||
}
|
}
|
||||||
@ -64,7 +67,7 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
|||||||
refreshTask.setOnRefreshListener(this);
|
refreshTask.setOnRefreshListener(this);
|
||||||
refreshTask.execute();
|
refreshTask.execute();
|
||||||
} else {
|
} else {
|
||||||
getView().onNoNetworkError();
|
getView().showNoNetworkMessage();
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,9 +93,11 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
|||||||
|
|
||||||
getView().onRefreshSuccess();
|
getView().onRefreshSuccess();
|
||||||
} else {
|
} else {
|
||||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||||
}
|
}
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
|
|
||||||
|
FabricUtils.logRefresh("Exams", result, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -154,9 +159,9 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
isFirstSight = false;
|
isFirstSight = false;
|
||||||
cancelAsyncTasks();
|
cancelAsyncTasks();
|
||||||
super.onDestroy();
|
super.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package io.github.wulkanowy.ui.main.grades;
|
package io.github.wulkanowy.ui.main.grades;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -30,15 +30,16 @@ public interface GradesContract {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void onFragmentVisible(boolean isVisible);
|
void onFragmentVisible(boolean isVisible);
|
||||||
|
|
||||||
void onRefresh();
|
void onRefresh();
|
||||||
|
|
||||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||||
|
|
||||||
void onSemesterChange(int which);
|
void onSemesterChange(int which);
|
||||||
|
|
||||||
|
void onSemesterSwitchActive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import android.content.DialogInterface;
|
|||||||
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.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@ -20,11 +19,9 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
|
||||||
@ -55,14 +52,9 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_grades, container, false);
|
View view = inflater.inflate(R.layout.fragment_grades, container, false);
|
||||||
|
injectViews(view);
|
||||||
|
|
||||||
FragmentComponent component = getFragmentComponent();
|
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||||
if (component != null) {
|
|
||||||
component.inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
|
||||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +72,7 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.action_filter) {
|
if (item.getItemId() == R.id.action_filter) {
|
||||||
|
presenter.onSemesterSwitchActive();
|
||||||
CharSequence[] items = new CharSequence[]{
|
CharSequence[] items = new CharSequence[]{
|
||||||
getResources().getString(R.string.semester_text, 1),
|
getResources().getString(R.string.semester_text, 1),
|
||||||
getResources().getString(R.string.semester_text, 2),
|
getResources().getString(R.string.semester_text, 2),
|
||||||
@ -101,14 +94,14 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUpOnViewCreated(View fragmentView) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
noItemView.setVisibility(View.GONE);
|
noItemView.setVisibility(View.GONE);
|
||||||
|
|
||||||
adapter.setAutoCollapseOnExpand(true);
|
adapter.setAutoCollapseOnExpand(true);
|
||||||
adapter.setAutoScrollOnExpand(true);
|
adapter.setAutoScrollOnExpand(true);
|
||||||
adapter.expandItemsAtStartUp();
|
adapter.expandItemsAtStartUp();
|
||||||
|
|
||||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||||
@ -154,25 +147,17 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshSuccessNoGrade() {
|
public void onRefreshSuccessNoGrade() {
|
||||||
onError(R.string.snackbar_no_grades);
|
showMessage(R.string.snackbar_no_grades);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshSuccess(int number) {
|
public void onRefreshSuccess(int number) {
|
||||||
onError(getString(R.string.snackbar_new_grade, number));
|
showMessage(getString(R.string.snackbar_new_grade, number));
|
||||||
}
|
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
presenter.onDestroy();
|
presenter.detachView();
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.grades;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class GradesModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract GradesContract.Presenter provideGradesPresenter(GradesPresenter gradesPresenter);
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
static FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
|
||||||
|
return new FlexibleAdapter<>(null);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,12 @@
|
|||||||
package io.github.wulkanowy.ui.main.grades;
|
package io.github.wulkanowy.ui.main.grades;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.crashlytics.android.answers.Answers;
|
||||||
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
|
||||||
|
import org.threeten.bp.LocalDate;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -10,6 +17,7 @@ import io.github.wulkanowy.data.db.dao.entities.Grade;
|
|||||||
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
||||||
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.utils.FabricUtils;
|
||||||
import io.github.wulkanowy.utils.async.AbstractTask;
|
import io.github.wulkanowy.utils.async.AbstractTask;
|
||||||
import io.github.wulkanowy.utils.async.AsyncListeners;
|
import io.github.wulkanowy.utils.async.AsyncListeners;
|
||||||
|
|
||||||
@ -35,8 +43,8 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(GradesContract.View view, OnFragmentIsReadyListener listener) {
|
public void attachView(@NonNull GradesContract.View view, OnFragmentIsReadyListener listener) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
||||||
if (getView().isMenuVisible()) {
|
if (getView().isMenuVisible()) {
|
||||||
@ -53,12 +61,19 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSemesterSwitchActive() {
|
||||||
|
cancelAsyncTasks();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSemesterChange(int which) {
|
public void onSemesterChange(int which) {
|
||||||
semesterName = which + 1;
|
semesterName = which + 1;
|
||||||
getView().setCurrentSemester(which);
|
getView().setCurrentSemester(which);
|
||||||
|
|
||||||
reloadGrades();
|
reloadGrades();
|
||||||
|
|
||||||
|
Answers.getInstance().logCustom(new CustomEvent("Semester change")
|
||||||
|
.putCustomAttribute("Name", semesterName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadGrades() {
|
private void reloadGrades() {
|
||||||
@ -81,7 +96,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
refreshTask.setOnRefreshListener(this);
|
refreshTask.setOnRefreshListener(this);
|
||||||
refreshTask.execute();
|
refreshTask.execute();
|
||||||
} else {
|
} else {
|
||||||
getView().onNoNetworkError();
|
getView().showNoNetworkMessage();
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,8 +115,8 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEndRefreshAsync(boolean success, Exception exception) {
|
public void onEndRefreshAsync(boolean result, Exception exception) {
|
||||||
if (success) {
|
if (result) {
|
||||||
reloadGrades();
|
reloadGrades();
|
||||||
|
|
||||||
int numberOfNewGrades = getRepository().getDbRepo().getNewGrades(semesterName).size();
|
int numberOfNewGrades = getRepository().getDbRepo().getNewGrades(semesterName).size();
|
||||||
@ -112,9 +127,11 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
getView().onRefreshSuccess(numberOfNewGrades);
|
getView().onRefreshSuccess(numberOfNewGrades);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||||
}
|
}
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
|
|
||||||
|
FabricUtils.logRefresh("Grades", result, LocalDate.now().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -156,10 +173,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
listener.onFragmentIsReady();
|
listener.onFragmentIsReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void cancelAsyncTasks() {
|
||||||
public void onDestroy() {
|
|
||||||
isFirstSight = false;
|
|
||||||
|
|
||||||
if (refreshTask != null) {
|
if (refreshTask != null) {
|
||||||
refreshTask.cancel(true);
|
refreshTask.cancel(true);
|
||||||
refreshTask = null;
|
refreshTask = null;
|
||||||
@ -168,6 +182,12 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
|||||||
loadingTask.cancel(true);
|
loadingTask.cancel(true);
|
||||||
loadingTask = null;
|
loadingTask = null;
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detachView() {
|
||||||
|
isFirstSight = false;
|
||||||
|
cancelAsyncTasks();
|
||||||
|
super.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main.timetable;
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -21,12 +22,11 @@ public interface TimetableContract {
|
|||||||
void setThemeForTab(int position);
|
void setThemeForTab(int position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerFragment
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
|
|
||||||
void onFragmentActivated(boolean isVisible);
|
void onFragmentActivated(boolean isVisible);
|
||||||
|
|
||||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||||
|
|
||||||
void setRestoredPosition(int position);
|
void setRestoredPosition(int position);
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,14 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||||
|
import io.github.wulkanowy.ui.main.timetable.tab.TimetableTabFragment;
|
||||||
|
|
||||||
public class TimetableFragment extends BaseFragment implements TimetableContract.View {
|
public class TimetableFragment extends BaseFragment implements TimetableContract.View {
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
@BindView(R.id.timetable_fragment_tab_layout)
|
@BindView(R.id.timetable_fragment_tab_layout)
|
||||||
TabLayout tabLayout;
|
TabLayout tabLayout;
|
||||||
|
|
||||||
|
@Named("Timetable")
|
||||||
@Inject
|
@Inject
|
||||||
BasePagerAdapter pagerAdapter;
|
BasePagerAdapter pagerAdapter;
|
||||||
|
|
||||||
@ -40,17 +41,13 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_timetable, container, false);
|
View view = inflater.inflate(R.layout.fragment_timetable, container, false);
|
||||||
|
injectViews(view);
|
||||||
|
|
||||||
FragmentComponent component = getFragmentComponent();
|
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||||
if (component != null) {
|
|
||||||
component.inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
|
||||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,14 +88,6 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
setTitle(getString(R.string.timetable_text));
|
setTitle(getString(R.string.timetable_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
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
||||||
@ -107,7 +96,7 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
presenter.onDestroy();
|
presenter.detachView();
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.timetable;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import dagger.android.ContributesAndroidInjector;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||||
|
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||||
|
import io.github.wulkanowy.ui.main.timetable.tab.TimetableTabFragment;
|
||||||
|
import io.github.wulkanowy.ui.main.timetable.tab.TimetableTabModule;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class TimetableModule {
|
||||||
|
|
||||||
|
@Named("Timetable")
|
||||||
|
@PerFragment
|
||||||
|
@Provides
|
||||||
|
static BasePagerAdapter providePagerAdapter(TimetableFragment fragment) {
|
||||||
|
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PerFragment
|
||||||
|
@Binds
|
||||||
|
abstract TimetableContract.Presenter provideTimetablePresenter(TimetablePresenter timetablePresenter);
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@ContributesAndroidInjector(modules = TimetableTabModule.class)
|
||||||
|
abstract TimetableTabFragment bindTimetableTabFragment();
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main.timetable;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -31,8 +33,8 @@ public class TimetablePresenter extends BasePresenter<TimetableContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(TimetableContract.View view, OnFragmentIsReadyListener listener) {
|
public void attachView(@NonNull TimetableContract.View view, OnFragmentIsReadyListener listener) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
||||||
if (getView().isMenuVisible()) {
|
if (getView().isMenuVisible()) {
|
||||||
@ -64,7 +66,7 @@ public class TimetablePresenter extends BasePresenter<TimetableContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDoInBackgroundLoading() throws Exception {
|
public void onDoInBackgroundLoading() {
|
||||||
for (String date : dates) {
|
for (String date : dates) {
|
||||||
getView().setTabDataToAdapter(date);
|
getView().setTabDataToAdapter(date);
|
||||||
}
|
}
|
||||||
@ -91,13 +93,13 @@ public class TimetablePresenter extends BasePresenter<TimetableContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
isFirstSight = false;
|
isFirstSight = false;
|
||||||
|
|
||||||
if (loadingTask != null) {
|
if (loadingTask != null) {
|
||||||
loadingTask.cancel(true);
|
loadingTask.cancel(true);
|
||||||
loadingTask = null;
|
loadingTask = null;
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
@ -21,6 +21,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
|||||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||||
|
import io.github.wulkanowy.ui.main.timetable.TimetableDialogFragment;
|
||||||
|
|
||||||
|
|
||||||
public class TimetableSubItem
|
public class TimetableSubItem
|
||||||
@ -106,7 +107,7 @@ public class TimetableSubItem
|
|||||||
|
|
||||||
lessonName.setText(lesson.getSubject());
|
lessonName.setText(lesson.getSubject());
|
||||||
lessonTime.setText(getLessonTimeString());
|
lessonTime.setText(getLessonTimeString());
|
||||||
numberOfLesson.setText(lesson.getNumber());
|
numberOfLesson.setText(String.valueOf(lesson.getNumber()));
|
||||||
room.setText(getRoomString());
|
room.setText(getRoomString());
|
||||||
alert.setVisibility(lesson.getMovedOrCanceled() || lesson.getNewMovedInOrChanged()
|
alert.setVisibility(lesson.getMovedOrCanceled() || lesson.getNewMovedInOrChanged()
|
||||||
? View.VISIBLE : View.INVISIBLE);
|
? View.VISIBLE : View.INVISIBLE);
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@ -16,11 +16,9 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||||
|
|
||||||
public class TimetableTabFragment extends BaseFragment implements TimetableTabContract.View,
|
public class TimetableTabFragment extends BaseFragment implements TimetableTabContract.View,
|
||||||
@ -65,33 +63,27 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_timetable_tab, container, false);
|
View view = inflater.inflate(R.layout.fragment_timetable_tab, container, false);
|
||||||
|
injectViews(view);
|
||||||
FragmentComponent component = getFragmentComponent();
|
|
||||||
if (component != null) {
|
|
||||||
component.inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this, view));
|
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||||
}
|
}
|
||||||
presenter.onStart(this);
|
presenter.attachView(this);
|
||||||
presenter.onFragmentActivated(isFragmentVisible);
|
presenter.onFragmentActivated(isFragmentVisible);
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUpOnViewCreated(View fragmentView) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
adapter.setAutoCollapseOnExpand(true);
|
adapter.setAutoCollapseOnExpand(true);
|
||||||
adapter.setAutoScrollOnExpand(true);
|
adapter.setAutoScrollOnExpand(true);
|
||||||
adapter.expandItemsAtStartUp();
|
adapter.expandItemsAtStartUp();
|
||||||
|
|
||||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||||
refreshLayout.setOnRefreshListener(this);
|
refreshLayout.setOnRefreshListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -120,7 +112,7 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshSuccess() {
|
public void onRefreshSuccess() {
|
||||||
onError(R.string.sync_completed);
|
showMessage(R.string.sync_completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -138,17 +130,9 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
|
|||||||
noItemView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
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
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
presenter.onDestroy();
|
presenter.detachView();
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class TimetableTabModule {
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@Binds
|
||||||
|
abstract TimetableTabContract.Presenter provideTimetableTabPresneter(TimetableTabPresenter timetableTabPresenter);
|
||||||
|
|
||||||
|
@PerChildFragment
|
||||||
|
@Provides
|
||||||
|
static FlexibleAdapter<TimetableHeaderItem> provideTimetableAdapter() {
|
||||||
|
return new FlexibleAdapter<>(null);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package io.github.wulkanowy.ui.main.timetable;
|
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||||
|
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,6 +13,7 @@ import io.github.wulkanowy.data.db.dao.entities.Day;
|
|||||||
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter;
|
import io.github.wulkanowy.ui.base.BasePresenter;
|
||||||
|
import io.github.wulkanowy.utils.FabricUtils;
|
||||||
import io.github.wulkanowy.utils.async.AbstractTask;
|
import io.github.wulkanowy.utils.async.AbstractTask;
|
||||||
import io.github.wulkanowy.utils.async.AsyncListeners;
|
import io.github.wulkanowy.utils.async.AsyncListeners;
|
||||||
|
|
||||||
@ -36,8 +39,8 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(TimetableTabContract.View view) {
|
public void attachView(@NonNull TimetableTabContract.View view) {
|
||||||
super.onStart(view);
|
super.attachView(view);
|
||||||
getView().showProgressBar(true);
|
getView().showProgressBar(true);
|
||||||
getView().showNoItem(false);
|
getView().showNoItem(false);
|
||||||
}
|
}
|
||||||
@ -62,7 +65,7 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
|||||||
refreshTask.setOnRefreshListener(this);
|
refreshTask.setOnRefreshListener(this);
|
||||||
refreshTask.execute();
|
refreshTask.execute();
|
||||||
} else {
|
} else {
|
||||||
getView().onNoNetworkError();
|
getView().showNoNetworkMessage();
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,9 +91,11 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
|||||||
|
|
||||||
getView().onRefreshSuccess();
|
getView().onRefreshSuccess();
|
||||||
} else {
|
} else {
|
||||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||||
}
|
}
|
||||||
getView().hideRefreshingBar();
|
getView().hideRefreshingBar();
|
||||||
|
|
||||||
|
FabricUtils.logRefresh("Timetable", result, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -175,9 +180,9 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void detachView() {
|
||||||
isFirstSight = false;
|
isFirstSight = false;
|
||||||
cancelAsyncTasks();
|
cancelAsyncTasks();
|
||||||
super.onDestroy();
|
super.detachView();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||||
import io.github.wulkanowy.services.notifies.NotificationService;
|
import io.github.wulkanowy.services.notifies.NotificationService;
|
||||||
import io.github.wulkanowy.ui.base.BaseActivity;
|
import io.github.wulkanowy.ui.base.BaseActivity;
|
||||||
import io.github.wulkanowy.ui.login.LoginActivity;
|
import io.github.wulkanowy.ui.login.LoginActivity;
|
||||||
@ -18,16 +18,12 @@ public class SplashActivity extends BaseActivity implements SplashContract.View
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
presenter.attachView(this);
|
||||||
getActivityComponent().inject(this);
|
|
||||||
setButterKnife(ButterKnife.bind(this));
|
|
||||||
|
|
||||||
presenter.onStart(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
presenter.onDestroy();
|
presenter.detachView();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package io.github.wulkanowy.ui.splash;
|
package io.github.wulkanowy.ui.splash;
|
||||||
|
|
||||||
|
|
||||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
|
||||||
import io.github.wulkanowy.ui.base.BaseContract;
|
import io.github.wulkanowy.ui.base.BaseContract;
|
||||||
|
|
||||||
public interface SplashContract {
|
public interface SplashContract {
|
||||||
@ -15,7 +13,6 @@ public interface SplashContract {
|
|||||||
void cancelNotifications();
|
void cancelNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
|
||||||
interface Presenter extends BaseContract.Presenter<View> {
|
interface Presenter extends BaseContract.Presenter<View> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package io.github.wulkanowy.ui.splash;
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class SplashModule {
|
||||||
|
|
||||||
|
@PerActivity
|
||||||
|
@Binds
|
||||||
|
abstract SplashContract.Presenter provideSplashPresenter(SplashPresenter splashPresenter);
|
||||||
|
}
|
@ -16,8 +16,8 @@ public class SplashPresenter extends BasePresenter<SplashContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(@NonNull SplashContract.View activity) {
|
public void attachView(@NonNull SplashContract.View view) {
|
||||||
super.onStart(activity);
|
super.attachView(view);
|
||||||
getView().cancelNotifications();
|
getView().cancelNotifications();
|
||||||
|
|
||||||
if (getRepository().getSharedRepo().isUserLoggedIn()) {
|
if (getRepository().getSharedRepo().isUserLoggedIn()) {
|
||||||
|
@ -12,10 +12,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.WulkanowyApp;
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||||
@ -23,22 +20,17 @@ import io.github.wulkanowy.utils.TimeUtils;
|
|||||||
|
|
||||||
public class TimetableWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
|
public class TimetableWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
|
|
||||||
private List<TimetableLesson> lessonList = new ArrayList<>();
|
private List<TimetableLesson> lessonList = new ArrayList<>();
|
||||||
|
|
||||||
@Inject
|
private final RepositoryContract repository;
|
||||||
RepositoryContract repository;
|
|
||||||
|
|
||||||
public TimetableWidgetFactory(Context context) {
|
public TimetableWidgetFactory(Context context, RepositoryContract repository) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void inject() {
|
|
||||||
if (repository == null) {
|
|
||||||
((WulkanowyApp) context).getApplicationComponent().inject(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -47,7 +39,6 @@ public class TimetableWidgetFactory implements RemoteViewsService.RemoteViewsFac
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDataSetChanged() {
|
public void onDataSetChanged() {
|
||||||
inject();
|
|
||||||
lessonList = new ArrayList<>();
|
lessonList = new ArrayList<>();
|
||||||
|
|
||||||
if (repository.getSharedRepo().isUserLoggedIn()) {
|
if (repository.getSharedRepo().isUserLoggedIn()) {
|
||||||
|
@ -11,8 +11,8 @@ import android.widget.RemoteViews;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.android.AndroidInjection;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
import io.github.wulkanowy.WulkanowyApp;
|
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.services.widgets.TimetableWidgetServices;
|
import io.github.wulkanowy.services.widgets.TimetableWidgetServices;
|
||||||
import io.github.wulkanowy.ui.main.MainActivity;
|
import io.github.wulkanowy.ui.main.MainActivity;
|
||||||
@ -26,7 +26,6 @@ public class TimetableWidgetProvider extends AppWidgetProvider {
|
|||||||
RepositoryContract repository;
|
RepositoryContract repository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
inject(context);
|
inject(context);
|
||||||
|
|
||||||
@ -106,7 +105,7 @@ public class TimetableWidgetProvider extends AppWidgetProvider {
|
|||||||
|
|
||||||
private void inject(Context context) {
|
private void inject(Context context) {
|
||||||
if (repository == null) {
|
if (repository == null) {
|
||||||
((WulkanowyApp) context.getApplicationContext()).getApplicationComponent().inject(this);
|
AndroidInjection.inject(this, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public final class DataObjectConverter {
|
|||||||
|
|
||||||
for (io.github.wulkanowy.api.generic.Lesson lesson : lessonList) {
|
for (io.github.wulkanowy.api.generic.Lesson lesson : lessonList) {
|
||||||
lessonEntityList.add(new AttendanceLesson()
|
lessonEntityList.add(new AttendanceLesson()
|
||||||
.setNumber(Integer.valueOf(lesson.getNumber()))
|
.setNumber(lesson.getNumber())
|
||||||
.setSubject(lesson.getSubject())
|
.setSubject(lesson.getSubject())
|
||||||
.setDate(lesson.getDate())
|
.setDate(lesson.getDate())
|
||||||
.setPresence(lesson.isPresence())
|
.setPresence(lesson.isPresence())
|
||||||
|
27
app/src/main/java/io/github/wulkanowy/utils/FabricUtils.java
Normal file
27
app/src/main/java/io/github/wulkanowy/utils/FabricUtils.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package io.github.wulkanowy.utils;
|
||||||
|
|
||||||
|
import com.crashlytics.android.answers.Answers;
|
||||||
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
import com.crashlytics.android.answers.SignUpEvent;
|
||||||
|
|
||||||
|
public final class FabricUtils {
|
||||||
|
|
||||||
|
private FabricUtils() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void logRegister(boolean result, String symbol) {
|
||||||
|
Answers.getInstance().logSignUp(new SignUpEvent()
|
||||||
|
.putMethod("Login activity")
|
||||||
|
.putSuccess(result)
|
||||||
|
.putCustomAttribute("symbol", symbol));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void logRefresh(String name, boolean result, String date) {
|
||||||
|
Answers.getInstance().logCustom(
|
||||||
|
new CustomEvent(name + " refresh")
|
||||||
|
.putCustomAttribute("Success", result ? 1 : 0)
|
||||||
|
.putCustomAttribute("Date", date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,38 +0,0 @@
|
|||||||
package io.github.wulkanowy.utils;
|
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public final class RootChecker {
|
|
||||||
|
|
||||||
private RootChecker() {
|
|
||||||
throw new IllegalStateException("Utility class");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isRooted() {
|
|
||||||
return checkOne() || checkTwo() || checkThree();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean checkOne() {
|
|
||||||
return Build.TAGS != null && Build.TAGS.contains("test-keys");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean checkTwo() {
|
|
||||||
return new File("/system/app/Superuser.apk").exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean checkThree() {
|
|
||||||
String[] commands = {"/system/xbin/which su", "/system/bin/which su", "which su"};
|
|
||||||
for (String command : commands) {
|
|
||||||
try {
|
|
||||||
Runtime.getRuntime().exec(command);
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user