diff --git a/app/build.gradle b/app/build.gradle index d89680c..1f08782 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 26 - buildToolsVersion '26.0.2' + compileSdkVersion 29 + buildToolsVersion '29.0.3' defaultConfig { applicationId "devs.mulham.raee.horizontalcalendarlibrary" minSdkVersion 14 - targetSdkVersion 26 + targetSdkVersion 29 versionCode 1 versionName "1.0" } @@ -20,10 +20,10 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile project(':horizontalcalendar') - compile 'com.android.support:appcompat-v7:26.1.0' - compile 'com.android.support:design:26.1.0' - compile 'com.android.support:support-v4:26.1.0' - testCompile 'junit:junit:4.12' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation project(':horizontalcalendar') + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + testImplementation 'junit:junit:4.13' } diff --git a/app/src/main/java/devs/mulham/raee/sample/MainActivity.java b/app/src/main/java/devs/mulham/raee/sample/MainActivity.java index d92a815..f5c2a67 100644 --- a/app/src/main/java/devs/mulham/raee/sample/MainActivity.java +++ b/app/src/main/java/devs/mulham/raee/sample/MainActivity.java @@ -2,9 +2,6 @@ import android.graphics.Color; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.text.format.DateFormat; import android.util.Log; import android.view.Menu; @@ -12,6 +9,11 @@ import android.view.View; import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; + import java.util.ArrayList; import java.util.Calendar; import java.util.List; diff --git a/app/src/main/java/devs/mulham/raee/sample/SampleFragment.java b/app/src/main/java/devs/mulham/raee/sample/SampleFragment.java index ac5f2dc..531af61 100644 --- a/app/src/main/java/devs/mulham/raee/sample/SampleFragment.java +++ b/app/src/main/java/devs/mulham/raee/sample/SampleFragment.java @@ -2,13 +2,14 @@ import android.graphics.Color; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; +import androidx.fragment.app.Fragment; + import java.util.Calendar; import devs.mulham.horizontalcalendar.HorizontalCalendar; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index eb5ab00..01491a9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ - - - + app:popupTheme="@style/AppTheme.PopupOverlay" /> + app:sizeMiddleText="20sp" + app:textColorSelected="#FFFF" /> - + - + android:src="@drawable/ic_calendar_24dp" /> diff --git a/app/src/main/res/layout/fragment_sample.xml b/app/src/main/res/layout/fragment_sample.xml index f1dbe5d..b4e3ceb 100644 --- a/app/src/main/res/layout/fragment_sample.xml +++ b/app/src/main/res/layout/fragment_sample.xml @@ -8,13 +8,13 @@ android:fitsSystemWindows="true" tools:context="devs.mulham.raee.sample.MainActivity"> - - - + diff --git a/build.gradle b/build.gradle index d3807b8..e577dc4 100644 --- a/build.gradle +++ b/build.gradle @@ -2,16 +2,13 @@ buildscript { repositories { + google() jcenter() - maven { - url 'https://maven.google.com/' - name 'Google' - } } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + classpath "com.android.tools.build:gradle:4.0.0" + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } diff --git a/gradle.properties b/gradle.properties index 1d3591c..4d15d01 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,21 @@ # Project-wide Gradle settings. - # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. - # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - +org.gradle.jvmargs=-Xmx2048m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 16acf6d..1e72f0d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/horizontalcalendar/build.gradle b/horizontalcalendar/build.gradle index 2af1479..fae5628 100644 --- a/horizontalcalendar/build.gradle +++ b/horizontalcalendar/build.gradle @@ -28,8 +28,8 @@ ext { version = libraryVersion android { - compileSdkVersion 26 - buildToolsVersion '26.0.2' + compileSdkVersion 29 + buildToolsVersion '29.0.3' lintOptions { abortOnError false @@ -37,7 +37,7 @@ android { defaultConfig { minSdkVersion 14 - targetSdkVersion 26 + targetSdkVersion 29 versionCode 1 versionName version } @@ -50,9 +50,9 @@ android { } dependencies { - implementation 'com.android.support:appcompat-v7:26.1.0' - implementation 'com.android.support:recyclerview-v7:26.1.0' - compile 'com.android.support.constraint:constraint-layout:1.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' } diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendar.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendar.java index 0e6e194..ce0ba3c 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendar.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendar.java @@ -4,14 +4,16 @@ import android.app.Activity; import android.content.Context; import android.graphics.Color; -import android.support.v7.widget.RecyclerView; import android.view.View; +import androidx.recyclerview.widget.RecyclerView; + import java.util.Calendar; import devs.mulham.horizontalcalendar.adapter.DaysAdapter; import devs.mulham.horizontalcalendar.adapter.HorizontalCalendarBaseAdapter; import devs.mulham.horizontalcalendar.adapter.MonthsAdapter; +import devs.mulham.horizontalcalendar.adapter.YearsAdapter; import devs.mulham.horizontalcalendar.model.CalendarItemStyle; import devs.mulham.horizontalcalendar.model.HorizontalCalendarConfig; import devs.mulham.horizontalcalendar.utils.CalendarEventsPredicate; @@ -30,7 +32,7 @@ */ public final class HorizontalCalendar { - public enum Mode {DAYS, MONTHS} + public enum Mode {DAYS, MONTHS, YEARS} //region private Fields HorizontalCalendarView calendarView; @@ -85,7 +87,9 @@ void init(View rootView, final Calendar defaultSelectedDate, HorizontalCalendarP disablePredicate = new HorizontalCalendarPredicate.Or(disablePredicate, defaultDisablePredicate); } - if (mode == Mode.MONTHS){ + if (mode == Mode.YEARS){ + mCalendarAdapter = new YearsAdapter(this, startDate, endDate, disablePredicate, eventsPredicate); + } else if (mode == Mode.MONTHS){ mCalendarAdapter = new MonthsAdapter(this, startDate, endDate, disablePredicate, eventsPredicate); } else { mCalendarAdapter = new DaysAdapter(this, startDate, endDate, disablePredicate, eventsPredicate); diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendarView.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendarView.java index 7f2e4a4..0b7cac1 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendarView.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalCalendarView.java @@ -4,10 +4,11 @@ import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.drawable.Drawable; -import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.util.TypedValue; +import androidx.recyclerview.widget.RecyclerView; + import devs.mulham.horizontalcalendar.adapter.HorizontalCalendarBaseAdapter; import devs.mulham.horizontalcalendar.model.CalendarItemStyle; import devs.mulham.horizontalcalendar.model.HorizontalCalendarConfig; diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalLayoutManager.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalLayoutManager.java index 32ad277..d7e2184 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalLayoutManager.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/HorizontalLayoutManager.java @@ -1,11 +1,12 @@ package devs.mulham.horizontalcalendar; import android.content.Context; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.LinearSmoothScroller; -import android.support.v7.widget.RecyclerView; import android.util.DisplayMetrics; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.LinearSmoothScroller; +import androidx.recyclerview.widget.RecyclerView; + /** * @author Mulham-Raee * @since v1.0.0 diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/DateViewHolder.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/DateViewHolder.java index 6bdd7dd..111cb13 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/DateViewHolder.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/DateViewHolder.java @@ -1,9 +1,10 @@ package devs.mulham.horizontalcalendar.adapter; -import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; + import devs.mulham.horizontalcalendar.R; /** diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/EventsAdapter.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/EventsAdapter.java index 133fbf1..54ff619 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/EventsAdapter.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/EventsAdapter.java @@ -2,13 +2,14 @@ import android.content.Context; import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; -import android.support.v4.graphics.drawable.DrawableCompat; -import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.drawable.DrawableCompat; +import androidx.recyclerview.widget.RecyclerView; + import java.util.List; import devs.mulham.horizontalcalendar.R; diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/HorizontalCalendarBaseAdapter.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/HorizontalCalendarBaseAdapter.java index b0a395a..d2937dc 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/HorizontalCalendarBaseAdapter.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/HorizontalCalendarBaseAdapter.java @@ -1,12 +1,13 @@ package devs.mulham.horizontalcalendar.adapter; import android.os.Build; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import java.util.Calendar; import java.util.Collections; import java.util.List; diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/YearsAdapter.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/YearsAdapter.java new file mode 100644 index 0000000..a76617c --- /dev/null +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/adapter/YearsAdapter.java @@ -0,0 +1,105 @@ +package devs.mulham.horizontalcalendar.adapter; + +import android.text.format.DateFormat; +import android.util.TypedValue; +import android.view.View; + +import java.util.Calendar; +import java.util.List; + +import devs.mulham.horizontalcalendar.HorizontalCalendar; +import devs.mulham.horizontalcalendar.HorizontalCalendarView; +import devs.mulham.horizontalcalendar.R; +import devs.mulham.horizontalcalendar.model.HorizontalCalendarConfig; +import devs.mulham.horizontalcalendar.utils.CalendarEventsPredicate; +import devs.mulham.horizontalcalendar.utils.HorizontalCalendarPredicate; +import devs.mulham.horizontalcalendar.utils.Utils; + +/** + * custom adapter for {@link HorizontalCalendarView HorizontalCalendarView} + * + * @author Mulham-Raee + * @since v1.3.3 + *

+ * See {devs.mulham.horizontalcalendar.R.layout#hc_item_calendar} Calendar CustomItem Layout + */ +public class YearsAdapter extends HorizontalCalendarBaseAdapter { + + public YearsAdapter(HorizontalCalendar horizontalCalendar, Calendar startDate, Calendar endDate, HorizontalCalendarPredicate disablePredicate, CalendarEventsPredicate eventsPredicate) { + super(R.layout.hc_item_calendar, horizontalCalendar, startDate, endDate, disablePredicate, eventsPredicate); + } + + @Override + protected DateViewHolder createViewHolder(View itemView, int cellWidth) { + final DateViewHolder holder = new DateViewHolder(itemView); + + holder.layoutContent.setMinimumWidth(cellWidth); + //holder.textTop.setVisibility(View.GONE); + + return holder; + } + + @Override + public void onBindViewHolder(DateViewHolder holder, int position) { + Calendar year = getItem(position); + HorizontalCalendarConfig config = horizontalCalendar.getConfig(); + + final Integer selectorColor = horizontalCalendar.getConfig().getSelectorColor(); + if (selectorColor != null) { + holder.selectionView.setBackgroundColor(selectorColor); + } + + holder.textMiddle.setText(DateFormat.format(config.getFormatMiddleText(), year)); + holder.textMiddle.setTextSize(TypedValue.COMPLEX_UNIT_SP, config.getSizeMiddleText()); + + if (config.isShowTopText()) { + holder.textTop.setText(DateFormat.format(config.getFormatTopText(), year)); + holder.textTop.setTextSize(TypedValue.COMPLEX_UNIT_SP, config.getSizeTopText()); + } else { + holder.textTop.setVisibility(View.GONE); + } + + if (config.isShowBottomText()) { + holder.textBottom.setText(DateFormat.format(config.getFormatBottomText(), year)); + holder.textBottom.setTextSize(TypedValue.COMPLEX_UNIT_SP, config.getSizeBottomText()); + } else { + holder.textBottom.setVisibility(View.GONE); + } + + showEvents(holder, year); + applyStyle(holder, year, position); + + } + + @Override + public void onBindViewHolder(DateViewHolder holder, int position, List payloads) { + if ((payloads == null) || payloads.isEmpty()) { + onBindViewHolder(holder, position); + return; + } + + Calendar date = getItem(position); + applyStyle(holder, date, position); + } + + @Override + public Calendar getItem(int position) throws IndexOutOfBoundsException { + if (position >= itemsCount) { + throw new IndexOutOfBoundsException(); + } + + int yearsDiff = position - horizontalCalendar.getShiftCells(); + + Calendar calendar = (Calendar) startDate.clone(); + calendar.add(Calendar.YEAR, yearsDiff); + + return calendar; + } + + @Override + protected int calculateItemsCount(Calendar startDate, Calendar endDate) { + int year = Utils.yearsBetween(startDate, endDate) + 1; + return year + (horizontalCalendar.getShiftCells() * 2); + } + +} diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/HorizontalSnapHelper.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/HorizontalSnapHelper.java index eb04597..964089e 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/HorizontalSnapHelper.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/HorizontalSnapHelper.java @@ -1,10 +1,11 @@ package devs.mulham.horizontalcalendar.utils; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearSnapHelper; -import android.support.v7.widget.RecyclerView; import android.view.View; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearSnapHelper; +import androidx.recyclerview.widget.RecyclerView; + import devs.mulham.horizontalcalendar.HorizontalCalendar; import devs.mulham.horizontalcalendar.HorizontalCalendarView; diff --git a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/Utils.java b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/Utils.java index 4ff5987..615b8a0 100644 --- a/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/Utils.java +++ b/horizontalcalendar/src/main/java/devs/mulham/horizontalcalendar/utils/Utils.java @@ -108,6 +108,13 @@ public static int monthsBetween(Calendar startInclusive, Calendar endExclusive){ return (endMonth - startMonth) + (yearsDiff * 12); } + public static int yearsBetween(Calendar startInclusive, Calendar endExclusive){ + int startYear = startInclusive.get(Calendar.YEAR); + int endYear = endExclusive.get(Calendar.YEAR); + + return endYear - startYear; + } + public static void zeroTime(Calendar calendar){ calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); diff --git a/horizontalcalendar/src/main/res/layout/hc_item_calendar.xml b/horizontalcalendar/src/main/res/layout/hc_item_calendar.xml index dd4fb2c..081492f 100644 --- a/horizontalcalendar/src/main/res/layout/hc_item_calendar.xml +++ b/horizontalcalendar/src/main/res/layout/hc_item_calendar.xml @@ -1,5 +1,5 @@ - - - +