├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── libraries
│ ├── animated_vector_drawable_23_4_0.xml
│ ├── appcompat_v7_23_4_0.xml
│ ├── design_23_4_0.xml
│ ├── gson_2_6_2.xml
│ ├── hamcrest_core_1_3.xml
│ ├── junit_4_12.xml
│ ├── recyclerview_v7_23_4_0.xml
│ ├── support_annotations_23_4_0.xml
│ ├── support_v4_23_4_0.xml
│ └── support_vector_drawable_23_4_0.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
├── vcs.xml
└── workspace.xml
├── README.md
├── build.gradle
├── calendar
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── riontech
│ │ └── calendar
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── riontech
│ │ │ └── calendar
│ │ │ ├── CalendarConstant.java
│ │ │ ├── CustomCalendar.java
│ │ │ ├── Singleton.java
│ │ │ ├── adapter
│ │ │ ├── CalendarDataAdapter.java
│ │ │ ├── CalendarGridviewAdapter.java
│ │ │ └── ViewPagerAdapter.java
│ │ │ ├── dao
│ │ │ ├── CalendarDecoratorDao.java
│ │ │ ├── CalendarResponse.java
│ │ │ ├── Event.java
│ │ │ ├── EventData.java
│ │ │ ├── SectionDataViewHolder.java
│ │ │ ├── SectionTitleViewHolder.java
│ │ │ └── dataAboutDate.java
│ │ │ ├── fragment
│ │ │ └── CalendarFragment.java
│ │ │ └── utils
│ │ │ └── CalendarUtils.java
│ └── res
│ │ ├── drawable-hdpi
│ │ ├── ic_add.png
│ │ ├── ic_arrow_left.png
│ │ └── ic_arrow_right.png
│ │ ├── drawable-land
│ │ ├── circle_decorator.xml
│ │ ├── circle_decorator_white.xml
│ │ ├── circle_shape.xml
│ │ ├── circle_shape_selected.xml
│ │ ├── ic_cont_failed.png
│ │ └── list_item_background.xml
│ │ ├── drawable-mdpi
│ │ ├── ic_add.png
│ │ ├── ic_arrow_left.png
│ │ └── ic_arrow_right.png
│ │ ├── drawable-xhdpi
│ │ ├── ic_add.png
│ │ ├── ic_arrow_left.png
│ │ └── ic_arrow_right.png
│ │ ├── drawable-xxhdpi
│ │ ├── ic_add.png
│ │ ├── ic_arrow_left.png
│ │ └── ic_arrow_right.png
│ │ ├── drawable-xxxhdpi
│ │ ├── ic_add.png
│ │ ├── ic_arrow_left.png
│ │ └── ic_arrow_right.png
│ │ ├── drawable
│ │ ├── circle_decorator.xml
│ │ ├── circle_decorator_white.xml
│ │ ├── circle_shape.xml
│ │ ├── circle_shape_selected.xml
│ │ ├── ic_cont_failed.png
│ │ └── list_item_background.xml
│ │ ├── layout-land
│ │ └── layout_viewpager_recyclerview.xml
│ │ ├── layout
│ │ ├── calendar_item.xml
│ │ ├── fragement.xml
│ │ ├── layout_viewpager_recyclerview.xml
│ │ ├── row_event_desc.xml
│ │ └── row_event_header.xml
│ │ └── values
│ │ ├── attr.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── riontech
│ └── calendar
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── riontech
│ │ └── sample
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── riontech
│ │ │ └── sample
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── riontech
│ └── sample
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 |
38 | # Keystore files
39 | *.jks
40 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | CustomCalendar
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/libraries/animated_vector_drawable_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/libraries/design_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/gson_2_6_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/recyclerview_v7_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/libraries/support_vector_drawable_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | 1.8
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Custom Android Calendar
2 |
3 | 
4 |
5 | #Usage
6 | ---
7 | Maven repo
8 | ```
9 | maven {
10 | url "https://dl.bintray.com/riontech/maven"
11 | }
12 | ```
13 | Add the dependency to your build.gradle.
14 | ```
15 | dependencies {
16 | compile 'com.riontech:calendar:1.0'
17 | }
18 | ```
19 | Add the indicator to your layout.
20 |
21 | ```
22 |
30 | ```
31 |
32 | Create object of CustomCalendar in your activity
33 | ```
34 | private CustomCalendar customCalendar;
35 | ```
36 |
37 | In your acitivty onCreate initialize the object and set eventDate with count.
38 | And add it to customCalendar object by using addAnEvent method.
39 | ```
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_main);
44 | customCalendar = (CustomCalendar) findViewById(R.id.customCalendar);
45 |
46 | String[] arr = {"2016-06-10", "2016-06-11", "2016-06-15", "2016-06-16", "2016-06-25"};
47 | for (int i = 0; i < 5; i++) {
48 | int eventCount = 3;
49 | customCalendar.addAnEvent(arr[i], eventCount, getEventDataList(eventCount));
50 | }
51 | }
52 | ```
53 |
54 | # TODOs
55 | * Add Event with Plus button
56 | * Adding Reminders for Event, Birthday, etc
57 | * Awesome UI-UX
58 |
59 | Developed By
60 | ---
61 | * Keyur -
62 | * G+ [Keyur Ashra](https://plus.google.com/u/0/+KeyurAshra)
63 | * LinkedIn [Keyur Ashra](https://www.linkedin.com/in/keyurashra)
64 |
65 | License
66 | ---
67 |
68 | Copyright 2016 Riontech
69 |
70 | Licensed under the Apache License, Version 2.0 (the "License");
71 | you may not use this file except in compliance with the License.
72 | You may obtain a copy of the License at
73 |
74 | http://www.apache.org/licenses/LICENSE-2.0
75 |
76 | Unless required by applicable law or agreed to in writing, software
77 | distributed under the License is distributed on an "AS IS" BASIS,
78 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
79 | See the License for the specific language governing permissions and
80 | limitations under the License.
81 |
82 |
83 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.2'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/calendar/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/calendar/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.4.0'
25 | compile 'com.android.support:recyclerview-v7:23.4.0'
26 | compile 'com.google.code.gson:gson:2.6.2'
27 | compile 'com.android.support:design:23.4.0'
28 | }
29 |
30 |
31 | ext {
32 | bintrayRepo = 'maven'
33 | bintrayName = 'CustomCalendar'
34 |
35 | publishedGroupId = 'com.riontech'
36 | libraryName = 'Custom Calendar'
37 | artifact = 'calendar'
38 |
39 | libraryDescription = 'Custom calendar library for Android'
40 |
41 | siteUrl = 'https://github.com/Riontech/CustomCalendar'
42 | gitUrl = 'https://github.com/Riontech/CustomCalendar.git'
43 |
44 | libraryVersion = '1.0'
45 |
46 | developerId = 'riontech'
47 | developerName = 'Keyur Ashra'
48 | developerEmail = 'keyuraashra@gmail.com'
49 |
50 | licenseName = 'The Apache Software License, Version 2.0'
51 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
52 | allLicenses = ["Apache-2.0"]
53 | }
54 |
55 | // Place it at the end of the file
56 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
57 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
58 |
59 |
60 |
--------------------------------------------------------------------------------
/calendar/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/calendar/src/androidTest/java/com/riontech/calendar/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.riontech.calendar;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/calendar/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/calendar/src/main/java/com/riontech/calendar/CalendarConstant.java:
--------------------------------------------------------------------------------
1 | package com.riontech.calendar;
2 |
3 | /**
4 | * Created by Dhaval Soneji on 25/5/16.
5 | */
6 | public class CalendarConstant {
7 |
8 | public static final String PREFERENCE_NAME = "com.calendarlibrary";
9 | public static final String EVENT = PREFERENCE_NAME + "event";
10 | }
11 |
--------------------------------------------------------------------------------
/calendar/src/main/java/com/riontech/calendar/CustomCalendar.java:
--------------------------------------------------------------------------------
1 | package com.riontech.calendar;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.Configuration;
6 | import android.content.res.TypedArray;
7 | import android.os.Build;
8 | import android.support.v4.app.FragmentActivity;
9 | import android.support.v4.app.FragmentManager;
10 | import android.support.v4.view.ViewPager;
11 | import android.support.v7.widget.LinearLayoutManager;
12 | import android.support.v7.widget.RecyclerView;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.widget.ImageView;
18 | import android.widget.LinearLayout;
19 | import android.widget.TextView;
20 |
21 | import com.riontech.calendar.adapter.CalendarDataAdapter;
22 | import com.riontech.calendar.adapter.ViewPagerAdapter;
23 | import com.riontech.calendar.dao.Event;
24 | import com.riontech.calendar.dao.EventData;
25 | import com.riontech.calendar.fragment.CalendarFragment;
26 | import com.riontech.calendar.utils.CalendarUtils;
27 | import com.riontech.calendar.R;
28 |
29 | import java.text.ParseException;
30 | import java.text.SimpleDateFormat;
31 | import java.util.ArrayList;
32 | import java.util.Calendar;
33 | import java.util.Date;
34 | import java.util.GregorianCalendar;
35 |
36 | /**
37 | * Created by Dhaval Soneji on 2/6/16.
38 | */
39 | public class CustomCalendar extends LinearLayout {
40 | private static final String TAG = CustomCalendar.class.getSimpleName();
41 | private String mStartMonth;
42 | private String mEndMonth;
43 | private ViewPager mViewPager;
44 | private ViewPagerAdapter mAdapter;
45 | private int mTotalMonthCount;
46 | private int mDuplicateTotalMonthCount;
47 | private int mCurrentPosition;
48 | private RecyclerView mRvCalendar;
49 | private LinearLayoutManager mLinearLayoutManager;
50 | private TextView mTxtEventMessage;
51 | private TextView mTxtFailed;
52 | private ImageView mImgFailed;
53 | private ArrayList mEventList;
54 | private boolean isValidAttr = true;
55 |
56 | private Context mContext;
57 | private AttributeSet mAttributeSet = null;
58 |
59 | public CustomCalendar(Context context) {
60 | super(context);
61 | LayoutInflater.from(context).inflate(R.layout.layout_viewpager_recyclerview, this);
62 | Calendar calendar = Calendar.getInstance();
63 | mStartMonth = "1, " + String.valueOf(calendar.get(Calendar.YEAR));
64 | mEndMonth = "12, " + String.valueOf(calendar.get(Calendar.YEAR));
65 | mContext = context;
66 | initViews();
67 | }
68 |
69 | public CustomCalendar(Context context, AttributeSet attrs) {
70 | super(context, attrs);
71 | LayoutInflater.from(context).inflate(R.layout.layout_viewpager_recyclerview, this);
72 | mContext = context;
73 | mAttributeSet = attrs;
74 | initViews();
75 | }
76 |
77 | public CustomCalendar(Context context, AttributeSet attrs, int defStyleAttr) {
78 | super(context, attrs, defStyleAttr);
79 | LayoutInflater.from(context).inflate(R.layout.layout_viewpager_recyclerview, this);
80 | mContext = context;
81 | mAttributeSet = attrs;
82 | initViews();
83 | }
84 |
85 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
86 | public CustomCalendar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
87 | super(context, attrs, defStyleAttr, defStyleRes);
88 | LayoutInflater.from(context).inflate(R.layout.layout_viewpager_recyclerview, this);
89 | this.mContext = context;
90 | this.mAttributeSet = attrs;
91 | initViews();
92 | }
93 |
94 | private void initViews() {
95 | if (mAttributeSet != null) {
96 | TypedArray a = mContext.getTheme().obtainStyledAttributes(mAttributeSet,
97 | R.styleable.CustomCalendar, 0, 0);
98 | try {
99 | String startMonth = a.getString(R.styleable.CustomCalendar_startMonth);
100 | String startYear = a.getString(R.styleable.CustomCalendar_startYear);
101 | String endMonth = a.getString(R.styleable.CustomCalendar_endMonth);
102 | String endYear = a.getString(R.styleable.CustomCalendar_endYear);
103 |
104 | validateAttributes(startMonth, startYear, endMonth, endYear);
105 |
106 | mStartMonth = startMonth + ", " + startYear;
107 | mEndMonth = endMonth + ", " + endYear;
108 | } finally {
109 | a.recycle();
110 | }
111 | }
112 | mViewPager = (ViewPager) findViewById(R.id.viewPager);
113 | mTxtEventMessage = (TextView) findViewById(R.id.txtEventMessage);
114 | mImgFailed = (ImageView) findViewById(R.id.imgFailed);
115 | mTxtFailed = (TextView) findViewById(R.id.txtCalendarMessage);
116 | mRvCalendar = (RecyclerView) findViewById(R.id.rvCalendar);
117 |
118 | if (!isValidAttr) {
119 | invalidAttributes(getResources().getString(R.string.invalid_attribute));
120 | return;
121 | }
122 |
123 | /*
124 | first time setup calendar currentMonth
125 | */
126 | Singleton.getInstance().setMonth((GregorianCalendar) GregorianCalendar.getInstance());
127 | Singleton.getInstance().setCurrentDate(
128 | CalendarUtils.getCalendarDBFormat().format(Calendar.getInstance().getTime()));
129 | Singleton.getInstance().setTodayDate(
130 | CalendarUtils.getCalendarDBFormat().format(Calendar.getInstance().getTime()));
131 |
132 | mEventList = new ArrayList();
133 |
134 | mLinearLayoutManager = new LinearLayoutManager(mContext);
135 | mRvCalendar.setLayoutManager(mLinearLayoutManager);
136 | Singleton.getInstance().setStartMonth(mStartMonth);
137 | Singleton.getInstance().setEndMonth(mEndMonth);
138 |
139 | setupCalendar(Singleton.getInstance().getStartMonth(), Singleton.getInstance().getEndMonth());
140 |
141 | Singleton.getInstance().setEventManager(mEventList);
142 | }
143 |
144 | private void validateAttributes(String startMonth, String startYear, String endMonth, String endYear) {
145 | if (Integer.parseInt(startMonth) < 1 || Integer.parseInt(startMonth) > 12) {
146 | isValidAttr = false;
147 | }
148 | if (Integer.parseInt(endMonth) < 1 || Integer.parseInt(endMonth) > 12) {
149 | isValidAttr = false;
150 | }
151 | }
152 |
153 | private void invalidAttributes(String message) {
154 | mViewPager.setVisibility(GONE);
155 | mTxtEventMessage.setVisibility(GONE);
156 | mRvCalendar.setVisibility(GONE);
157 | mImgFailed.setVisibility(VISIBLE);
158 | mTxtFailed.setText(message);
159 | mTxtFailed.setVisibility(VISIBLE);
160 | }
161 |
162 | public void addAnEvent(String eventDate, int eventCount, ArrayList eventData) {
163 | if (!isValidAttr)
164 | return;
165 |
166 | Event date = new Event();
167 | date.setDate(eventDate);
168 | date.setCount(String.valueOf(eventCount));
169 | date.setEventData(eventData);
170 |
171 | mEventList.add(date);
172 | Singleton.getInstance().setEventManager(mEventList);
173 | }
174 |
175 | private void setupCalendar(String startMonth, String endMonth) {
176 | String temp[] = endMonth.split(",");
177 | int a = Integer.parseInt(temp[0]);
178 | String b = temp[1];
179 | a = a + 1;
180 | mStartMonth = startMonth;
181 | mEndMonth = String.valueOf(a) + ", " + b;
182 |
183 | SimpleDateFormat sdf = new SimpleDateFormat("MM, yyyy");
184 | Calendar currentCalendar = Calendar.getInstance();
185 | Calendar startCalendar = Calendar.getInstance();
186 | Calendar endCalendar = Calendar.getInstance();
187 |
188 | Date startDate = null;
189 | Date endDate = null;
190 |
191 | try {
192 |
193 | startDate = sdf.parse(mStartMonth);
194 | endDate = sdf.parse(mEndMonth);
195 | startCalendar.setTime(startDate);
196 | endCalendar.setTime(endDate);
197 | } catch (ParseException e) {
198 | Log.e(TAG, e.getMessage(), e);
199 | }
200 |
201 | int diffYear = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
202 | mTotalMonthCount = diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
203 | mDuplicateTotalMonthCount = mTotalMonthCount;
204 | int diffCurrentYear = currentCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
205 | int diffCurrentMonth = diffCurrentYear * 12 + currentCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
206 | mCurrentPosition = diffCurrentMonth;
207 |
208 | FragmentActivity fragmentActivity = (FragmentActivity) mContext;
209 | FragmentManager fm = fragmentActivity.getSupportFragmentManager();
210 |
211 | mAdapter = new ViewPagerAdapter(fm, mTotalMonthCount, this);
212 | mViewPager.setOffscreenPageLimit(1);
213 | mViewPager.setAdapter(mAdapter);
214 |
215 | mViewPager.setCurrentItem(diffCurrentMonth);
216 | mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
217 |
218 | @Override
219 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
220 | }
221 |
222 | @Override
223 | public void onPageSelected(int position) {
224 | if (position <= mDuplicateTotalMonthCount && position >= 0) {
225 | if (position > mCurrentPosition) {
226 | Singleton.getInstance().setIsSwipeViewPager(1);
227 |
228 | ((CalendarFragment) mAdapter.getRegisteredFragment(position)).setNextMonth();
229 | ((CalendarFragment) mAdapter.getRegisteredFragment(position)).refreshCalendar();
230 | } else {
231 | Singleton.getInstance().setIsSwipeViewPager(0);
232 |
233 | ((CalendarFragment) mAdapter.getRegisteredFragment(position)).setPreviousMonth();
234 | ((CalendarFragment) mAdapter.getRegisteredFragment(position)).refreshCalendar();
235 | }
236 | mCurrentPosition = position;
237 | }
238 | }
239 |
240 | @Override
241 | public void onPageScrollStateChanged(int state) {
242 |
243 | }
244 | });
245 | }
246 |
247 | /**
248 | * @param dateData
249 | */
250 | public void setDateSelectionData(ArrayList dateData) {
251 |
252 | mRvCalendar.setVisibility(View.VISIBLE);
253 | mTxtEventMessage.setVisibility(View.GONE);
254 | mTxtEventMessage.setText("");
255 | ArrayList