Skip to content

Commit

Permalink
Merge pull request #1 from MOLO17/develop
Browse files Browse the repository at this point in the history
First usable implementation
  • Loading branch information
francesco-furlan authored Jul 5, 2017
2 parents a6c0a7f + b38e0e9 commit 4578e67
Show file tree
Hide file tree
Showing 49 changed files with 2,419 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.francesco.furlan.customizablecalendar;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.francesco.furlan.customizablecalendar.library.adapter.WeekDaysViewAdapter;
import com.francesco.furlan.customizablecalendar.library.interactors.ViewInteractor;
import com.francesco.furlan.customizablecalendar.library.model.Calendar;
import com.francesco.furlan.customizablecalendar.library.model.CalendarItem;

import org.joda.time.DateTime;

import java.util.List;

/**
* Created by francescofurlan on 03/07/17.
*/

public class CalendarViewInteractor implements ViewInteractor {
private Context context;
private Calendar calendar;
private TextView firstDaySelectedTxt;
private TextView lastDaySelectedTxt;

CalendarViewInteractor(Context context) {
this.context = context;
}

@Override
public void onCustomizableCalendarBindView(View view) {

}

@Override
public void onHeaderBindView(ViewGroup view) {
RelativeLayout layout = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.calendar_header, view);
firstDaySelectedTxt = (TextView) layout.findViewById(R.id.first_day_selected);
lastDaySelectedTxt = (TextView) layout.findViewById(R.id.last_day_selected);
updateCalendar(calendar);
}

@Override
public void onWeekDaysBindView(View view) {

}

@Override
public void onWeekDayBindView(WeekDaysViewAdapter.WeekDayVH holder, String weekDay) {

}

@Override
public void onSubViewBindView(View view, String month) {

}

@Override
public void onCalendarBindView(View view) {

}

@Override
public void onMonthBindView(View view) {

}

@Override
public View onMonthCellBindView(View view, CalendarItem currentItem) {
return null;
}

@Override
public boolean hasImplementedDayCalculation() {
return false;
}

@Override
public List<CalendarItem> calculateDays(int year, int month, int firstDayOfMonth, int lastDayOfMonth) {
return null;
}

@Override
public boolean hasImplementedSelection() {
return false;
}

@Override
public int setSelected(boolean multipleSelection, DateTime dateSelected) {
return -1;
}

@Override
public boolean hasImplementedMonthCellBinding() {
return false;
}

@Override
public View getMonthGridView(View rootView) {
return null;
}

void updateCalendar(Calendar calendar) {
this.calendar = calendar;
if (firstDaySelectedTxt != null && lastDaySelectedTxt != null) {
DateTime firstDate = calendar.getFirstSelectedDay();
DateTime lastDate = calendar.getLastSelectedDay();
if (firstDate != null) {
firstDaySelectedTxt.setText(firstDate.toString("dd MMMMM yyyy"));
}
if (lastDate != null) {
lastDaySelectedTxt.setText(lastDate.toString("dd MMMMM yyyy"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,63 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.francesco.furlan.customizablecalendar.library.components.CustomizableCalendar;
import com.francesco.furlan.customizablecalendar.library.interactors.AUCalendar;
import com.francesco.furlan.customizablecalendar.library.model.Calendar;

import org.joda.time.DateTime;

import butterknife.ButterKnife;
import butterknife.InjectView;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.functions.Consumer;

public class MainActivity extends AppCompatActivity {

@InjectView(R.id.view_month)
CustomizableCalendar customizableCalendar;

private CompositeDisposable subscriptions;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
subscriptions = new CompositeDisposable();
updateData();
}

}
private void updateData() {
// setting up first and last month that must be showed in the calendar
DateTime firstMonth = new DateTime().withDayOfMonth(1);
DateTime lastMonth = new DateTime().plusMonths(3).withDayOfMonth(1);

// create the Calendar obj and setting it up with some configs like:
// - first selected day
// - last selected day
// - multiple selection
final Calendar calendar = new Calendar(firstMonth, lastMonth);
calendar.setFirstSelectedDay(new DateTime().plusDays(4));
calendar.setLastSelectedDay(new DateTime().plusDays(6));
calendar.setMultipleSelection(true);

// create a CalendarViewInteractor obj needed to interact with the CustomizableCalendar
final CalendarViewInteractor calendarViewInteractor = new CalendarViewInteractor(getBaseContext());

// create the AUCalendar obj and observes changes on it
AUCalendar auCalendar = AUCalendar.getInstance(calendar);
calendarViewInteractor.updateCalendar(calendar);
subscriptions.add(
auCalendar.observeChangesOnCalendar().subscribe(new Consumer<AUCalendar.ChangeSet>() {
@Override
public void accept(AUCalendar.ChangeSet changeSet) throws Exception {
calendarViewInteractor.updateCalendar(calendar);
}
})
);

// inject (set) the calendarViewInteractor to the CustomizableCalendar
customizableCalendar.injectViewInteractor(calendarViewInteractor);
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/white"
android:orientation="vertical">

<com.francesco.furlan.customizablecalendar.library.components.CustomizableCalendar
android:id="@+id/view_month"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout="@layout/c_calendar" />

</LinearLayout>
33 changes: 33 additions & 0 deletions app/src/main/res/layout/c_calendar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:orientation="vertical">

<com.francesco.furlan.customizablecalendar.library.components.HeaderView
android:id="@android:id/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.francesco.furlan.customizablecalendar.library.components.SubView
android:id="@android:id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" />

<com.francesco.furlan.customizablecalendar.library.components.WeekDaysView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp" />

<com.francesco.furlan.customizablecalendar.library.components.CalendarRecyclerView
android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="@dimen/customizable_calendar_height"
android:layout_marginTop="15dp" />

</LinearLayout>
80 changes: 80 additions & 0 deletions app/src/main/res/layout/calendar_header.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/firstDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:maxWidth="250dp"
android:singleLine="true"
android:text="@string/first_day_selected"
android:textColor="@android:color/black"
android:textSize="18sp" />

<TextView
android:id="@+id/first_day_selected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:maxWidth="250dp"
android:singleLine="true"
android:text="@string/day_month_year"
android:textColor="@android:color/black"
android:textSize="20sp" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="6dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:maxWidth="250dp"
android:singleLine="true"
android:text="@string/last_day_selected"
android:textColor="@android:color/black"
android:textSize="18sp" />

<TextView
android:id="@+id/last_day_selected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:maxWidth="250dp"
android:singleLine="true"
android:text="@string/day_month_year"
android:textColor="@android:color/black"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">CustomizableCalendar</string>
<string name="day_month_year">day month year</string>
<string name="first_day_selected">First day selected</string>
<string name="last_day_selected">Last day selected</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
1 change: 1 addition & 0 deletions library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
14 changes: 14 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 25
Expand All @@ -19,6 +20,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand All @@ -27,5 +32,14 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'joda-time:joda-time:2.9.9'
compile 'com.jakewharton:butterknife:6.1.0'
compile "io.reactivex.rxjava2:rxjava:2.0.1"
retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:2.5.1'
}

retrolambda {
javaVersion JavaVersion.VERSION_1_7
}
Loading

0 comments on commit 4578e67

Please sign in to comment.