Skip to content

Commit

Permalink
Merge pull request Tibolte#5 from FHellmann/master
Browse files Browse the repository at this point in the history
Add possibility for custom event layouts
  • Loading branch information
Tibolte committed Nov 26, 2015
2 parents 281574a + 8fe1fd3 commit 8a59410
Show file tree
Hide file tree
Showing 21 changed files with 658 additions and 418 deletions.
14 changes: 7 additions & 7 deletions agendacalendarview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
buildToolsVersion "23.0.1"

android {
lintOptions {
Expand Down Expand Up @@ -40,16 +40,16 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

// Google libraries
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.google.collections:google-collections:1.0-rc2'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:design:23.1.1'

// other libraries
compile 'se.emilsjolander:stickylistheaders:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'pl.charmas.android:android-reactive-location:0.6@aar'
compile 'io.reactivex:rxjava:1.0.15'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'io.reactivex:rxjava:1.0.16'
compile 'io.reactivex:rxandroid:1.0.1'
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.github.tibolte.agendacalendarview;

import com.github.tibolte.agendacalendarview.agenda.AgendaAdapter;
import com.github.tibolte.agendacalendarview.agenda.AgendaListView;
import com.github.tibolte.agendacalendarview.agenda.AgendaView;
import com.github.tibolte.agendacalendarview.calendar.CalendarView;
import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.render.DefaultEventRenderer;
import com.github.tibolte.agendacalendarview.render.EventRenderer;
import com.github.tibolte.agendacalendarview.utils.BusProvider;
import com.github.tibolte.agendacalendarview.utils.Events;
import com.github.tibolte.agendacalendarview.utils.ListViewScrollTracker;
Expand All @@ -16,6 +18,7 @@
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -197,6 +200,14 @@ public void init(List<CalendarEvent> eventList, Calendar minDate, Calendar maxDa
mAgendaView.getAgendaListView().setAdapter(agendaAdapter);
mAgendaView.getAgendaListView().setOnStickyHeaderChangedListener(this);
CalendarManager.getInstance().loadEvents(eventList);

// add default event renderer
addEventRenderer(new DefaultEventRenderer());
}

public void addEventRenderer(@NonNull final EventRenderer<?> renderer) {
AgendaAdapter adapter = (AgendaAdapter) mAgendaView.getAgendaListView().getAdapter();
adapter.addEventRenderer(renderer);
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.tibolte.agendacalendarview;

import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.models.DayItem;
import com.github.tibolte.agendacalendarview.models.MonthItem;
Expand Down Expand Up @@ -231,7 +232,7 @@ public void loadEvents(List<CalendarEvent> eventList) {
boolean isEventForDay = false;
for (CalendarEvent event : eventList) {
if (DateHelper.isBetweenInclusive(dayItem.getDate(), event.getStartTime(), event.getEndTime())) {
CalendarEvent copy = new CalendarEvent(event);
CalendarEvent copy = event.copy();

Calendar dayInstance = Calendar.getInstance();
dayInstance.setTime(dayItem.getDate());
Expand All @@ -246,7 +247,7 @@ public void loadEvents(List<CalendarEvent> eventList) {
if (!isEventForDay) {
Calendar dayInstance = Calendar.getInstance();
dayInstance.setTime(dayItem.getDate());
CalendarEvent event = new CalendarEvent(dayInstance, getContext().getResources().getString(R.string.agenda_event_no_events));
BaseCalendarEvent event = new BaseCalendarEvent(dayInstance, getContext().getResources().getString(R.string.agenda_event_no_events));
event.setDayReference(dayItem);
event.setWeekReference(weekItem);
getEvents().add(event);
Expand Down Expand Up @@ -391,7 +392,7 @@ protected Void doInBackground(String... params) {

Log.d(LOG_TAG, String.format("Found %d events", cursor.getCount()));
while (cursor.moveToNext()) {
CalendarEvent event = new CalendarEvent(
BaseCalendarEvent event = new BaseCalendarEvent(
cursor.getLong(0),
colors.get(cursor.getString(10)),
cursor.getString(2),
Expand Down Expand Up @@ -429,7 +430,7 @@ protected void onPostExecute(Void result) {
boolean isEventForDay = false;
for (CalendarEvent event : mEvents) {
if (DateHelper.isBetweenInclusive(dayItem.getDate(), event.getStartTime(), event.getEndTime())) {
CalendarEvent copy = new CalendarEvent(event);
CalendarEvent copy = event.copy();

Calendar dayInstance = Calendar.getInstance();
dayInstance.setTime(dayItem.getDate());
Expand All @@ -444,7 +445,7 @@ protected void onPostExecute(Void result) {
if (!isEventForDay) {
Calendar dayInstance = Calendar.getInstance();
dayInstance.setTime(dayItem.getDate());
CalendarEvent event = new CalendarEvent(dayInstance, getContext().getResources().getString(R.string.agenda_event_no_events));
BaseCalendarEvent event = new BaseCalendarEvent(dayInstance, getContext().getResources().getString(R.string.agenda_event_no_events));
event.setDayReference(dayItem);
event.setWeekReference(weekItem);
getEvents().add(event);
Expand Down Expand Up @@ -484,7 +485,7 @@ private List<CalendarEvent> sortForecast(Forecast forecast) {
List<CalendarEvent> filteredCalendarList = new ArrayList<>();

for (DataPoint dataPoint : forecast.getHourly().getData()) {
CalendarEvent calendarEvent = new CalendarEvent(dataPoint);
CalendarEvent calendarEvent = new BaseCalendarEvent(dataPoint);

Calendar tomorrow = Calendar.getInstance();
tomorrow.setTime(getToday().getTime());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.tibolte.agendacalendarview;

import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.models.DayItem;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.github.tibolte.agendacalendarview.agenda;

import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.render.DefaultEventRenderer;
import com.github.tibolte.agendacalendarview.render.EventRenderer;

import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
Expand All @@ -18,6 +23,7 @@
public class AgendaAdapter extends BaseAdapter implements StickyListHeadersAdapter {

private List<CalendarEvent> mEvents = new ArrayList<>();
private List<EventRenderer<?>> mRenderers = new ArrayList<>();
private int mCurrentDayColor;

// region Constructor
Expand Down Expand Up @@ -76,12 +82,24 @@ public long getItemId(int position) {

@Override
public View getView(int position, View convertView, ViewGroup parent) {
AgendaEventView agendaEventView = (AgendaEventView) convertView;
if (agendaEventView == null) {
agendaEventView = AgendaEventView.inflate(parent);
EventRenderer eventRenderer = new DefaultEventRenderer();
final CalendarEvent event = getItem(position);

// Search for the correct event renderer
for (EventRenderer renderer : mRenderers) {
if(event.getClass().isAssignableFrom(renderer.getRenderType())) {
eventRenderer = renderer;
break;
}
}
agendaEventView.setEvent(getItem(position));
return agendaEventView;
convertView = LayoutInflater.from(parent.getContext())
.inflate(eventRenderer.getEventLayout(), parent, false);
eventRenderer.render(convertView, event);
return convertView;
}

public void addEventRenderer(@NonNull final EventRenderer<?> renderer) {
mRenderers.add(renderer);
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,38 @@
package com.github.tibolte.agendacalendarview.agenda;

import com.github.tibolte.agendacalendarview.R;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
* List item view for the StickyHeaderListView of the agenda view
*/
public class AgendaEventView extends LinearLayout {
public static AgendaEventView inflate(ViewGroup parent) {
AgendaEventView agendaEventView = (AgendaEventView) LayoutInflater.from(parent.getContext()).inflate(R.layout.view_agenda_event, parent, false);
return agendaEventView;
return (AgendaEventView) LayoutInflater.from(parent.getContext()).inflate(R.layout.view_agenda_event, parent, false);
}

// region Constructors

public AgendaEventView(Context context, AttributeSet attrs) {
super(context, attrs);
public AgendaEventView(Context context) {
this(context, null);
}

public AgendaEventView(Context context) {
super(context);
public AgendaEventView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public AgendaEventView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setPadding(getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_left),
getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_top),
getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_right),
getResources().getDimensionPixelSize(R.dimen.agenda_event_view_padding_bottom));
}

// endregion

// region Public methods

public void setEvent(CalendarEvent event) {
TextView txtTitle = (TextView) findViewById(R.id.view_agenda_event_title);
TextView txtLocation = (TextView) findViewById(R.id.view_agenda_event_location);
LinearLayout descriptionContainer = (LinearLayout) findViewById(R.id.view_agenda_event_description_container);
LinearLayout locationContainer = (LinearLayout) findViewById(R.id.view_agenda_event_location_container);

descriptionContainer.setVisibility(VISIBLE);
txtTitle.setTextColor(getResources().getColor(android.R.color.black));

txtTitle.setText(event.getTitle());
txtLocation.setText(event.getLocation());
if (event.getLocation().length() > 0) {
locationContainer.setVisibility(VISIBLE);
txtLocation.setText(event.getLocation());
} else {
locationContainer.setVisibility(GONE);
}

if (event.getTitle().equals(getResources().getString(R.string.agenda_event_no_events))) {
txtTitle.setTextColor(getResources().getColor(android.R.color.black));
} else {
txtTitle.setTextColor(getResources().getColor(R.color.theme_text_icons));
}
descriptionContainer.setBackgroundColor(event.getColor());
txtLocation.setTextColor(getResources().getColor(R.color.theme_text_icons));
}

// endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
public class AgendaHeaderView extends LinearLayout {

public static AgendaHeaderView inflate(ViewGroup parent) {
AgendaHeaderView agendaHeaderView = (AgendaHeaderView) LayoutInflater.from(parent.getContext()).inflate(R.layout.view_agenda_header, parent, false);
return agendaHeaderView;
return (AgendaHeaderView) LayoutInflater.from(parent.getContext()).inflate(R.layout.view_agenda_header, parent, false);
}

// region Constructors
Expand All @@ -51,9 +50,6 @@ public void setDay(Calendar day, int currentDayTextColor) {
View circleView = findViewById(R.id.view_day_circle_selected);

Calendar today = CalendarManager.getInstance().getToday();
Calendar tomorrow = Calendar.getInstance();
tomorrow.setTime(today.getTime());
tomorrow.add(Calendar.DATE, 1);

SimpleDateFormat dayWeekFormatter = new SimpleDateFormat("E");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package com.github.tibolte.agendacalendarview.agenda;

import com.github.tibolte.agendacalendarview.CalendarManager;
import com.github.tibolte.agendacalendarview.R;
import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.utils.BusProvider;
import com.github.tibolte.agendacalendarview.utils.DateHelper;
import com.github.tibolte.agendacalendarview.utils.Events;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;

import java.util.Calendar;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onGlobalLayout() {

getAgendaListView().scrollToCurrentDate(CalendarManager.getInstance().getToday());

getViewTreeObserver().removeOnGlobalLayoutListener(this);
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.tibolte.agendacalendarview.R;
import com.github.tibolte.agendacalendarview.calendar.weekslist.WeekListView;
import com.github.tibolte.agendacalendarview.calendar.weekslist.WeeksAdapter;
import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent;
import com.github.tibolte.agendacalendarview.models.CalendarEvent;
import com.github.tibolte.agendacalendarview.models.DayItem;
import com.github.tibolte.agendacalendarview.models.WeekItem;
Expand Down Expand Up @@ -105,7 +106,7 @@ protected void onFinishInflate() {
public void onGlobalLayout() {
if (getWidth() != 0 && getHeight() != 0) {
collapseCalendarView();
getViewTreeObserver().removeOnGlobalLayoutListener(this);
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
}
Expand Down
Loading

0 comments on commit 8a59410

Please sign in to comment.