Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

122 next day events on agenda #123

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@


/**
* @author Max Dobler - [email protected]
* @author Max Dobler - [email protected]
*/
public interface EventRepository {

/**
* Load today's events for room.
*/
Observable<EventModel> loadAllEventsForRoom(long roomId);


/**
* Load events for room.
*
* @param roomId room id
* @param days amount of days to query events. Pass 1 for today, to for today and tomorrow, etc.
*/
Observable<EventModel> loadAllEventsForRoom(long roomId, int days);


Maybe<Long> insertEvent(long calendarId, String title, DateTime start, DateTime end);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public interface EventAdapter {

Observable<EventModel> getEventsForRoom(long roomId);
Observable<EventModel> getEventsForRoom(long roomId, int days);


Maybe<Long> insertEvent(long calendarId, DateTime start, DateTime end, String title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public EventAdapterImpl(ContentResolver contentResolver) {
}

@Override
public Observable<EventModel> getEventsForRoom(long roomId) {
public Observable<EventModel> getEventsForRoom(long roomId, int days) {

String[] projection = {
Instances.EVENT_ID, //
Expand All @@ -58,7 +58,7 @@ public Observable<EventModel> getEventsForRoom(long roomId) {
String selection = Instances.CALENDAR_ID + " = " + roomId;
String sortChronological = Instances.BEGIN + " ASC";

Cursor result = contentResolver.query(constructContentUri(), projection, selection, null, sortChronological);
Cursor result = contentResolver.query(constructContentUri(days), projection, selection, null, sortChronological);

return Observable.fromIterable(fromCursor(result)) //
.doAfterNext(closeCursorIfLast()) //
Expand Down Expand Up @@ -138,11 +138,15 @@ private String getNewDuration(DateTime start, DateTime end) {
}


private Uri constructContentUri() {
private Uri constructContentUri(int days) {

Uri.Builder builder = Instances.CONTENT_URI.buildUpon();
long now = new Date().getTime();
long endOfDay = LocalDateTime.now().withTime(23, 59, 59, 999).toDate().getTime();
long endOfDay = LocalDateTime
.now()
.plusDays(days - 1)
.withTime(23, 59, 59, 999)
.toDate().getTime();
ContentUris.appendId(builder, now);
ContentUris.appendId(builder, endOfDay);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

import androidx.annotation.NonNull;

import org.joda.time.DateTime;

import java.util.concurrent.ConcurrentHashMap;

import de.synyx.android.meeroo.business.event.EventModel;
import de.synyx.android.meeroo.business.event.EventRepository;

import io.reactivex.Maybe;
import io.reactivex.Observable;

import io.reactivex.functions.Function;

import org.joda.time.DateTime;

import java.util.concurrent.ConcurrentHashMap;


/**
* @author Max Dobler - [email protected]
* @author Max Dobler - [email protected]
*/
public class EventRepositoryImpl implements EventRepository {

Expand All @@ -35,12 +33,18 @@ public EventRepositoryImpl(EventAdapter eventAdapter, AttendeeAdapter attendeeAd
@Override
public Observable<EventModel> loadAllEventsForRoom(long roomId) {

return eventAdapter.getEventsForRoom(roomId) //
.map(this::setEndIfCached)
.flatMap(loadAttendees());
return loadAllEventsForRoom(roomId, 1);
}


@Override
public Observable<EventModel> loadAllEventsForRoom(long roomId, int days) {

return eventAdapter.getEventsForRoom(roomId, days) //
.map(this::setEndIfCached)
.flatMap(loadAttendees());
}

private EventModel setEndIfCached(EventModel event) {

DateTime end = eventEndCache.get(event.getId());
Expand Down Expand Up @@ -73,8 +77,8 @@ public boolean updateEvent(long eventId, DateTime start, DateTime end, boolean r
private Function<EventModel, Observable<EventModel>> loadAttendees() {

return
event ->
attendeeAdapter.getAttendeesForEvent(event.getId())
.collectInto(event, EventModel::addAttendee).toObservable();
event ->
attendeeAdapter.getAttendeesForEvent(event.getId())
.collectInto(event, EventModel::addAttendee).toObservable();
}
}
18 changes: 10 additions & 8 deletions app/src/main/java/de/synyx/android/meeroo/domain/Agenda.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class Agenda {
fun getCurrentMeeting() = reservations.firstOrNull { it.isCurrentlyActive }


fun getUpcomingReservation() = reservations.firstOrNull { it.isUpcoming }
fun getUpcomingReservation() = getReservationsToday().firstOrNull { it.isUpcoming }


fun getSecondUpcomingReservation() =
reservations
getReservationsToday()
.filter { it.isUpcoming }
.drop(1)
.firstOrNull()
Expand All @@ -68,14 +68,16 @@ class Agenda {
fun getReservations(): List<Reservation> = unmodifiableList<Reservation>(reservations)


fun hasCurrentReservation() = reservations.any { it.isCurrentlyActive }
fun hasCurrentReservation() = reservations.any { it.isCurrentlyActive }


private fun sumTimeOfOngoingReservations(): (TimeSpan, TimeSpan) -> TimeSpan {
private fun sumTimeOfOngoingReservations(): (TimeSpan, TimeSpan) -> TimeSpan {

return { available, nextTimeSpan ->
if (nextTimeSpan.begin.isAfter(available.end)) available
else TimeSpan(available.begin, nextTimeSpan.end)
}
return { available, nextTimeSpan ->
if (nextTimeSpan.begin.isAfter(available.end)) available
else TimeSpan(available.begin, nextTimeSpan.end)
}
}

public fun getReservationsToday() = reservations.filter { it.isToday }
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MeetingRoom(val calendarId: Long, val name: String) {
fun getUpcomingReservation(): Reservation? = agenda.getUpcomingReservation()


fun getReservations(): List<Reservation> = agenda.getReservations();
fun getReservations(): List<Reservation> = agenda.getReservations()


fun getAvailabilityTime(): Duration? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public boolean isUpcoming() {
return begin.isAfter(timeProvider.now());
}

public boolean isToday() {
return begin.withTimeAtStartOfDay().equals(timeProvider.now().withTimeAtStartOfDay());
}


public String getTitle() {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.synyx.android.meeroo.screen.main.agenda

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import de.synyx.android.meeroo.domain.Reservation
import android.widget.TextView
import de.synyx.android.meeroo.R
import org.joda.time.DateTime
import org.joda.time.LocalDate
import org.joda.time.format.DateTimeFormat

/**
* @author Max Dobler - [email protected]
*/
class ReservationViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(item: AgendaListItem.ReservationItem) {
setTitle(item.reservation)
setTimespan(item.reservation)
}

private fun setTitle(reservation: Reservation) {
val reservationTitle = itemView.findViewById<TextView>(R.id.reservation_title)
reservationTitle.text = reservation.title
}

private fun setTimespan(reservation: Reservation) {
val reservationTimespan = itemView.findViewById<TextView>(R.id.reservation_timespan)
val beginTime = formatTime(reservation.getBegin())
val endTime = formatTime(reservation.getEnd())
reservationTimespan.text = String.format("%s - %s", beginTime, endTime)
}

private fun formatTime(dateTime: DateTime): String {
return DateTimeFormat.forPattern("HH:mm").print(dateTime)
}
}

class DateHeaderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

fun bind(dateHeader: AgendaListItem.DateHeader) {
val label = when (dateHeader.dateTime) {
LocalDate() -> itemView.context.getString(R.string.today)
LocalDate().plusDays(1) -> itemView.context.getString(R.string.tomorrow)
else -> DateTimeFormat.fullDate().print(dateHeader.dateTime)
}

itemView.findViewById<TextView>(R.id.date_header).text = label
}
}

This file was deleted.

Loading