Merge branch 'feature/teacher-absence' into develop

This commit is contained in:
Kacper Ziubryniewicz 2019-09-29 17:58:22 +02:00
commit fea51fc493
31 changed files with 1022 additions and 536 deletions

View File

@ -56,7 +56,7 @@ import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesFragment
import pl.szczodrzynski.edziennik.utils.models.NavTarget
import pl.szczodrzynski.edziennik.network.ServerRequest
import pl.szczodrzynski.edziennik.sync.SyncJob
import pl.szczodrzynski.edziennik.ui.modules.agenda.AgendaDefaultFragment
import pl.szczodrzynski.edziennik.ui.modules.agenda.AgendaFragment
import pl.szczodrzynski.edziennik.ui.modules.announcements.AnnouncementsFragment
import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceFragment
import pl.szczodrzynski.edziennik.ui.modules.base.DebugFragment
@ -128,7 +128,7 @@ class MainActivity : AppCompatActivity() {
.withBadgeTypeId(TYPE_LESSON_CHANGE)
.isInDrawer(true)
list += NavTarget(DRAWER_ITEM_AGENDA, R.string.menu_agenda, AgendaDefaultFragment::class)
list += NavTarget(DRAWER_ITEM_AGENDA, R.string.menu_agenda, AgendaFragment::class)
.withIcon(CommunityMaterial.Icon.cmd_calendar)
.withBadgeTypeId(TYPE_EVENT)
.isInDrawer(true)

View File

@ -72,6 +72,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile;
import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileFull;
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject;
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.teams.Team;
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesComposeInfo;
import pl.szczodrzynski.edziennik.utils.models.Date;
@ -170,6 +171,7 @@ public class Librus implements EdziennikInterface {
private List<Team> teamList;
private List<Teacher> teacherList;
private List<TeacherAbsence> teacherAbsenceList;
private List<Subject> subjectList;
private List<Lesson> lessonList;
private List<LessonChange> lessonChangeList;
@ -240,6 +242,7 @@ public class Librus implements EdziennikInterface {
teamList = profileId == -1 ? new ArrayList<>() : app.db.teamDao().getAllNow(profileId);
teacherList = profileId == -1 ? new ArrayList<>() : app.db.teacherDao().getAllNow(profileId);
teacherAbsenceList = new ArrayList<>();
subjectList = new ArrayList<>();
lessonList = new ArrayList<>();
lessonChangeList = new ArrayList<>();
@ -294,6 +297,7 @@ public class Librus implements EdziennikInterface {
targetEndpoints.add("GradesComments");
targetEndpoints.add("Events");
targetEndpoints.add("TeacherFreeDays");
targetEndpoints.add("CustomTypes");
targetEndpoints.add("Homework");
targetEndpoints.add("LuckyNumbers");
@ -350,6 +354,7 @@ public class Librus implements EdziennikInterface {
targetEndpoints.add("CustomTypes");
targetEndpoints.add("PtMeetings");
targetEndpoints.add("SchoolFreeDays");
targetEndpoints.add("TeacherFreeDays");
break;
case FEATURE_GRADES:
targetEndpoints.add("SavedGradeCategories");
@ -595,6 +600,8 @@ public class Librus implements EdziennikInterface {
}
if (eventTypeList.size() > 0)
app.db.eventTypeDao().addAll(eventTypeList);
if (teacherAbsenceList.size() > 0)
app.db.teacherAbsenceDao().addAll(teacherAbsenceList);
if (noticeList.size() > 0) {
app.db.noticeDao().clear(profileId);
app.db.noticeDao().addAll(noticeList);
@ -3139,6 +3146,10 @@ public class Librus implements EdziennikInterface {
private SparseArray<String> teacherFreeDaysTypes = new SparseArray<>();
private void getTeacherFreeDaysTypes() {
if (!fullSync) {
r("finish", "TeacherFreeDaysTypes");
return;
}
callback.onActionStarted(R.string.sync_action_syncing_teacher_free_days_types);
apiRequest("TeacherFreeDays/Types", data -> {
if (data == null) {
@ -3173,27 +3184,35 @@ public class Librus implements EdziennikInterface {
JsonObject freeDay = freeDayEl.getAsJsonObject();
long id = freeDay.get("Id").getAsLong();
long teacherId = freeDay.getAsJsonObject("Teacher").get("Id").getAsLong();
Date dateFrom = Date.fromY_m_d(freeDay.get("DateFrom").getAsString());
Date dateTo = Date.fromY_m_d(freeDay.get("DateTo").getAsString());
int type = freeDay.getAsJsonObject("Type").get("Id").getAsInt();
String topic = teacherFreeDaysTypes.get(type)+"\n"+(dateFrom.getValue() != dateTo.getValue() ? dateFrom.getFormattedString()+" - "+dateTo.getFormattedString() : "");
Event eventObject = new Event(
long type = freeDay.getAsJsonObject("Type").get("Id").getAsLong();
//String topic = teacherFreeDaysTypes.get(type)+"\n"+(dateFrom.getValue() != dateTo.getValue() ? dateFrom.getFormattedString()+" - "+dateTo.getFormattedString() : "");
TeacherAbsence teacherAbsence = new TeacherAbsence(
profileId,
id,
teacherId,
type,
dateFrom,
null,
topic,
-1,
TYPE_TEACHER_ABSENCE,
false,
freeDay.getAsJsonObject("Teacher").get("Id").getAsLong(),
-1,
-1
dateTo
);
eventList.add(eventObject);
metadataList.add(new Metadata(profileId, Metadata.TYPE_EVENT, eventObject.id, profile.getEmpty(), profile.getEmpty(), System.currentTimeMillis()));
teacherAbsenceList.add(teacherAbsence);
metadataList.add(
new Metadata(
profileId,
Metadata.TYPE_TEACHER_ABSENCE,
teacherAbsence.getId(),
true,
true,
System.currentTimeMillis())
);
}
r("finish", "TeacherFreeDays");
}

View File

@ -1,5 +1,6 @@
package pl.szczodrzynski.edziennik.data.db;
import androidx.annotation.NonNull;
import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.room.Database;
import androidx.room.Room;
@ -49,6 +50,8 @@ import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileDao;
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject;
import pl.szczodrzynski.edziennik.data.db.modules.subjects.SubjectDao;
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.TeacherAbsenceDao;
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherDao;
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team;
import pl.szczodrzynski.edziennik.data.db.modules.teams.TeamDao;
@ -60,6 +63,7 @@ import android.content.Context;
Grade.class,
//GradeCategory.class,
Teacher.class,
TeacherAbsence.class,
Subject.class,
Notice.class,
Lesson.class,
@ -77,7 +81,7 @@ import android.content.Context;
Message.class,
MessageRecipient.class,
DebugLog.class,
Metadata.class}, version = 52)
Metadata.class}, version = 53)
@TypeConverters({
ConverterTime.class,
ConverterDate.class,
@ -89,6 +93,7 @@ public abstract class AppDb extends RoomDatabase {
public abstract GradeDao gradeDao();
//public abstract GradeCategoryDao gradeCategoryDao();
public abstract TeacherDao teacherDao();
public abstract TeacherAbsenceDao teacherAbsenceDao();
public abstract SubjectDao subjectDao();
public abstract NoticeDao noticeDao();
public abstract LessonDao lessonDao();
@ -532,6 +537,20 @@ public abstract class AppDb extends RoomDatabase {
database.execSQL("ALTER TABLE teachers ADD teacherTypeDescription TEXT DEFAULT NULL");
}
};
private static final Migration MIGRATION_52_53 = new Migration(52, 53) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS teacherAbsence (" +
"profileId INTEGER NOT NULL," +
"teacherAbsenceId INTEGER NOT NULL," +
"teacherId INTEGER NOT NULL," +
"teacherAbsenceType INTEGER NOT NULL," +
"teacherAbsenceDateFrom TEXT NOT NULL," +
"teacherAbsenceDateTo TEXT NOT NULL," +
"PRIMARY KEY(profileId, teacherAbsenceId)" +
")");
}
};
public static AppDb getDatabase(final Context context) {
@ -581,7 +600,8 @@ public abstract class AppDb extends RoomDatabase {
MIGRATION_48_49,
MIGRATION_49_50,
MIGRATION_50_51,
MIGRATION_51_52)
MIGRATION_51_52,
MIGRATION_52_53)
.allowMainThreadQueries()
//.fallbackToDestructiveMigration()
.build();

View File

@ -12,7 +12,7 @@ import androidx.room.RawQuery;
import java.util.List;
import pl.szczodrzynski.edziennik.utils.models.Date;
import pl.szczodrzynski.edziennik.utils.models.db.LessonChangeCounter;
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;

View File

@ -18,6 +18,7 @@ public class Metadata {
public static final int TYPE_LESSON_CHANGE = 6;
public static final int TYPE_ANNOUNCEMENT = 7;
public static final int TYPE_MESSAGE = 8;
public static final int TYPE_TEACHER_ABSENCE = 9;
public int profileId;

View File

@ -17,7 +17,7 @@ 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.utils.models.db.UnreadCounter;
import pl.szczodrzynski.edziennik.utils.models.UnreadCounter;
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_ANNOUNCEMENT;
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_ATTENDANCE;

View File

@ -0,0 +1,27 @@
package pl.szczodrzynski.edziennik.data.db.modules.teachers
import androidx.room.ColumnInfo
import androidx.room.Entity
import pl.szczodrzynski.edziennik.utils.models.Date
@Entity(tableName = "teacherAbsence",
primaryKeys = ["profileId", "teacherAbsenceId"])
open class TeacherAbsence (
val profileId: Int,
@ColumnInfo(name = "teacherAbsenceId")
val id: Long,
val teacherId: Long,
@ColumnInfo(name = "teacherAbsenceType")
val type: Long,
@ColumnInfo(name = "teacherAbsenceDateFrom")
val dateFrom: Date,
@ColumnInfo(name = "teacherAbsenceDateTo")
val dateTo: Date
)

View File

@ -0,0 +1,37 @@
package pl.szczodrzynski.edziennik.data.db.modules.teachers
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
import pl.szczodrzynski.edziennik.utils.models.Date
@Dao
interface TeacherAbsenceDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun add(teacherAbsence: TeacherAbsence)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun addAll(teacherAbsenceList: List<TeacherAbsence>)
@Query("SELECT * FROM teacherAbsence WHERE profileId = :profileId")
fun getAll(profileId: Int): List<TeacherAbsence>
@Query("SELECT *, teachers.teacherName || ' ' || teachers.teacherSurname as teacherFullName, " +
"metadata.seen, metadata.notified, metadata.addedDate FROM teacherAbsence " +
"LEFT JOIN teachers USING (profileId, teacherId) " +
"LEFT JOIN metadata ON teacherAbsenceId = thingId AND metadata.thingType = " + Metadata.TYPE_TEACHER_ABSENCE +
" AND metadata.profileId = :profileId WHERE teachers.profileId = :profileId")
fun getAllFull(profileId: Int): List<TeacherAbsenceFull>
@Query("SELECT *, teachers.teacherName || ' ' || teachers.teacherSurname as teacherFullName, " +
"metadata.seen, metadata.notified, metadata.addedDate FROM teacherAbsence " +
"LEFT JOIN teachers USING (profileId, teacherId) " +
"LEFT JOIN metadata ON teacherAbsenceId = thingId AND metadata.thingType = " + Metadata.TYPE_TEACHER_ABSENCE +
" AND metadata.profileId = :profileId WHERE teachers.profileId = :profileId " +
"AND :date BETWEEN teacherAbsenceDateFrom AND teacherAbsenceDateTo")
fun getAllByDateFull(profileId: Int, date: Date): LiveData<List<TeacherAbsenceFull>>
}

View File

@ -0,0 +1,14 @@
package pl.szczodrzynski.edziennik.data.db.modules.teachers
import pl.szczodrzynski.edziennik.utils.models.Date
class TeacherAbsenceFull(profileId: Int, id: Long, teacherId: Long, type: Long, dateFrom: Date, dateTo: Date)
: TeacherAbsence(profileId, id, teacherId, type, dateFrom, dateTo) {
var teacherFullName = ""
// metadata
var seen: Boolean = false
var notified: Boolean = false
var addedDate: Long = 0
}

View File

@ -20,7 +20,9 @@ import pl.szczodrzynski.edziennik.App;
import pl.szczodrzynski.edziennik.R;
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.teachers.TeacherAbsenceFull;
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog;
import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog;
import pl.szczodrzynski.edziennik.utils.models.Date;
import pl.szczodrzynski.edziennik.utils.models.Time;
@ -171,7 +173,8 @@ public class EventListDialog {
examsView.setNestedScrollingEnabled(false);
examsView.setLayoutManager(new LinearLayoutManager(context));
CardView lessonChangeContainer = dialogView.findViewById(R.id.lesson_change_container);
CardView lessonChangeContainer = dialogView.findViewById(R.id.lessonChangeContainer);
CardView teacherAbsenceContainer = dialogView.findViewById(R.id.teacherAbsenceContainer);
//lessonChangeContainer.setVisibility(View.GONE);
if (time == null) {
app.db.lessonChangeDao().getLessonChangeCounterByDate(App.profileId, date).observe((LifecycleOwner) context, counter -> {
@ -179,14 +182,38 @@ public class EventListDialog {
return;
if (counter.lessonChangeCount > 0) {
lessonChangeContainer.setVisibility(View.VISIBLE);
TextView lessonChangeCount = dialogView.findViewById(R.id.lesson_change_count);
lessonChangeCount.setText(Integer.toString(counter.lessonChangeCount));
TextView lessonChangeCount = dialogView.findViewById(R.id.lessonChangeCount);
lessonChangeCount.setText(String.valueOf(counter.lessonChangeCount));
lessonChangeContainer.setCardBackgroundColor(0xff78909c);
lessonChangeContainer.setOnClickListener((v -> {
new LessonChangeDialog(context).show(app, date);
}));
}
});
app.db.teacherAbsenceDao().getAllByDateFull(App.profileId, date).observe((LifecycleOwner) context, teacherAbsenceList -> {
if (teacherAbsenceList == null)
return;
if (teacherAbsenceList.size() > 0) {
int count = 0;
for (TeacherAbsenceFull teacherAbsence : teacherAbsenceList) {
Date dateFrom = teacherAbsence.getDateFrom();
Date dateTo = teacherAbsence.getDateTo();
if (date.compareTo(dateFrom) >= 0 && date.compareTo(dateTo) <= 0) {
count++;
}
}
teacherAbsenceContainer.setVisibility(View.VISIBLE);
TextView teacherAbsenceCount = dialogView.findViewById(R.id.teacherAbsenceCount);
teacherAbsenceCount.setText(String.valueOf(count));
teacherAbsenceContainer.setCardBackgroundColor(0xffff1744);
teacherAbsenceContainer.setOnClickListener(( v -> {
new TeacherAbsenceDialog(context).show(app, date);
}));
}
});
}
app.db.eventDao().getAllByDateTime(profileId, date, time).observe((LifecycleOwner) context, events -> {

View File

@ -0,0 +1,46 @@
package pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceFull
import pl.szczodrzynski.edziennik.utils.models.Date
class TeacherAbsenceAdapter(
private val context: Context,
private val date: Date,
private val teacherAbsenceList: List<TeacherAbsenceFull>
) : RecyclerView.Adapter<TeacherAbsenceAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater: LayoutInflater = LayoutInflater.from(context)
val view: View = inflater.inflate(R.layout.row_dialog_teacher_absence_item, parent, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return teacherAbsenceList.size
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val teacherAbsence: TeacherAbsenceFull = teacherAbsenceList[position]
holder.teacherAbsenceTeacher.text = teacherAbsence.teacherFullName
val time = when(teacherAbsence.dateFrom.compareTo(teacherAbsence.dateTo)) {
0 -> teacherAbsence.dateFrom.formattedStringShort
else -> teacherAbsence.dateFrom.formattedStringShort + " - " + teacherAbsence.dateTo.formattedStringShort
}
holder.teacherAbsenceTime.text = time
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var teacherAbsenceTeacher: TextView = itemView.findViewById(R.id.teacherAbsenceTeacher)
var teacherAbsenceTime: TextView = itemView.findViewById(R.id.teacherAbsenceTime)
}
}

View File

@ -0,0 +1,43 @@
package pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence
import android.content.Context
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.DialogTeacherAbsenceListBinding
import pl.szczodrzynski.edziennik.utils.models.Date
class TeacherAbsenceDialog(val context: Context) {
val profileId: Int = App.profileId
private lateinit var b: DialogTeacherAbsenceListBinding
fun show(app: App, date: Date) {
val dialog = MaterialDialog.Builder(context)
.title(date.formattedString)
.customView(R.layout.dialog_teacher_absence_list, true)
.positiveText(R.string.close)
.autoDismiss(false)
.onPositive { dialog, _ -> dialog.dismiss()}
.show()
val customView: View = dialog.customView ?: return
b = DataBindingUtil.bind(customView) ?: return
b.teacherAbsenceView.setHasFixedSize(false)
b.teacherAbsenceView.isNestedScrollingEnabled = false
b.teacherAbsenceView.layoutManager = LinearLayoutManager(context)
app.db.teacherAbsenceDao().getAllByDateFull(profileId, date).observe(context as LifecycleOwner, Observer { absenceList ->
val adapter = TeacherAbsenceAdapter(context, date, absenceList)
b.teacherAbsenceView.adapter = adapter
b.teacherAbsenceView.visibility = View.VISIBLE
})
}
}

View File

@ -1,138 +0,0 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.applandeo.materialcalendarview.CalendarView;
import com.applandeo.materialcalendarview.EventDay;
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.ArrayList;
import java.util.Calendar;
import java.util.List;
import pl.szczodrzynski.edziennik.App;
import pl.szczodrzynski.edziennik.R;
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaCalendarBinding;
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListDialog;
import pl.szczodrzynski.edziennik.utils.models.Date;
import pl.szczodrzynski.edziennik.utils.Themes;
import static pl.szczodrzynski.edziennik.utils.Utils.intToStr;
public class AgendaCalendarFragment extends Fragment {
private App app = null;
private Activity activity = null;
private FragmentAgendaCalendarBinding b = null;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
activity = 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_agenda_calendar, 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;
List<Integer> unreadEventDates = new ArrayList<>();
final Handler handler = new Handler();
handler.postDelayed(() -> AsyncTask.execute(() -> {
Context c = getContext();
Activity a = getActivity();
assert c != null;
assert a != null;
if (!isAdded()) {
return;
}
List<EventDay> eventList = new ArrayList<>();
List<EventFull> events = app.db.eventDao().getAllNow(App.profileId);
for (EventFull event : events) {
if (event.eventDate == null)
continue;
Calendar startTime = Calendar.getInstance();
startTime.set(
event.eventDate.year,
event.eventDate.month - 1,
event.eventDate.day,
event.startTime == null ? 0 : event.startTime.hour,
event.startTime == null ? 0 : event.startTime.minute,
event.startTime == null ? 0 : event.startTime.second
);
Drawable eventIcon = new IconicsDrawable(activity).icon(CommunityMaterial.Icon.cmd_checkbox_blank_circle).size(IconicsSize.dp(10)).color(IconicsColor.colorInt(event.getColor()));
eventList.add(new EventDay(startTime, eventIcon));
if (!event.seen) {
unreadEventDates.add(event.eventDate.getValue());
}
}
List<LessonFull> lessonChanges = app.db.lessonChangeDao().getAllChangesWithLessonsNow(App.profileId);
for (LessonFull lesson: lessonChanges) {
Calendar startTime = Calendar.getInstance();
if (lesson.lessonDate == null) {
continue;
}
startTime.set(
lesson.lessonDate.year,
lesson.lessonDate.month - 1,
lesson.lessonDate.day,
lesson.startTime.hour,
lesson.startTime.minute,
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));
}
getActivity().runOnUiThread(() -> {
//List<EventDay> eventList = new ArrayList<>();
//Collections.sort(eventList, new EventListComparator());
CalendarView calendarView = b.agendaCalendarView;
calendarView.setEvents(eventList);
calendarView.setOnDayClickListener(eventDay -> {
Date dayDate = Date.fromCalendar(eventDay.getCalendar());
int scrolledDate = dayDate.getValue();
if (unreadEventDates.contains(scrolledDate)) {
AsyncTask.execute(() -> app.db.eventDao().setSeenByDate(App.profileId, Date.fromYmd(intToStr(scrolledDate)), true));
unreadEventDates.remove(unreadEventDates.indexOf(scrolledDate));
}
new EventListDialog(getContext()).show(app, dayDate);
});
b.progressBar.setVisibility(View.GONE);
});
}), 300);
}
}

View File

@ -1,364 +0,0 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.applandeo.materialcalendarview.CalendarView;
import com.applandeo.materialcalendarview.EventDay;
import com.github.tibolte.agendacalendarview.AgendaCalendarView;
import com.github.tibolte.agendacalendarview.CalendarPickerController;
import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.models.IDayItem;
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.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import pl.szczodrzynski.edziennik.App;
import pl.szczodrzynski.edziennik.R;
import pl.szczodrzynski.edziennik.MainActivity;
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaCalendarBinding;
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding;
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListDialog;
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog;
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog;
import pl.szczodrzynski.edziennik.utils.models.Date;
import pl.szczodrzynski.edziennik.utils.models.Time;
import pl.szczodrzynski.edziennik.utils.models.db.LessonChangeCounter;
import pl.szczodrzynski.edziennik.utils.Colors;
import pl.szczodrzynski.edziennik.utils.Themes;
import pl.szczodrzynski.edziennik.utils.Utils;
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem;
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_EVENT;
import static pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile.AGENDA_CALENDAR;
import static pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile.AGENDA_DEFAULT;
import static pl.szczodrzynski.edziennik.utils.Utils.intToStr;
public class AgendaDefaultFragment extends Fragment {
private App app = null;
private MainActivity activity = null;
private FragmentAgendaDefaultBinding b_default = null;
private FragmentAgendaCalendarBinding b_calendar = null;
private int viewType = AGENDA_DEFAULT;
@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
viewType = app.profile.getAgendaViewType();
if (viewType == AGENDA_DEFAULT) {
b_default = DataBindingUtil.inflate(inflater, R.layout.fragment_agenda_default, container, false);
return b_default.getRoot();
}
else {
b_calendar = DataBindingUtil.inflate(inflater, R.layout.fragment_agenda_calendar, container, false);
return b_calendar.getRoot();
}
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
if (app == null || app.profile == null || activity == null || (b_default == null && b_calendar == null) || !isAdded())
return;
activity.getBottomSheet().prependItems(
new BottomSheetPrimaryItem(true)
.withTitle(R.string.menu_add_event)
.withDescription(R.string.menu_add_event_desc)
.withIcon(CommunityMaterial.Icon.cmd_calendar_plus)
.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 EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_EVENT);
break;
case 1:
new EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK);
break;
}
})
.show();
}),
new BottomSheetPrimaryItem(true)
.withTitle(R.string.menu_agenda_change_view)
.withIcon(viewType == AGENDA_DEFAULT ? CommunityMaterial.Icon.cmd_calendar : CommunityMaterial.Icon2.cmd_view_list)
.withOnClickListener(v3 -> {
activity.getBottomSheet().close();
viewType = viewType == AGENDA_DEFAULT ? AGENDA_CALENDAR : AGENDA_DEFAULT;
app.profile.setAgendaViewType(viewType);
app.profileSaveAsync();
activity.reloadTarget();
}),
new BottomSheetSeparatorItem(true),
new BottomSheetPrimaryItem(true)
.withTitle(R.string.menu_mark_as_read)
.withIcon(CommunityMaterial.Icon.cmd_eye_check)
.withOnClickListener(v3 -> {
activity.getBottomSheet().close();
AsyncTask.execute(() -> app.db.metadataDao().setAllSeen(App.profileId, TYPE_EVENT, true));
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show();
})
);
activity.gainAttention();
if (viewType == AGENDA_DEFAULT) {
List<Integer> unreadEventDates = new ArrayList<>();
final Handler handler = new Handler();
handler.postDelayed(() -> AsyncTask.execute(() -> {
if (app == null || app.profile == null || activity == null || b_default == null || !isAdded())
return;
List<CalendarEvent> eventList = new ArrayList<>();
List<LessonChangeCounter> lessonChangeCounters = app.db.lessonChangeDao().getLessonChangeCountersNow(App.profileId);
for (LessonChangeCounter counter : lessonChangeCounters) {
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
if (counter.lessonChangeDate == null) {
continue;
}
startTime.set(counter.lessonChangeDate.year, counter.lessonChangeDate.month - 1, counter.lessonChangeDate.day, 10, 0, 0);
endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45));
eventList.add(new LessonChangeEvent(
counter.lessonChangeDate.getInMillis(),
0xff78909c,
Colors.legibleTextColor(0xff78909c),
startTime,
endTime,
counter.profileId,
counter.lessonChangeDate,
counter.lessonChangeCount
));
}
List<EventFull> events = app.db.eventDao().getAllNow(App.profileId);
for (EventFull event : events) {
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
if (event.eventDate == null)
continue;
startTime.set(
event.eventDate.year,
event.eventDate.month - 1,
event.eventDate.day,
event.startTime == null ? 0 : event.startTime.hour,
event.startTime == null ? 0 : event.startTime.minute,
event.startTime == null ? 0 : event.startTime.second
);
endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45));
eventList.add(new BaseCalendarEvent(event.typeName + " - " + event.topic,
"",
(event.startTime == null ? getString(R.string.agenda_event_all_day) : event.startTime.getStringHM()) +
Utils.bs(", ", event.subjectLongName) +
Utils.bs(", ", event.teacherFullName) +
Utils.bs(", ", event.teamName),
event.getColor(),
Colors.legibleTextColor(event.getColor()),
startTime,
endTime,
event.startTime == null,
event.id, !event.seen));
if (!event.seen) {
unreadEventDates.add(event.eventDate.getValue());
}
}
/*List<LessonFull> lessonChanges = app.db.lessonChangeDao().getAllChangesWithLessonsNow(App.profileId);
for (LessonFull lesson: lessonChanges) {
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
if (lesson.lessonDate == null) {
continue;
}
startTime.set(lesson.lessonDate.year, lesson.lessonDate.month - 1, lesson.lessonDate.day, lesson.startTime.hour, lesson.startTime.minute, lesson.startTime.second);
endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45));
String description = lesson.changeTypeStr(activity);
if (lesson.changeType != TYPE_CANCELLED) {
if (lesson.subjectId != lesson.changeSubjectId && lesson.teacherId != lesson.changeTeacherId) {
description += " -> " + bs(null, lesson.changeSubjectLongName, ", ") + bs(lesson.changeTeacherFullName);
} else if (lesson.subjectId != lesson.changeSubjectId) {
description += " -> " + bs(lesson.changeSubjectLongName);
} else if (lesson.teacherId != lesson.changeTeacherId) {
description += " -> " + bs(lesson.changeTeacherFullName);
}
}
eventList.add(new BaseCalendarEvent(description,
"",
(lesson.startTime.getStringHM()) +
Utils.bs(", ", lesson.subjectLongName) +
Utils.bs(", ", lesson.teacherFullName) +
Utils.bs(", ", lesson.teamName),
0xff78909c,
Colors.legibleTextColor(0xff78909c),
startTime,
endTime,
false,
(int)lesson.changeId, false));
}*/
activity.runOnUiThread(() -> {
AgendaCalendarView mAgendaCalendarView = b_default.agendaDefaultView;
// minimum and maximum date of our calendar
// 2 month behind, one year ahead, example: March 2015 <-> May 2015 <-> May 2016
Calendar minDate = Calendar.getInstance();
Calendar maxDate = Calendar.getInstance();
minDate.add(Calendar.MONTH, -2);
minDate.set(Calendar.DAY_OF_MONTH, 1);
maxDate.add(Calendar.MONTH, 2);
mAgendaCalendarView.init(eventList, minDate, maxDate, Locale.getDefault(), new CalendarPickerController() {
@Override
public void onDaySelected(IDayItem dayItem) {
}
@Override
public void onScrollToDate(Calendar calendar) {
int scrolledDate = Date.fromCalendar(calendar).getValue();
if (unreadEventDates.contains(scrolledDate)) {
AsyncTask.execute(() -> app.db.eventDao().setSeenByDate(App.profileId, Date.fromYmd(intToStr(scrolledDate)), true));
unreadEventDates.remove(unreadEventDates.indexOf(scrolledDate));
}
}
@Override
public void onEventSelected(CalendarEvent calendarEvent) {
if (calendarEvent instanceof BaseCalendarEvent) {
if (!calendarEvent.isPlaceholder() && !calendarEvent.isAllDay()) {
new EventListDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()), Time.fromMillis(calendarEvent.getStartTime().getTimeInMillis()), true);
} else {
new EventListDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
}
} else if (calendarEvent instanceof LessonChangeEvent) {
new LessonChangeDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
//Toast.makeText(app, "Clicked "+((LessonChangeEvent) calendarEvent).getLessonChangeDate().getFormattedString(), Toast.LENGTH_SHORT).show();
}
}
}, new LessonChangeEventRenderer());
b_default.progressBar.setVisibility(View.GONE);
});
}), 500);
}
else {
List<Integer> unreadEventDates = new ArrayList<>();
final Handler handler = new Handler();
handler.postDelayed(() -> AsyncTask.execute(() -> {
if (app == null || app.profile == null || activity == null || b_calendar == null || !isAdded())
return;
Context c = getContext();
Activity a = getActivity();
assert c != null;
assert a != null;
if (!isAdded()) {
return;
}
List<EventDay> eventList = new ArrayList<>();
List<EventFull> events = app.db.eventDao().getAllNow(App.profileId);
for (EventFull event : events) {
if (event.eventDate == null)
continue;
Calendar startTime = Calendar.getInstance();
startTime.set(
event.eventDate.year,
event.eventDate.month - 1,
event.eventDate.day,
event.startTime == null ? 0 : event.startTime.hour,
event.startTime == null ? 0 : event.startTime.minute,
event.startTime == null ? 0 : event.startTime.second
);
Drawable eventIcon = new IconicsDrawable(activity).icon(CommunityMaterial.Icon.cmd_checkbox_blank_circle).size(IconicsSize.dp(10)).color(IconicsColor.colorInt(event.getColor()));
eventList.add(new EventDay(startTime, eventIcon));
if (!event.seen) {
unreadEventDates.add(event.eventDate.getValue());
}
}
List<LessonFull> lessonChanges = app.db.lessonChangeDao().getAllChangesWithLessonsNow(App.profileId);
for (LessonFull lesson: lessonChanges) {
Calendar startTime = Calendar.getInstance();
if (lesson.lessonDate == null) {
continue;
}
startTime.set(
lesson.lessonDate.year,
lesson.lessonDate.month - 1,
lesson.lessonDate.day,
lesson.startTime.hour,
lesson.startTime.minute,
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));
}
getActivity().runOnUiThread(() -> {
//List<EventDay> eventList = new ArrayList<>();
//Collections.sort(eventList, new EventListComparator());
CalendarView calendarView = b_calendar.agendaCalendarView;
calendarView.setEvents(eventList);
calendarView.setOnDayClickListener(eventDay -> {
Date dayDate = Date.fromCalendar(eventDay.getCalendar());
int scrolledDate = dayDate.getValue();
if (unreadEventDates.contains(scrolledDate)) {
AsyncTask.execute(() -> app.db.eventDao().setSeenByDate(App.profileId, Date.fromYmd(intToStr(scrolledDate)), true));
unreadEventDates.remove(unreadEventDates.indexOf(scrolledDate));
}
new EventListDialog(getContext()).show(app, dayDate);
});
b_calendar.progressBar.setVisibility(View.GONE);
});
}), 300);
}
}
public static class EventListComparator implements java.util.Comparator<CalendarEvent> {
@Override
public int compare(CalendarEvent o1, CalendarEvent o2) {
return Long.compare(o1.getStartTime().getTimeInMillis(), o2.getStartTime().getTimeInMillis());
//return (int)(o1.getStartTime().getTimeInMillis() - o2.getStartTime().getTimeInMillis());
}
}
}

View File

@ -0,0 +1,420 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.applandeo.materialcalendarview.CalendarView;
import com.applandeo.materialcalendarview.EventDay;
import com.github.tibolte.agendacalendarview.AgendaCalendarView;
import com.github.tibolte.agendacalendarview.CalendarPickerController;
import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.models.IDayItem;
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.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import pl.szczodrzynski.edziennik.App;
import pl.szczodrzynski.edziennik.R;
import pl.szczodrzynski.edziennik.MainActivity;
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceFull;
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaCalendarBinding;
import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding;
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListDialog;
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;
import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEvent;
import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEventRenderer;
import pl.szczodrzynski.edziennik.utils.models.Date;
import pl.szczodrzynski.edziennik.utils.models.Time;
import pl.szczodrzynski.edziennik.utils.Colors;
import pl.szczodrzynski.edziennik.utils.Themes;
import pl.szczodrzynski.edziennik.utils.Utils;
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem;
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_EVENT;
import static pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile.AGENDA_CALENDAR;
import static pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile.AGENDA_DEFAULT;
import static pl.szczodrzynski.edziennik.utils.Utils.intToStr;
public class AgendaFragment extends Fragment {
private App app = null;
private MainActivity activity = null;
private FragmentAgendaDefaultBinding b_default = null;
private FragmentAgendaCalendarBinding b_calendar = null;
private int viewType = AGENDA_DEFAULT;
@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
viewType = app.profile.getAgendaViewType();
if (viewType == AGENDA_DEFAULT) {
b_default = DataBindingUtil.inflate(inflater, R.layout.fragment_agenda_default, container, false);
return b_default.getRoot();
}
else {
b_calendar = DataBindingUtil.inflate(inflater, R.layout.fragment_agenda_calendar, container, false);
return b_calendar.getRoot();
}
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
if (app == null || app.profile == null || activity == null || (b_default == null && b_calendar == null) || !isAdded())
return;
activity.getBottomSheet().prependItems(
new BottomSheetPrimaryItem(true)
.withTitle(R.string.menu_add_event)
.withDescription(R.string.menu_add_event_desc)
.withIcon(CommunityMaterial.Icon.cmd_calendar_plus)
.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 EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_EVENT);
break;
case 1:
new EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK);
break;
}
})
.show();
}),
new BottomSheetPrimaryItem(true)
.withTitle(R.string.menu_agenda_change_view)
.withIcon(viewType == AGENDA_DEFAULT ? CommunityMaterial.Icon.cmd_calendar : CommunityMaterial.Icon2.cmd_view_list)
.withOnClickListener(v3 -> {
activity.getBottomSheet().close();
viewType = viewType == AGENDA_DEFAULT ? AGENDA_CALENDAR : AGENDA_DEFAULT;
app.profile.setAgendaViewType(viewType);
app.profileSaveAsync();
activity.reloadTarget();
}),
new BottomSheetSeparatorItem(true),
new BottomSheetPrimaryItem(true)
.withTitle(R.string.menu_mark_as_read)
.withIcon(CommunityMaterial.Icon.cmd_eye_check)
.withOnClickListener(v3 -> {
activity.getBottomSheet().close();
AsyncTask.execute(() -> app.db.metadataDao().setAllSeen(App.profileId, TYPE_EVENT, true));
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show();
})
);
activity.gainAttention();
if (viewType == AGENDA_DEFAULT) {
createDefaultAgendaView();
}
else {
createCalendarAgendaView();
}
}
private void createDefaultAgendaView() {
List<Integer> unreadEventDates = new ArrayList<>();
final Handler handler = new Handler();
handler.postDelayed(() -> AsyncTask.execute(() -> {
if (app == null || app.profile == null || activity == null || b_default == null || !isAdded())
return;
List<CalendarEvent> eventList = new ArrayList<>();
List<LessonChangeCounter> lessonChangeCounters = app.db.lessonChangeDao().getLessonChangeCountersNow(App.profileId);
for (LessonChangeCounter counter : lessonChangeCounters) {
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
if (counter.lessonChangeDate == null) {
continue;
}
startTime.set(counter.lessonChangeDate.year, counter.lessonChangeDate.month - 1, counter.lessonChangeDate.day, 10, 0, 0);
endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45));
eventList.add(new LessonChangeEvent(
counter.lessonChangeDate.getInMillis(),
0xff78909c,
Colors.legibleTextColor(0xff78909c),
startTime,
endTime,
counter.profileId,
counter.lessonChangeDate,
counter.lessonChangeCount
));
}
List<TeacherAbsenceFull> teacherAbsenceList = app.db.teacherAbsenceDao().getAllFull(App.profileId);
List<TeacherAbsenceCounter> teacherAbsenceCounters = new ArrayList<>();
for (TeacherAbsenceFull absence : teacherAbsenceList) {
for (Date date = absence.getDateFrom().clone(); date.compareTo(absence.getDateTo()) < 1; date.stepForward(0, 0, 1)) {
boolean counterFound = false;
for (TeacherAbsenceCounter counter : teacherAbsenceCounters) {
if (counter.getTeacherAbsenceDate().compareTo(date) == 0) {
counter.setTeacherAbsenceCount(counter.getTeacherAbsenceCount() + 1);
counterFound = true;
break;
}
}
if (!counterFound) {
teacherAbsenceCounters.add(new TeacherAbsenceCounter(date.clone(), 1));
}
}
}
for (TeacherAbsenceCounter counter : teacherAbsenceCounters) {
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
Date date = counter.getTeacherAbsenceDate();
startTime.set(date.year, date.month - 1, date.day, 10, 0, 0);
endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45));
eventList.add(new TeacherAbsenceEvent(
date.getInMillis(),
0xffff1744,
Colors.legibleTextColor(0xffff1744),
startTime,
endTime,
App.profileId,
date,
counter.getTeacherAbsenceCount()
));
}
List<EventFull> events = app.db.eventDao().getAllNow(App.profileId);
for (EventFull event : events) {
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
if (event.eventDate == null)
continue;
startTime.set(
event.eventDate.year,
event.eventDate.month - 1,
event.eventDate.day,
event.startTime == null ? 0 : event.startTime.hour,
event.startTime == null ? 0 : event.startTime.minute,
event.startTime == null ? 0 : event.startTime.second
);
endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45));
eventList.add(new BaseCalendarEvent(event.typeName + " - " + event.topic,
"",
(event.startTime == null ? getString(R.string.agenda_event_all_day) : event.startTime.getStringHM()) +
Utils.bs(", ", event.subjectLongName) +
Utils.bs(", ", event.teacherFullName) +
Utils.bs(", ", event.teamName),
event.getColor(),
Colors.legibleTextColor(event.getColor()),
startTime,
endTime,
event.startTime == null,
event.id, !event.seen));
if (!event.seen) {
unreadEventDates.add(event.eventDate.getValue());
}
}
/*List<LessonFull> lessonChanges = app.db.lessonChangeDao().getAllChangesWithLessonsNow(App.profileId);
for (LessonFull lesson: lessonChanges) {
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
if (lesson.lessonDate == null) {
continue;
}
startTime.set(lesson.lessonDate.year, lesson.lessonDate.month - 1, lesson.lessonDate.day, lesson.startTime.hour, lesson.startTime.minute, lesson.startTime.second);
endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45));
String description = lesson.changeTypeStr(activity);
if (lesson.changeType != TYPE_CANCELLED) {
if (lesson.subjectId != lesson.changeSubjectId && lesson.teacherId != lesson.changeTeacherId) {
description += " -> " + bs(null, lesson.changeSubjectLongName, ", ") + bs(lesson.changeTeacherFullName);
} else if (lesson.subjectId != lesson.changeSubjectId) {
description += " -> " + bs(lesson.changeSubjectLongName);
} else if (lesson.teacherId != lesson.changeTeacherId) {
description += " -> " + bs(lesson.changeTeacherFullName);
}
}
eventList.add(new BaseCalendarEvent(description,
"",
(lesson.startTime.getStringHM()) +
Utils.bs(", ", lesson.subjectLongName) +
Utils.bs(", ", lesson.teacherFullName) +
Utils.bs(", ", lesson.teamName),
0xff78909c,
Colors.legibleTextColor(0xff78909c),
startTime,
endTime,
false,
(int)lesson.changeId, false));
}*/
activity.runOnUiThread(() -> {
AgendaCalendarView mAgendaCalendarView = b_default.agendaDefaultView;
// minimum and maximum date of our calendar
// 2 month behind, one year ahead, example: March 2015 <-> May 2015 <-> May 2016
Calendar minDate = Calendar.getInstance();
Calendar maxDate = Calendar.getInstance();
minDate.add(Calendar.MONTH, -2);
minDate.set(Calendar.DAY_OF_MONTH, 1);
maxDate.add(Calendar.MONTH, 2);
mAgendaCalendarView.init(eventList, minDate, maxDate, Locale.getDefault(), new CalendarPickerController() {
@Override
public void onDaySelected(IDayItem dayItem) {
}
@Override
public void onScrollToDate(Calendar calendar) {
int scrolledDate = Date.fromCalendar(calendar).getValue();
if (unreadEventDates.contains(scrolledDate)) {
AsyncTask.execute(() -> app.db.eventDao().setSeenByDate(App.profileId, Date.fromYmd(intToStr(scrolledDate)), true));
unreadEventDates.remove(unreadEventDates.indexOf(scrolledDate));
}
}
@Override
public void onEventSelected(CalendarEvent calendarEvent) {
if (calendarEvent instanceof BaseCalendarEvent) {
if (!calendarEvent.isPlaceholder() && !calendarEvent.isAllDay()) {
new EventListDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()), Time.fromMillis(calendarEvent.getStartTime().getTimeInMillis()), true);
} else {
new EventListDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
}
} else if (calendarEvent instanceof LessonChangeEvent) {
new LessonChangeDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
//Toast.makeText(app, "Clicked "+((LessonChangeEvent) calendarEvent).getLessonChangeDate().getFormattedString(), Toast.LENGTH_SHORT).show();
} else if (calendarEvent instanceof TeacherAbsenceEvent) {
new TeacherAbsenceDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
}
}
}, new LessonChangeEventRenderer(), new TeacherAbsenceEventRenderer());
b_default.progressBar.setVisibility(View.GONE);
});
}), 500);
}
private void createCalendarAgendaView() {
List<Integer> unreadEventDates = new ArrayList<>();
final Handler handler = new Handler();
handler.postDelayed(() -> AsyncTask.execute(() -> {
if (app == null || app.profile == null || activity == null || b_calendar == null || !isAdded())
return;
Context c = getContext();
Activity a = getActivity();
assert c != null;
assert a != null;
if (!isAdded()) {
return;
}
List<EventDay> eventList = new ArrayList<>();
List<EventFull> events = app.db.eventDao().getAllNow(App.profileId);
for (EventFull event : events) {
if (event.eventDate == null)
continue;
Calendar startTime = Calendar.getInstance();
startTime.set(
event.eventDate.year,
event.eventDate.month - 1,
event.eventDate.day,
event.startTime == null ? 0 : event.startTime.hour,
event.startTime == null ? 0 : event.startTime.minute,
event.startTime == null ? 0 : event.startTime.second
);
Drawable eventIcon = new IconicsDrawable(activity).icon(CommunityMaterial.Icon.cmd_checkbox_blank_circle).size(IconicsSize.dp(10)).color(IconicsColor.colorInt(event.getColor()));
eventList.add(new EventDay(startTime, eventIcon));
if (!event.seen) {
unreadEventDates.add(event.eventDate.getValue());
}
}
List<LessonFull> lessonChanges = app.db.lessonChangeDao().getAllChangesWithLessonsNow(App.profileId);
for (LessonFull lesson: lessonChanges) {
Calendar startTime = Calendar.getInstance();
if (lesson.lessonDate == null) {
continue;
}
startTime.set(
lesson.lessonDate.year,
lesson.lessonDate.month - 1,
lesson.lessonDate.day,
lesson.startTime.hour,
lesson.startTime.minute,
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));
}
getActivity().runOnUiThread(() -> {
//List<EventDay> eventList = new ArrayList<>();
//Collections.sort(eventList, new EventListComparator());
CalendarView calendarView = b_calendar.agendaCalendarView;
calendarView.setEvents(eventList);
calendarView.setOnDayClickListener(eventDay -> {
Date dayDate = Date.fromCalendar(eventDay.getCalendar());
int scrolledDate = dayDate.getValue();
if (unreadEventDates.contains(scrolledDate)) {
AsyncTask.execute(() -> app.db.eventDao().setSeenByDate(App.profileId, Date.fromYmd(intToStr(scrolledDate)), true));
unreadEventDates.remove(unreadEventDates.indexOf(scrolledDate));
}
new EventListDialog(getContext()).show(app, dayDate);
});
b_calendar.progressBar.setVisibility(View.GONE);
});
}), 300);
}
public static class EventListComparator implements java.util.Comparator<CalendarEvent> {
@Override
public int compare(CalendarEvent o1, CalendarEvent o2) {
return Long.compare(o1.getStartTime().getTimeInMillis(), o2.getStartTime().getTimeInMillis());
//return (int)(o1.getStartTime().getTimeInMillis() - o2.getStartTime().getTimeInMillis());
}
}
}

View File

@ -1,4 +1,4 @@
package pl.szczodrzynski.edziennik.utils.models.db;
package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange;
import pl.szczodrzynski.edziennik.utils.models.Date;

View File

@ -1,4 +1,4 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda;
package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.models.IDayItem;

View File

@ -1,4 +1,4 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda;
package pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange;
import android.view.View;
import android.widget.TextView;
@ -14,7 +14,7 @@ public class LessonChangeEventRenderer extends EventRenderer<LessonChangeEvent>
public void render(View view, LessonChangeEvent event) {
CardView card = view.findViewById(R.id.lesson_change_card);
TextView changeText = view.findViewById(R.id.lesson_change_text);
TextView changeCount = view.findViewById(R.id.lesson_change_count);
TextView changeCount = view.findViewById(R.id.lessonChangeCount);
card.setCardBackgroundColor(event.getColor());
changeText.setTextColor(event.getTextColor());
changeCount.setTextColor(event.getTextColor());

View File

@ -0,0 +1,10 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence
import pl.szczodrzynski.edziennik.utils.models.Date
class TeacherAbsenceCounter (
val teacherAbsenceDate: Date,
var teacherAbsenceCount: Int = 0
)

View File

@ -0,0 +1,188 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence
import com.github.tibolte.agendacalendarview.models.CalendarEvent
import com.github.tibolte.agendacalendarview.models.IDayItem
import com.github.tibolte.agendacalendarview.models.IWeekItem
import pl.szczodrzynski.edziennik.utils.models.Date
import java.util.*
class TeacherAbsenceEvent : CalendarEvent {
/**
* Id of the event.
*/
private var mId: Long = 0
/**
* Color to be displayed in the agenda view.
*/
private var mColor: Int = 0
/**
* Text color displayed on the background color
*/
private var mTextColor: Int = 0
/**
* Calendar instance helping sorting the events per section in the agenda view.
*/
private var mInstanceDay: Calendar? = null
/**
* Start time of the event.
*/
private var mStartTime: Calendar? = null
/**
* End time of the event.
*/
private var mEndTime: Calendar? = null
/**
* References to a DayItem instance for that event, used to link interaction between the
* calendar view and the agenda view.
*/
private var mDayReference: IDayItem? = null
/**
* References to a WeekItem instance for that event, used to link interaction between the
* calendar view and the agenda view.
*/
private var mWeekReference: IWeekItem? = null
private var profileId: Int = 0
var teacherAbsenceDate: Date? = null
var teacherAbsenceCount: Int = 0
constructor(calendarEvent: TeacherAbsenceEvent) {
this.mId = calendarEvent.id
this.mColor = calendarEvent.color
this.mTextColor = calendarEvent.textColor
this.mStartTime = calendarEvent.startTime
this.mEndTime = calendarEvent.endTime
this.profileId = calendarEvent.profileId
this.teacherAbsenceDate = calendarEvent.teacherAbsenceDate
this.teacherAbsenceCount = calendarEvent.teacherAbsenceCount
}
constructor(mId: Long, mColor: Int, mTextColor: Int, mStartTime: Calendar, mEndTime: Calendar, profileId: Int, teacherAbsenceDate: Date, teacherAbsenceCount: Int) {
this.mId = mId
this.mColor = mColor
this.mTextColor = mTextColor
this.mStartTime = mStartTime
this.mEndTime = mEndTime
this.profileId = profileId
this.teacherAbsenceDate = teacherAbsenceDate
this.teacherAbsenceCount = teacherAbsenceCount
}
override fun setPlaceholder(placeholder: Boolean) {
}
override fun isPlaceholder(): Boolean {
return false
}
override fun getLocation(): String? {
return null
}
override fun setLocation(mLocation: String) {
}
override fun getId(): Long {
return mId
}
override fun setId(mId: Long) {
this.mId = mId
}
override fun getShowBadge(): Boolean {
return false
}
override fun setShowBadge(mShowBadge: Boolean) {
}
override fun getTextColor(): Int {
return mTextColor
}
override fun setTextColor(mTextColor: Int) {
this.mTextColor = mTextColor
}
override fun getDescription(): String? {
return null
}
override fun setDescription(mDescription: String) {
}
override fun isAllDay(): Boolean {
return false
}
override fun setAllDay(allDay: Boolean) {
}
override fun getStartTime(): Calendar? {
return mStartTime
}
override fun setStartTime(mStartTime: Calendar) {
this.mStartTime = mStartTime
}
override fun getEndTime(): Calendar? {
return mEndTime
}
override fun setEndTime(mEndTime: Calendar) {
this.mEndTime = mEndTime
}
override fun getTitle(): String? {
return null
}
override fun setTitle(mTitle: String) {
}
override fun getInstanceDay(): Calendar? {
return mInstanceDay
}
override fun setInstanceDay(mInstanceDay: Calendar) {
this.mInstanceDay = mInstanceDay
this.mInstanceDay!!.set(Calendar.HOUR, 0)
this.mInstanceDay!!.set(Calendar.MINUTE, 0)
this.mInstanceDay!!.set(Calendar.SECOND, 0)
this.mInstanceDay!!.set(Calendar.MILLISECOND, 0)
this.mInstanceDay!!.set(Calendar.AM_PM, 0)
}
override fun getDayReference(): IDayItem? {
return mDayReference
}
override fun setDayReference(mDayReference: IDayItem) {
this.mDayReference = mDayReference
}
override fun getWeekReference(): IWeekItem? {
return mWeekReference
}
override fun setWeekReference(mWeekReference: IWeekItem) {
this.mWeekReference = mWeekReference
}
override fun copy(): CalendarEvent {
return TeacherAbsenceEvent(this)
}
override fun getColor(): Int {
return mColor
}
}

View File

@ -0,0 +1,21 @@
package pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence
import android.view.View
import android.widget.TextView
import androidx.cardview.widget.CardView
import com.github.tibolte.agendacalendarview.render.EventRenderer
import pl.szczodrzynski.edziennik.R
class TeacherAbsenceEventRenderer : EventRenderer<TeacherAbsenceEvent>() {
override fun render(view: View?, event: TeacherAbsenceEvent) {
val card = view?.findViewById<CardView>(R.id.teacherAbsenceCard)
val changeText = view?.findViewById<TextView>(R.id.teacherAbsenceText)
val changeCount = view?.findViewById<TextView>(R.id.teacherAbsenceCount)
card?.setCardBackgroundColor(event.color)
changeText?.setTextColor(event.textColor)
changeCount?.setTextColor(event.textColor)
changeCount?.text = event.teacherAbsenceCount.toString()
}
override fun getEventLayout(): Int { return R.layout.agenda_event_teacher_absence }
}

View File

@ -1,4 +1,4 @@
package pl.szczodrzynski.edziennik.utils.models.db
package pl.szczodrzynski.edziennik.utils.models
import pl.szczodrzynski.navlib.drawer.IUnreadCounter

View File

@ -9,7 +9,7 @@
<include
layout="@layout/row_dialog_lesson_change_item"
layout="@layout/row_lesson_change_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<com.github.tibolte.agendacalendarview.agenda.AgendaEventView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<include
layout="@layout/row_teacher_absence_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</com.github.tibolte.agendacalendarview.agenda.AgendaEventView>

View File

@ -15,8 +15,17 @@
app:layout_constraintTop_toTopOf="parent">
<include
android:id="@+id/lesson_change_container"
layout="@layout/row_dialog_lesson_change_item"
android:id="@+id/lessonChangeContainer"
layout="@layout/row_lesson_change_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:visibility="gone"
tools:visibility="visible" />
<include
android:id="@+id/teacherAbsenceContainer"
layout="@layout/row_teacher_absence_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/teacherAbsenceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/row_dialog_teacher_absence_item" />
</LinearLayout>
</layout>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?selectableItemBackground"
app:cardCornerRadius="5dp"
app:cardElevation="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/teacherAbsenceTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
tools:text="2 września - 5 kwietnia"/>
<TextView
android:id="@+id/teacherAbsenceTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Jan Kowalski"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>

View File

@ -23,7 +23,7 @@
android:text="@string/agenda_lesson_changes" />
<TextView
android:id="@+id/lesson_change_count"
android:id="@+id/lessonChangeCount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"

View File

@ -0,0 +1,35 @@
<androidx.cardview.widget.CardView android:id="@+id/teacherAbsenceCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:cardBackgroundColor="@color/blue_selected"
app:cardCornerRadius="5dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="@+id/teacherAbsenceText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAppearance="@style/NavView.TextView.Medium"
android:text="@string/agenda_teacher_absence" />
<TextView
android:id="@+id/teacherAbsenceCount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20sp"
tools:text="3" />
</LinearLayout>
</androidx.cardview.widget.CardView>

View File

@ -851,6 +851,7 @@
<string name="messages_compose_menu_discard">Abort message</string>
<string name="messages_compose_menu_save_draft">Save draft</string>
<string name="messages_compose_menu_send">Send</string>
<string name="agenda_teacher_absence">Absent teachers</string>
<string name="sync_action_syncing_grade_comments">Getting grade comments</string>
<string name="sync_action_syncing_school_free_days">Getting school free days</string>
</resources>

View File

@ -908,5 +908,6 @@
<string name="homework_tab_current">Aktualne</string>
<string name="homework_tab_past">Minione</string>
<string name="homework_no_data">Brak zadań domowych.</string>
<string name="agenda_teacher_absence">Nieobecni nauczyciele</string>
<string name="sync_action_syncing_grade_comments">Pobieranie komentarzy ocen</string>
</resources>