Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Feb 11, 2024
1 parent 731add9 commit cbc6d0c
Show file tree
Hide file tree
Showing 49 changed files with 67 additions and 73 deletions.
14 changes: 13 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class CalendarState internal constructor(
outDateStyle: OutDateStyle,
visibleItemState: VisibleItemState?,
) : ScrollableState {

/** Backing state for [startMonth] */
private var _startMonth by mutableStateOf(startMonth)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class HeatMapCalendarState internal constructor(
firstDayOfWeek: DayOfWeek,
visibleItemState: VisibleItemState?,
) : ScrollableState {

/** Backing state for [startMonth] */
private var _startMonth by mutableStateOf(startMonth)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@ import java.util.*
@JvmOverloads
fun daysOfWeek(firstDayOfWeek: DayOfWeek = firstDayOfWeekFromLocale()): List<DayOfWeek> {
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))
}
Expand Down
7 changes: 4 additions & 3 deletions data/src/main/java/com/kizitonwose/calendar/data/MonthData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import java.time.temporal.WeekFields
@RunWith(AndroidJUnit4::class)
@LargeTest
class CalendarComposeTests {

@get:Rule
val composeTestRule = createComposeRule()

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import java.time.YearMonth
@RunWith(AndroidJUnit4::class)
@LargeTest
class CalendarViewTests {

@get:Rule
val homeScreenRule = ActivityScenarioRule(CalendarViewActivity::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import java.time.YearMonth
@RunWith(AndroidJUnit4::class)
@LargeTest
class WeekCalendarViewTests {

@get:Rule
val homeScreenRule = ActivityScenarioRule(CalendarViewActivity::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ fun Modifier.backgroundHighlight(
) {
padding(vertical = padding)
.background(color = continuousSelectionColor)
} else this
} else {
this
}
}
DayPosition.OutDate -> {
textColor(Color.Transparent)
Expand All @@ -123,7 +125,9 @@ fun Modifier.backgroundHighlight(
) {
padding(vertical = padding)
.background(color = continuousSelectionColor)
} else this
} else {
this
}
}
}
}
Expand Down Expand Up @@ -199,7 +203,9 @@ fun Modifier.backgroundHighlightLegacy(
) {
padding(vertical = padding)
.background(color = selectionColor)
} else this
} else {
this
}
}
DayPosition.OutDate -> {
textColor(Color.Transparent)
Expand All @@ -208,7 +214,9 @@ fun Modifier.backgroundHighlightLegacy(
) {
padding(vertical = padding)
.background(color = selectionColor)
} else this
} else {
this
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface HasToolbar {
interface HasBackButton

abstract class BaseFragment(@LayoutRes layoutRes: Int) : Fragment(layoutRes) {

abstract val titleRes: Int?

val activityToolbar: Toolbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ val horizontal = Animation(

class CalendarViewOptionsAdapter(val onClick: (ExampleItem) -> Unit) :
RecyclerView.Adapter<CalendarViewOptionsAdapter.HomeOptionsViewHolder>() {

val examples = listOf(
ExampleItem(
R.string.example_1_title,
Expand Down Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Example3EventsAdapter.Example3EventsViewHolder>() {

val events = mutableListOf<Event>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Example3EventsViewHolder {
Expand All @@ -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])
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import java.time.YearMonth

class Example5FlightsAdapter :
RecyclerView.Adapter<Example5FlightsAdapter.Example5FlightsViewHolder>() {

val flights = mutableListOf<Flight>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Example5FlightsViewHolder {
Expand All @@ -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)
Expand All @@ -68,7 +66,6 @@ class Example5FlightsAdapter :
}

class Example5Fragment : BaseFragment(R.layout.example_5_fragment), HasToolbar {

override val toolbar: Toolbar?
get() = null

Expand Down
Loading

0 comments on commit cbc6d0c

Please sign in to comment.