WeekView Bib eigenkreation

This commit is contained in:
Joshua
2018-07-12 15:45:59 +02:00
parent 026497010c
commit 2326ede91c
12 changed files with 3464 additions and 9 deletions

2
.idea/misc.xml generated
View File

@@ -25,5 +25,5 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project> </project>

View File

@@ -45,7 +45,7 @@ dependencies {
implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
implementation 'com.android.support:support-v4:27.1.1' implementation 'com.android.support:support-v4:27.1.1'
implementation 'org.jetbrains:annotations-java5:15.0' implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'com.github.quivr:android-week-view:2.0.2'//com.github.alamkanak:android-week-view:1.2.6 //implementation 'com.github.quivr:android-week-view:2.0.2'//com.github.alamkanak:android-week-view:1.2.6
implementation 'com.ms-square:expandableTextView:0.1.4' implementation 'com.ms-square:expandableTextView:0.1.4'
// https://github.com/bignerdranch/expandable-recycler-view // https://github.com/bignerdranch/expandable-recycler-view
implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1' implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'

View File

@@ -10,10 +10,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.alamkanak.weekview.MonthLoader;
import com.alamkanak.weekview.WeekView;
import com.alamkanak.weekview.WeekViewEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Iterator; import java.util.Iterator;
@@ -25,6 +21,9 @@ import de.sebse.fuplanner.services.KVV.KVV;
import de.sebse.fuplanner.services.KVV.types.Event; import de.sebse.fuplanner.services.KVV.types.Event;
import de.sebse.fuplanner.services.KVV.types.Modules; import de.sebse.fuplanner.services.KVV.types.Modules;
import de.sebse.fuplanner.tools.logging.Logger; import de.sebse.fuplanner.tools.logging.Logger;
import de.sebse.fuplanner.tools.ui.weekview.MonthLoader;
import de.sebse.fuplanner.tools.ui.weekview.WeekView;
import de.sebse.fuplanner.tools.ui.weekview.WeekViewEvent;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.

View File

@@ -0,0 +1,12 @@
package de.sebse.fuplanner.tools.ui.weekview;
import java.util.Calendar;
/**
* Created by Raquib on 1/6/2015.
*/
public interface DateTimeInterpreter {
public String interpretDate(Calendar date);
public String interpretTime(int hour, int minutes);
}

View File

@@ -0,0 +1,46 @@
package de.sebse.fuplanner.tools.ui.weekview;
import java.util.Calendar;
import java.util.List;
public class MonthLoader implements WeekViewLoader {
private MonthChangeListener mOnMonthChangeListener;
public MonthLoader(MonthChangeListener listener) {
this.mOnMonthChangeListener = listener;
}
@Override
public double toWeekViewPeriodIndex(Calendar instance) {
return instance.get(Calendar.YEAR) * 12 + instance.get(Calendar.MONTH) + (instance.get(Calendar.DAY_OF_MONTH) - 1) / 30.0;
}
@Override
public List<? extends WeekViewEvent> onLoad(int periodIndex) {
return mOnMonthChangeListener.onMonthChange(periodIndex / 12, periodIndex % 12 + 1);
}
public MonthChangeListener getOnMonthChangeListener() {
return mOnMonthChangeListener;
}
public void setOnMonthChangeListener(MonthChangeListener onMonthChangeListener) {
this.mOnMonthChangeListener = onMonthChangeListener;
}
public interface MonthChangeListener {
/**
* <p>Very important interface, it's the base to load events in the calendar.
* This method is called three times: once to load the previous month, once to load the next month and once to load the current month.</p>
* <strong>That's why you can have three times the same event at the same place if you mess up with the configuration</strong>
*
* @param newYear : year of the events required by the view.
* @param newMonth : <p>month of the events required by the view </p><strong>1 based (not like JAVA API) : January = 1 and December = 12</strong>.
* @return a list of the events happening <strong>during the specified month</strong>.
*/
List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth);
}
}

View File

@@ -0,0 +1,12 @@
package de.sebse.fuplanner.tools.ui.weekview;
import android.support.annotation.ColorInt;
public interface TextColorPicker {
@ColorInt
int getTextColor(WeekViewEvent event);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,344 @@
package de.sebse.fuplanner.tools.ui.weekview;
import android.graphics.Shader;
import android.support.annotation.ColorInt;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import static de.sebse.fuplanner.tools.ui.weekview.WeekViewUtil.isSameDay;
/**
* Created by Raquib-ul-Alam Kanak on 7/21/2014.
* Website: http://april-shower.com
*/
public class WeekViewEvent {
private String mId;
private Calendar mStartTime;
private Calendar mEndTime;
private String mName;
private String mLocation;
private
@ColorInt
int mColor;
private boolean mAllDay;
private Shader mShader;
public WeekViewEvent() {
}
/**
* Initializes the event for week view.
*
* @param id The id of the event as String.
* @param name Name of the event.
* @param startYear Year when the event starts.
* @param startMonth Month when the event starts.
* @param startDay Day when the event starts.
* @param startHour Hour (in 24-hour format) when the event starts.
* @param startMinute Minute when the event starts.
* @param endYear Year when the event ends.
* @param endMonth Month when the event ends.
* @param endDay Day when the event ends.
* @param endHour Hour (in 24-hour format) when the event ends.
* @param endMinute Minute when the event ends.
*/
public WeekViewEvent(String id, String name, int startYear, int startMonth, int startDay, int startHour, int startMinute, int endYear, int endMonth, int endDay, int endHour, int endMinute) {
this.mId = id;
this.mStartTime = Calendar.getInstance();
this.mStartTime.set(Calendar.YEAR, startYear);
this.mStartTime.set(Calendar.MONTH, startMonth - 1);
this.mStartTime.set(Calendar.DAY_OF_MONTH, startDay);
this.mStartTime.set(Calendar.HOUR_OF_DAY, startHour);
this.mStartTime.set(Calendar.MINUTE, startMinute);
this.mEndTime = Calendar.getInstance();
this.mEndTime.set(Calendar.YEAR, endYear);
this.mEndTime.set(Calendar.MONTH, endMonth - 1);
this.mEndTime.set(Calendar.DAY_OF_MONTH, endDay);
this.mEndTime.set(Calendar.HOUR_OF_DAY, endHour);
this.mEndTime.set(Calendar.MINUTE, endMinute);
this.mName = name;
}
/**
* Initializes the event for week view.
*
* @param id The id of the event.
* @param name Name of the event.
* @param startYear Year when the event starts.
* @param startMonth Month when the event starts.
* @param startDay Day when the event starts.
* @param startHour Hour (in 24-hour format) when the event starts.
* @param startMinute Minute when the event starts.
* @param endYear Year when the event ends.
* @param endMonth Month when the event ends.
* @param endDay Day when the event ends.
* @param endHour Hour (in 24-hour format) when the event ends.
* @param endMinute Minute when the event ends.
*/
@Deprecated
public WeekViewEvent(long id, String name, int startYear, int startMonth, int startDay, int startHour, int startMinute, int endYear, int endMonth, int endDay, int endHour, int endMinute) {
this(String.valueOf(id), name, startYear, startMonth, startDay, startHour, startMinute, endYear, endMonth, endDay, endHour, endMinute);
}
/**
* Initializes the event for week view.
*
* @param id The id of the event as String.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
* @param allDay Is the event an all day event.
* @param shader the Shader of the event rectangle
*/
public WeekViewEvent(String id, String name, String location, Calendar startTime, Calendar endTime, boolean allDay, Shader shader) {
this.mId = id;
this.mName = name;
this.mLocation = location;
this.mStartTime = startTime;
this.mEndTime = endTime;
this.mAllDay = allDay;
this.mShader = shader;
}
/**
* Initializes the event for week view.
*
* @param id The id of the event.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
* @param allDay Is the event an all day event.
* @param shader the Shader of the event rectangle
*/
@Deprecated
public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime, boolean allDay, Shader shader) {
this(String.valueOf(id), name, location, startTime, endTime, allDay, shader);
}
/**
* Initializes the event for week view.
*
* @param id The id of the event as String.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
* @param allDay Is the event an all day event
*/
public WeekViewEvent(String id, String name, String location, Calendar startTime, Calendar endTime, boolean allDay) {
this(id, name, location, startTime, endTime, allDay, null);
}
/**
* Initializes the event for week view.
*
* @param id The id of the event.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
* @param allDay Is the event an all day event
*/
@Deprecated
public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime, boolean allDay) {
this(id, name, location, startTime, endTime, allDay, null);
}
/**
* Initializes the event for week view.
*
* @param id The id of the event as String.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
*/
public WeekViewEvent(String id, String name, String location, Calendar startTime, Calendar endTime) {
this(id, name, location, startTime, endTime, false);
}
/**
* Initializes the event for week view.
*
* @param id The id of the event.
* @param name Name of the event.
* @param location The location of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
*/
@Deprecated
public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime) {
this(id, name, location, startTime, endTime, false);
}
/**
* Initializes the event for week view.
*
* @param id The id of the event specified as String.
* @param name Name of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
*/
public WeekViewEvent(String id, String name, Calendar startTime, Calendar endTime) {
this(id, name, null, startTime, endTime);
}
/**
* Initializes the event for week view.
*
* @param id The id of the event.
* @param name Name of the event.
* @param startTime The time when the event starts.
* @param endTime The time when the event ends.
*/
@Deprecated
public WeekViewEvent(long id, String name, Calendar startTime, Calendar endTime) {
this(id, name, null, startTime, endTime);
}
public Calendar getStartTime() {
return mStartTime;
}
public void setStartTime(Calendar startTime) {
this.mStartTime = startTime;
}
public Calendar getEndTime() {
return mEndTime;
}
public void setEndTime(Calendar endTime) {
this.mEndTime = endTime;
}
public String getName() {
return mName;
}
public void setName(String name) {
this.mName = name;
}
public String getLocation() {
return mLocation;
}
public void setLocation(String location) {
this.mLocation = location;
}
public
@ColorInt
int getColor() {
return mColor;
}
public void setColor(int color) {
this.mColor = color;
}
public boolean isAllDay() {
return mAllDay;
}
public void setAllDay(boolean allDay) {
this.mAllDay = allDay;
}
public Shader getShader() {
return mShader;
}
public void setShader(Shader shader) {
mShader = shader;
}
public String getIdentifier() {
return mId;
}
@Deprecated
public long getId() {
return Long.parseLong(mId);
}
public void setIdentifier(String id) {
this.mId = id;
}
@Deprecated
public void setId(long id) {
this.mId = String.valueOf(id);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WeekViewEvent that = (WeekViewEvent) o;
return mId.equals(that.mId);
}
@Override
public int hashCode() {
return mId.hashCode();
}
public List<WeekViewEvent> splitWeekViewEvents() {
//This function splits the WeekViewEvent in WeekViewEvents by day
List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
// The first millisecond of the next day is still the same day. (no need to split events for this).
Calendar endTime = (Calendar) this.getEndTime().clone();
endTime.add(Calendar.MILLISECOND, -1);
if (!isSameDay(this.getStartTime(), endTime)) {
endTime = (Calendar) this.getStartTime().clone();
endTime.set(Calendar.HOUR_OF_DAY, 23);
endTime.set(Calendar.MINUTE, 59);
WeekViewEvent event1 = new WeekViewEvent(this.getIdentifier(), this.getName(), this.getLocation(), this.getStartTime(), endTime, this.isAllDay());
event1.setColor(this.getColor());
events.add(event1);
// Add other days.
Calendar otherDay = (Calendar) this.getStartTime().clone();
otherDay.add(Calendar.DATE, 1);
while (!isSameDay(otherDay, this.getEndTime())) {
Calendar overDay = (Calendar) otherDay.clone();
overDay.set(Calendar.HOUR_OF_DAY, 0);
overDay.set(Calendar.MINUTE, 0);
Calendar endOfOverDay = (Calendar) overDay.clone();
endOfOverDay.set(Calendar.HOUR_OF_DAY, 23);
endOfOverDay.set(Calendar.MINUTE, 59);
WeekViewEvent eventMore = new WeekViewEvent(this.getIdentifier(), this.getName(), null, overDay, endOfOverDay, this.isAllDay());
eventMore.setColor(this.getColor());
events.add(eventMore);
// Add next day.
otherDay.add(Calendar.DATE, 1);
}
// Add last day.
Calendar startTime = (Calendar) this.getEndTime().clone();
startTime.set(Calendar.HOUR_OF_DAY, 0);
startTime.set(Calendar.MINUTE, 0);
WeekViewEvent event2 = new WeekViewEvent(this.getIdentifier(), this.getName(), this.getLocation(), startTime, this.getEndTime(), this.isAllDay());
event2.setColor(this.getColor());
events.add(event2);
} else {
events.add(this);
}
return events;
}
}

View File

@@ -0,0 +1,27 @@
package de.sebse.fuplanner.tools.ui.weekview;
import java.util.Calendar;
import java.util.List;
public interface WeekViewLoader {
/**
* Convert a date into a double that will be used to reference when you're loading data.
* <p>
* All periods that have the same integer part, define one period. Dates that are later in time
* should have a greater return value.
*
* @param instance the date
* @return The period index in which the date falls (floating point number).
*/
double toWeekViewPeriodIndex(Calendar instance);
/**
* Load the events within the period
*
* @param periodIndex the period to load
* @return A list with the events of this period
*/
List<? extends WeekViewEvent> onLoad(int periodIndex);
}

View File

@@ -0,0 +1,88 @@
package de.sebse.fuplanner.tools.ui.weekview;
import java.util.Calendar;
/**
* Created by jesse on 6/02/2016.
*/
public class WeekViewUtil {
/////////////////////////////////////////////////////////////////
//
// Helper methods.
//
/////////////////////////////////////////////////////////////////
/**
* Checks if two dates are on the same day.
*
* @param dateOne The first date.
* @param dateTwo The second date. *
* @return Whether the dates are on the same day.
*/
public static boolean isSameDay(Calendar dateOne, Calendar dateTwo) {
return dateOne.get(Calendar.YEAR) == dateTwo.get(Calendar.YEAR) && dateOne.get(Calendar.DAY_OF_YEAR) == dateTwo.get(Calendar.DAY_OF_YEAR);
}
/**
* Returns a calendar instance at the start of today
*
* @return the calendar instance
*/
public static Calendar today() {
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
return today;
}
/**
* Checks if two dates are on the same day and hour.
*
* @param dateOne The first day.
* @param dateTwo The second day.
* @return Whether the dates are on the same day and hour.
*/
public static boolean isSameDayAndHour(Calendar dateOne, Calendar dateTwo) {
if (dateTwo != null) {
return isSameDay(dateOne, dateTwo) && dateOne.get(Calendar.HOUR_OF_DAY) == dateTwo.get(Calendar.HOUR_OF_DAY);
}
return false;
}
/**
* Returns the amount of days between the second date and the first date
*
* @param dateOne the first date
* @param dateTwo the second date
* @return the amount of days between dateTwo and dateOne
*/
public static int daysBetween(Calendar dateOne, Calendar dateTwo) {
return (int) (((dateTwo.getTimeInMillis() + dateTwo.getTimeZone().getOffset(dateTwo.getTimeInMillis())) / (1000 * 60 * 60 * 24)) -
((dateOne.getTimeInMillis() + dateOne.getTimeZone().getOffset(dateOne.getTimeInMillis())) / (1000 * 60 * 60 * 24)));
}
/*
* Returns the amount of minutes passed in the day before the time in the given date
* @param date
* @return amount of minutes in day before time
*/
public static int getPassedMinutesInDay(Calendar date) {
return getPassedMinutesInDay(date.get(Calendar.HOUR_OF_DAY), date.get(Calendar.MINUTE));
}
/**
* Returns the amount of minutes in the given hours and minutes
*
* @param hour
* @param minute
* @return amount of minutes in the given hours and minutes
*/
public static int getPassedMinutesInDay(int hour, int minute) {
return hour * 60 + minute;
}
}

View File

@@ -9,11 +9,11 @@
<com.alamkanak.weekview.WeekView <de.sebse.fuplanner.tools.ui.weekview.WeekView
android:id="@+id/weekView" android:id="@+id/weekView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:eventTextColor="@android:color/white" app:eventTextColor="@color/colorFUWhite"
app:textSize="12sp" app:textSize="12sp"
app:hourHeight="60dp" app:hourHeight="60dp"
app:headerColumnPadding="8dp" app:headerColumnPadding="8dp"
@@ -26,7 +26,11 @@
app:todayBackgroundColor="#1848adff" app:todayBackgroundColor="#1848adff"
app:headerColumnBackground="#ffffffff" app:headerColumnBackground="#ffffffff"
app:firstDayOfWeek="monday" app:firstDayOfWeek="monday"
app:futureWeekendBackgroundColor="@color/colorFUPrimary"/> app:showFirstDayOfWeekFirst="true"
app:futureWeekendBackgroundColor="@color/colorFUPrimary"
app:pastWeekendBackgroundColor="@color/colorFUPrimary"
app:maxTime="21"
app:minTime="7"/>
</FrameLayout> </FrameLayout>

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="WeekView">
<attr name="allDayEventHeight" format="dimension" />
<attr name="autoLimitTime" format="boolean" />
<attr name="columnGap" format="dimension" />
<attr name="dayBackgroundColor" format="color" />
<attr name="dayNameLength" format="enum">
<enum name="length_short" value="1" />
<enum name="length_long" value="2" />
</attr>
<attr name="eventCornerRadius" format="dimension" />
<attr name="eventMarginVertical" format="dimension" />
<attr name="eventPadding" format="dimension" />
<attr name="eventTextColor" format="color" />
<attr name="eventTextSize" format="dimension" />
<attr name="firstDayOfWeek" format="enum">
<enum name="sunday" value="1" />
<enum name="monday" value="2" />
<enum name="tuesday" value="3" />
<enum name="wednesday" value="4" />
<enum name="thursday" value="5" />
<enum name="friday" value="6" />
<enum name="saturday" value="7" />
</attr>
<attr name="futureBackgroundColor" format="color" />
<attr name="futureWeekendBackgroundColor" format="color" />
<attr name="headerColumnBackground" format="color" />
<attr name="headerColumnPadding" format="dimension" />
<attr name="headerColumnTextColor" format="color" />
<attr name="headerRowBackgroundColor" format="color" />
<attr name="headerRowPadding" format="dimension" />
<attr name="horizontalFlingEnabled" format="boolean" />
<attr name="hourHeight" format="dimension" />
<attr name="hourSeparatorColor" format="color" />
<attr name="hourSeparatorHeight" format="dimension" />
<attr name="maxHourHeight" format="dimension" />
<attr name="maxTime" format="integer" />
<attr name="minHourHeight" format="dimension" />
<attr name="minTime" format="integer" />
<attr name="minOverlappingMinutes" format="integer" />
<attr name="newEventColor" format="color" />
<attr name="newEventId" format="integer" />
<attr name="newEventIdentifier" format="string" />
<attr name="newEventIconResource" format="integer" />
<attr name="newEventLengthInMinutes" format="integer" />
<attr name="newEventTimeResolutionInMinutes" format="integer" />
<attr name="noOfVisibleDays" format="integer" />
<attr name="nowLineColor" format="color" />
<attr name="nowLineThickness" format="dimension" />
<attr name="overlappingEventGap" format="dimension" />
<attr name="pastBackgroundColor" format="color" />
<attr name="pastWeekendBackgroundColor" format="color" />
<attr name="scrollDuration" format="integer" />
<attr name="showDistinctPastFutureColor" format="boolean" />
<attr name="showDistinctWeekendColor" format="boolean" />
<attr name="showFirstDayOfWeekFirst" format="boolean" />
<attr name="showNowLine" format="boolean" />
<attr name="textSize" format="dimension" />
<attr name="timeColumnResolution" format="integer" />
<attr name="todayBackgroundColor" format="color" />
<attr name="todayHeaderTextColor" format="color" />
<attr name="verticalFlingEnabled" format="boolean" />
<attr name="xScrollingSpeed" format="float" />
<attr name="zoomFocusPoint" format="fraction" />
<attr name="zoomFocusPointEnabled" format="boolean" />
<attr name="dropListenerEnabled" format="boolean" />
</declare-styleable>
</resources>