mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-20 13:54:43 +01:00
[Database] Remove deprecated Lesson and LessonChange.
This commit is contained in:
parent
f05b39736c
commit
18b83e2ed8
@ -111,9 +111,6 @@
|
||||
android:name=".ui.modules.webpush.WebPushConfigActivity"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:theme="@style/AppTheme.Dark" />
|
||||
<activity
|
||||
android:name=".ui.modules.home.CounterActivityOld"
|
||||
android:theme="@style/AppTheme.Black" />
|
||||
<activity
|
||||
android:name=".ui.modules.home.CounterActivity"
|
||||
android:theme="@style/AppTheme.Black" />
|
||||
|
@ -72,7 +72,7 @@ import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesListFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.notifications.NotificationsFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.settings.ProfileManagerFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.settings.SettingsNewFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.webpush.WebPushFragment
|
||||
import pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoTouch
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
@ -12,7 +12,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZI
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessonrange.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
@ -111,7 +111,7 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
|
||||
it.id = it.buildId()
|
||||
}
|
||||
|
||||
data.lessonNewList.add(lessonObject)
|
||||
data.lessonList.add(lessonObject)
|
||||
dataDays.remove(lessonObject.date!!.value)
|
||||
|
||||
if (type != Lesson.TYPE_NORMAL) {
|
||||
@ -132,7 +132,7 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
|
||||
|
||||
for (day in dataDays) {
|
||||
val lessonDate = Date.fromValue(day)
|
||||
data.lessonNewList += Lesson(profileId, lessonDate.value.toLong()).apply {
|
||||
data.lessonList += Lesson(profileId, lessonDate.value.toLong()).apply {
|
||||
type = Lesson.TYPE_NO_LESSONS
|
||||
date = lessonDate
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessonrange.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
@ -182,7 +182,7 @@ class IdziennikWebTimetable(override val data: DataIdziennik,
|
||||
|
||||
d(TAG, "Clearing lessons between ${weekStart.stringY_m_d} and ${weekEnd.stringY_m_d} - timetable downloaded for $getDate")
|
||||
|
||||
data.lessonNewList.addAll(lessons)
|
||||
data.lessonList.addAll(lessons)
|
||||
data.toRemove.add(DataRemoveModel.Timetable.between(weekStart, weekEnd))
|
||||
|
||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_TIMETABLE, SYNC_ALWAYS)
|
||||
|
@ -8,7 +8,7 @@ import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_API_SCHOOLS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessonrange.LessonRange
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import java.util.*
|
||||
|
||||
|
@ -60,7 +60,7 @@ class LibrusApiTimetables(override val data: DataLibrus,
|
||||
}
|
||||
|
||||
if (day.isNullOrEmpty() || !lessonsFound) {
|
||||
data.lessonNewList.add(Lesson(profileId, lessonDate.value.toLong()).apply {
|
||||
data.lessonList.add(Lesson(profileId, lessonDate.value.toLong()).apply {
|
||||
type = Lesson.TYPE_NO_LESSONS
|
||||
date = lessonDate
|
||||
})
|
||||
@ -200,6 +200,6 @@ class LibrusApiTimetables(override val data: DataLibrus,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
data.lessonNewList.add(lessonObject)
|
||||
data.lessonList.add(lessonObject)
|
||||
}}
|
||||
}
|
||||
|
@ -89,13 +89,13 @@ class MobidziennikApiTimetable(val data: DataMobidziennik, rows: List<String>) {
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
data.lessonNewList += it
|
||||
data.lessonList += it
|
||||
}
|
||||
}
|
||||
|
||||
for (day in dataDays) {
|
||||
val lessonDate = Date.fromValue(day)
|
||||
data.lessonNewList += Lesson(data.profileId, lessonDate.value.toLong()).apply {
|
||||
data.lessonList += Lesson(data.profileId, lessonDate.value.toLong()).apply {
|
||||
type = Lesson.TYPE_NO_LESSONS
|
||||
date = lessonDate
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.AttendanceType
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessonrange.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.NoticeType
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
||||
|
@ -203,7 +203,7 @@ class VulcanApiTimetable(override val data: DataVulcan, val onSuccess: () -> Uni
|
||||
|
||||
d(TAG, "Clearing lessons between ${weekStart.stringY_m_d} and ${weekEnd.stringY_m_d} - timetable downloaded for $getDate")
|
||||
|
||||
data.lessonNewList.addAll(lessons)
|
||||
data.lessonList.addAll(lessons)
|
||||
data.toRemove.add(DataRemoveModel.Timetable.between(weekStart, weekEnd))
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_TIMETABLE, SYNC_ALWAYS)
|
||||
|
@ -19,9 +19,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventType
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessonrange.LessonRange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||
@ -36,6 +34,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsence
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceType
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.singleOrNull
|
||||
import pl.szczodrzynski.edziennik.toSparseArray
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
@ -138,8 +137,6 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
||||
var toRemove = mutableListOf<DataRemoveModel>()
|
||||
|
||||
val lessonList = mutableListOf<Lesson>()
|
||||
val lessonChangeList = mutableListOf<LessonChange>()
|
||||
val lessonNewList = mutableListOf<pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson>()
|
||||
|
||||
val gradeList = mutableListOf<Grade>()
|
||||
|
||||
@ -199,8 +196,6 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
||||
teacherAbsenceTypes.clear()
|
||||
|
||||
lessonList.clear()
|
||||
lessonChangeList.clear()
|
||||
lessonNewList.clear()
|
||||
gradeList.clear()
|
||||
noticeList.clear()
|
||||
attendanceList.clear()
|
||||
@ -284,15 +279,8 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
||||
if (setSeenMetadataList.isNotEmpty())
|
||||
db.metadataDao().setSeen(setSeenMetadataList)
|
||||
|
||||
// not extracted from DB - always new data
|
||||
if (lessonList.isNotEmpty()) {
|
||||
db.lessonDao().clear(profile.id)
|
||||
db.lessonDao().addAll(lessonList)
|
||||
}
|
||||
if (lessonChangeList.isNotEmpty())
|
||||
db.lessonChangeDao().addAll(lessonChangeList)
|
||||
if (lessonNewList.isNotEmpty()) {
|
||||
db.timetableDao() += lessonNewList
|
||||
db.timetableDao() += lessonList
|
||||
}
|
||||
if (gradeList.isNotEmpty()) {
|
||||
db.gradeDao().addAll(gradeList)
|
||||
|
@ -42,12 +42,8 @@ import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategoryDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.Lesson;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChangeDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRange;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonRangeDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessonrange.LessonRange;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessonrange.LessonRangeDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStoreDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber;
|
||||
@ -87,8 +83,6 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
TeacherAbsenceType.class,
|
||||
Subject.class,
|
||||
Notice.class,
|
||||
Lesson.class,
|
||||
LessonChange.class,
|
||||
Team.class,
|
||||
Attendance.class,
|
||||
Event.class,
|
||||
@ -110,7 +104,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
AttendanceType.class,
|
||||
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
|
||||
ConfigEntry.class,
|
||||
Metadata.class}, version = 72)
|
||||
Metadata.class}, version = 73)
|
||||
@TypeConverters({
|
||||
ConverterTime.class,
|
||||
ConverterDate.class,
|
||||
@ -127,8 +121,6 @@ public abstract class AppDb extends RoomDatabase {
|
||||
public abstract TeacherAbsenceTypeDao teacherAbsenceTypeDao();
|
||||
public abstract SubjectDao subjectDao();
|
||||
public abstract NoticeDao noticeDao();
|
||||
public abstract LessonDao lessonDao();
|
||||
public abstract LessonChangeDao lessonChangeDao();
|
||||
public abstract TeamDao teamDao();
|
||||
public abstract AttendanceDao attendanceDao();
|
||||
public abstract EventDao eventDao();
|
||||
@ -959,6 +951,16 @@ public abstract class AppDb extends RoomDatabase {
|
||||
database.execSQL("DROP TABLE _userCodes;");
|
||||
}
|
||||
};
|
||||
public static final Migration MIGRATION_72_73 = new Migration(72, 73) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
// Mark as seen all lucky number metadata.
|
||||
database.execSQL("UPDATE metadata SET seen=1 WHERE thingType=10");
|
||||
|
||||
database.execSQL("DROP TABLE lessons");
|
||||
database.execSQL("DROP TABLE lessonChanges");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static AppDb getDatabase(final Context context) {
|
||||
@ -1028,7 +1030,8 @@ public abstract class AppDb extends RoomDatabase {
|
||||
MIGRATION_68_69,
|
||||
MIGRATION_69_70,
|
||||
MIGRATION_70_71,
|
||||
MIGRATION_71_72
|
||||
MIGRATION_71_72,
|
||||
MIGRATION_72_73
|
||||
)
|
||||
.allowMainThreadQueries()
|
||||
//.fallbackToDestructiveMigration()
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-4.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessonrange
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
@ -22,4 +22,4 @@ class LessonRange (
|
||||
|
||||
@ColumnInfo(name = "lessonRangeEnd")
|
||||
val endTime: Time
|
||||
)
|
||||
)
|
@ -2,7 +2,7 @@
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-5.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessonrange
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
@ -23,4 +23,4 @@ interface LessonRangeDao {
|
||||
|
||||
@Query("DELETE FROM lessonRanges WHERE profileId = :profileId")
|
||||
fun clear(profileId: Int)
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.Ignore;
|
||||
import androidx.room.Index;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week;
|
||||
|
||||
@Entity(tableName = "lessons",
|
||||
primaryKeys = {"profileId", "lessonWeekDay", "lessonStartTime", "lessonEndTime"},
|
||||
indices = {@Index(value = {"profileId", "lessonWeekDay"})})
|
||||
public class Lesson {
|
||||
public int profileId;
|
||||
|
||||
@ColumnInfo(name = "lessonWeekDay")
|
||||
public int weekDay;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "lessonStartTime")
|
||||
public Time startTime;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "lessonEndTime")
|
||||
public Time endTime;
|
||||
@ColumnInfo(name = "lessonClassroomName")
|
||||
public String classroomName;
|
||||
|
||||
public long teacherId;
|
||||
public long subjectId;
|
||||
public long teamId;
|
||||
|
||||
@Ignore
|
||||
public Lesson() {
|
||||
this.profileId = -1;
|
||||
this.startTime = new Time();
|
||||
this.endTime = new Time();
|
||||
}
|
||||
|
||||
public Lesson(int profileId, int weekDay, @NonNull Time startTime, @NonNull Time endTime) {
|
||||
this.profileId = profileId;
|
||||
this.weekDay = weekDay;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.teacherId = -1;
|
||||
this.subjectId = -1;
|
||||
this.teamId = -1;
|
||||
}
|
||||
|
||||
public Lesson(int profileId, int weekDay, String startTime, String endTime) {
|
||||
this(profileId, weekDay, new Time().parseFromYmdHm(startTime), new Time().parseFromYmdHm(endTime));
|
||||
}
|
||||
|
||||
public Lesson(int profileId, String dateStr, String startTime, String endTime) {
|
||||
this(profileId, Week.getWeekDayFromDate(dateStr), startTime, endTime);
|
||||
}
|
||||
|
||||
public static Lesson fromLessonChange(LessonChange lessonChange)
|
||||
{
|
||||
Lesson lesson = new Lesson(lessonChange.profileId, lessonChange.lessonDate.getWeekDay(), lessonChange.startTime, lessonChange.endTime);
|
||||
lesson.profileId = lessonChange.profileId;
|
||||
lesson.teacherId = lessonChange.teacherId;
|
||||
lesson.teamId = lessonChange.teamId;
|
||||
lesson.subjectId = lessonChange.subjectId;
|
||||
lesson.classroomName = lessonChange.classroomName;
|
||||
return lesson;
|
||||
}
|
||||
|
||||
public static Lesson getByWeekDayAndSubject(List<Lesson> lessonList, int weekDay, long subjectId) {
|
||||
for (Lesson lesson: lessonList) {
|
||||
if (lesson.weekDay == weekDay && lesson.subjectId == subjectId)
|
||||
return lesson;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,97 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons;
|
||||
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.Index;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
|
||||
@Entity(tableName = "lessonChanges",
|
||||
primaryKeys = {"profileId", "lessonChangeDate", "lessonChangeStartTime", "lessonChangeEndTime"},
|
||||
indices = {@Index(value = {"profileId", "lessonChangeDate"})})
|
||||
public class LessonChange {
|
||||
public int profileId;
|
||||
|
||||
@ColumnInfo(name = "lessonChangeId")
|
||||
public long id;
|
||||
|
||||
@ColumnInfo(name = "lessonChangeWeekDay")
|
||||
public int weekDay;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "lessonChangeDate")
|
||||
public Date lessonDate;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "lessonChangeStartTime")
|
||||
public Time startTime;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "lessonChangeEndTime")
|
||||
public Time endTime;
|
||||
@ColumnInfo(name = "lessonChangeClassroomName")
|
||||
public String classroomName;
|
||||
@ColumnInfo(name = "lessonChangeType")
|
||||
public int type;
|
||||
public static int TYPE_CANCELLED = 1;
|
||||
public static int TYPE_CHANGE = 2;
|
||||
public static int TYPE_ADDED = 3;
|
||||
|
||||
public long teacherId;
|
||||
public long subjectId;
|
||||
public long teamId;
|
||||
|
||||
public LessonChange()
|
||||
{
|
||||
this.profileId = -1;
|
||||
this.lessonDate = Date.getToday();
|
||||
this.weekDay = this.lessonDate.getWeekDay();
|
||||
this.startTime = Time.getNow();
|
||||
this.endTime = Time.getNow();
|
||||
this.id = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public LessonChange(int profileId, String dateStr, String startTime, String endTime)
|
||||
{
|
||||
this(profileId, new Date().parseFromYmd(dateStr), new Time().parseFromYmdHm(startTime), new Time().parseFromYmdHm(endTime));
|
||||
}
|
||||
|
||||
public LessonChange(int profileId, @NonNull Date date, @NonNull Time startTime, @NonNull Time endTime)
|
||||
{
|
||||
this.profileId = profileId;
|
||||
this.lessonDate = date;
|
||||
this.weekDay = this.lessonDate.getWeekDay();
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.id = date.combineWith(startTime);
|
||||
}
|
||||
|
||||
public Lesson getOriginalLesson(List<Lesson> lessonList)
|
||||
{
|
||||
int weekDay = this.lessonDate.getWeekDay();
|
||||
for (Lesson lesson: lessonList) {
|
||||
if (lesson.weekDay == weekDay
|
||||
&& lesson.startTime.getValue() == this.startTime.getValue()
|
||||
&& lesson.endTime.getValue() == this.endTime.getValue())
|
||||
{
|
||||
return lesson;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean matches(Lesson lesson) {
|
||||
if (lesson == null) {
|
||||
return false;
|
||||
}
|
||||
// we are assuming the start and end time is equal
|
||||
return this.profileId == lesson.profileId
|
||||
&& this.teacherId == lesson.teacherId
|
||||
&& this.subjectId == lesson.subjectId
|
||||
&& this.teamId == lesson.teamId
|
||||
&& this.classroomName.equals(lesson.classroomName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,113 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery;
|
||||
import androidx.sqlite.db.SupportSQLiteQuery;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.RawQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeCounter;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_LESSON_CHANGE;
|
||||
import static pl.szczodrzynski.edziennik.utils.Utils.d;
|
||||
|
||||
@Dao
|
||||
public abstract class LessonChangeDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract long add(LessonChange lessonChange);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract void addAll(List<LessonChange> lessonChangeList);
|
||||
|
||||
@Query("DELETE FROM lessonChanges WHERE profileId = :profileId")
|
||||
public abstract void clear(int profileId);
|
||||
|
||||
public static String getQueryString(int profileId, String filter) {
|
||||
return "SELECT\n" +
|
||||
"lessonChanges.profileId AS lessonChangeProfileId,\n" +
|
||||
"lessonChanges.lessonChangeId,\n" +
|
||||
"lessonChanges.lessonChangeDate,\n" +
|
||||
"lessonChanges.lessonChangeStartTime,\n" +
|
||||
"lessonChanges.lessonChangeType,\n" +
|
||||
"lessonChanges.lessonChangeClassroomName,\n" +
|
||||
"lessonChanges.subjectId AS changeSubjectId,\n" +
|
||||
"lessonChanges.teacherId AS changeTeacherId,\n" +
|
||||
"lessonChanges.teamId AS changeTeamId,\n" +
|
||||
"subjects.subjectLongName AS changeSubjectLongName,\n" +
|
||||
"subjects.subjectShortName AS changeSubjectShortName,\n" +
|
||||
"teams.teamName AS changeTeamName," +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS changeTeacherFullName,\n" +
|
||||
"metadata.seen, metadata.notified, metadata.addedDate\n" +
|
||||
"FROM lessonChanges\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"LEFT JOIN metadata ON lessonChangeId = thingId AND thingType = " + TYPE_LESSON_CHANGE + " AND metadata.profileId = lessonChanges.profileId\n" +// TODO validate this works!. I hope so
|
||||
"WHERE "+(profileId == -1 ? "" : "lessonChanges.profileId = "+profileId+" AND ")+filter+"\n" +
|
||||
"ORDER BY lessonChanges.profileId, lessonChangeDate, lessonChangeStartTime ASC";
|
||||
}
|
||||
|
||||
@RawQuery(observedEntities = {Lesson.class, LessonChange.class})
|
||||
abstract LiveData<List<LessonFull>> getAll(SupportSQLiteQuery query);
|
||||
@RawQuery
|
||||
abstract List<LessonFull> getAllNow(SupportSQLiteQuery query);
|
||||
@RawQuery
|
||||
abstract LessonFull getNow(SupportSQLiteQuery query);
|
||||
|
||||
public String getQueryWithLessons(int profileId, String filter) {
|
||||
return "SELECT\n" +
|
||||
"lessonChanges.profileId,\n" +
|
||||
"lessonChangeId,\n" +
|
||||
"lessonChangeDate AS lessonDate,\n" +
|
||||
"lessonChangeStartTime,\n" +
|
||||
"lessonChangeType,\n" +
|
||||
"lessonChangeClassroomName,\n" +
|
||||
"lessonChanges.subjectId AS changeSubjectId,\n" +
|
||||
"lessonChanges.teacherId AS changeTeacherId,\n" +
|
||||
"lessonChanges.teamId AS changeTeamId,\n" +
|
||||
"subjects.subjectLongName AS changeSubjectLongName,\n" +
|
||||
"subjects.subjectShortName AS changeSubjectShortName,\n" +
|
||||
"lessonsFull.*,\n" +
|
||||
"teams.teamName AS changeTeamName,teachers.teacherName || ' ' || teachers.teacherSurname AS changeTeacherFullName\n" +
|
||||
",metadata.*FROM lessonChanges\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"LEFT JOIN metadata ON lessonChangeId = thingId AND thingType = 6 AND metadata.profileId = "+profileId+"\n" +
|
||||
"JOIN (\n" +
|
||||
"SELECT subjects.subjectLongName,\n" +
|
||||
"lessons.*,\n" +
|
||||
"subjects.subjectShortName,\n" +
|
||||
"teams.teamName,\n" +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName\n" +
|
||||
"FROM lessons\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"WHERE lessons.profileId = "+profileId+") lessonsFull ON lessonChangeWeekDay = lessonsFull.lessonWeekDay AND lessonChangeStartTime = lessonStartTime\n" +
|
||||
"WHERE lessonChanges.profileId = "+profileId+" AND "+filter+"\n" +
|
||||
"ORDER BY lessonChangeDate, lessonChangeStartTime ASC";
|
||||
}
|
||||
|
||||
public List<LessonFull> getAllChangesWithLessonsNow(int profileId) {
|
||||
String query = getQueryWithLessons(profileId, "1");
|
||||
d("DB", query);
|
||||
return getAllNow(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
|
||||
public List<LessonFull> getNotNotifiedNow(int profileId) {
|
||||
return getAllNow(new SimpleSQLiteQuery(getQueryWithLessons(profileId, "notified = 0")));
|
||||
}
|
||||
|
||||
@Query("SELECT profileId, lessonChangeDate, count(*) AS lessonChangeCount FROM lessonChanges WHERE profileId = :profileId GROUP BY lessonChangeDate")
|
||||
public abstract List<LessonChangeCounter> getLessonChangeCountersNow(int profileId);
|
||||
|
||||
@Query("SELECT profileId, lessonChangeDate, count(*) AS lessonChangeCount FROM lessonChanges WHERE profileId = :profileId AND lessonChangeDate = :date GROUP BY lessonChangeDate")
|
||||
public abstract LiveData<LessonChangeCounter> getLessonChangeCounterByDate(int profileId, Date date);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons;
|
||||
|
||||
public class LessonChangeFull extends LessonChange {
|
||||
/*public String changeTeacherFullName = "";
|
||||
|
||||
public String changeSubjectLongName = "";
|
||||
public String changeSubjectShortName = "";
|
||||
|
||||
public String changeTeamName = "";
|
||||
|
||||
// metadata
|
||||
public boolean seen;
|
||||
public boolean notified;
|
||||
public long addedDate;*/
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery;
|
||||
import androidx.sqlite.db.SupportSQLiteQuery;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.RawQuery;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
|
||||
@Dao
|
||||
public abstract class LessonDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract long add(Lesson lesson);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract void addAll(List<Lesson> lessonList);
|
||||
|
||||
@Query("DELETE FROM lessons WHERE profileId = :profileId")
|
||||
public abstract void clear(int profileId);
|
||||
|
||||
@RawQuery(observedEntities = {Lesson.class, LessonChange.class})
|
||||
abstract LiveData<List<LessonFull>> getAll(SupportSQLiteQuery query);
|
||||
@RawQuery
|
||||
abstract List<LessonFull> getAllNow(SupportSQLiteQuery query);
|
||||
@RawQuery
|
||||
abstract LessonFull getNow(SupportSQLiteQuery query);
|
||||
|
||||
public LiveData<List<LessonFull>> getAllByDate(int profileId, @NonNull Date date, @NonNull Time nowTime) {
|
||||
int weekDay = date.getWeekDay();
|
||||
String query = "SELECT\n" +
|
||||
"lessons.*,\n" +
|
||||
"subjects.subjectLongName,\n" +
|
||||
"subjects.subjectShortName,\n" +
|
||||
"teams.teamName,\n" +
|
||||
"lessonChangesFull.*,\n" +
|
||||
"('"+nowTime.getStringValue()+"' > lessonEndTime AND lessonWeekDay = "+weekDay+") AS lessonPassed,\n" +
|
||||
"('"+nowTime.getStringValue()+"' BETWEEN lessonStartTime AND lessonEndTime AND lessonWeekDay = "+weekDay+") AS lessonCurrent,\n" +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName\n" +
|
||||
"FROM lessons\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"LEFT JOIN \n" +
|
||||
"("
|
||||
+LessonChangeDao.getQueryString(profileId, "lessonChangeDate = '"+date.getStringY_m_d()+"'")+
|
||||
") lessonChangesFull ON lessons.profileId = lessonChangesFull.lessonChangeProfileId AND lessonStartTime = lessonChangeStartTime\n" +
|
||||
"WHERE lessons.profileId = "+profileId+" AND lessonWeekDay = "+weekDay+"\n" +
|
||||
"ORDER BY lessonStartTime ASC";
|
||||
//Log.d("DB", "Query "+query);
|
||||
return getAll(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
|
||||
public List<LessonFull> getAllWeekNow(int profileId, @NonNull Date weekBeginDate, @NonNull Date todayDate) {
|
||||
String query = "SELECT\n" +
|
||||
"lessons.*,\n" +
|
||||
"subjects.subjectLongName,\n" +
|
||||
"subjects.subjectShortName,\n" +
|
||||
"teams.teamName,\n" +
|
||||
"lessonChangesFull.*,\n" +
|
||||
"date(\n" +
|
||||
"'"+weekBeginDate.getStringY_m_d()+"', \n" +
|
||||
"'+'||(case 1 when lessonWeekDay < "+todayDate.getWeekDay()+" then lessonWeekDay+7 else lessonWeekDay end)||' days'\n" +
|
||||
") AS lessonDate,\n" +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName\n" +
|
||||
"FROM lessons\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"LEFT JOIN \n" +
|
||||
"("
|
||||
+LessonChangeDao.getQueryString(profileId, "1")+
|
||||
") lessonChangesFull ON lessons.profileId = lessonChangesFull.lessonChangeProfileId AND lessonStartTime = lessonChangeStartTime AND lessonChangesFull.lessonChangeDate = lessonDate\n" +
|
||||
(profileId == -1 ? "" : "WHERE lessons.profileId = "+profileId+"\n") +
|
||||
"ORDER BY lessons.profileId, lessonDate, lessonStartTime ASC\n";
|
||||
//Log.d("DB", "Query "+query);
|
||||
return getAllNow(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
|
||||
public LessonFull getByDateTimeNow(int profileId, @NonNull Date date, @NonNull Time time) {
|
||||
String query = "SELECT\n" +
|
||||
"lessons.*,\n" +
|
||||
"subjects.subjectLongName,\n" +
|
||||
"subjects.subjectShortName,\n" +
|
||||
"teams.teamName,\n" +
|
||||
"lessonChangesFull.*,\n" +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName\n" +
|
||||
"FROM lessons\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"LEFT JOIN \n" +
|
||||
"("
|
||||
+LessonChangeDao.getQueryString(profileId, "lessonChangeDate = '"+date.getStringY_m_d()+"'")+
|
||||
") lessonChangesFull ON lessons.profileId = lessonChangesFull.lessonChangeProfileId AND lessonStartTime = lessonChangeStartTime\n" +
|
||||
"WHERE lessons.profileId = "+profileId+" AND lessonWeekDay = "+date.getWeekDay()+" AND ('"+time.getStringValue()+"' BETWEEN lessonStartTime AND lessonEndTime)\n" +
|
||||
"ORDER BY lessonStartTime ASC";
|
||||
//Log.d("DB", "Query "+query);
|
||||
return getNow(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
|
||||
public List<LessonFull> getAllNearestNow(int profileId, @NonNull Date weekBeginDate, @NonNull Date todayDate, @NonNull Time nowTime) {
|
||||
int todayWeekDay = todayDate.getWeekDay();
|
||||
String query = "SELECT\n" +
|
||||
"lessons.*,\n" +
|
||||
"subjects.subjectLongName,\n" +
|
||||
"subjects.subjectShortName,\n" +
|
||||
"teams.teamName,\n" +
|
||||
"lessonChangesFull.*,\n" +
|
||||
"date(\n" +
|
||||
"'"+weekBeginDate.getStringY_m_d()+"', \n" +
|
||||
"'+'||(case 1 when lessonWeekDay < "+todayWeekDay+" then lessonWeekDay+7 else lessonWeekDay end)||' days'\n" +
|
||||
") AS lessonDate,\n" +
|
||||
"('"+nowTime.getStringValue()+"' > lessonEndTime AND lessonWeekDay = "+todayWeekDay+") AS lessonPassed,\n" +
|
||||
"('"+nowTime.getStringValue()+"' BETWEEN lessonStartTime AND lessonEndTime AND lessonWeekDay = "+todayWeekDay+") AS lessonCurrent,\n" +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName\n" +
|
||||
"FROM lessons\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"LEFT JOIN \n" +
|
||||
"("
|
||||
+LessonChangeDao.getQueryString(profileId, "1")+
|
||||
") lessonChangesFull ON lessons.profileId = lessonChangesFull.lessonChangeProfileId AND lessonStartTime = lessonChangeStartTime AND lessonChangesFull.lessonChangeDate = lessonDate\n" +
|
||||
"WHERE lessons.profileId = "+profileId+" AND (lessonWeekDay != "+todayWeekDay+" OR '"+nowTime.getStringValue()+"' < lessonEndTime OR '"+nowTime.getStringValue()+"' > lessonStartTime)\n" +
|
||||
"ORDER BY lessonDate, lessonStartTime ASC";
|
||||
//Log.d("DB", "Query "+query);
|
||||
return getAllNow(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
|
||||
public LiveData<List<LessonFull>> getAllByDateWithoutChanges(int profileId, @NonNull Date date) {
|
||||
String query = "SELECT\n" +
|
||||
"lessons.*,\n" +
|
||||
"subjects.subjectLongName,\n" +
|
||||
"subjects.subjectShortName,\n" +
|
||||
"teams.teamName,\n" +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName\n" +
|
||||
"FROM lessons\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"WHERE lessons.profileId = "+profileId+" AND lessonWeekDay = "+date.getWeekDay()+"\n" +
|
||||
"ORDER BY lessonStartTime ASC";
|
||||
//Log.d("DB", "Query "+query);
|
||||
return getAll(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
|
||||
public LessonFull getByDateTimeWithoutChangesNow(int profileId, @NonNull Date date, @NonNull Time time) {
|
||||
String query = "SELECT\n" +
|
||||
"lessons.*,\n" +
|
||||
"subjects.subjectLongName,\n" +
|
||||
"subjects.subjectShortName,\n" +
|
||||
"teams.teamName,\n" +
|
||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName\n" +
|
||||
"FROM lessons\n" +
|
||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||
"WHERE lessons.profileId = "+profileId+" AND lessonWeekDay = "+date.getWeekDay()+" AND lessonStartTime = '"+time.getStringValue()+"'\n" +
|
||||
"ORDER BY lessonStartTime ASC";
|
||||
//Log.d("DB", "Query "+query);
|
||||
return getNow(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.lessons;
|
||||
|
||||
import androidx.room.ColumnInfo;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_ADDED;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CANCELLED;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CHANGE;
|
||||
import static pl.szczodrzynski.edziennik.utils.Utils.bs;
|
||||
|
||||
public class LessonFull extends Lesson {
|
||||
public String teacherFullName = "";
|
||||
|
||||
public String subjectLongName = "";
|
||||
public String subjectShortName = "";
|
||||
|
||||
public String teamName = "";
|
||||
|
||||
@Nullable
|
||||
public Date lessonDate;
|
||||
|
||||
@ColumnInfo(name = "lessonChangeId")
|
||||
public long changeId;
|
||||
@ColumnInfo(name = "lessonChangeType")
|
||||
public int changeType = -1;
|
||||
@ColumnInfo(name = "lessonChangeClassroomName")
|
||||
public String changeClassroomName = "";
|
||||
public String changeTeacherFullName = "";
|
||||
|
||||
public String changeSubjectLongName = "";
|
||||
public String changeSubjectShortName = "";
|
||||
|
||||
public String changeTeamName = "";
|
||||
|
||||
public long changeTeacherId;
|
||||
public long changeSubjectId;
|
||||
public long changeTeamId;
|
||||
|
||||
// metadata
|
||||
public boolean seen;
|
||||
public boolean notified;
|
||||
public long addedDate;
|
||||
|
||||
public boolean lessonPassed;
|
||||
public boolean lessonCurrent;
|
||||
|
||||
public boolean changedTeacherFullName() {
|
||||
return changeId != 0 && changeType != TYPE_CANCELLED && changeTeacherFullName != null && !changeTeacherFullName.equals(teacherFullName) && !changeTeacherFullName.equals("");
|
||||
}
|
||||
public boolean changedSubjectLongName() {
|
||||
return changeId != 0 && changeType != TYPE_CANCELLED && changeSubjectLongName != null && !changeSubjectLongName.equals(subjectLongName) && !changeSubjectLongName.equals("");
|
||||
}
|
||||
public boolean changedTeamName() {
|
||||
return changeId != 0 && changeType != TYPE_CANCELLED && changeTeamName != null && !changeTeamName.equals(teamName) && !changeTeamName.equals("");
|
||||
}
|
||||
public boolean changedClassroomName() {
|
||||
return changeId != 0 && changeType != TYPE_CANCELLED && changeClassroomName != null && !changeClassroomName.equals(classroomName) && !changeClassroomName.equals("");
|
||||
}
|
||||
|
||||
public String getTeacherFullName() {
|
||||
return getTeacherFullName(false);
|
||||
}
|
||||
public String getTeacherFullName(boolean formatted) {
|
||||
if (!changedTeacherFullName())
|
||||
return bs(teacherFullName);
|
||||
else
|
||||
return (formatted?bs(teacherFullName)+" -> ":"") + bs(changeTeacherFullName);
|
||||
}
|
||||
|
||||
public String getSubjectLongName() {
|
||||
return getSubjectLongName(false);
|
||||
}
|
||||
public String getSubjectLongName(boolean formatted) {
|
||||
if (!changedSubjectLongName())
|
||||
return bs(subjectLongName);
|
||||
else
|
||||
return (formatted?bs(subjectLongName)+" -> ":"") + bs(changeSubjectLongName);
|
||||
}
|
||||
|
||||
public String getTeamName() {
|
||||
return getTeamName(false);
|
||||
}
|
||||
public String getTeamName(boolean formatted) {
|
||||
if (!changedTeamName())
|
||||
return bs(teamName);
|
||||
else
|
||||
return (formatted?bs(teamName)+" -> ":"") + bs(changeTeamName);
|
||||
}
|
||||
|
||||
public String getClassroomName() {
|
||||
return getClassroomName(false);
|
||||
}
|
||||
public String getClassroomName(boolean formatted) {
|
||||
if (!changedClassroomName())
|
||||
return bs(classroomName);
|
||||
else
|
||||
return (formatted?bs(classroomName)+" -> ":"") + bs(changeClassroomName);
|
||||
}
|
||||
|
||||
public String changeTypeStr(Context context) {
|
||||
if (changeType == TYPE_CANCELLED) {
|
||||
return context.getString(R.string.lesson_cancelled);
|
||||
}
|
||||
if (changeType == TYPE_CHANGE) {
|
||||
return context.getString(R.string.lesson_change);
|
||||
}
|
||||
if (changeType == TYPE_ADDED) {
|
||||
return context.getString(R.string.lesson_added);
|
||||
}
|
||||
return context.getString(R.string.lesson_timetable_change);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LessonFull{" +
|
||||
"profileId=" + profileId +
|
||||
", weekDay=" + weekDay +
|
||||
", startTime=" + startTime +
|
||||
", endTime=" + endTime +
|
||||
", classroomName='" + classroomName + '\'' +
|
||||
", teacherId=" + teacherId +
|
||||
", subjectId=" + subjectId +
|
||||
", teamId=" + teamId +
|
||||
", teacherFullName='" + teacherFullName + '\'' +
|
||||
", subjectLongName='" + subjectLongName + '\'' +
|
||||
", subjectShortName='" + subjectShortName + '\'' +
|
||||
", teamName='" + teamName + '\'' +
|
||||
", lessonDate=" + lessonDate +
|
||||
", changeId=" + changeId +
|
||||
", changeType=" + changeType +
|
||||
", changeClassroomName='" + changeClassroomName + '\'' +
|
||||
", changeTeacherFullName='" + changeTeacherFullName + '\'' +
|
||||
", changeSubjectLongName='" + changeSubjectLongName + '\'' +
|
||||
", changeSubjectShortName='" + changeSubjectShortName + '\'' +
|
||||
", changeTeamName='" + changeTeamName + '\'' +
|
||||
", changeTeacherId=" + changeTeacherId +
|
||||
", changeSubjectId=" + changeSubjectId +
|
||||
", changeTeamId=" + changeTeamId +
|
||||
", seen=" + seen +
|
||||
", notified=" + notified +
|
||||
", addedDate=" + addedDate +
|
||||
", lessonPassed=" + lessonPassed +
|
||||
", lessonCurrent=" + lessonCurrent +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -13,10 +13,9 @@ import pl.szczodrzynski.edziennik.data.db.modules.announcements.Announcement;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.utils.models.UnreadCounter;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_ANNOUNCEMENT;
|
||||
@ -75,19 +74,9 @@ public abstract class MetadataDao {
|
||||
updateSeen(profileId, ((Event) o).type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).id, seen);
|
||||
}
|
||||
}
|
||||
if (o instanceof LessonChange) {
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((LessonChange) o).id, seen, false, 0)) == -1) {
|
||||
updateSeen(profileId, TYPE_LESSON_CHANGE, ((LessonChange) o).id, seen);
|
||||
}
|
||||
}
|
||||
if (o instanceof LessonFull) {
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).changeId, seen, false, 0)) == -1) {
|
||||
updateSeen(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).changeId, seen);
|
||||
}
|
||||
}
|
||||
if (o instanceof pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) {
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), seen, false, 0)) == -1) {
|
||||
updateSeen(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), seen);
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).getId(), seen, false, 0)) == -1) {
|
||||
updateSeen(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).getId(), seen);
|
||||
}
|
||||
}
|
||||
if (o instanceof Announcement) {
|
||||
@ -124,19 +113,9 @@ public abstract class MetadataDao {
|
||||
updateNotified(profileId, ((Event) o).type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).id, notified);
|
||||
}
|
||||
}
|
||||
if (o instanceof LessonChange) {
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((LessonChange) o).id, false, notified, 0)) == -1) {
|
||||
updateNotified(profileId, TYPE_LESSON_CHANGE, ((LessonChange) o).id, notified);
|
||||
}
|
||||
}
|
||||
if (o instanceof LessonFull) {
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).changeId, false, notified, 0)) == -1) {
|
||||
updateNotified(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).changeId, notified);
|
||||
}
|
||||
}
|
||||
if (o instanceof pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) {
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), false, notified, 0)) == -1) {
|
||||
updateNotified(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), notified);
|
||||
if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).getId(), false, notified, 0)) == -1) {
|
||||
updateNotified(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).getId(), notified);
|
||||
}
|
||||
}
|
||||
if (o instanceof Announcement) {
|
||||
@ -228,9 +207,6 @@ public abstract class MetadataDao {
|
||||
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = "+TYPE_HOMEWORK+" AND thingId NOT IN (SELECT eventId FROM events WHERE profileId = :profileId AND eventType = -1);")
|
||||
public abstract void deleteUnusedHomework(int profileId);
|
||||
|
||||
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = "+TYPE_LESSON_CHANGE+" AND thingId NOT IN (SELECT lessonChangeId FROM lessonChanges WHERE profileId = :profileId);")
|
||||
public abstract void deleteUnusedLessonChanges(int profileId);
|
||||
|
||||
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = "+TYPE_ANNOUNCEMENT+" AND thingId NOT IN (SELECT announcementId FROM announcements WHERE profileId = :profileId);")
|
||||
public abstract void deleteUnusedAnnouncements(int profileId);
|
||||
|
||||
@ -244,7 +220,6 @@ public abstract class MetadataDao {
|
||||
deleteUnusedAttendance(profileId);
|
||||
deleteUnusedEvents(profileId);
|
||||
deleteUnusedHomework(profileId);
|
||||
deleteUnusedLessonChanges(profileId);
|
||||
deleteUnusedAnnouncements(profileId);
|
||||
deleteUnusedMessages(profileId);
|
||||
}
|
||||
|
@ -1,24 +1,16 @@
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.lessonchange;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableAdapter;
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogLessonChangeListBinding;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
|
||||
public class LessonChangeDialog {
|
||||
private App app;
|
||||
@ -56,7 +48,7 @@ public class LessonChangeDialog {
|
||||
b.lessonChangeView.setHasFixedSize(true);
|
||||
b.lessonChangeView.setLayoutManager(new LinearLayoutManager(context));
|
||||
|
||||
app.db.lessonDao().getAllByDate(profileId, date, Time.getNow()).observe((LifecycleOwner) context, lessons -> {
|
||||
/*app.db.lessonDao().getAllByDate(profileId, date, Time.getNow()).observe((LifecycleOwner) context, lessons -> {
|
||||
if (app == null || app.profile == null || b == null)
|
||||
return;
|
||||
|
||||
@ -72,6 +64,6 @@ public class LessonChangeDialog {
|
||||
b.lessonChangeView.setAdapter(adapter);
|
||||
b.lessonChangeView.setVisibility(View.VISIBLE);
|
||||
});
|
||||
});
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
@ -56,8 +56,6 @@ class ProfileRemoveDialog(
|
||||
app.db.eventTypeDao().clear(profileId)
|
||||
app.db.gradeDao().clear(profileId)
|
||||
app.db.gradeCategoryDao().clear(profileId)
|
||||
app.db.lessonDao().clear(profileId)
|
||||
app.db.lessonChangeDao().clear(profileId)
|
||||
app.db.luckyNumberDao().clear(profileId)
|
||||
app.db.noticeDao().clear(profileId)
|
||||
app.db.subjectDao().clear(profileId)
|
||||
@ -100,4 +98,4 @@ class ProfileRemoveDialog(
|
||||
activity.reloadTarget()
|
||||
Toast.makeText(activity, R.string.dialog_profile_remove_success, Toast.LENGTH_LONG).show()
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import pl.szczodrzynski.edziennik.setText
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventDetailsDialog
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
@ -38,7 +38,6 @@ import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.MainActivity;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceFull;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaCalendarBinding;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding;
|
||||
@ -46,7 +45,6 @@ import pl.szczodrzynski.edziennik.ui.dialogs.day.DayDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeCounter;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeEvent;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeEventRenderer;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceCounter;
|
||||
@ -174,7 +172,7 @@ public class AgendaFragment extends Fragment {
|
||||
|
||||
List<CalendarEvent> eventList = new ArrayList<>();
|
||||
|
||||
List<LessonChangeCounter> lessonChangeCounters = app.db.lessonChangeDao().getLessonChangeCountersNow(App.profileId);
|
||||
/* List<LessonChangeCounter> lessonChangeCounters = app.db.lessonChangeDao().getLessonChangeCountersNow(App.profileId);
|
||||
for (LessonChangeCounter counter : lessonChangeCounters) {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
@ -193,7 +191,7 @@ public class AgendaFragment extends Fragment {
|
||||
counter.lessonChangeDate,
|
||||
counter.lessonChangeCount
|
||||
));
|
||||
}
|
||||
} TODO: Implement new timetable lesson changes */
|
||||
|
||||
if (app.profile.getStudentData("showTeacherAbsences", true)) {
|
||||
List<TeacherAbsenceFull> teacherAbsenceList = app.db.teacherAbsenceDao().getAllFullNow(App.profileId);
|
||||
@ -407,7 +405,7 @@ public class AgendaFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
List<LessonFull> lessonChanges = app.db.lessonChangeDao().getAllChangesWithLessonsNow(App.profileId);
|
||||
/* List<LessonFull> lessonChanges = app.db.lessonChangeDao().getAllChangesWithLessonsNow(App.profileId);
|
||||
|
||||
for (LessonFull lesson: lessonChanges) {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
@ -423,7 +421,7 @@ public class AgendaFragment extends Fragment {
|
||||
lesson.startTime.second);
|
||||
Drawable eventIcon = new IconicsDrawable(activity).icon(CommunityMaterial.Icon.cmd_checkbox_blank_circle).size(IconicsSize.dp(10)).color(IconicsColor.colorInt(0xff78909c));
|
||||
eventList.add(new EventDay(startTime, eventIcon));
|
||||
}
|
||||
} TODO: Implement new timetable lesson changes */
|
||||
|
||||
getActivity().runOnUiThread(() -> {
|
||||
//List<EventDay> eventList = new ArrayList<>();
|
||||
|
@ -1,240 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.home;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.databinding.ActivityCounterBinding;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld.updateInterval;
|
||||
|
||||
public class CounterActivityOld extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "CounterActivityOld";
|
||||
private App app;
|
||||
private ActivityCounterBinding b;
|
||||
|
||||
Timer timetableTimer;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = (App) getApplication();
|
||||
b = DataBindingUtil.inflate(getLayoutInflater(), R.layout.activity_counter, null, false);
|
||||
setContentView(b.getRoot());
|
||||
|
||||
timetableTimer = new Timer();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
private List<LessonFull> lessons = new ArrayList<>();
|
||||
|
||||
private void update() {
|
||||
// BELL SYNCING
|
||||
Time now = Time.getNow();
|
||||
Time syncedNow = now;
|
||||
//Time updateDiff = null;
|
||||
if (app.config.getTimetable().getBellSyncDiff() != null) {
|
||||
if (app.config.getTimetable().getBellSyncMultiplier() < 0) {
|
||||
// the bell is too fast, need to step further to go with it
|
||||
// add some time
|
||||
syncedNow = Time.sum(now, app.config.getTimetable().getBellSyncDiff());
|
||||
//Toast.makeText(c, "Bell sync diff is "+app.appConfig.bellSyncDiff.getStringHMS()+"\n\n Synced now is "+syncedNow.getStringHMS(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (app.config.getTimetable().getBellSyncMultiplier() > 0) {
|
||||
// the bell is delayed, need to roll the "now" time back
|
||||
// subtract some time
|
||||
syncedNow = Time.diff(now, app.config.getTimetable().getBellSyncDiff());
|
||||
}
|
||||
}
|
||||
|
||||
assert counterTarget != null;
|
||||
if (lessons.size() == 0 || syncedNow.getValue() > counterTarget.getValue()) {
|
||||
findLessons(syncedNow);
|
||||
}
|
||||
else {
|
||||
scheduleUpdate(updateCounter(syncedNow));
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleUpdate(long newRefreshInterval) {
|
||||
try {
|
||||
timetableTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runOnUiThread(() -> update());
|
||||
}
|
||||
}, newRefreshInterval);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void findLessons(Time syncedNow) {
|
||||
AsyncTask.execute(() -> {
|
||||
Date today = Date.getToday();
|
||||
lessons = app.db.lessonDao().getAllNearestNow(App.profileId, today.getWeekStart(), today, syncedNow);
|
||||
|
||||
if (lessons != null && lessons.size() != 0) {
|
||||
Date displayingDate = lessons.get(0).lessonDate;
|
||||
if (displayingDate == null) {
|
||||
runOnUiThread(() -> scheduleUpdate(updateViews(null, syncedNow, 0, 0)));
|
||||
return;
|
||||
}
|
||||
int displayingWeekDay = displayingDate.getWeekDay();
|
||||
|
||||
Log.d(TAG, "Displaying date is "+displayingDate.getStringY_m_d()+", weekDay is "+displayingWeekDay);
|
||||
|
||||
int notPassedIndex = -1;
|
||||
int notPassedWeekDay = -1;
|
||||
//int firstIndex = -1;
|
||||
int lastIndex = -1;
|
||||
int index = 0;
|
||||
for (LessonFull lesson: lessons) {
|
||||
if (notPassedIndex == -1 && !lesson.lessonPassed) {
|
||||
if (lesson.lessonDate != null)
|
||||
displayingDate = lesson.lessonDate;
|
||||
displayingWeekDay = lesson.weekDay;
|
||||
notPassedIndex = index;
|
||||
notPassedWeekDay = lesson.weekDay;
|
||||
}
|
||||
if (lesson.weekDay == notPassedWeekDay) {
|
||||
/*if (firstIndex == -1)
|
||||
firstIndex = index;*/
|
||||
lastIndex = index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
// for safety
|
||||
/*if (firstIndex == -1)
|
||||
firstIndex++;*/
|
||||
if (notPassedIndex == -1)
|
||||
notPassedIndex++;
|
||||
if (lastIndex == -1)
|
||||
lastIndex++;
|
||||
|
||||
Log.d(TAG, "Not passed index is "+notPassedIndex);
|
||||
Log.d(TAG, "Last index is "+lastIndex);
|
||||
Log.d(TAG, "New Displaying date is "+displayingDate.getStringY_m_d()+", weekDay is "+displayingWeekDay);
|
||||
|
||||
Date finalDisplayingDate = displayingDate;
|
||||
int finalNotPassedIndex = notPassedIndex;
|
||||
int finalLastIndex = lastIndex;
|
||||
runOnUiThread(() -> scheduleUpdate(updateViews(finalDisplayingDate, syncedNow, finalNotPassedIndex, finalLastIndex)));
|
||||
}
|
||||
else {
|
||||
runOnUiThread(() -> scheduleUpdate(updateViews(null, syncedNow, 0, 0)));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private Time counterTarget = new Time(0, 0, 0);
|
||||
private static final short TIME_TILL = 0;
|
||||
private static final short TIME_LEFT = 1;
|
||||
private short counterType = TIME_LEFT;
|
||||
private long updateCounter(Time syncedNow) {
|
||||
Time diff = Time.diff(counterTarget, syncedNow);
|
||||
b.timeLeft.setText(counterType == TIME_TILL ? HomeFragmentOld.timeTill(app, diff, app.config.getTimetable().getCountInSeconds(), "\n") : HomeFragmentOld.timeLeft(app, diff, app.config.getTimetable().getCountInSeconds(), "\n"));
|
||||
return updateInterval(app, diff);
|
||||
}
|
||||
|
||||
private long updateViews(Date displayingDate, Time syncedNow, int notPassedIndex, int lastIndex) {
|
||||
long newRefreshInterval = 1000*5;
|
||||
|
||||
if (displayingDate == null) {
|
||||
return newRefreshInterval;
|
||||
}
|
||||
|
||||
int dayDiff = Date.diffDays(displayingDate, Date.getToday());
|
||||
if (displayingDate.getValue() != Date.getToday().getValue() && dayDiff == 0) {
|
||||
dayDiff++;
|
||||
}
|
||||
|
||||
LessonFull lessonFirst = lessons.get(dayDiff == 0 ? 0 : notPassedIndex);
|
||||
// should never be out of range
|
||||
LessonFull lessonLast = lessons.get(lastIndex);
|
||||
|
||||
boolean duringLessons = Time.inRange(lessonFirst.startTime, lessonLast.endTime, syncedNow) && dayDiff == 0;
|
||||
if (duringLessons) {
|
||||
LessonFull lessonCurrent = null;
|
||||
LessonFull lessonNext = null;
|
||||
|
||||
if (lessons.get(notPassedIndex).lessonCurrent) {
|
||||
lessonCurrent = lessons.get(notPassedIndex);
|
||||
if (lessons.size() > notPassedIndex+1 && lessons.get(notPassedIndex+1).weekDay == displayingDate.getWeekDay())
|
||||
lessonNext = lessons.get(notPassedIndex+1);
|
||||
}
|
||||
else {
|
||||
lessonNext = lessons.get(notPassedIndex);
|
||||
}
|
||||
|
||||
if (lessonCurrent != null) { // show time to the end of this lesson
|
||||
b.lessonName.setText(lessonCurrent.subjectLongName);
|
||||
|
||||
counterType = TIME_LEFT;
|
||||
counterTarget = lessonCurrent.endTime;
|
||||
newRefreshInterval = updateCounter(syncedNow);
|
||||
}
|
||||
else if (lessonNext != null) { // it's break time, show time to the start of next lesson
|
||||
b.lessonName.setText(R.string.lesson_break);
|
||||
|
||||
counterType = TIME_LEFT;
|
||||
counterTarget = lessonNext.startTime;
|
||||
newRefreshInterval = updateCounter(syncedNow);
|
||||
}
|
||||
else { // idk what it is now (during lessons, but not during lesson or a break)
|
||||
b.lessonName.setText(R.string.card_timetable_wtf);
|
||||
b.timeLeft.setText(R.string.card_timetable_wtf_report);
|
||||
newRefreshInterval = 1000*60*2;
|
||||
finish();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (syncedNow.getValue() < lessonFirst.startTime.getValue()) {
|
||||
// before lessons
|
||||
b.lessonName.setText(R.string.lesson_break);
|
||||
|
||||
counterType = TIME_LEFT;
|
||||
counterTarget = lessonFirst.startTime;
|
||||
newRefreshInterval = updateCounter(syncedNow);
|
||||
}
|
||||
else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
return newRefreshInterval;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//Log.d(TAG, "OnDestroy");
|
||||
try {
|
||||
timetableTimer.cancel();
|
||||
timetableTimer.purge();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -48,7 +48,6 @@ import pl.szczodrzynski.edziennik.BuildConfig;
|
||||
import pl.szczodrzynski.edziennik.MainActivity;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject;
|
||||
import pl.szczodrzynski.edziennik.databinding.CardUpdateBinding;
|
||||
@ -58,7 +57,6 @@ import pl.szczodrzynski.edziennik.ui.modules.login.LoginLibrusCaptchaActivity;
|
||||
import pl.szczodrzynski.edziennik.utils.Colors;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.ItemGradesSubjectModel;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
|
||||
@ -239,8 +237,8 @@ public class HomeFragmentOld extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
timetableCard = new HomeTimetableCardOld(app, activity, this, layoutInflater, insertPoint);
|
||||
timetableCard.run();
|
||||
// timetableCard = new HomeTimetableCardOld(app, activity, this, layoutInflater, insertPoint);
|
||||
// timetableCard.run();
|
||||
|
||||
configCardGrades(activity, layoutInflater, activity, insertPoint);
|
||||
|
||||
@ -369,60 +367,6 @@ public class HomeFragmentOld extends Fragment {
|
||||
.color(IconicsColor.colorInt(Utils.getAttr(c, android.R.attr.textColorPrimary)))
|
||||
.size(IconicsSize.dp(16)), null);
|
||||
}
|
||||
public static Date findDateWithLessons(int profileId, List<LessonFull> lessons) {
|
||||
return findDateWithLessons(profileId, lessons, 0);
|
||||
}
|
||||
public static Date findDateWithLessons(int profileId, List<LessonFull> lessons, int nextDayHourThreshold) {
|
||||
return findDateWithLessons(profileId, lessons, Time.getNow(), nextDayHourThreshold);
|
||||
}
|
||||
public static Date findDateWithLessons(int profileId, List<LessonFull> lessons, Time now) {
|
||||
return findDateWithLessons(profileId, lessons, now, 0);
|
||||
}
|
||||
public static Date findDateWithLessons(int profileId, @NonNull List<LessonFull> lessons, Time now, int nextDayHourThreshold) {
|
||||
now = now.clone().stepForward(-nextDayHourThreshold, 0, 0);
|
||||
Date displayingDate = Date.getToday();
|
||||
int displayingWeekDay = displayingDate.getWeekDay();
|
||||
//boolean foundSomething = false;
|
||||
//int weekDayNum = displayingDate.getWeekDay();//Week.getTodayWeekDay();
|
||||
//int checkedDays = 0;
|
||||
|
||||
for (LessonFull lesson: lessons) {
|
||||
if (lesson.profileId != profileId)
|
||||
continue;
|
||||
if (lesson.weekDay == displayingWeekDay
|
||||
&& now.getValue() <= lesson.endTime.getValue()) {
|
||||
return lesson.lessonDate;
|
||||
}
|
||||
if (lesson.weekDay != displayingWeekDay) {
|
||||
return lesson.lessonDate;
|
||||
}
|
||||
}
|
||||
return displayingDate;
|
||||
|
||||
/*while (!foundSomething && checkedDays < 14)
|
||||
{
|
||||
weekDay = profile.timetable.weekdays[displayingDate.getWeekDay()];
|
||||
if (weekDay.lessons.size() == 0) // this day has no lessons
|
||||
{
|
||||
displayingDate.stepForward(0, 0, 1);
|
||||
checkedDays++;
|
||||
continue;
|
||||
}
|
||||
if (displayingDate.getWeekDay() == Week.getTodayWeekDay() // today
|
||||
&& now.getValue() > weekDay.lessons.get(weekDay.lessons.size() - 1).endTime.getValue()) // this day has lessons, but last lesson is over already
|
||||
{
|
||||
displayingDate.stepForward(0, 0, 1);
|
||||
checkedDays++;
|
||||
continue;
|
||||
}
|
||||
// this day has lessons, and we are during the lessons
|
||||
foundSomething = true;
|
||||
}
|
||||
return displayingDate;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void updateCardGrades(Context c, Activity a, View root, int maxWidthPx) {
|
||||
@ -558,8 +502,8 @@ public class HomeFragmentOld extends Fragment {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (timetableCard != null)
|
||||
timetableCard.destroy();
|
||||
//if (timetableCard != null)
|
||||
// timetableCard.destroy();
|
||||
}
|
||||
|
||||
private void configCardGrades(Context c, LayoutInflater layoutInflater, Activity a, ViewGroup insertPoint) {
|
||||
@ -568,6 +512,4 @@ public class HomeFragmentOld extends Fragment {
|
||||
updateCardGrades(c, a, root, displayMetrics.widthPixels - Utils.dpToPx((app.config.getUi().getMiniMenuVisible() ? 72 : 0)/*miniDrawer size*/ + 24 + 24/*left and right offsets*/ + 16/*ellipsize width*/));
|
||||
insertPoint.addView(root, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
|
||||
private HomeTimetableCardOld timetableCard;
|
||||
}
|
||||
|
@ -1,471 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.home;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.MainActivity;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.databinding.CardTimetableBinding;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CANCELLED;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CHANGE;
|
||||
import static pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld.updateInterval;
|
||||
import static pl.szczodrzynski.edziennik.utils.Utils.bs;
|
||||
|
||||
public class HomeTimetableCardOld {
|
||||
private static final String TAG = "HomeTimetableCardOld";
|
||||
private App app;
|
||||
private MainActivity a;
|
||||
private HomeFragmentOld f;
|
||||
private LayoutInflater layoutInflater;
|
||||
private ViewGroup insertPoint;
|
||||
private CardTimetableBinding b;
|
||||
private Timer timetableTimer;
|
||||
private Time bellSyncTime = null;
|
||||
|
||||
public HomeTimetableCardOld(App app, MainActivity a, HomeFragmentOld f, LayoutInflater layoutInflater, ViewGroup insertPoint) {
|
||||
this.app = app;
|
||||
this.a = a;
|
||||
this.f = f;
|
||||
this.layoutInflater = layoutInflater;
|
||||
this.insertPoint = insertPoint;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
timetableTimer = new Timer();
|
||||
b = DataBindingUtil.inflate(layoutInflater, R.layout.card_timetable, null, false);
|
||||
update();
|
||||
insertPoint.addView(b.getRoot(), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
b.cardTimetableFullscreenCounter.setOnClickListener((v -> {
|
||||
Intent intent = new Intent(a, CounterActivityOld.class);
|
||||
a.startActivity(intent);
|
||||
}));
|
||||
|
||||
b.cardTimetableBellSync.setOnClickListener(v -> {
|
||||
if (bellSyncTime == null) {
|
||||
new MaterialDialog.Builder(a)
|
||||
.title(R.string.bell_sync_title)
|
||||
.content(R.string.bell_sync_cannot_now)
|
||||
.positiveText(R.string.ok)
|
||||
.show();
|
||||
}
|
||||
else {
|
||||
new MaterialDialog.Builder(a)
|
||||
.title(R.string.bell_sync_title)
|
||||
.content(app.getString(R.string.bell_sync_howto, bellSyncTime.getStringHM())+
|
||||
(app.config.getTimetable().getBellSyncDiff() != null ?
|
||||
""+app.getString(R.string.bell_sync_current_dialog, (app.config.getTimetable().getBellSyncMultiplier() == -1 ? "-" : "+")+app.config.getTimetable().getBellSyncDiff().getStringHMS())
|
||||
: ""))
|
||||
.positiveText(R.string.ok)
|
||||
.negativeText(R.string.cancel)
|
||||
.neutralText(R.string.reset)
|
||||
.onPositive((dialog, which) -> {
|
||||
Time bellDiff = Time.diff(Time.getNow(), bellSyncTime);
|
||||
app.config.getTimetable().setBellSyncDiff(bellDiff);
|
||||
app.config.getTimetable().setBellSyncMultiplier(bellSyncTime.getValue() > Time.getNow().getValue() ? -1 : 1);
|
||||
new MaterialDialog.Builder(a)
|
||||
.title(R.string.bell_sync_title)
|
||||
.content(app.getString(R.string.bell_sync_results, (bellSyncTime.getValue() > Time.getNow().getValue() ? "-" : "+"), bellDiff.getStringHMS()))
|
||||
.positiveText(R.string.ok)
|
||||
.show();
|
||||
})
|
||||
.onNeutral((dialog, which) -> {
|
||||
new MaterialDialog.Builder(a)
|
||||
.title(R.string.bell_sync_title)
|
||||
.content(R.string.bell_sync_reset_confirm)
|
||||
.positiveText(R.string.yes)
|
||||
.negativeText(R.string.no)
|
||||
.onPositive(((dialog1, which1) -> {
|
||||
app.config.getTimetable().setBellSyncDiff(null);
|
||||
app.config.getTimetable().setBellSyncMultiplier(0);
|
||||
}))
|
||||
.show();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
HomeFragmentOld.buttonAddDrawable(a, b.cardTimetableButton, CommunityMaterial.Icon.cmd_arrow_right);
|
||||
}
|
||||
|
||||
private List<LessonFull> lessons = new ArrayList<>();
|
||||
private List<EventFull> events = new ArrayList<>();
|
||||
|
||||
private void update() {
|
||||
//Log.d(TAG, "Now "+System.currentTimeMillis());
|
||||
if (a == null || !f.isAdded())
|
||||
return;
|
||||
// BELL SYNCING
|
||||
Time now = Time.getNow();
|
||||
Time syncedNow = now;
|
||||
//Time updateDiff = null;
|
||||
if (app.config.getTimetable().getBellSyncDiff() != null) {
|
||||
if (app.config.getTimetable().getBellSyncMultiplier() < 0) {
|
||||
// the bell is too fast, need to step further to go with it
|
||||
// add some time
|
||||
syncedNow = Time.sum(now, app.config.getTimetable().getBellSyncDiff());
|
||||
//Toast.makeText(c, "Bell sync diff is "+app.appConfig.bellSyncDiff.getStringHMS()+"\n\n Synced now is "+syncedNow.getStringHMS(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (app.config.getTimetable().getBellSyncMultiplier() > 0) {
|
||||
// the bell is delayed, need to roll the "now" time back
|
||||
// subtract some time
|
||||
syncedNow = Time.diff(now, app.config.getTimetable().getBellSyncDiff());
|
||||
}
|
||||
}
|
||||
|
||||
assert counterTarget != null;
|
||||
if (lessons.size() == 0 || syncedNow.getValue() > counterTarget.getValue()) {
|
||||
findLessons(syncedNow);
|
||||
}
|
||||
else {
|
||||
scheduleUpdate(updateCounter(syncedNow));
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleUpdate(long newRefreshInterval) {
|
||||
try {
|
||||
timetableTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
a.runOnUiThread(() -> update());
|
||||
}
|
||||
}, newRefreshInterval);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void findLessons(Time syncedNow) {
|
||||
AsyncTask.execute(() -> {
|
||||
Date today = Date.getToday();
|
||||
lessons = app.db.lessonDao().getAllNearestNow(App.profileId, today.clone().stepForward(0, 0, -today.getWeekDay()), today, syncedNow);
|
||||
|
||||
if (lessons != null && lessons.size() != 0) {
|
||||
Date displayingDate = lessons.get(0).lessonDate;
|
||||
if (displayingDate == null) {
|
||||
a.runOnUiThread(() -> scheduleUpdate(updateViews(null, syncedNow, 0, 0)));
|
||||
return;
|
||||
}
|
||||
int displayingWeekDay = displayingDate.getWeekDay();
|
||||
|
||||
Log.d(TAG, "Displaying date is "+displayingDate.getStringY_m_d()+", weekDay is "+displayingWeekDay);
|
||||
|
||||
int notPassedIndex = -1;
|
||||
int notPassedWeekDay = -1;
|
||||
//int firstIndex = -1;
|
||||
int lastIndex = -1;
|
||||
int index = 0;
|
||||
for (LessonFull lesson: lessons) {
|
||||
if (notPassedIndex == -1 && !lesson.lessonPassed) {
|
||||
if (lesson.lessonDate != null)
|
||||
displayingDate = lesson.lessonDate;
|
||||
displayingWeekDay = lesson.weekDay;
|
||||
notPassedIndex = index;
|
||||
notPassedWeekDay = lesson.weekDay;
|
||||
}
|
||||
if (lesson.weekDay == notPassedWeekDay) {
|
||||
/*if (firstIndex == -1)
|
||||
firstIndex = index;*/
|
||||
lastIndex = index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
// for safety
|
||||
/*if (firstIndex == -1)
|
||||
firstIndex++;*/
|
||||
if (notPassedIndex == -1)
|
||||
notPassedIndex++;
|
||||
if (lastIndex == -1)
|
||||
lastIndex++;
|
||||
|
||||
Log.d(TAG, "Not passed index is "+notPassedIndex);
|
||||
Log.d(TAG, "Last index is "+lastIndex);
|
||||
Log.d(TAG, "New Displaying date is "+displayingDate.getStringY_m_d()+", weekDay is "+displayingWeekDay);
|
||||
events = app.db.eventDao().getAllByDateNow(App.profileId, displayingDate);
|
||||
|
||||
Date finalDisplayingDate = displayingDate;
|
||||
int finalNotPassedIndex = notPassedIndex;
|
||||
int finalLastIndex = lastIndex;
|
||||
a.runOnUiThread(() -> scheduleUpdate(updateViews(finalDisplayingDate, syncedNow, finalNotPassedIndex, finalLastIndex)));
|
||||
}
|
||||
else {
|
||||
a.runOnUiThread(() -> scheduleUpdate(updateViews(null, syncedNow, 0, 0)));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private Time counterTarget = new Time(0, 0, 0);
|
||||
private static final short TIME_TILL = 0;
|
||||
private static final short TIME_LEFT = 1;
|
||||
private short counterType = TIME_TILL;
|
||||
private long updateCounter(Time syncedNow) {
|
||||
Time diff = Time.diff(counterTarget, syncedNow);
|
||||
b.cardTimetableTimeLeft.setText(counterType == TIME_TILL ? HomeFragmentOld.timeTill(app, diff, app.config.getTimetable().getCountInSeconds()) : HomeFragmentOld.timeLeft(app, diff, app.config.getTimetable().getCountInSeconds()));
|
||||
bellSyncTime = counterTarget;
|
||||
b.cardTimetableFullscreenCounter.setVisibility(View.VISIBLE);
|
||||
return updateInterval(app, diff);
|
||||
}
|
||||
|
||||
private long updateViews(Date displayingDate, Time syncedNow, int notPassedIndex, int lastIndex) {
|
||||
//Date weekEnd = Date.getToday().stepForward(0, 0, 6 - Week.getTodayWeekDay()); // Sunday of the current week
|
||||
|
||||
if (displayingDate == null) {
|
||||
b.cardTimetableTitle.setText(R.string.card_timetable_no_timetable);
|
||||
b.cardTimetableNoData.setVisibility(View.VISIBLE);
|
||||
b.cardTimetableContent.setVisibility(View.GONE);
|
||||
return 1000*60*30;
|
||||
}
|
||||
|
||||
// at this point lessons.size() must be greater than 0
|
||||
|
||||
int displayingWeekDay = displayingDate.getWeekDay();
|
||||
|
||||
|
||||
|
||||
String weekDayStr = Week.getFullDayName(displayingWeekDay);
|
||||
int dayDiff = Date.diffDays(displayingDate, Date.getToday());
|
||||
if (displayingDate.getValue() != Date.getToday().getValue() && dayDiff == 0) {
|
||||
dayDiff++;
|
||||
}
|
||||
String dayDiffStr = (dayDiff == 0 ? app.getString(R.string.day_today_format, weekDayStr) : (dayDiff == 1 ? app.getString(R.string.day_tomorrow_format,weekDayStr) : app.getString(R.string.day_other_format, weekDayStr, displayingDate.getStringDm())));
|
||||
|
||||
b.cardTimetableTitle.setText(app.getString(R.string.card_timetable_title, dayDiffStr));
|
||||
|
||||
long newRefreshInterval = 1000*5; // 5 seconds
|
||||
|
||||
b.cardTimetableNoData.setVisibility(View.GONE);
|
||||
b.cardTimetableContent.setVisibility(View.VISIBLE);
|
||||
|
||||
LessonFull lessonFirst = lessons.get(dayDiff == 0 ? 0 : notPassedIndex);
|
||||
// should never be out of range
|
||||
LessonFull lessonLast = lessons.get(lastIndex);
|
||||
|
||||
boolean duringLessons = Time.inRange(lessonFirst.startTime, lessonLast.endTime, syncedNow) && dayDiff == 0;
|
||||
if (!duringLessons) {
|
||||
|
||||
LessonFull lessonSecond = null;
|
||||
if (lessons.size() > notPassedIndex+1 && lessons.get(notPassedIndex+1).weekDay == displayingDate.getWeekDay())
|
||||
lessonSecond = lessons.get(notPassedIndex+1);
|
||||
|
||||
b.cardTimetableType.setText(R.string.card_timetable_lesson_duration);
|
||||
b.cardTimetableSummary.setText(app.getString(R.string.card_timetable_lesson_duration_format, lessonFirst.startTime.getStringHM(), lessonLast.endTime.getStringHM()));
|
||||
if (dayDiff == 0) {
|
||||
counterTarget = lessonFirst.startTime;
|
||||
counterType = TIME_TILL;
|
||||
newRefreshInterval = updateCounter(syncedNow);
|
||||
}
|
||||
else {
|
||||
b.cardTimetableTimeLeft.setText("");
|
||||
newRefreshInterval = 1000*60*30;
|
||||
b.cardTimetableFullscreenCounter.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
String lessonFirstStr = null;
|
||||
if (lessonFirst.changeId != 0) {
|
||||
if (lessonFirst.changeType == TYPE_CANCELLED) {
|
||||
lessonFirstStr = "<del>" + bs(lessonFirst.getSubjectLongName()) + "</del>";
|
||||
} else if (lessonFirst.changeType == TYPE_CHANGE) {
|
||||
lessonFirstStr = "<i>" + bs(lessonFirst.getSubjectLongName()) + "</i>";
|
||||
}
|
||||
} else {
|
||||
lessonFirstStr = bs(lessonFirst.subjectLongName);
|
||||
}
|
||||
String lessonSecondStr = null;
|
||||
if (lessonSecond != null) {
|
||||
if (lessonSecond.changeId != 0) {
|
||||
if (lessonSecond.changeType == TYPE_CANCELLED) {
|
||||
lessonSecondStr = "<del>" + bs(lessonSecond.getSubjectLongName()) + "</del>";
|
||||
} else if (lessonSecond.changeType == TYPE_CHANGE) {
|
||||
lessonSecondStr = "<i>" + bs(lessonSecond.getSubjectLongName()) + "</i>";
|
||||
}
|
||||
} else {
|
||||
lessonSecondStr = bs(lessonSecond.getSubjectLongName());
|
||||
}
|
||||
}
|
||||
b.cardTimetableLessonOverview.setText(
|
||||
Html.fromHtml(
|
||||
app.getString(R.string.card_timetable_lesson_overview,
|
||||
lessonFirst.startTime.getStringHM(),
|
||||
bs(null, lessonFirstStr, ", ")+lessonFirst.getClassroomName(),
|
||||
(lessonSecond == null ? "" : lessonSecond.startTime.getStringHM()),
|
||||
(lessonSecond == null ? "" : bs(null, lessonSecondStr, ", "+lessonSecond.getClassroomName())))
|
||||
)
|
||||
);
|
||||
|
||||
StringBuilder eventSummary = new StringBuilder();
|
||||
eventSummary.append(app.getString(R.string.card_timetable_event_overview));
|
||||
for (EventFull event : events) {
|
||||
if (displayingDate.getValue() == event.eventDate.getValue()) {
|
||||
eventSummary.append(app.getString(
|
||||
R.string.card_timetable_event_overview_format,
|
||||
event.startTime == null ? app.getString(R.string.event_all_day) : event.startTime.getStringHM(),
|
||||
event.typeName,
|
||||
event.topic));
|
||||
}
|
||||
}
|
||||
b.cardTimetableEventOverview.setText(eventSummary.toString());
|
||||
}
|
||||
else {
|
||||
b.cardTimetableFullscreenCounter.setVisibility(View.VISIBLE);
|
||||
LessonFull lessonCurrent = null;
|
||||
LessonFull lessonInAMoment = null;
|
||||
LessonFull lessonNext = null;
|
||||
LessonFull lessonAfterNext = null;
|
||||
|
||||
if (lessons.get(notPassedIndex).lessonCurrent) {
|
||||
lessonCurrent = lessons.get(notPassedIndex);
|
||||
if (lessons.size() > notPassedIndex+1 && lessons.get(notPassedIndex+1).weekDay == displayingDate.getWeekDay())
|
||||
lessonNext = lessons.get(notPassedIndex+1);
|
||||
if (lessons.size() > notPassedIndex+2 && lessons.get(notPassedIndex+2).weekDay == displayingDate.getWeekDay())
|
||||
lessonAfterNext = lessons.get(notPassedIndex+2);
|
||||
}
|
||||
else {
|
||||
lessonInAMoment = lessons.get(notPassedIndex);
|
||||
if (lessons.size() > notPassedIndex+1 && lessons.get(notPassedIndex+1).weekDay == displayingDate.getWeekDay())
|
||||
lessonNext = lessons.get(notPassedIndex+1);
|
||||
if (lessons.size() > notPassedIndex+2 && lessons.get(notPassedIndex+2).weekDay == displayingDate.getWeekDay())
|
||||
lessonAfterNext = lessons.get(notPassedIndex+2);
|
||||
}
|
||||
|
||||
if (lessonCurrent != null) { // show time to the end of this lesson
|
||||
b.cardTimetableType.setText(R.string.card_timetable_now);
|
||||
if (lessonCurrent.changeId != 0) {
|
||||
if (lessonCurrent.changeType == TYPE_CANCELLED) {
|
||||
b.cardTimetableSummary.setText(Html.fromHtml("<del>"+bs(lessonCurrent.getSubjectLongName())+"</del><br>"+lessonCurrent.getClassroomName()));
|
||||
}
|
||||
else if (lessonCurrent.changeType == TYPE_CHANGE) {
|
||||
b.cardTimetableSummary.setText(Html.fromHtml("<i>"+bs(lessonCurrent.getSubjectLongName())+"<br>"+lessonCurrent.getClassroomName()+"</i>"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
b.cardTimetableSummary.setText(bs(lessonCurrent.getSubjectLongName())+"\n"+lessonCurrent.getClassroomName());
|
||||
}
|
||||
|
||||
counterTarget = lessonCurrent.endTime;
|
||||
counterType = TIME_LEFT;
|
||||
newRefreshInterval = updateCounter(syncedNow);
|
||||
}
|
||||
else if (lessonInAMoment != null) { // it's break time, show time to the start of next lesson
|
||||
b.cardTimetableType.setText(R.string.card_timetable_following);
|
||||
if (lessonInAMoment.changeId != 0) {
|
||||
if (lessonInAMoment.changeType == TYPE_CANCELLED) {
|
||||
b.cardTimetableSummary.setText(Html.fromHtml("<del>"+bs(lessonInAMoment.getSubjectLongName())+"</del><br>"+lessonInAMoment.getClassroomName()));
|
||||
}
|
||||
else if (lessonInAMoment.changeType == TYPE_CHANGE) {
|
||||
b.cardTimetableSummary.setText(Html.fromHtml("<i>"+bs(lessonInAMoment.getSubjectLongName())+"<br>"+lessonInAMoment.getClassroomName()+"</i>"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
b.cardTimetableSummary.setText(bs(lessonInAMoment.getSubjectLongName())+"\n"+lessonInAMoment.getClassroomName());
|
||||
}
|
||||
|
||||
counterTarget = lessonInAMoment.startTime;
|
||||
counterType = TIME_TILL;
|
||||
newRefreshInterval = updateCounter(syncedNow);
|
||||
}
|
||||
else { // idk what it is now (during lessons, but not during lesson or a break)
|
||||
b.cardTimetableType.setText(R.string.card_timetable_wtf);
|
||||
b.cardTimetableSummary.setText(R.string.card_timetable_wtf_report);
|
||||
b.cardTimetableTimeLeft.setText("");
|
||||
newRefreshInterval = 1000*60*2;
|
||||
}
|
||||
String lessonNextStr = null;
|
||||
if (lessonNext != null) {
|
||||
if (lessonNext.changeId != 0) {
|
||||
if (lessonNext.changeType == TYPE_CANCELLED) {
|
||||
lessonNextStr = "<del>" + lessonNext.getSubjectLongName() + "</del>";
|
||||
} else if (lessonNext.changeType == TYPE_CHANGE) {
|
||||
lessonNextStr = "<i>" + lessonNext.getSubjectLongName() + "</i>";
|
||||
}
|
||||
} else {
|
||||
lessonNextStr = lessonNext.getSubjectLongName();
|
||||
}
|
||||
}
|
||||
String lessonAfterNextStr = null;
|
||||
if (lessonAfterNext != null) {
|
||||
if (lessonAfterNext.changeId != 0) {
|
||||
if (lessonAfterNext.changeType == TYPE_CANCELLED) {
|
||||
lessonAfterNextStr = "<del>" + lessonAfterNext.getSubjectLongName() + "</del>";
|
||||
} else if (lessonAfterNext.changeType == TYPE_CHANGE) {
|
||||
lessonAfterNextStr = "<i>" + lessonAfterNext.getSubjectLongName() + "</i>";
|
||||
}
|
||||
} else {
|
||||
lessonAfterNextStr = lessonAfterNext.getSubjectLongName();
|
||||
}
|
||||
}
|
||||
b.cardTimetableLessonOverview.setText(
|
||||
Html.fromHtml(app.getString(
|
||||
R.string.card_timetable_lesson_overview_ongoing,
|
||||
(lessonNext == null ? "" : lessonNext.startTime.getStringHM()),
|
||||
(lessonNext == null ? "" : bs(null, lessonNextStr, ", "+lessonNext.getClassroomName())),
|
||||
(lessonAfterNext == null ? "" : lessonAfterNext.startTime.getStringHM()),
|
||||
(lessonAfterNext == null ? "" : bs(null, lessonAfterNextStr, ", "+lessonAfterNext.getClassroomName()))
|
||||
))
|
||||
);
|
||||
|
||||
StringBuilder eventSummary = new StringBuilder();
|
||||
eventSummary.append(app.getString(R.string.card_timetable_event_overview));
|
||||
for (EventFull event : events) {
|
||||
// display the event only if it's AllDay or it hasn't started yet
|
||||
boolean timeMatching = event.startTime == null || syncedNow.getValue() < event.startTime.getValue();
|
||||
if (displayingDate.getValue() == event.eventDate.getValue()
|
||||
&& timeMatching) {
|
||||
eventSummary.append(app.getString(
|
||||
R.string.card_timetable_event_overview_format,
|
||||
event.startTime == null ? app.getString(R.string.agenda_event_all_day)+" - " : event.startTime.getStringHM(),
|
||||
event.typeName,
|
||||
event.topic));
|
||||
}
|
||||
}
|
||||
b.cardTimetableEventOverview.setText(eventSummary.toString());
|
||||
}
|
||||
|
||||
b.cardTimetableButton.setOnClickListener((v1 -> new Handler().postDelayed(() -> a.runOnUiThread(() -> {
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putInt("timetableDate", displayingDate.getValue());
|
||||
a.loadTarget(MainActivity.DRAWER_ITEM_TIMETABLE, arguments);
|
||||
}), 100)));
|
||||
|
||||
return newRefreshInterval;
|
||||
|
||||
//new Handler().postDelayed(() -> a.runOnUiThread(() -> updateCardTimetable(c, a, root)), newRefreshInterval);
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
//Log.d(TAG, "OnDestroy");
|
||||
try {
|
||||
timetableTimer.cancel();
|
||||
timetableTimer.purge();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,201 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.AsyncTask;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.mikepenz.iconics.IconicsColor;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
import com.mikepenz.iconics.IconicsSize;
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.utils.SpannableHtmlTagHandler;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.events.Event.TYPE_HOMEWORK;
|
||||
|
||||
public class TimetableAdapter extends RecyclerView.Adapter<TimetableAdapter.ViewHolder> {
|
||||
private static final String TAG = "TimetableAdapter";
|
||||
private Context context;
|
||||
private Date lessonDate;
|
||||
private List<LessonFull> lessonList;
|
||||
private List<EventFull> eventList;
|
||||
public boolean setAsRead = false;
|
||||
|
||||
//getting the context and product list with constructor
|
||||
public TimetableAdapter(Context mCtx, Date lessonDate, List<LessonFull> lessonList, List<EventFull> eventList) {
|
||||
this.context = mCtx;
|
||||
this.lessonDate = lessonDate;
|
||||
this.lessonList = lessonList;
|
||||
this.eventList = eventList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
//inflating and returning our view holder
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(R.layout.row_timetable_item, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
App app = (App) context.getApplicationContext();
|
||||
|
||||
LessonFull lesson = lessonList.get(position);
|
||||
holder.timetableItemStartTime.setText(lesson.startTime.getStringHM());
|
||||
holder.timetableItemEndTime.setText(lesson.endTime.getStringHM());
|
||||
holder.timetableItemSubjectName.setText(lesson.subjectLongName);
|
||||
holder.timetableItemClassroomName.setText(lesson.getClassroomName());
|
||||
holder.timetableItemTeamName.setText(lesson.getTeamName());
|
||||
holder.timetableItemTeacherName.setText(lesson.getTeacherFullName());
|
||||
|
||||
holder.timetableItemCard.setCardBackgroundColor(Utils.getAttr(context, R.attr.colorSurface));
|
||||
|
||||
if (lesson.changeId != 0)
|
||||
{
|
||||
if (!lesson.seen) {
|
||||
holder.timetableItemSubjectName.setBackground(context.getResources().getDrawable(R.drawable.bg_rounded_4dp));
|
||||
holder.timetableItemSubjectName.getBackground().setColorFilter(new PorterDuffColorFilter(0x692196f3, PorterDuff.Mode.MULTIPLY));
|
||||
AsyncTask.execute(() -> app.db.metadataDao().setSeen(App.profileId, lesson, true));
|
||||
}
|
||||
if (lesson.changeType == LessonChange.TYPE_CANCELLED)
|
||||
{
|
||||
holder.timetableItemSubjectName.setTypeface(null, Typeface.NORMAL);
|
||||
holder.timetableItemSubjectChange.setVisibility(View.GONE);
|
||||
|
||||
holder.timetableItemSubjectName.setText(Html.fromHtml("<del>"+lesson.subjectLongName+"</del>", null, new SpannableHtmlTagHandler()));
|
||||
}
|
||||
else if (lesson.changeType == LessonChange.TYPE_CHANGE)
|
||||
{
|
||||
holder.timetableItemSubjectName.setTypeface(null, Typeface.BOLD_ITALIC);
|
||||
if (lesson.changedSubjectLongName()) {
|
||||
holder.timetableItemSubjectChange.setText(lesson.subjectLongName);
|
||||
holder.timetableItemSubjectName.setText(lesson.changeSubjectLongName);
|
||||
holder.timetableItemSubjectChange.setVisibility(View.VISIBLE);
|
||||
|
||||
holder.timetableItemSubjectChange.setText(Html.fromHtml("<del>"+lesson.subjectLongName+"</del>", null, new SpannableHtmlTagHandler()));
|
||||
}
|
||||
else {
|
||||
holder.timetableItemSubjectChange.setVisibility(View.GONE);
|
||||
}
|
||||
holder.timetableItemTeacherName.setText(lesson.getTeacherFullName(true));
|
||||
holder.timetableItemTeamName.setText(lesson.getTeamName(true));
|
||||
holder.timetableItemClassroomName.setText(lesson.getClassroomName(true));
|
||||
}
|
||||
else if (lesson.changeType == LessonChange.TYPE_ADDED)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
holder.timetableItemLayout.getBackground().setColorFilter(new PorterDuffColorFilter(0xffffffff, PorterDuff.Mode.CLEAR));
|
||||
|
||||
if (lesson.changeType == LessonChange.TYPE_CANCELLED) {
|
||||
holder.timetableItemCard.setCardBackgroundColor(Themes.INSTANCE.isDark() ? 0x60000000 : 0xffeeeeee);
|
||||
}
|
||||
else if (lesson.changeType == LessonChange.TYPE_CHANGE) {
|
||||
holder.timetableItemLayout.getBackground().setColorFilter(new PorterDuffColorFilter(Utils.getAttr(context, R.attr.colorPrimary), PorterDuff.Mode.SRC_ATOP));//.setBackgroundColor(App.getAttr(context, R.attr.cardBackgroundHighlight));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
holder.timetableItemLayout.getBackground().setColorFilter(new PorterDuffColorFilter(0xffffffff, PorterDuff.Mode.CLEAR));
|
||||
holder.timetableItemSubjectName.setBackground(null);
|
||||
holder.timetableItemSubjectName.setTypeface(null, Typeface.NORMAL);
|
||||
holder.timetableItemSubjectChange.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
int eventCount = 0;
|
||||
|
||||
for (EventFull event: eventList) {
|
||||
if (event.eventDate.getValue() == lessonDate.getValue()
|
||||
&& event.startTime != null
|
||||
&& event.startTime.getValue() == lesson.startTime.getValue()) {
|
||||
eventCount++;
|
||||
if (eventCount == 1) {
|
||||
holder.timetableItemEvent1.setVisibility(View.VISIBLE);
|
||||
if (event.type == TYPE_HOMEWORK)
|
||||
holder.timetableItemEvent1.setBackground(new IconicsDrawable(context).color(IconicsColor.colorRes(R.color.md_red_500)).size(IconicsSize.dp(10)).icon(CommunityMaterial.Icon2.cmd_home));
|
||||
else
|
||||
holder.timetableItemEvent1.setBackgroundColor(event.getColor());
|
||||
}
|
||||
else if (eventCount == 2) {
|
||||
holder.timetableItemEvent2.setVisibility(View.VISIBLE);
|
||||
if (event.type == TYPE_HOMEWORK)
|
||||
holder.timetableItemEvent2.setBackground(new IconicsDrawable(context).color(IconicsColor.colorRes(R.color.md_red_500)).size(IconicsSize.dp(10)).icon(CommunityMaterial.Icon2.cmd_home));
|
||||
else
|
||||
holder.timetableItemEvent2.setBackgroundColor(event.getColor());
|
||||
}
|
||||
else if (eventCount == 3) {
|
||||
holder.timetableItemEvent3.setVisibility(View.VISIBLE);
|
||||
if (event.type == TYPE_HOMEWORK)
|
||||
holder.timetableItemEvent3.setBackground(new IconicsDrawable(context).color(IconicsColor.colorRes(R.color.md_red_500)).size(IconicsSize.dp(10)).icon(CommunityMaterial.Icon2.cmd_home));
|
||||
else
|
||||
holder.timetableItemEvent3.setBackgroundColor(event.getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// holder.timetableItemCard.setOnClickListener(v -> new EventListDialogOld(context).show(app, lessonDate, lesson.startTime));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return lessonList.size();
|
||||
}
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
CardView timetableItemCard;
|
||||
ConstraintLayout timetableItemLayout;
|
||||
TextView timetableItemStartTime;
|
||||
TextView timetableItemClassroomName;
|
||||
TextView timetableItemTeamName;
|
||||
TextView timetableItemSubjectChange;
|
||||
TextView timetableItemSubjectName;
|
||||
TextView timetableItemTeacherName;
|
||||
TextView timetableItemEndTime;
|
||||
View timetableItemEvent1;
|
||||
View timetableItemEvent2;
|
||||
View timetableItemEvent3;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
timetableItemCard = itemView.findViewById(R.id.timetableItemCard);
|
||||
timetableItemLayout = itemView.findViewById(R.id.timetableItemLayout);
|
||||
timetableItemStartTime = itemView.findViewById(R.id.timetableItemStartTime);
|
||||
timetableItemClassroomName = itemView.findViewById(R.id.timetableItemClassroomName);
|
||||
timetableItemTeamName = itemView.findViewById(R.id.timetableItemTeamName);
|
||||
timetableItemSubjectChange = itemView.findViewById(R.id.timetableItemSubjectChange);
|
||||
timetableItemSubjectName = itemView.findViewById(R.id.timetableItemSubjectName);
|
||||
timetableItemTeacherName = itemView.findViewById(R.id.noticesItemTeacherName);
|
||||
timetableItemEndTime = itemView.findViewById(R.id.timetableItemEndTime);
|
||||
timetableItemEvent1 = itemView.findViewById(R.id.timetableItemEvent1);
|
||||
timetableItemEvent2 = itemView.findViewById(R.id.timetableItemEvent2);
|
||||
timetableItemEvent3 = itemView.findViewById(R.id.timetableItemEvent3);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.MainActivity;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentTimetableDayBinding;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
|
||||
public class TimetableDayFragment extends Fragment {
|
||||
|
||||
private App app = null;
|
||||
private MainActivity activity = null;
|
||||
private FragmentTimetableDayBinding b = null;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
activity = (MainActivity) getActivity();
|
||||
if (getActivity() == null || getContext() == null)
|
||||
return null;
|
||||
app = (App) activity.getApplication();
|
||||
getContext().getTheme().applyStyle(Themes.INSTANCE.getAppTheme(), true);
|
||||
if (app.profile == null)
|
||||
return inflater.inflate(R.layout.fragment_loading, container, false);
|
||||
// activity, context and profile is valid
|
||||
b = DataBindingUtil.inflate(inflater, R.layout.fragment_timetable_day, container, false);
|
||||
b.refreshLayout.setParent(activity.getSwipeRefreshLayout());
|
||||
return b.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
if (app == null || app.profile == null || activity == null || b == null || !isAdded())
|
||||
return;
|
||||
|
||||
/*b.getRoot().setOnTouchListener((v, event) -> {
|
||||
d("TimetableDay", "event "+event);
|
||||
event.setSource(0x10000000); // set a unique source
|
||||
activity.swipeRefreshLayout.onTouchEvent(event);
|
||||
return true;
|
||||
});*/
|
||||
//b.refreshLayout.setNestedScrollingEnabled(true);
|
||||
/*b.refreshLayout.setOnRefreshListener(() -> {
|
||||
activity.syncCurrentFeature(MainActivity.DRAWER_ITEM_TIMETABLE, b.refreshLayout);
|
||||
});*/
|
||||
|
||||
assert getArguments() != null;
|
||||
Date date = new Date().parseFromYmd(Long.toString(getArguments().getLong("date", 20181009)));
|
||||
|
||||
recyclerView = b.timetableView;
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
app.db.lessonDao().getAllByDate(App.profileId, date, Time.getNow()).observe(this, lessons -> {
|
||||
if (app == null || app.profile == null || activity == null || b == null || !isAdded())
|
||||
return;
|
||||
|
||||
if (lessons != null && lessons.size() > 0) {
|
||||
app.db.eventDao().getAllByDate(App.profileId, date).observe(this, events -> {
|
||||
TimetableAdapter adapter = new TimetableAdapter(getContext(), date, lessons, events == null ? new ArrayList<>() : events);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
b.timetableNoData.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
else {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
b.timetableNoData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2.day
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable
|
||||
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
@ -25,8 +29,8 @@ import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
|
||||
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
|
||||
import pl.szczodrzynski.edziennik.databinding.TimetableNoTimetableBinding
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.timetable.LessonDetailsDialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment.Companion.DEFAULT_END_HOUR
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment.Companion.DEFAULT_START_HOUR
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment.Companion.DEFAULT_END_HOUR
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment.Companion.DEFAULT_START_HOUR
|
||||
import pl.szczodrzynski.edziennik.utils.ListenerScrollView
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.navlib.getColorFromAttr
|
@ -1,628 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.DashPathEffect;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial;
|
||||
import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.MainActivity;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentTimetableBinding;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.error.ErrorDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld;
|
||||
import pl.szczodrzynski.edziennik.utils.SpannableHtmlTagHandler;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week;
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CANCELLED;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CHANGE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_LESSON_CHANGE;
|
||||
import static pl.szczodrzynski.edziennik.utils.Utils.bs;
|
||||
import static pl.szczodrzynski.edziennik.utils.Utils.d;
|
||||
|
||||
public class TimetableFragment extends Fragment {
|
||||
private static final String TAG = "RegisterTimetable";
|
||||
|
||||
private App app = null;
|
||||
private MainActivity activity = null;
|
||||
private FragmentTimetableBinding b = null;
|
||||
|
||||
private ViewPager viewPager;
|
||||
private static int pageSelection = -1;
|
||||
private static Date displayingDate;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
activity = (MainActivity) getActivity();
|
||||
if (getActivity() == null || getContext() == null)
|
||||
return null;
|
||||
app = (App) activity.getApplication();
|
||||
getContext().getTheme().applyStyle(Themes.INSTANCE.getAppTheme(), true);
|
||||
if (app.profile == null)
|
||||
return inflater.inflate(R.layout.fragment_loading, container, false);
|
||||
// activity, context and profile is valid
|
||||
b = DataBindingUtil.inflate(inflater, R.layout.fragment_timetable, container, false);
|
||||
return b.getRoot();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
if (app == null || app.profile == null || activity == null || b == null || !isAdded())
|
||||
return;
|
||||
|
||||
activity.getBottomSheet().prependItems(
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_add_event)
|
||||
.withDescription(R.string.menu_add_event_desc)
|
||||
.withIcon(SzkolnyFont.Icon.szf_calendar_plus_outline)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title(R.string.main_menu_add)
|
||||
.items(R.array.main_menu_add_options)
|
||||
.itemsCallback((dialog, itemView, position, text) -> {
|
||||
switch (position) {
|
||||
case 0:
|
||||
//new EventManualDialogOld(activity).show(app, null, displayingDate, null, EventManualDialogOld.DIALOG_EVENT);
|
||||
break;
|
||||
case 1:
|
||||
//new EventManualDialogOld(activity).show(app, null, displayingDate, null, EventManualDialogOld.DIALOG_HOMEWORK);
|
||||
break;
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}),
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_generate_block_timetable)
|
||||
.withDescription(R.string.menu_generate_block_timetable_desc)
|
||||
.withIcon(CommunityMaterial.Icon2.cmd_table_large)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
generateBlockTimetable();
|
||||
}),
|
||||
new BottomSheetSeparatorItem(true),
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_mark_as_read)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_eye_check_outline)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
AsyncTask.execute(() -> app.db.metadataDao().setAllSeen(App.profileId, TYPE_LESSON_CHANGE, true));
|
||||
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show();
|
||||
})
|
||||
);
|
||||
activity.gainAttention();
|
||||
|
||||
// Setting ViewPager for each Tabs
|
||||
viewPager = b.viewpager;
|
||||
Adapter adapter = new Adapter(getChildFragmentManager());
|
||||
|
||||
Date today = Date.getToday();
|
||||
|
||||
Date date = Date.getToday();
|
||||
int weekBeginning = 2 - date.getWeekDay();
|
||||
int weekEnd = weekBeginning + 6;
|
||||
date.stepForward(0, 0, 0 - (2));
|
||||
for (int i = 0; i < 7 + 2 + 1; i++) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("date", date.getValue());
|
||||
TimetableDayFragment timetableDayFragment = new TimetableDayFragment();
|
||||
timetableDayFragment.setArguments(args);
|
||||
StringBuilder pageTitle = new StringBuilder(Week.getFullDayName(date.getWeekDay()));
|
||||
if (i > weekEnd || i < weekBeginning) {
|
||||
pageTitle.append(", ").append(date.getStringDm());
|
||||
}
|
||||
adapter.addFragment(timetableDayFragment, pageTitle.toString());
|
||||
date.stepForward(0, 0, 1);
|
||||
}
|
||||
viewPager.setAdapter(adapter);
|
||||
|
||||
|
||||
if (getArguments() != null && getArguments().getLong("timetableDate", 0) != 0) {
|
||||
Date gotDate = new Date().parseFromYmd(Long.toString(getArguments().getLong("timetableDate", 0))); // OVERRIDE HERE
|
||||
// DAMNIT
|
||||
// THE TIMETABLE WAS DOING LOTS OF WEIRD THINGS (incorrect default days, sometimes scrolling to the beginning)
|
||||
// BECAUSE THESE TWO LINES WERE SWAPPED.
|
||||
//pageSelection += Date.diffDays(gotDate, displayingDate);
|
||||
|
||||
Log.d(TAG, "Got date "+getArguments().getLong("timetableDate", 0));
|
||||
|
||||
pageSelection = 2 + Date.diffDays(gotDate, today);
|
||||
displayingDate = gotDate;
|
||||
}
|
||||
else if (pageSelection == -1) {
|
||||
AsyncTask.execute(() -> {
|
||||
if (app == null || app.profile == null || activity == null || b == null || !isAdded())
|
||||
return;
|
||||
|
||||
List<LessonFull> lessons = app.db.lessonDao().getAllWeekNow(App.profileId, today.getWeekStart(), today);
|
||||
displayingDate = HomeFragmentOld.findDateWithLessons(App.profileId, lessons);
|
||||
pageSelection = 2 + Date.diffDays(displayingDate, today); // DEFAULT HERE
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
viewPager.setCurrentItem(pageSelection, false);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
viewPager.setCurrentItem(pageSelection, false);
|
||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { }
|
||||
@Override public void onPageScrollStateChanged(int state) { }
|
||||
@Override public void onPageSelected(int position) {
|
||||
pageSelection = position;
|
||||
Fragment fragment = adapter.getItem(position);
|
||||
assert fragment.getArguments() != null;
|
||||
displayingDate = new Date().parseFromYmd(Long.toString(fragment.getArguments().getLong("date", 20181009)));
|
||||
/*
|
||||
Fragment fragment = adapter.getItem(position);
|
||||
int scrolledDate = fragment.getArguments().getInt("date", 0);
|
||||
//Toast.makeText(app, "Date: "+scrolledDate, Toast.LENGTH_SHORT).show();
|
||||
Collection<Integer> removeDates = new ArrayList<>();
|
||||
for (Integer lessonChangeDate: unreadLessonChangesDates) {
|
||||
if (lessonChangeDate.equals(scrolledDate)) {
|
||||
for (RegisterLessonChange lessonChange: app.profile.timetable.lessonChanges) {
|
||||
if (lessonChange.lessonDate.getValue() == lessonChangeDate) {
|
||||
lessonChange.notified = true;
|
||||
}
|
||||
}
|
||||
removeDates.add(lessonChangeDate);
|
||||
}
|
||||
}
|
||||
unreadLessonChangesDates.removeAll(removeDates);
|
||||
|
||||
if (app.profile.unreadLessonChanges != unreadLessonChangesDates.size()) {
|
||||
app.profile.unreadLessonChanges = unreadLessonChangesDates.size();
|
||||
app.profile.savePending = true;
|
||||
Intent i = new Intent("android.intent.action.MAIN").putExtra(MainActivity.ACTION_UPDATE_BADGES, "yes, sure");
|
||||
getContext().sendBroadcast(i);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
});
|
||||
|
||||
// Set Tabs inside Toolbar
|
||||
TabLayout tabs = view.findViewById(R.id.result_tabs);
|
||||
tabs.setupWithViewPager(viewPager);
|
||||
|
||||
/*if (!app.appConfig.tapTargetSetAsRead) {
|
||||
new MaterialTapTargetPrompt.Builder(activity)
|
||||
.setTarget(activity.findViewById(R.id.action_mark_as_read))
|
||||
.setPrimaryText(R.string.tap_target_set_as_read_title)
|
||||
.setSecondaryText(R.string.tap_target_set_as_read_text)
|
||||
.setFocalColour(Color.TRANSPARENT)
|
||||
.setPromptStateChangeListener((prompt, state) -> {
|
||||
if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED) {
|
||||
// User has pressed the prompt target
|
||||
}
|
||||
})
|
||||
.show();
|
||||
app.appConfig.tapTargetSetAsRead = true;
|
||||
app.appConfig.savePending = true;
|
||||
}*/
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapFromView(View view) {
|
||||
//Define a bitmap with the same size as the view
|
||||
Bitmap returnedBitmap = Bitmap.createBitmap(view.getLayoutParams().width, view.getLayoutParams().height, Bitmap.Config.ARGB_8888);
|
||||
//Bind a canvas to it
|
||||
Canvas canvas = new Canvas(returnedBitmap);
|
||||
//Get the view's background
|
||||
Drawable bgDrawable = view.getBackground();
|
||||
if (bgDrawable!=null)
|
||||
//has background drawable, then draw it on the canvas
|
||||
bgDrawable.draw(canvas);
|
||||
else
|
||||
//does not have background drawable, then draw white background on the canvas
|
||||
canvas.drawColor(Color.TRANSPARENT);
|
||||
// draw the view on the canvas
|
||||
view.draw(canvas);
|
||||
//return the bitmap
|
||||
return returnedBitmap;
|
||||
}
|
||||
|
||||
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
|
||||
int width = bm.getWidth();
|
||||
int height = bm.getHeight();
|
||||
float scaleWidth = ((float) newWidth) / width;
|
||||
float scaleHeight = ((float) newHeight) / height;
|
||||
// CREATE A MATRIX FOR THE MANIPULATION
|
||||
Matrix matrix = new Matrix();
|
||||
// RESIZE THE BIT MAP
|
||||
matrix.postScale(scaleWidth, scaleHeight);
|
||||
|
||||
// "RECREATE" THE NEW BITMAP
|
||||
Bitmap resizedBitmap = Bitmap.createBitmap(
|
||||
bm, 0, 0, width, height, matrix, true);
|
||||
bm.recycle();
|
||||
return resizedBitmap;
|
||||
}
|
||||
|
||||
public void generateBlockTimetable() {
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Date weekCurrentStart = Week.getWeekStart();
|
||||
Date weekCurrentEnd = Week.getWeekEnd();
|
||||
Date weekNextStart = weekCurrentEnd.clone().stepForward(0, 0, 1);
|
||||
Date weekNextEnd = weekNextStart.clone().stepForward(0, 0, 6);
|
||||
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.title(R.string.timetable_generate_range)
|
||||
.items(
|
||||
getString(R.string.timetable_generate_no_changes),
|
||||
getString(R.string.timetable_generate_current_week_format, weekCurrentStart.getFormattedStringShort(), weekCurrentEnd.getFormattedStringShort()),
|
||||
getString(R.string.timetable_generate_next_week_format, weekNextStart.getFormattedStringShort(), weekNextEnd.getFormattedStringShort()),
|
||||
getString(R.string.timetable_generate_for_printout))
|
||||
.positiveText(R.string.ok)
|
||||
.negativeText(R.string.cancel)
|
||||
.checkBoxPromptRes(R.string.timetable_generate_include_profile_name, true, null)
|
||||
.itemsCallbackSingleChoice(0, (dialog, itemView, which, text) -> {
|
||||
Toast.makeText(app, "Selected "+which, Toast.LENGTH_SHORT).show();
|
||||
AsyncTask.execute(() -> {
|
||||
switch (which) {
|
||||
case 0:
|
||||
generateBlockTimetableWithLessons(app.db.lessonDao().getAllWeekNow(App.profileId, weekCurrentStart, weekCurrentStart), false, dialog.isPromptCheckBoxChecked(), null, null, false);
|
||||
break;
|
||||
case 1:
|
||||
generateBlockTimetableWithLessons(app.db.lessonDao().getAllWeekNow(App.profileId, weekCurrentStart, weekCurrentStart), true, dialog.isPromptCheckBoxChecked(), weekCurrentStart, weekCurrentEnd, false);
|
||||
break;
|
||||
case 2:
|
||||
generateBlockTimetableWithLessons(app.db.lessonDao().getAllWeekNow(App.profileId, weekNextStart, weekNextStart), true, dialog.isPromptCheckBoxChecked(), weekNextStart, weekNextEnd, false);
|
||||
break;
|
||||
case 3:
|
||||
generateBlockTimetableWithLessons(app.db.lessonDao().getAllWeekNow(App.profileId, weekCurrentStart, weekCurrentStart), false, dialog.isPromptCheckBoxChecked(), null, null, true);
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (which == 0) {
|
||||
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.show();
|
||||
|
||||
}
|
||||
|
||||
private MaterialDialog progressDialog;
|
||||
|
||||
private void generateBlockTimetableWithLessons(List<LessonFull> lessonList, boolean markChanges, boolean showProfileName, Date weekStart, Date weekEnd, boolean noColors) {
|
||||
d(TAG, Arrays.toString(lessonList.toArray()));
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
progressDialog = new MaterialDialog.Builder(activity)
|
||||
.title(R.string.timetable_generate_progress_title)
|
||||
.content(R.string.timetable_generate_progress_text)
|
||||
.progress(true, 0)
|
||||
.show();
|
||||
});
|
||||
|
||||
// block size: 190x90, so one minute is 2px
|
||||
// spacing: 15x10
|
||||
// left size: 45px
|
||||
// header size: 45px
|
||||
// overall width: 45 + n*(190+15)
|
||||
// overall height: 45 + n*(90+10)
|
||||
// footer size 30px
|
||||
|
||||
int WIDTH_CONSTANT = 70;
|
||||
int WIDTH_WEEKDAY = 285;
|
||||
int WIDTH_SPACING = 15;
|
||||
int HEIGHT_PROFILE_NAME = showProfileName ? 100 : 0;
|
||||
int HEIGHT_CONSTANT = 60;
|
||||
int HEIGHT_MINUTE = 3;
|
||||
int HEIGHT_FOOTER = 40;
|
||||
|
||||
List<List<LessonFull>> weekdays = new ArrayList<>();
|
||||
for(int i = 0; i < 7; i++) {
|
||||
weekdays.add(new ArrayList<>());
|
||||
}
|
||||
int maxWeekDay = 5;
|
||||
Time minTime = null;
|
||||
Time maxTime = null;
|
||||
|
||||
TreeMap<Integer, Integer> lessonRanges = new TreeMap<>();
|
||||
|
||||
for (LessonFull lesson: lessonList) {
|
||||
if (lesson.weekDay > maxWeekDay)
|
||||
maxWeekDay = lesson.weekDay;
|
||||
List<LessonFull> weekdayLessons = weekdays.get(lesson.weekDay);
|
||||
weekdayLessons.add(lesson);
|
||||
lessonRanges.put(lesson.startTime.getValue(), lesson.endTime.getValue());
|
||||
if (minTime == null || lesson.startTime.getValue() < minTime.getValue()) {
|
||||
minTime = lesson.startTime;
|
||||
}
|
||||
if (maxTime == null || lesson.endTime.getValue() > maxTime.getValue()) {
|
||||
maxTime = lesson.endTime;
|
||||
}
|
||||
}
|
||||
|
||||
if (minTime != null) {
|
||||
d(TAG, "Min time "+minTime.getValue()+" max time "+maxTime.getValue());
|
||||
Time diff = Time.diff(maxTime, minTime);
|
||||
int minutes = diff.hour*60+diff.minute;
|
||||
|
||||
Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
|
||||
int imgWidth = WIDTH_CONSTANT + maxWeekDay * WIDTH_WEEKDAY + (maxWeekDay-1) * WIDTH_SPACING;
|
||||
int imgHeight = HEIGHT_PROFILE_NAME + HEIGHT_CONSTANT + minutes*HEIGHT_MINUTE + HEIGHT_FOOTER;
|
||||
Bitmap bmp = Bitmap.createBitmap(imgWidth+20, imgHeight+30, conf); // this creates a MUTABLE bitmap
|
||||
Canvas canvas = new Canvas(bmp);
|
||||
if (noColors)
|
||||
canvas.drawARGB(255, 255, 255, 255);
|
||||
else
|
||||
canvas.drawARGB(255, 225, 225, 225);
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setFilterBitmap(true);
|
||||
paint.setDither(true);
|
||||
|
||||
for (LessonFull lesson: lessonList) {
|
||||
Time lessonLength = Time.diff(lesson.endTime, lesson.startTime);
|
||||
Time firstOffset = Time.diff(lesson.startTime, minTime);
|
||||
|
||||
int left = WIDTH_CONSTANT + lesson.weekDay*WIDTH_WEEKDAY + lesson.weekDay * WIDTH_SPACING;
|
||||
int top = HEIGHT_PROFILE_NAME + HEIGHT_CONSTANT + (firstOffset.hour*60+firstOffset.minute)*HEIGHT_MINUTE;
|
||||
int blockWidth = WIDTH_WEEKDAY;
|
||||
int blockHeight = (lessonLength.hour*60+lessonLength.minute)*HEIGHT_MINUTE;
|
||||
int viewWidth = Utils.dpToPx(380);
|
||||
int viewHeight = Utils.dpToPx((lessonLength.hour*60+lessonLength.minute)*4);
|
||||
|
||||
LinearLayout linearLayout;
|
||||
try {
|
||||
linearLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.row_timetable_block_item, null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
new ErrorDialog(activity, e);
|
||||
return;
|
||||
}
|
||||
|
||||
LinearLayout layout = linearLayout.findViewById(R.id.timetableItemLayout);
|
||||
CardView card = linearLayout.findViewById(R.id.timetableItemCard);
|
||||
TextView subjectName = linearLayout.findViewById(R.id.timetableItemSubjectName);
|
||||
TextView classroomName = linearLayout.findViewById(R.id.timetableItemClassroomName);
|
||||
TextView teacherName = linearLayout.findViewById(R.id.timetableItemTeacherName);
|
||||
TextView teamName = linearLayout.findViewById(R.id.timetableItemTeamName);
|
||||
|
||||
if (noColors) {
|
||||
card.setCardBackgroundColor(0xffffffff);
|
||||
card.setCardElevation(0.0f);
|
||||
layout.setBackgroundResource(R.drawable.bg_rounded_16dp_outline);
|
||||
subjectName.setTextColor(0xff000000);
|
||||
classroomName.setTextColor(0xffaaaaaa);
|
||||
teacherName.setTextColor(0xffaaaaaa);
|
||||
teamName.setTextColor(0xffaaaaaa);
|
||||
}
|
||||
|
||||
subjectName.setText(lesson.subjectLongName);
|
||||
classroomName.setText(bs(lesson.classroomName));
|
||||
teacherName.setText(bs(lesson.teacherFullName));
|
||||
teamName.setText(bs(lesson.teamName));
|
||||
|
||||
if (markChanges) {
|
||||
if (lesson.changeId != 0) {
|
||||
if (lesson.changeType == TYPE_CANCELLED) {
|
||||
card.setCardBackgroundColor(Color.BLACK);
|
||||
subjectName.setText(Html.fromHtml("<del>"+lesson.subjectLongName+"</del>", null, new SpannableHtmlTagHandler()));
|
||||
}
|
||||
else if (lesson.changeType == TYPE_CHANGE) {
|
||||
card.setCardBackgroundColor(0xff234158); // 0x40 x primary
|
||||
subjectName.setTypeface(null, Typeface.BOLD_ITALIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
linearLayout.setDrawingCacheEnabled(true);
|
||||
linearLayout.measure(View.MeasureSpec.makeMeasureSpec(viewWidth, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(viewHeight, View.MeasureSpec.EXACTLY));
|
||||
linearLayout.layout(0, 0, linearLayout.getMeasuredWidth(), linearLayout.getMeasuredHeight());
|
||||
linearLayout.buildDrawingCache(true);
|
||||
|
||||
Bitmap bm = linearLayout.getDrawingCache();
|
||||
canvas.drawBitmap(bm, null, new Rect(left, top, left+blockWidth, top+blockHeight), paint);
|
||||
}
|
||||
|
||||
Paint textPaint = new Paint();
|
||||
textPaint.setARGB(255, 0, 0, 0);
|
||||
textPaint.setTextAlign(Paint.Align.CENTER);
|
||||
textPaint.setTextSize(30);
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setFilterBitmap(true);
|
||||
textPaint.setDither(true);
|
||||
|
||||
for (int w = 0; w < maxWeekDay+1; w++) {
|
||||
int x = WIDTH_CONSTANT + w*WIDTH_WEEKDAY + w * WIDTH_SPACING;
|
||||
canvas.drawText(Week.getFullDayName(w), x + (WIDTH_WEEKDAY/2), HEIGHT_PROFILE_NAME + HEIGHT_CONSTANT/2+10, textPaint);
|
||||
}
|
||||
|
||||
if (showProfileName) {
|
||||
textPaint.setTextSize(50);
|
||||
if (weekStart != null && weekEnd != null) {
|
||||
canvas.drawText(app.profile.getName() + " - plan lekcji, "+weekStart.getFormattedStringShort() + " - " + weekEnd.getFormattedStringShort(), (imgWidth + 20) / 2, 80, textPaint);
|
||||
}
|
||||
else {
|
||||
canvas.drawText(app.profile.getName() + " - plan lekcji", (imgWidth + 20) / 2, 80, textPaint);
|
||||
}
|
||||
}
|
||||
|
||||
textPaint.setARGB(128, 0, 0, 0);
|
||||
textPaint.setTextAlign(Paint.Align.RIGHT);
|
||||
textPaint.setTextSize(26);
|
||||
textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC));
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setFilterBitmap(true);
|
||||
textPaint.setDither(true);
|
||||
int textPaintCenter = Math.round((textPaint.descent() + textPaint.ascent()) / 2);
|
||||
canvas.drawText("Wygenerowano w aplikacji Szkolny.eu", imgWidth - 10, imgHeight - textPaintCenter - 10, textPaint);
|
||||
|
||||
textPaint.setARGB(255, 127, 127, 127);
|
||||
textPaint.setTextAlign(Paint.Align.CENTER);
|
||||
textPaint.setTextSize(16);
|
||||
textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setFilterBitmap(true);
|
||||
textPaint.setDither(true);
|
||||
textPaintCenter = Math.round((textPaint.descent() + textPaint.ascent()) / 2); // it's probably negative
|
||||
|
||||
Paint linePaint = new Paint();
|
||||
linePaint.setARGB(255, 100, 100, 100);
|
||||
linePaint.setStyle(Paint.Style.STROKE);
|
||||
linePaint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
|
||||
linePaint.setAntiAlias(true);
|
||||
linePaint.setFilterBitmap(true);
|
||||
linePaint.setDither(true);
|
||||
|
||||
int minTimeVal = minTime.getValue();
|
||||
int minTimeInt = (minTimeVal/10000)*60 + ((minTimeVal/100)%100);
|
||||
for (int startTime: lessonRanges.keySet()) {
|
||||
Integer endTime = lessonRanges.get(startTime);
|
||||
if (endTime == null)
|
||||
continue;
|
||||
|
||||
int hour = startTime/10000;
|
||||
int minute = (startTime/100)%100;
|
||||
int firstOffset = hour * 60 + minute - minTimeInt; // offset in minutes
|
||||
int top = HEIGHT_PROFILE_NAME + HEIGHT_CONSTANT + firstOffset*HEIGHT_MINUTE;
|
||||
String text = hour+":"+(minute < 10 ? "0"+minute : minute);
|
||||
canvas.drawText(text, WIDTH_CONSTANT/2, top-textPaintCenter, textPaint);
|
||||
canvas.drawLine(WIDTH_CONSTANT, top, imgWidth, top, linePaint);
|
||||
|
||||
hour = endTime/10000;
|
||||
minute = (endTime/100)%100;
|
||||
firstOffset = hour * 60 + minute - minTimeInt; // offset in minutes
|
||||
top = HEIGHT_PROFILE_NAME + HEIGHT_CONSTANT + firstOffset*HEIGHT_MINUTE;
|
||||
text = hour+":"+(minute < 10 ? "0"+minute : minute);
|
||||
canvas.drawText(text, WIDTH_CONSTANT/2, top-textPaintCenter, textPaint);
|
||||
canvas.drawLine(WIDTH_CONSTANT, top, imgWidth, top, linePaint);
|
||||
}
|
||||
|
||||
File outputDir = Environment.getExternalStoragePublicDirectory("Szkolny.eu");
|
||||
outputDir.mkdirs();
|
||||
|
||||
File outputFile = new File(outputDir, "plan_lekcji_"+app.profile.getName()+"_"+Date.getToday().getStringY_m_d()+"_"+Time.getNow().getStringH_M()+".png");
|
||||
|
||||
FileOutputStream fos;
|
||||
try {
|
||||
fos = new FileOutputStream(outputFile);
|
||||
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
Log.e("SAVE_IMAGE", e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
activity.runOnUiThread(() -> {
|
||||
if (progressDialog != null)
|
||||
progressDialog.dismiss();
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title(R.string.timetable_generate_success_title)
|
||||
.content(R.string.timetable_generate_success_text)
|
||||
.positiveText(R.string.share)
|
||||
.negativeText(R.string.open)
|
||||
.neutralText(R.string.do_nothing)
|
||||
.onPositive(((dialog, which) -> {
|
||||
Uri uri = Uri.parse("file://" + outputFile.getAbsolutePath());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
uri = FileProvider.getUriForFile(activity, app.getPackageName() + ".provider", outputFile);
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setDataAndType(null, "image/*");
|
||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.share_intent)));
|
||||
}))
|
||||
.onNegative(((dialog, which) -> {
|
||||
Uri uri = Uri.parse("file://" + outputFile.getAbsolutePath());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
uri = FileProvider.getUriForFile(activity, app.getPackageName() + ".provider", outputFile);
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "image/*");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
startActivity(intent);
|
||||
}))
|
||||
.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static class Adapter extends FragmentPagerAdapter {
|
||||
private final List<Fragment> mFragmentList = new ArrayList<>();
|
||||
private final List<String> mFragmentTitleList = new ArrayList<>();
|
||||
|
||||
public Adapter(FragmentManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return mFragmentList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mFragmentList.size();
|
||||
}
|
||||
|
||||
public void addFragment(Fragment fragment, String title) {
|
||||
mFragmentList.add(fragment);
|
||||
mFragmentTitleList.add(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return mFragmentTitleList.get(position);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
@ -1,10 +1,13 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.day.TimetableDayFragment
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
@ -1,18 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.utils.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
|
||||
public class ItemTimetableModel {
|
||||
public LessonFull lesson;
|
||||
public List<Event> events;
|
||||
public Date lessonDate;
|
||||
|
||||
public ItemTimetableModel(LessonFull lesson, List<Event> events, Date lessonDate) {
|
||||
this.lesson = lesson;
|
||||
this.events = events;
|
||||
this.lessonDate = lessonDate;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user