Skip to content

Commit

Permalink
Migrate from legacy Support Libraries to the new AndroidX packages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsurinov committed Apr 7, 2019
1 parent 591309b commit 5737bf6
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 63 deletions.
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ buildscript {
version_code : 1,
version_name : '1.1.0',
min_sdk_version : 16,
target_sdk_version : 27,
compile_sdk_version: 27
target_sdk_version : 28,
compile_sdk_version: 28
]

// 3-rd party libraries versions
libs = [
kotlin_version : '1.2.61',
kotlin_version : '1.3.21',
supportX : '1.0.0',
support_lib_version: '27.1.1',

// libs for testing
junit_version : '4.12',
mockito_version : '1.10.19',
powermock_version : '1.6.2'
junit_version : '4.12',
mockito_version : '1.10.19',
powermock_version : '1.6.2'
]

// Gradle plugins versions
gradle_plugins = [
android_plugin_version: '3.1.4',
android_plugin_version: '3.3.2',
kotlin_plugin_version : libs.kotlin_version,
bintray_plugin_version: '1.8.0',
maven_plugin_version: '2.0'
maven_plugin_version : '2.0'
]
}

Expand Down
5 changes: 2 additions & 3 deletions crunchycalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ dependencies {
// Kotlin language standard lib
implementation "org.jetbrains.kotlin:kotlin-stdlib:$libs.kotlin_version"

// Support libraries
implementation "com.android.support:appcompat-v7:$libs.support_lib_version"
implementation "com.android.support:recyclerview-v7:$libs.support_lib_version"
// AndroidX.
implementation "androidx.recyclerview:recyclerview:$libs.supportX"

// JUnit
testImplementation "junit:junit:$libs.junit_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Canvas
import android.graphics.Paint
import android.support.annotation.AttrRes
import android.text.TextPaint
import android.util.AttributeSet
import android.view.View
import androidx.annotation.AttrRes
import ru.cleverpumpkin.calendar.utils.dpToPix
import ru.cleverpumpkin.calendar.utils.getColorInt
import ru.cleverpumpkin.calendar.utils.spToPix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package ru.cleverpumpkin.calendar
import android.content.Context
import android.os.Bundle
import android.os.Parcelable
import android.support.annotation.AttrRes
import android.support.v4.util.ArrayMap
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.AttrRes
import androidx.collection.ArrayMap
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ru.cleverpumpkin.calendar.adapter.CalendarAdapter
import ru.cleverpumpkin.calendar.adapter.CalendarItemsGenerator
import ru.cleverpumpkin.calendar.adapter.item.DateItem
Expand Down Expand Up @@ -93,7 +93,7 @@ class CalendarView @JvmOverloads constructor(
/**
* Selection is unavailable. No dates will be selectable.
*/
NON,
NONE,

/**
* Only one date can be selected at a time.
Expand Down Expand Up @@ -139,12 +139,12 @@ class CalendarView @JvmOverloads constructor(
private val dateInfoProvider: DateInfoProvider = DefaultDateInfoProvider()
private val adapterDataManager: AdapterDataManager

private var selectionMode: SelectionMode = SelectionMode.NON
private var selectionMode: SelectionMode = SelectionMode.NONE
set(value) {
field = value

dateSelectionStrategy = when (value) {
SelectionMode.NON -> {
SelectionMode.NONE -> {
NoDateSelectionStrategy()
}
SelectionMode.SINGLE -> {
Expand Down Expand Up @@ -199,7 +199,7 @@ class CalendarView @JvmOverloads constructor(
field = value
groupedDatesIndicators.clear()
value.groupByTo(groupedDatesIndicators) { it.date }
recyclerView.adapter.notifyDataSetChanged()
recyclerView.adapter?.notifyDataSetChanged()
}

/**
Expand Down Expand Up @@ -230,7 +230,7 @@ class CalendarView @JvmOverloads constructor(
* Returns selected dates according to the [selectionMode].
*
* When selection mode is:
* [SelectionMode.NON] returns empty list
* [SelectionMode.NONE] returns empty list
* [SelectionMode.SINGLE] returns list with a single selected date
* [SelectionMode.MULTIPLE] returns all selected dates in order they were added
* [SelectionMode.RANGE] returns all dates in selected range
Expand Down Expand Up @@ -367,7 +367,7 @@ class CalendarView @JvmOverloads constructor(

gridLayoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return when (recyclerView.adapter.getItemViewType(position)) {
return when (recyclerView.adapter?.getItemViewType(position)) {
CalendarAdapter.MONTH_VIEW_TYPE -> DAYS_IN_WEEK
else -> 1
}
Expand Down Expand Up @@ -413,7 +413,7 @@ class CalendarView @JvmOverloads constructor(
* Default value - null
*
* [selectionMode] mode for dates selecting.
* Default value - [SelectionMode.NON]
* Default value - [SelectionMode.NONE]
*
* When selection mode is:
* [SelectionMode.SINGLE], [selectedDates] should contains only single date.
Expand All @@ -434,7 +434,7 @@ class CalendarView @JvmOverloads constructor(
initialDate: CalendarDate = CalendarDate.today,
minDate: CalendarDate? = null,
maxDate: CalendarDate? = null,
selectionMode: SelectionMode = SelectionMode.NON,
selectionMode: SelectionMode = SelectionMode.NONE,
selectedDates: List<CalendarDate> = emptyList(),
firstDayOfWeek: Int = defaultFirstDayOfWeek,
showYearSelectionView: Boolean = true
Expand Down Expand Up @@ -538,7 +538,7 @@ class CalendarView @JvmOverloads constructor(
}

when {
selectionMode == SelectionMode.NON -> {
selectionMode == SelectionMode.NONE -> {
throw IllegalArgumentException(
"You cannot define selected dates when the SelectionMode is NONE"
)
Expand Down Expand Up @@ -731,19 +731,26 @@ class CalendarView @JvmOverloads constructor(
super.onRestoreInstanceState(superState)

if (initializedWithSetup.not()) {
val modeName = state.getString(BUNDLE_SELECTION_MODE, SelectionMode.NON.name)
val modeName = state.getString(BUNDLE_SELECTION_MODE, SelectionMode.NONE.name)
selectionMode = SelectionMode.valueOf(modeName)

displayDatesRange = state.getParcelable(BUNDLE_DISPLAY_DATE_RANGE)
?: displayDatesRange

minMaxDatesRange = state.getParcelable(BUNDLE_LIMIT_DATE_RANGE)
?:minMaxDatesRange

showYearSelectionView = state.getBoolean(BUNDLE_SHOW_YEAR_SELECTION_VIEW)
firstDayOfWeek = state.getInt(BUNDLE_FIRST_DAY_OF_WEEK)
dateSelectionStrategy.restoreSelectedDates(state)

val displayedDate: CalendarDate = state.getParcelable(BUNDLE_DISPLAYED_DATE)
yearSelectionView.setupYearSelectionView(
displayedDate = displayedDate,
minMaxDatesRange = minMaxDatesRange
)
val displayedDate: CalendarDate? = state.getParcelable(BUNDLE_DISPLAYED_DATE)
if (displayedDate != null) {
yearSelectionView.setupYearSelectionView(
displayedDate = displayedDate,
minMaxDatesRange = minMaxDatesRange
)
}

generateCalendarItems(displayDatesRange)
}
Expand Down Expand Up @@ -785,15 +792,15 @@ class CalendarView @JvmOverloads constructor(
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)

val lastChildIndex = recyclerView.layoutManager.childCount
val lastChild = recyclerView.layoutManager.getChildAt(lastChildIndex - 1)
val lastChildIndex = recyclerView.layoutManager?.childCount ?: return
val lastChild = recyclerView.layoutManager?.getChildAt(lastChildIndex - 1) ?: return
val lastChildAdapterPosition = recyclerView.getChildAdapterPosition(lastChild) + 1

if (recyclerView.adapter.itemCount == lastChildAdapterPosition) {
if (recyclerView.adapter?.itemCount == lastChildAdapterPosition) {
recyclerView.post { generateNextCalendarItems() }
}

val firstChild = recyclerView.layoutManager.getChildAt(0)
val firstChild = recyclerView.layoutManager?.getChildAt(0) ?: return
val firstChildAdapterPosition = recyclerView.getChildAdapterPosition(firstChild)

if (firstChildAdapterPosition == 0) {
Expand All @@ -807,7 +814,7 @@ class CalendarView @JvmOverloads constructor(
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)

val firstChild = recyclerView.layoutManager.getChildAt(0)
val firstChild = recyclerView.layoutManager?.getChildAt(0) ?: return
val firstChildAdapterPosition = recyclerView.getChildAdapterPosition(firstChild)

val calendarItem = calendarAdapter.getCalendarItemAt(firstChildAdapterPosition)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ru.cleverpumpkin.calendar

import android.content.Context
import android.support.annotation.AttrRes
import android.support.annotation.ColorInt
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import java.text.SimpleDateFormat
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package ru.cleverpumpkin.calendar

import android.content.Context
import android.content.res.ColorStateList
import android.support.annotation.AttrRes
import android.support.annotation.ColorInt
import android.support.v4.widget.ImageViewCompat
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View.OnClickListener
Expand All @@ -13,6 +10,9 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextSwitcher
import android.widget.TextView
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.core.widget.ImageViewCompat
import java.text.SimpleDateFormat
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ru.cleverpumpkin.calendar.adapter

import android.content.Context
import android.support.annotation.ColorInt
import android.support.annotation.ColorRes
import android.support.annotation.DrawableRes
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import ru.cleverpumpkin.calendar.CalendarDate
import ru.cleverpumpkin.calendar.CalendarDateView
import ru.cleverpumpkin.calendar.CalendarView
Expand All @@ -21,7 +21,6 @@ import ru.cleverpumpkin.calendar.adapter.item.CalendarItem
import ru.cleverpumpkin.calendar.adapter.item.DateItem
import ru.cleverpumpkin.calendar.adapter.item.EmptyItem
import ru.cleverpumpkin.calendar.adapter.item.MonthItem
import java.lang.IllegalStateException
import java.text.SimpleDateFormat
import java.util.*

Expand Down Expand Up @@ -151,8 +150,7 @@ internal class CalendarAdapter(
dateView.isDateSelected = dateInfoProvider.isDateSelected(date)

dateView.isDateDisabled =
dateInfoProvider.isDateOutOfRange(date) ||
dateInfoProvider.isDateSelectable(date).not()
dateInfoProvider.isDateOutOfRange(date) || dateInfoProvider.isDateSelectable(date).not()

dateView.isWeekend = dateInfoProvider.isWeekend(date)
dateView.dateIndicators = dateInfoProvider.getDateIndicators(date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ru.cleverpumpkin.calendar.decorations

import android.graphics.Canvas
import android.graphics.Rect
import android.support.v7.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView
import ru.cleverpumpkin.calendar.CalendarDate
import ru.cleverpumpkin.calendar.adapter.CalendarAdapter
import ru.cleverpumpkin.calendar.adapter.item.DateItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ru.cleverpumpkin.calendar.decorations
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.support.annotation.ColorInt
import android.support.v7.widget.RecyclerView
import androidx.annotation.ColorInt
import androidx.recyclerview.widget.RecyclerView
import ru.cleverpumpkin.calendar.CalendarDateView
import ru.cleverpumpkin.calendar.R
import ru.cleverpumpkin.calendar.utils.dpToPix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal class MultipleDateSelectionStrategy(

override fun restoreSelectedDates(bundle: Bundle) {
val selectedDatesArray = bundle.getParcelableArray(BUNDLE_SELECTED_DATES)
selectedDatesArray.mapTo(selectedDates) { it as CalendarDate }
selectedDatesArray?.mapTo(selectedDates) { it as CalendarDate }
}

override fun clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ internal class RangeDateSelectionStrategy(
}

override fun restoreSelectedDates(bundle: Bundle) {
datesRange = bundle.getParcelable(BUNDLE_DATES_RANGE)
datesRange = bundle.getParcelable(BUNDLE_DATES_RANGE) ?: datesRange
}

override fun clear() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ru.cleverpumpkin.calendar.utils

import android.content.Context
import android.support.annotation.ColorInt
import android.support.annotation.ColorRes
import android.support.v4.content.ContextCompat
import android.util.TypedValue
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat

fun Context.spToPix(spValue: Float): Float {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, resources.displayMetrics)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ru.cleverpumpkin.calendar.utils

import android.support.annotation.ColorInt
import android.support.annotation.ColorRes
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes

@ColorInt
fun View.getColorInt(@ColorRes colorRes: Int): Int {
Expand Down
5 changes: 3 additions & 2 deletions crunchycalendar/src/main/res/layout/view_calendar.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -14,7 +15,7 @@
style="@style/CalendarWeekDaysBar"
android:layout_below="@id/year_selection_view" />

<android.support.v7.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 28 17:26:21 MSK 2018
#Sun Apr 07 13:01:29 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip

0 comments on commit 5737bf6

Please sign in to comment.