Skip to content

Commit

Permalink
Add calendar prefix for all library resources to avoid collisions with
Browse files Browse the repository at this point in the history
resources from other clients modules
  • Loading branch information
Alexander Surinov committed May 14, 2019
1 parent 354cf9a commit 1c2c907
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 51 deletions.
5 changes: 5 additions & 0 deletions crunchycalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ android {
}
}

android {
// Use resource prefix to avoid collisions with resources from other modules.
resourcePrefix 'calendar_'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ class CalendarView @JvmOverloads constructor(
* Init block where we read custom attributes and set up internal views.
*/
init {
LayoutInflater.from(context).inflate(R.layout.view_calendar, this, true)
LayoutInflater.from(context).inflate(R.layout.calendar_view, this, true)

yearSelectionView = findViewById(R.id.year_selection_view)
daysBarView = findViewById(R.id.days_bar_view)
recyclerView = findViewById(R.id.recycler_view)
yearSelectionView = findViewById(R.id.calendar_year_selection_view)
daysBarView = findViewById(R.id.calendar_days_bar_view)
recyclerView = findViewById(R.id.calendar_recycler_view)

if (attrs != null) {
CalendarStyleAttributesReader.readStyleAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class DaysBarView @JvmOverloads constructor(
}

init {
LayoutInflater.from(context).inflate(R.layout.view_days_bar, this, true)
LayoutInflater.from(context).inflate(R.layout.calendar_days_bar_view, this, true)
}

fun applyStyle(styleAttributes: CalendarStyleAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import android.content.res.ColorStateList
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View.OnClickListener
import android.view.animation.AnimationUtils
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextSwitcher
import android.widget.TextView
import androidx.annotation.AttrRes
import androidx.core.widget.ImageViewCompat
import ru.cleverpumpkin.calendar.extension.loadAnim
import ru.cleverpumpkin.calendar.style.CalendarStyleAttributes
import java.text.SimpleDateFormat
import java.util.*
Expand All @@ -35,10 +35,10 @@ internal class YearSelectionView @JvmOverloads constructor(
private val arrowNextView: ImageView
private val textSwitcher: TextSwitcher

private val slideInBottomAnim = AnimationUtils.loadAnimation(context, R.anim.slide_in_bottom)
private val slideInTopAnim = AnimationUtils.loadAnimation(context, R.anim.slide_in_top)
private val slideOutBottomAnim = AnimationUtils.loadAnimation(context, R.anim.slide_out_bottom)
private val slideOutTopAnim = AnimationUtils.loadAnimation(context, R.anim.slide_out_top)
private val slideInBottomAnim = context.loadAnim(R.anim.calendar_slide_in_bottom)
private val slideInTopAnim = context.loadAnim(R.anim.calendar_slide_in_top)
private val slideOutBottomAnim = context.loadAnim(R.anim.calendar_slide_out_bottom)
private val slideOutTopAnim = context.loadAnim(R.anim.calendar_slide_out_top)

private val yearFormatter = SimpleDateFormat(YEAR_FORMAT, Locale.getDefault())
private var minMaxDatesRange = NullableDatesRange()
Expand All @@ -60,7 +60,7 @@ internal class YearSelectionView @JvmOverloads constructor(
var onYearClickListener: ((Int) -> Unit)? = null

init {
LayoutInflater.from(context).inflate(R.layout.view_year_selection, this, true)
LayoutInflater.from(context).inflate(R.layout.calendar_year_selection_view, this, true)

arrowPrevView = findViewById(R.id.arrow_prev)
arrowNextView = findViewById(R.id.arrow_next)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal class CalendarAdapter(
}

private fun createMonthItemViewHolder(parent: ViewGroup): MonthItemViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_month, parent, false)
val view = LayoutInflater.from(parent.context).inflate(R.layout.calendar_item_month, parent, false)
return MonthItemViewHolder(view as TextView)
}

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

import android.content.Context
import android.util.TypedValue
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.annotation.AnimRes
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
Expand All @@ -17,4 +20,8 @@ fun Context.dpToPix(dpValue: Float): Float {
@ColorInt
fun Context.getColorInt(@ColorRes colorRes: Int): Int {
return ContextCompat.getColor(this, colorRes)
}

fun Context.loadAnim(@AnimRes animResId: Int): Animation {
return AnimationUtils.loadAnimation(this, animResId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromYDelta="100%p"
android:toYDelta="0" />

<alpha
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromAlpha="0.0"
android:toAlpha="1.0" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromYDelta="-100%p"
android:toYDelta="0" />

<alpha
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromAlpha="0.0"
android:toAlpha="1.0" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromYDelta="0"
android:toYDelta="100%p" />

<alpha
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromAlpha="0.0"
android:toAlpha="1.0" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromYDelta="0"
android:toYDelta="-100%p" />

<alpha
android:duration="@integer/year_anim_duration"
android:duration="@integer/calendar_year_anim_duration"
android:fromAlpha="0.0"
android:toAlpha="1.0" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
android:ellipsize="middle"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingStart="@dimen/margin_medium"
android:paddingLeft="@dimen/margin_medium"
android:paddingEnd="@dimen/margin_medium"
android:paddingRight="@dimen/margin_medium"
android:paddingStart="@dimen/calendar_margin_medium"
android:paddingLeft="@dimen/calendar_margin_medium"
android:paddingEnd="@dimen/calendar_margin_medium"
android:paddingRight="@dimen/calendar_margin_medium"
android:singleLine="true"
android:textSize="@dimen/calendar_month_text_size"
tools:text="February 2017" />
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
android:layout_height="match_parent">

<ru.cleverpumpkin.calendar.YearSelectionView
android:id="@+id/year_selection_view"
android:id="@+id/calendar_year_selection_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" />

<ru.cleverpumpkin.calendar.DaysBarView
android:id="@+id/days_bar_view"
android:id="@+id/calendar_days_bar_view"
style="@style/CalendarWeekDaysBar"
android:layout_below="@id/year_selection_view" />
android:layout_below="@id/calendar_year_selection_view" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:id="@+id/calendar_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/days_bar_view" />
android:layout_below="@id/calendar_days_bar_view" />

<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_below="@id/days_bar_view"
android:background="@drawable/shadow" />
android:layout_below="@id/calendar_days_bar_view"
android:background="@drawable/calendar_days_of_week_bar_shadow" />

</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -9,10 +10,10 @@

<ImageView
android:id="@+id/arrow_prev"
style="@style/ClickableView.YearSelectionArrow"
style="@style/CalendarClickableView.YearSelectionArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_keyboard_arrow_left_24dp"
app:srcCompat="@drawable/calendar_ic_arrow_left"
tools:ignore="ContentDescription" />

<TextSwitcher
Expand All @@ -22,13 +23,13 @@
android:layout_weight="1">

<TextView
style="@style/YearSelectionText"
style="@style/CalendarYearSelectionText"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:text="2017 Год" />

<TextView
style="@style/YearSelectionText"
style="@style/CalendarYearSelectionText"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:text="2017 Год" />
Expand All @@ -37,10 +38,10 @@

<ImageView
android:id="@+id/arrow_next"
style="@style/ClickableView.YearSelectionArrow"
style="@style/CalendarClickableView.YearSelectionArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_keyboard_arrow_right_24dp"
app:srcCompat="@drawable/calendar_ic_arrow_right"
tools:ignore="ContentDescription" />

</LinearLayout>
2 changes: 1 addition & 1 deletion crunchycalendar/src/main/res/values-ldrtl/integers.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="angle">180</integer>
<integer name="calendar_arrow_icon_angle">180</integer>
</resources>
4 changes: 2 additions & 2 deletions crunchycalendar/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="margin_small">8dp</dimen>
<dimen name="margin_medium">16dp</dimen>
<dimen name="calendar_margin_small">8dp</dimen>
<dimen name="calendar_margin_medium">16dp</dimen>

<dimen name="calendar_week_days_bar_height">24dp</dimen>
<dimen name="calendar_month_text_size">21sp</dimen>
Expand Down
4 changes: 2 additions & 2 deletions crunchycalendar/src/main/res/values/integers.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="angle">0</integer>
<integer name="year_anim_duration">300</integer>
<integer name="calendar_arrow_icon_angle">0</integer>
<integer name="calendar_year_anim_duration">300</integer>
</resources>
14 changes: 7 additions & 7 deletions crunchycalendar/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
<item name="android:gravity">center</item>
</style>

<style name="TextStyleRegular">
<style name="CalendarTextStyleRegular">
<item name="android:fontFamily">sans-serif</item>
</style>

<style name="TextStyleMedium">
<style name="CalendarTextStyleMedium">
<item name="android:fontFamily">sans-serif-medium</item>
</style>

<style name="ClickableView">
<style name="CalendarClickableView">
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
</style>

<style name="YearSelectionText">
<style name="CalendarYearSelectionText">
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textColor">@color/calendar_year_selection_text_color</item>
<item name="android:gravity">center</item>
<item name="android:textSize">16sp</item>
</style>

<style name="ClickableView.YearSelectionArrow">
<style name="CalendarClickableView.YearSelectionArrow">
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
<item name="android:padding">@dimen/margin_small</item>
<item name="android:rotationY">@integer/angle</item>
<item name="android:padding">@dimen/calendar_margin_small</item>
<item name="android:rotationY">@integer/calendar_arrow_icon_angle</item>
<item name="android:tint">@color/calendar_date_today_text_color</item>
</style>

Expand Down

0 comments on commit 1c2c907

Please sign in to comment.