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

Clean Code (refractor move --> interfaces) #271

Open
wants to merge 6 commits into
base: develop
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
@@ -1,11 +1,13 @@
package com.alamkanak.weekview;

import java.util.Calendar;

/**
* Created by Raquib on 1/6/2015.
*/
public interface DateTimeInterpreter {
String interpretDate(Calendar date);
String interpretTime(int hour);
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.DateTimeInterpreter} instead.
*/
@Deprecated
public interface DateTimeInterpreter extends com.alamkanak.weekview.interfaces.DateTimeInterpreter{
}
28 changes: 14 additions & 14 deletions library/src/main/java/com/alamkanak/weekview/MonthLoader.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.alamkanak.weekview;

import com.alamkanak.weekview.interfaces.WeekViewLoader;

import java.util.Calendar;
import java.util.List;

public class MonthLoader implements WeekViewLoader {

private MonthChangeListener mOnMonthChangeListener;
private com.alamkanak.weekview.interfaces.MonthChangeListener mOnMonthChangeListener;

public MonthLoader(MonthChangeListener listener){
public MonthLoader(com.alamkanak.weekview.interfaces.MonthChangeListener listener){
this.mOnMonthChangeListener = listener;
}

Expand All @@ -21,23 +23,21 @@ public List<? extends WeekViewEvent> onLoad(int periodIndex){
return mOnMonthChangeListener.onMonthChange(periodIndex / 12, periodIndex % 12 + 1);
}

public MonthChangeListener getOnMonthChangeListener() {
public com.alamkanak.weekview.interfaces.MonthChangeListener getOnMonthChangeListener() {
return mOnMonthChangeListener;
}

public void setOnMonthChangeListener(MonthChangeListener onMonthChangeListener) {
public void setOnMonthChangeListener(com.alamkanak.weekview.interfaces.MonthChangeListener onMonthChangeListener) {
this.mOnMonthChangeListener = onMonthChangeListener;
}

public interface MonthChangeListener {
/**
* 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.<br/>
* <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 : month of the events required by the view <br/><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);
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.MonthChangeListener} instead.
*/
@Deprecated
public interface MonthChangeListener extends com.alamkanak.weekview.interfaces.MonthChangeListener{

}
}
130 changes: 65 additions & 65 deletions library/src/main/java/com/alamkanak/weekview/WeekView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.alamkanak.weekview;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
Expand Down Expand Up @@ -33,13 +41,8 @@
import android.view.ViewConfiguration;
import android.widget.OverScroller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import com.alamkanak.weekview.interfaces.DateTimeInterpreter;
import com.alamkanak.weekview.interfaces.WeekViewLoader;

import static com.alamkanak.weekview.WeekViewUtil.*;

Expand Down Expand Up @@ -146,13 +149,13 @@ private enum Direction {
private int mScrollDuration = 250;

// Listeners.
private EventClickListener mEventClickListener;
private EventLongPressListener mEventLongPressListener;
private WeekViewLoader mWeekViewLoader;
private EmptyViewClickListener mEmptyViewClickListener;
private EmptyViewLongPressListener mEmptyViewLongPressListener;
private DateTimeInterpreter mDateTimeInterpreter;
private ScrollListener mScrollListener;
private com.alamkanak.weekview.interfaces.EventClickListener mEventClickListener;
private com.alamkanak.weekview.interfaces.EventLongPressListener mEventLongPressListener;
private com.alamkanak.weekview.interfaces.WeekViewLoader mWeekViewLoader;
private com.alamkanak.weekview.interfaces.EmptyViewClickListener mEmptyViewClickListener;
private com.alamkanak.weekview.interfaces.EmptyViewLongPressListener mEmptyViewLongPressListener;
private com.alamkanak.weekview.interfaces.DateTimeInterpreter mDateTimeInterpreter;
private com.alamkanak.weekview.interfaces.ScrollListener mScrollListener;

private final GestureDetector.SimpleOnGestureListener mGestureListener = new GestureDetector.SimpleOnGestureListener() {

Expand Down Expand Up @@ -1222,21 +1225,21 @@ public void invalidate() {
//
/////////////////////////////////////////////////////////////////

public void setOnEventClickListener (EventClickListener listener) {
public void setOnEventClickListener (com.alamkanak.weekview.interfaces.EventClickListener listener) {
this.mEventClickListener = listener;
}

public EventClickListener getEventClickListener() {
public com.alamkanak.weekview.interfaces.EventClickListener getEventClickListener() {
return mEventClickListener;
}

public @Nullable MonthLoader.MonthChangeListener getMonthChangeListener() {
public @Nullable com.alamkanak.weekview.interfaces.MonthChangeListener getMonthChangeListener() {
if (mWeekViewLoader instanceof MonthLoader)
return ((MonthLoader) mWeekViewLoader).getOnMonthChangeListener();
return null;
}

public void setMonthChangeListener(MonthLoader.MonthChangeListener monthChangeListener) {
public void setMonthChangeListener(com.alamkanak.weekview.interfaces.MonthChangeListener monthChangeListener) {
this.mWeekViewLoader = new MonthLoader(monthChangeListener);
}

Expand All @@ -1260,35 +1263,35 @@ public void setWeekViewLoader(WeekViewLoader loader){
this.mWeekViewLoader = loader;
}

public EventLongPressListener getEventLongPressListener() {
public com.alamkanak.weekview.interfaces.EventLongPressListener getEventLongPressListener() {
return mEventLongPressListener;
}

public void setEventLongPressListener(EventLongPressListener eventLongPressListener) {
public void setEventLongPressListener(com.alamkanak.weekview.interfaces.EventLongPressListener eventLongPressListener) {
this.mEventLongPressListener = eventLongPressListener;
}

public void setEmptyViewClickListener(EmptyViewClickListener emptyViewClickListener){
public void setEmptyViewClickListener(com.alamkanak.weekview.interfaces.EmptyViewClickListener emptyViewClickListener){
this.mEmptyViewClickListener = emptyViewClickListener;
}

public EmptyViewClickListener getEmptyViewClickListener(){
public com.alamkanak.weekview.interfaces.EmptyViewClickListener getEmptyViewClickListener(){
return mEmptyViewClickListener;
}

public void setEmptyViewLongPressListener(EmptyViewLongPressListener emptyViewLongPressListener){
public void setEmptyViewLongPressListener(com.alamkanak.weekview.interfaces.EmptyViewLongPressListener emptyViewLongPressListener){
this.mEmptyViewLongPressListener = emptyViewLongPressListener;
}

public EmptyViewLongPressListener getEmptyViewLongPressListener(){
public com.alamkanak.weekview.interfaces.EmptyViewLongPressListener getEmptyViewLongPressListener(){
return mEmptyViewLongPressListener;
}

public void setScrollListener(ScrollListener scrolledListener){
public void setScrollListener(com.alamkanak.weekview.interfaces.ScrollListener scrolledListener){
this.mScrollListener = scrolledListener;
}

public ScrollListener getScrollListener(){
public com.alamkanak.weekview.interfaces.ScrollListener getScrollListener(){
return mScrollListener;
}

Expand Down Expand Up @@ -1989,54 +1992,51 @@ public double getFirstVisibleHour(){




/////////////////////////////////////////////////////////////////
//
// Interfaces.
//
/////////////////////////////////////////////////////////////////

public interface EventClickListener {
/**
* Triggered when clicked on one existing event
* @param event: event clicked.
* @param eventRect: view containing the clicked event.
*/
void onEventClick(WeekViewEvent event, RectF eventRect);
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.EventClickListener} instead.
*/
@Deprecated
public interface EventClickListener extends com.alamkanak.weekview.interfaces.EventClickListener{
}

public interface EventLongPressListener {
/**
* Similar to {@link com.alamkanak.weekview.WeekView.EventClickListener} but with a long press.
* @param event: event clicked.
* @param eventRect: view containing the clicked event.
*/
void onEventLongPress(WeekViewEvent event, RectF eventRect);
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.EventLongPressListener} instead.
*/
@Deprecated
public interface EventLongPressListener extends com.alamkanak.weekview.interfaces.EventLongPressListener{
}

public interface EmptyViewClickListener {
/**
* Triggered when the users clicks on a empty space of the calendar.
* @param time: {@link Calendar} object set with the date and time of the clicked position on the view.
*/
void onEmptyViewClicked(Calendar time);
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.EmptyViewClickListener} instead.
*/
@Deprecated
public interface EmptyViewClickListener extends com.alamkanak.weekview.interfaces.EmptyViewClickListener{
}

public interface EmptyViewLongPressListener {
/**
* Similar to {@link com.alamkanak.weekview.WeekView.EmptyViewClickListener} but with long press.
* @param time: {@link Calendar} object set with the date and time of the long pressed position on the view.
*/
void onEmptyViewLongPress(Calendar time);
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.EmptyViewLongPressListener} instead.
*/
@Deprecated
public interface EmptyViewLongPressListener extends com.alamkanak.weekview.interfaces.EmptyViewLongPressListener{
}
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.ScrollListener} instead.
*/
@Deprecated
public interface ScrollListener extends com.alamkanak.weekview.interfaces.ScrollListener{

public interface ScrollListener {
/**
* Called when the first visible day has changed.
*
* (this will also be called during the first draw of the weekview)
* @param newFirstVisibleDay The new first visible day
* @param oldFirstVisibleDay The old first visible day (is null on the first call).
*/
void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay);
}
}
29 changes: 7 additions & 22 deletions library/src/main/java/com/alamkanak/weekview/WeekViewLoader.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
package com.alamkanak.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.
*
* 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);
/**
* @deprecated code refractoring
* {will be removed in next version} </br>
* use {@link com.alamkanak.weekview.interfaces.WeekViewLoader} instead.
*/
@Deprecated
public interface WeekViewLoader extends com.alamkanak.weekview.interfaces.WeekViewLoader{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.alamkanak.weekview.interfaces;

import java.util.Calendar;

/**
* Created by Raquib on 1/6/2015.
*/
public interface DateTimeInterpreter{
String interpretDate(Calendar date);
String interpretTime(int hour);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.alamkanak.weekview.interfaces;

import java.util.Calendar;

/**
* Created by Thomas on 01/02/2016.
*/
public interface EmptyViewClickListener {
/**
* Triggered when the users clicks on a empty space of the calendar.
* @param time: {@link Calendar} object set with the date and time of the clicked position on the view.
*/
void onEmptyViewClicked(Calendar time);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.alamkanak.weekview.interfaces;

import java.util.Calendar;

/**
* Created by Thomas on 01/02/2016.
*/
public interface EmptyViewLongPressListener {
/**
* Similar to {@link com.alamkanak.weekview.WeekView.EmptyViewClickListener} but with long press.
* @param time: {@link Calendar} object set with the date and time of the long pressed position on the view.
*/
void onEmptyViewLongPress(Calendar time);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.alamkanak.weekview.interfaces;

import android.graphics.RectF;

import com.alamkanak.weekview.WeekViewEvent;

/**
* Created by Thomas on 01/02/2016.
*/
public interface EventClickListener{
/**
* Triggered when clicked on one existing event
* @param event: event clicked.
* @param eventRect: view containing the clicked event.
*/
void onEventClick(WeekViewEvent event, RectF eventRect);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.alamkanak.weekview.interfaces;

import android.graphics.RectF;

import com.alamkanak.weekview.WeekViewEvent;

/**
* Created by Thomas on 01/02/2016.
*/
public interface EventLongPressListener{
/**
* Similar to {@link com.alamkanak.weekview.WeekView.EventClickListener} but with a long press.
* @param event: event clicked.
* @param eventRect: view containing the clicked event.
*/
void onEventLongPress(WeekViewEvent event, RectF eventRect);
}
Loading