diff --git a/.editorconfig b/.editorconfig index 50d88ddb..6b37b845 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,19 @@ trim_trailing_whitespace = true [*.{kt,kts}] ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true -ktlint_standard_multiline-if-else = disabled +ktlint_standard_multiline-expression-wrapping = disabled +# string-template-indent requires multiline-expression-wrapping to be enabled +ktlint_standard_string-template-indent = disabled +ktlint_standard_parameter-list-wrapping = disabled +ktlint_standard_function-signature = disabled +ktlint_standard_blank-line-before-declaration = disabled +ktlint_standard_value-argument-comment = disabled +ktlint_function_naming_ignore_when_annotated_with = Composable +ktlint_standard_annotation = disabled +max_line_length = 200 + +[**/test/**/*.kt] +ktlint_experimental = disabled [*.md] trim_trailing_whitespace = false diff --git a/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarLayoutInfo.kt b/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarLayoutInfo.kt index d12c0f57..d78948da 100644 --- a/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarLayoutInfo.kt +++ b/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarLayoutInfo.kt @@ -13,7 +13,6 @@ import com.kizitonwose.calendar.core.CalendarMonth */ class CalendarLayoutInfo(info: LazyListLayoutInfo, private val month: (Int) -> CalendarMonth) : LazyListLayoutInfo by info { - /** * The list of [CalendarItemInfo] representing all the currently visible months. */ diff --git a/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarState.kt b/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarState.kt index 7cd45d7b..08c994eb 100644 --- a/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarState.kt +++ b/compose/src/main/java/com/kizitonwose/calendar/compose/CalendarState.kt @@ -76,7 +76,6 @@ class CalendarState internal constructor( outDateStyle: OutDateStyle, visibleItemState: VisibleItemState?, ) : ScrollableState { - /** Backing state for [startMonth] */ private var _startMonth by mutableStateOf(startMonth) diff --git a/compose/src/main/java/com/kizitonwose/calendar/compose/heatmapcalendar/HeatMapCalendarState.kt b/compose/src/main/java/com/kizitonwose/calendar/compose/heatmapcalendar/HeatMapCalendarState.kt index aef39282..1381b45d 100644 --- a/compose/src/main/java/com/kizitonwose/calendar/compose/heatmapcalendar/HeatMapCalendarState.kt +++ b/compose/src/main/java/com/kizitonwose/calendar/compose/heatmapcalendar/HeatMapCalendarState.kt @@ -72,7 +72,6 @@ class HeatMapCalendarState internal constructor( firstDayOfWeek: DayOfWeek, visibleItemState: VisibleItemState?, ) : ScrollableState { - /** Backing state for [startMonth] */ private var _startMonth by mutableStateOf(startMonth) diff --git a/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarLayoutInfo.kt b/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarLayoutInfo.kt index c199e77a..b8c7fbac 100644 --- a/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarLayoutInfo.kt +++ b/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarLayoutInfo.kt @@ -16,7 +16,6 @@ class WeekCalendarLayoutInfo( info: LazyListLayoutInfo, private val getIndexData: (Int) -> Week, ) : LazyListLayoutInfo by info { - /** * The list of [WeekCalendarItemInfo] representing all the currently visible weeks. */ diff --git a/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt b/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt index 80e62705..083f7a86 100644 --- a/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt +++ b/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt @@ -78,7 +78,6 @@ class WeekCalendarState internal constructor( firstDayOfWeek: DayOfWeek, visibleItemState: VisibleItemState?, ) : ScrollableState { - /** * The adjusted first date on the calendar to ensure proper alignment * of the provided [firstDayOfWeek]. diff --git a/compose/src/test/java/com/kizitonwose/calendar/compose/CalendarStateTests.kt b/compose/src/test/java/com/kizitonwose/calendar/compose/CalendarStateTests.kt index daab4d49..7c7eb0aa 100644 --- a/compose/src/test/java/com/kizitonwose/calendar/compose/CalendarStateTests.kt +++ b/compose/src/test/java/com/kizitonwose/calendar/compose/CalendarStateTests.kt @@ -9,7 +9,6 @@ import java.time.LocalDate import java.time.YearMonth class CalendarStateTests { - @Test fun `start month update is reflected in the state`() { val now = YearMonth.now() diff --git a/compose/src/test/java/com/kizitonwose/calendar/compose/HeatMapCalendarStateTests.kt b/compose/src/test/java/com/kizitonwose/calendar/compose/HeatMapCalendarStateTests.kt index b5d4875d..9c6367a9 100644 --- a/compose/src/test/java/com/kizitonwose/calendar/compose/HeatMapCalendarStateTests.kt +++ b/compose/src/test/java/com/kizitonwose/calendar/compose/HeatMapCalendarStateTests.kt @@ -9,7 +9,6 @@ import java.time.LocalDate import java.time.YearMonth class HeatMapCalendarStateTests { - @Test fun `start month update is reflected in the state`() { val now = YearMonth.now() diff --git a/compose/src/test/java/com/kizitonwose/calendar/compose/StateSaverTests.kt b/compose/src/test/java/com/kizitonwose/calendar/compose/StateSaverTests.kt index 606b0d42..02417ca3 100644 --- a/compose/src/test/java/com/kizitonwose/calendar/compose/StateSaverTests.kt +++ b/compose/src/test/java/com/kizitonwose/calendar/compose/StateSaverTests.kt @@ -19,7 +19,6 @@ import java.time.YearMonth * state restoration (e.g via rotation) will likely not happen often. */ class StateSaverTests { - @Test fun `month calendar state can be restored`() { val now = YearMonth.now() diff --git a/compose/src/test/java/com/kizitonwose/calendar/compose/WeekCalendarStateTests.kt b/compose/src/test/java/com/kizitonwose/calendar/compose/WeekCalendarStateTests.kt index fb0487af..15bf885a 100644 --- a/compose/src/test/java/com/kizitonwose/calendar/compose/WeekCalendarStateTests.kt +++ b/compose/src/test/java/com/kizitonwose/calendar/compose/WeekCalendarStateTests.kt @@ -9,7 +9,6 @@ import java.time.DayOfWeek import java.time.LocalDate class WeekCalendarStateTests { - @Test fun `start date update is reflected in the state`() { val now = LocalDate.now() diff --git a/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt b/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt index 7a882f93..f63f5ee1 100644 --- a/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt +++ b/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt @@ -4,7 +4,7 @@ import java.time.DayOfWeek import java.time.LocalDate import java.time.YearMonth import java.time.temporal.WeekFields -import java.util.* +import java.util.Locale /** * Returns the days of week values such that the desired @@ -15,7 +15,7 @@ import java.util.* @JvmOverloads fun daysOfWeek(firstDayOfWeek: DayOfWeek = firstDayOfWeekFromLocale()): List { val pivot = 7 - firstDayOfWeek.ordinal - val daysOfWeek = DayOfWeek.values() + val daysOfWeek = DayOfWeek.entries // Order `daysOfWeek` array so that firstDayOfWeek is at the start position. return (daysOfWeek.takeLast(pivot) + daysOfWeek.dropLast(pivot)) } diff --git a/data/src/main/java/com/kizitonwose/calendar/data/MonthData.kt b/data/src/main/java/com/kizitonwose/calendar/data/MonthData.kt index 9c7228ee..5b38d842 100644 --- a/data/src/main/java/com/kizitonwose/calendar/data/MonthData.kt +++ b/data/src/main/java/com/kizitonwose/calendar/data/MonthData.kt @@ -17,7 +17,6 @@ data class MonthData internal constructor( private val inDays: Int, private val outDays: Int, ) { - private val totalDays = inDays + month.lengthOfMonth() + outDays private val firstDay = month.atStartOfMonth().minusDays(inDays.toLong()) @@ -54,9 +53,11 @@ fun getCalendarMonthData( val inDays = firstDayOfWeek.daysUntil(firstDay.dayOfWeek) val outDays = (inDays + month.lengthOfMonth()).let { inAndMonthDays -> val endOfRowDays = if (inAndMonthDays % 7 != 0) 7 - (inAndMonthDays % 7) else 0 - val endOfGridDays = if (outDateStyle == OutDateStyle.EndOfRow) 0 else run { + val endOfGridDays = if (outDateStyle == OutDateStyle.EndOfRow) { + 0 + } else { val weeksInMonth = (inAndMonthDays + endOfRowDays) / 7 - return@run (6 - weeksInMonth) * 7 + (6 - weeksInMonth) * 7 } return@let endOfRowDays + endOfGridDays } diff --git a/data/src/test/java/com/kizitonwose/calendar/data/HeatMapDataTests.kt b/data/src/test/java/com/kizitonwose/calendar/data/HeatMapDataTests.kt index 2c371aa1..408a0d10 100644 --- a/data/src/test/java/com/kizitonwose/calendar/data/HeatMapDataTests.kt +++ b/data/src/test/java/com/kizitonwose/calendar/data/HeatMapDataTests.kt @@ -15,7 +15,6 @@ import java.time.Month.OCTOBER import java.time.YearMonth class HeatMapDataTests { - private val october2022 = YearMonth.of(2022, OCTOBER) private val november2022 = YearMonth.of(2022, NOVEMBER) private val december2022 = YearMonth.of(2022, DECEMBER) diff --git a/data/src/test/java/com/kizitonwose/calendar/data/MonthDataTests.kt b/data/src/test/java/com/kizitonwose/calendar/data/MonthDataTests.kt index dc37516d..71a0e1f8 100644 --- a/data/src/test/java/com/kizitonwose/calendar/data/MonthDataTests.kt +++ b/data/src/test/java/com/kizitonwose/calendar/data/MonthDataTests.kt @@ -15,7 +15,6 @@ import java.time.Month.NOVEMBER import java.time.YearMonth class MonthDataTests { - private val may2019 = YearMonth.of(2019, MAY) private val november2019 = YearMonth.of(2019, NOVEMBER) private val firstDayOfWeek = DayOfWeek.MONDAY diff --git a/data/src/test/java/com/kizitonwose/calendar/data/WeekDataTests.kt b/data/src/test/java/com/kizitonwose/calendar/data/WeekDataTests.kt index c3cf97b7..deea9e77 100644 --- a/data/src/test/java/com/kizitonwose/calendar/data/WeekDataTests.kt +++ b/data/src/test/java/com/kizitonwose/calendar/data/WeekDataTests.kt @@ -13,7 +13,6 @@ import java.time.Month.NOVEMBER import java.time.YearMonth class WeekDataTests { - private val may2019 = YearMonth.of(2019, MAY) private val november2019 = YearMonth.of(2019, NOVEMBER) private val firstDayOfWeek = DayOfWeek.MONDAY diff --git a/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarComposeTests.kt b/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarComposeTests.kt index 099f68a0..4efb7bf6 100644 --- a/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarComposeTests.kt +++ b/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarComposeTests.kt @@ -45,7 +45,6 @@ import java.time.temporal.WeekFields @RunWith(AndroidJUnit4::class) @LargeTest class CalendarComposeTests { - @get:Rule val composeTestRule = createComposeRule() @@ -132,11 +131,11 @@ class CalendarComposeTests { .size.height assertEquals( - /* expected = */ + // expected monthHeight.value, - /* actual = */ + // actual headerHeight.value + firstDayHeight.value * weeksInMonth, - /* delta = */ + // delta firstDayHeight.value, // Account for when larger adjacent month is used as calendar height. ) assertNotEquals(0, headerHeight) diff --git a/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarViewTests.kt b/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarViewTests.kt index f9ae60c5..0505b08a 100644 --- a/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarViewTests.kt +++ b/sample/src/androidTest/java/com/kizitonwose/calendar/sample/CalendarViewTests.kt @@ -42,7 +42,6 @@ import java.time.YearMonth @RunWith(AndroidJUnit4::class) @LargeTest class CalendarViewTests { - @get:Rule val homeScreenRule = ActivityScenarioRule(CalendarViewActivity::class.java) diff --git a/sample/src/androidTest/java/com/kizitonwose/calendar/sample/WeekCalendarViewTests.kt b/sample/src/androidTest/java/com/kizitonwose/calendar/sample/WeekCalendarViewTests.kt index 694bb025..6dbcc75a 100644 --- a/sample/src/androidTest/java/com/kizitonwose/calendar/sample/WeekCalendarViewTests.kt +++ b/sample/src/androidTest/java/com/kizitonwose/calendar/sample/WeekCalendarViewTests.kt @@ -31,7 +31,6 @@ import java.time.YearMonth @RunWith(AndroidJUnit4::class) @LargeTest class WeekCalendarViewTests { - @get:Rule val homeScreenRule = ActivityScenarioRule(CalendarViewActivity::class.java) diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/HomeActivity.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/HomeActivity.kt index 54188919..43910049 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/HomeActivity.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/HomeActivity.kt @@ -8,7 +8,6 @@ import com.kizitonwose.calendar.sample.databinding.HomeActivityBinding import com.kizitonwose.calendar.sample.view.CalendarViewActivity class HomeActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = HomeActivityBinding.inflate(layoutInflater) diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/compose/CalendarComposeActivity.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/compose/CalendarComposeActivity.kt index e0e6a971..dadd1eef 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/compose/CalendarComposeActivity.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/compose/CalendarComposeActivity.kt @@ -27,7 +27,6 @@ import com.kizitonwose.calendar.sample.shared.dateRangeDisplayText import kotlinx.coroutines.launch class CalendarComposeActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example2PageHighlight.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example2PageHighlight.kt index b3697f50..a90030f2 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example2PageHighlight.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example2PageHighlight.kt @@ -114,7 +114,9 @@ fun Modifier.backgroundHighlight( ) { padding(vertical = padding) .background(color = continuousSelectionColor) - } else this + } else { + this + } } DayPosition.OutDate -> { textColor(Color.Transparent) @@ -123,7 +125,9 @@ fun Modifier.backgroundHighlight( ) { padding(vertical = padding) .background(color = continuousSelectionColor) - } else this + } else { + this + } } } } @@ -199,7 +203,9 @@ fun Modifier.backgroundHighlightLegacy( ) { padding(vertical = padding) .background(color = selectionColor) - } else this + } else { + this + } } DayPosition.OutDate -> { textColor(Color.Transparent) @@ -208,7 +214,9 @@ fun Modifier.backgroundHighlightLegacy( ) { padding(vertical = padding) .background(color = selectionColor) - } else this + } else { + this + } } } } diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example3Page.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example3Page.kt index c48e88cc..f494f6b6 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example3Page.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example3Page.kt @@ -61,7 +61,7 @@ import com.kizitonwose.calendar.sample.shared.generateFlights import kotlinx.coroutines.launch import java.time.DayOfWeek import java.time.YearMonth -import java.util.* +import java.util.Locale private val flights = generateFlights().groupBy { it.time.toLocalDate() } diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/shared/ContinuousSelectionHelper.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/shared/ContinuousSelectionHelper.kt index aa5f9204..76d7495c 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/shared/ContinuousSelectionHelper.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/shared/ContinuousSelectionHelper.kt @@ -11,7 +11,9 @@ import kotlin.LazyThreadSafetyMode.NONE data class DateSelection(val startDate: LocalDate? = null, val endDate: LocalDate? = null) { val daysBetween by lazy(NONE) { - if (startDate == null || endDate == null) null else { + if (startDate == null || endDate == null) { + null + } else { ChronoUnit.DAYS.between(startDate, endDate) } } diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/shared/Utils.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/shared/Utils.kt index 7da9425b..798103c1 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/shared/Utils.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/shared/Utils.kt @@ -9,7 +9,7 @@ import java.time.DayOfWeek import java.time.Month import java.time.YearMonth import java.time.format.TextStyle -import java.util.* +import java.util.Locale fun YearMonth.displayText(short: Boolean = false): String { return "${this.month.displayText(short = short)} ${this.year}" diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/BaseFragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/BaseFragment.kt index ef34979c..974a5afc 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/BaseFragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/BaseFragment.kt @@ -13,7 +13,6 @@ interface HasToolbar { interface HasBackButton abstract class BaseFragment(@LayoutRes layoutRes: Int) : Fragment(layoutRes) { - abstract val titleRes: Int? val activityToolbar: Toolbar diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewActivity.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewActivity.kt index 7cb1104d..6c9cc9f1 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewActivity.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewActivity.kt @@ -10,7 +10,6 @@ import com.kizitonwose.calendar.sample.R import com.kizitonwose.calendar.sample.databinding.CalendarViewActivityBinding class CalendarViewActivity : AppCompatActivity() { - internal lateinit var binding: CalendarViewActivityBinding private val examplesAdapter = CalendarViewOptionsAdapter { diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewOptionsAdapter.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewOptionsAdapter.kt index 91ac8079..e72c1f70 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewOptionsAdapter.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/CalendarViewOptionsAdapter.kt @@ -37,7 +37,6 @@ val horizontal = Animation( class CalendarViewOptionsAdapter(val onClick: (ExampleItem) -> Unit) : RecyclerView.Adapter() { - val examples = listOf( ExampleItem( R.string.example_1_title, @@ -99,7 +98,6 @@ class CalendarViewOptionsAdapter(val onClick: (ExampleItem) -> Unit) : inner class HomeOptionsViewHolder(private val binding: CalendarViewOptionsItemViewBinding) : RecyclerView.ViewHolder(binding.root) { - init { itemView.setOnClickListener { onClick(examples[bindingAdapterPosition]) diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example1Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example1Fragment.kt index 0fd25f32..4f767217 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example1Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example1Fragment.kt @@ -35,7 +35,6 @@ import java.time.LocalDate import java.time.YearMonth class Example1Fragment : BaseFragment(R.layout.example_1_fragment), HasToolbar { - override val toolbar: Toolbar? get() = null diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example2Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example2Fragment.kt index b823de07..f242580c 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example2Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example2Fragment.kt @@ -26,7 +26,6 @@ import java.time.YearMonth import java.time.format.DateTimeFormatter class Example2Fragment : BaseFragment(R.layout.example_2_fragment), HasToolbar, HasBackButton { - override val toolbar: Toolbar get() = binding.exTwoToolbar diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt index b7326eae..2c70aead 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt @@ -32,13 +32,12 @@ import java.time.DayOfWeek import java.time.LocalDate import java.time.YearMonth import java.time.format.DateTimeFormatter -import java.util.* +import java.util.UUID data class Event(val id: String, val text: String, val date: LocalDate) class Example3EventsAdapter(val onClick: (Event) -> Unit) : RecyclerView.Adapter() { - val events = mutableListOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Example3EventsViewHolder { @@ -55,7 +54,6 @@ class Example3EventsAdapter(val onClick: (Event) -> Unit) : inner class Example3EventsViewHolder(private val binding: Example3EventItemViewBinding) : RecyclerView.ViewHolder(binding.root) { - init { itemView.setOnClickListener { onClick(events[bindingAdapterPosition]) @@ -69,7 +67,6 @@ class Example3EventsAdapter(val onClick: (Event) -> Unit) : } class Example3Fragment : BaseFragment(R.layout.example_3_fragment), HasBackButton { - private val eventsAdapter = Example3EventsAdapter { AlertDialog.Builder(requireContext()) .setMessage(R.string.example_3_dialog_delete_confirmation) diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example4Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example4Fragment.kt index 77991a07..aefcf2f3 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example4Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example4Fragment.kt @@ -36,7 +36,6 @@ import java.time.YearMonth import java.time.format.DateTimeFormatter class Example4Fragment : BaseFragment(R.layout.example_4_fragment), HasToolbar, HasBackButton { - override val toolbar: Toolbar get() = binding.exFourToolbar diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example5Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example5Fragment.kt index 282b283d..f8739cc2 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example5Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example5Fragment.kt @@ -34,7 +34,6 @@ import java.time.YearMonth class Example5FlightsAdapter : RecyclerView.Adapter() { - val flights = mutableListOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Example5FlightsViewHolder { @@ -51,7 +50,6 @@ class Example5FlightsAdapter : inner class Example5FlightsViewHolder(val binding: Example5EventItemViewBinding) : RecyclerView.ViewHolder(binding.root) { - fun bind(flight: Flight) { binding.itemFlightDateText.apply { text = flightDateTimeFormatter.format(flight.time) @@ -68,7 +66,6 @@ class Example5FlightsAdapter : } class Example5Fragment : BaseFragment(R.layout.example_5_fragment), HasToolbar { - override val toolbar: Toolbar? get() = null diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example6Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example6Fragment.kt index 1c0061d1..7095711d 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example6Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example6Fragment.kt @@ -50,7 +50,6 @@ import java.time.YearMonth * proguard examples above with your class full qualified name. */ class Example6MonthView @Keep constructor(context: Context) : CardView(context) { - init { setCardBackgroundColor(context.getColorCompat(R.color.example_6_month_bg_color)) radius = dpToPx(8, context).toFloat() @@ -59,7 +58,6 @@ class Example6MonthView @Keep constructor(context: Context) : CardView(context) } class Example6Fragment : BaseFragment(R.layout.example_6_fragment), HasBackButton { - override val titleRes: Int = R.string.example_6_title private lateinit var binding: Example6FragmentBinding diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example7Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example7Fragment.kt index f51e1858..86f38f6c 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example7Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example7Fragment.kt @@ -19,7 +19,6 @@ import java.time.YearMonth import java.time.format.DateTimeFormatter class Example7Fragment : BaseFragment(R.layout.example_7_fragment), HasToolbar, HasBackButton { - override val titleRes: Int = R.string.example_7_title override val toolbar: Toolbar diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example8Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example8Fragment.kt index 89a3c6e1..abb9adbd 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example8Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example8Fragment.kt @@ -23,7 +23,6 @@ import java.time.LocalDate import java.time.YearMonth class Example8Fragment : BaseFragment(R.layout.example_8_fragment), HasToolbar { - override val toolbar: Toolbar? = null override val titleRes: Int? = null diff --git a/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt b/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt index fd6d61ce..7e877edf 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt @@ -20,7 +20,6 @@ import java.time.LocalDate import java.time.YearMonth open class CalendarView : RecyclerView { - /** * The [MonthDayBinder] instance used for managing day * cell view creation and reuse on the calendar. @@ -352,6 +351,7 @@ open class CalendarView : RecyclerView { // method is called with named args: notifyDateChanged(date = *, position = DayPosition.*) // because assigning single elements to varargs in named form is not allowed. // May consider removing the other one at some point. + /** * Notify the CalendarView to reload the cells for this [LocalDate] in the * specified day positions. This causes [MonthDayBinder.bind] to be called diff --git a/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt b/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt index 29d56379..dfc6a935 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt @@ -15,7 +15,6 @@ import java.time.DayOfWeek import java.time.LocalDate open class WeekCalendarView : RecyclerView { - /** * The [WeekDayBinder] instance used for managing day * cell view creation and reuse. diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt index 7b0583c3..292f2d27 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt @@ -12,7 +12,6 @@ internal abstract class CalendarLayoutManager( private val calView: RecyclerView, @RecyclerView.Orientation orientation: Int, ) : LinearLayoutManager(calView.context, orientation, false) { - abstract fun getaItemAdapterPosition(data: IndexData): Int abstract fun getaDayAdapterPosition(data: DayData): Int abstract fun getDayTag(data: DayData): Int @@ -70,7 +69,6 @@ internal abstract class CalendarLayoutManager( private inner class CalendarSmoothScroller(position: Int, val day: DayData?) : LinearSmoothScroller(calView.context) { - init { targetPosition = position } diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelper.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelper.kt index 1d275c97..c9b82bb0 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelper.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelper.kt @@ -23,7 +23,6 @@ import kotlin.math.abs * or left(in horizontal) to match at the end of the snap. */ internal class CalendarPageSnapHelper : PagerSnapHelper() { - private var recyclerView: RecyclerView? = null private var flingTargetPosition: Int? = null private var scrollAction: ScrollAction? = null @@ -41,11 +40,15 @@ internal class CalendarPageSnapHelper : PagerSnapHelper() { return IntArray(2).apply { this[0] = if (lm.canScrollHorizontally()) { distanceToStart(targetView, getHorizontalHelper(lm)) - } else 0 + } else { + 0 + } this[1] = if (lm.canScrollVertically()) { distanceToStart(targetView, getVerticalHelper(lm)) - } else 0 + } else { + 0 + } } } @@ -74,7 +77,9 @@ internal class CalendarPageSnapHelper : PagerSnapHelper() { val firstVisibleItemPosition = findFirstVisibleItemPositionInLayout(lm) val firstVisibleItem = lm.findViewByPosition(firstVisibleItemPosition) ?: return null val firstVisibleItemDistanceToStart = distanceToStart(firstVisibleItem, helper) - if (firstVisibleItemDistanceToStart == 0) null else { + if (firstVisibleItemDistanceToStart == 0) { + null + } else { when (scrollAction) { Forward -> { if ( @@ -88,6 +93,7 @@ internal class CalendarPageSnapHelper : PagerSnapHelper() { firstVisibleItem } } + Backward -> { val nextPos = (firstVisibleItemPosition + increment).coerceIn(lm.indices) val nextItem = lm.findViewByPosition(nextPos) ?: return firstVisibleItem @@ -100,6 +106,7 @@ internal class CalendarPageSnapHelper : PagerSnapHelper() { firstVisibleItem } } + Layout -> firstVisibleItem null -> firstVisibleItem } @@ -177,7 +184,9 @@ internal class CalendarPageSnapHelper : PagerSnapHelper() { } private enum class ScrollAction { - Forward, Backward, Layout + Forward, + Backward, + Layout, } private val LayoutManager.indices: IntRange get() = 0 until itemCount diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelperLegacy.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelperLegacy.kt index 2f2dd6ee..fbdf0a1b 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelperLegacy.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarPageSnapHelperLegacy.kt @@ -6,7 +6,6 @@ import androidx.recyclerview.widget.PagerSnapHelper import androidx.recyclerview.widget.RecyclerView internal class CalendarPageSnapHelperLegacy : PagerSnapHelper() { - /** * The default implementation of this method in [PagerSnapHelper.calculateDistanceToFinalSnap] uses the distance * between the target view center vs RecyclerView center as final snap distance. This does not always give the @@ -25,11 +24,15 @@ internal class CalendarPageSnapHelperLegacy : PagerSnapHelper() { return IntArray(2).apply { this[0] = if (layoutManager.canScrollHorizontally()) { distanceToStart(targetView, getHorizontalHelper(layoutManager)) - } else 0 + } else { + 0 + } this[1] = if (layoutManager.canScrollVertically()) { distanceToStart(targetView, getVerticalHelper(layoutManager)) - } else 0 + } else { + 0 + } } } diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/DayHolder.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/DayHolder.kt index f59f3cc4..4a03e2d4 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/DayHolder.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/DayHolder.kt @@ -19,7 +19,6 @@ internal data class DayConfig( ) internal class DayHolder(private val config: DayConfig) { - private lateinit var dayView: View private lateinit var viewContainer: ViewContainer private var day: Day? = null diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt index 6ecd9eb0..4d0cd1c9 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt @@ -41,7 +41,9 @@ internal fun setupItemRoot( rootLayout.inflate(itemHeaderResource).also { headerView -> rootLayout.addView(headerView) } - } else null + } else { + null + } @Suppress("UNCHECKED_CAST") val dayConfig = DayConfig( @@ -63,7 +65,9 @@ internal fun setupItemRoot( rootLayout.inflate(itemFooterResource).also { footerView -> rootLayout.addView(footerView) } - } else null + } else { + null + } fun setupRoot(root: ViewGroup) { val width = if (daySize.parentDecidesWidth) MATCH_PARENT else WRAP_CONTENT diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt index 8d111f84..954c6502 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt @@ -41,7 +41,6 @@ internal class WeekHolder( private val daySize: DaySize, private val dayHolders: List>, ) { - private lateinit var weekContainer: LinearLayout fun inflateWeekView(parent: LinearLayout): View { diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarAdapter.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarAdapter.kt index 913f5d77..46408d0c 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarAdapter.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarAdapter.kt @@ -34,7 +34,6 @@ internal class MonthCalendarAdapter( private var endMonth: YearMonth, private var firstDayOfWeek: DayOfWeek, ) : RecyclerView.Adapter() { - private var itemCount = getMonthIndicesCount(startMonth, endMonth) private val dataStore = DataStore { offset -> getCalendarMonthData(startMonth, offset, firstDayOfWeek, outDateStyle).calendarMonth diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarLayoutManager.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarLayoutManager.kt index 32eae05f..0cb3fbed 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarLayoutManager.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthCalendarLayoutManager.kt @@ -9,7 +9,6 @@ import java.time.YearMonth internal class MonthCalendarLayoutManager(private val calView: CalendarView) : CalendarLayoutManager(calView, calView.orientation) { - private val adapter: MonthCalendarAdapter get() = calView.adapter as MonthCalendarAdapter diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt index 5f55e4d4..be0554ea 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt @@ -17,7 +17,6 @@ internal class MonthViewHolder( private var monthHeaderBinder: MonthHeaderFooterBinder?, private var monthFooterBinder: MonthHeaderFooterBinder?, ) : RecyclerView.ViewHolder(rootLayout) { - private var headerContainer: ViewContainer? = null private var footerContainer: ViewContainer? = null diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarAdapter.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarAdapter.kt index 64b704d9..b5f02c64 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarAdapter.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarAdapter.kt @@ -28,7 +28,6 @@ internal class WeekCalendarAdapter( private var endDate: LocalDate, private var firstDayOfWeek: DayOfWeek, ) : RecyclerView.Adapter() { - private var adjustedData = getWeekCalendarAdjustedRange(startDate, endDate, firstDayOfWeek) private val startDateAdjusted: LocalDate get() = adjustedData.startDateAdjusted private val endDateAdjusted: LocalDate get() = adjustedData.endDateAdjusted diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarLayoutManager.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarLayoutManager.kt index af34aebf..98add2e8 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarLayoutManager.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekCalendarLayoutManager.kt @@ -8,7 +8,6 @@ import java.time.LocalDate internal class WeekCalendarLayoutManager(private val calView: WeekCalendarView) : CalendarLayoutManager(calView, HORIZONTAL) { - private val adapter: WeekCalendarAdapter get() = calView.adapter as WeekCalendarAdapter diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt index 5ed4a41a..8466b4d1 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt @@ -17,7 +17,6 @@ internal class WeekViewHolder( private var weekHeaderBinder: WeekHeaderFooterBinder?, private var weekFooterBinder: WeekHeaderFooterBinder?, ) : RecyclerView.ViewHolder(rootLayout) { - private var headerContainer: ViewContainer? = null private var footerContainer: ViewContainer? = null