Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
m-i-n-a-r committed Mar 9, 2023
1 parent 6eee54c commit def4215
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion tasticalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.m-i-n-a-r'
artifactId = 'tasticalendar'
version = '1.2.1'
version = '1.2.2'

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,33 +441,13 @@ class TastiCalendarMonth(context: Context, attrs: AttributeSet) : LinearLayout(c

// Show snack bars on month header press
if (showSnackBars) {
var prefix = ""
try {
prefix = if (snackBarsPluralFormatting && snackBarsPrefix != null) {
String.format(
context.resources.getQuantityString(snackBarsPrefix!!, eventCount),
eventCount
)
} else context.getString(snackBarsPrefix!!)
} catch (_: Exception) {
snackBarsPrefix = null
snackBarsPluralFormatting = false
}

// Build the final, formatted message for the month header
val snackMessage = if (prefix.isNotEmpty())
if (snackBarsPluralFormatting) prefix
else "$prefix $eventCount"
else "-> $eventCount"
// Capitalize the first character
snackMessage.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.ROOT)
else it.toString()
}

// Set the appropriate header
monthTitle.setOnClickListener {
showSnackbar(snackMessage, snackBarsBaseView ?: binding.root, snackBarsDuration)
showSnackbar(
getSnackMessage(),
snackBarsBaseView ?: binding.root,
snackBarsDuration
)
}
} else {
// Else remove any click listener
Expand All @@ -489,12 +469,12 @@ class TastiCalendarMonth(context: Context, attrs: AttributeSet) : LinearLayout(c
var dayEvents = mutableListOf<TastiCalendarEvent>()
for (event in finalList) {
// Compute the snackbar text
if (event.date.isEqual(currentDate.withYear(event.date.year))) {
if (event.date.withYear(1970).isEqual(currentDate.withYear(1970))) {
dayEvents.add(event)
} else {
dayEvents = mutableListOf()
dayEvents.add(event)
currentDate = event.date
currentDate = event.date.withYear(1970)
}
// Highlight the dates
highlightDay(
Expand All @@ -517,6 +497,36 @@ class TastiCalendarMonth(context: Context, attrs: AttributeSet) : LinearLayout(c
}
}

/**
* Obtains the message to display in the snackbar, dynamically
*/
private fun getSnackMessage(): String {
var prefix = ""
try {
prefix = if (snackBarsPluralFormatting && snackBarsPrefix != null) {
String.format(
context.resources.getQuantityString(snackBarsPrefix!!, eventCount),
eventCount
)
} else context.getString(snackBarsPrefix!!)
} catch (_: Exception) {
snackBarsPrefix = null
snackBarsPluralFormatting = false
}

// Build the final, formatted message for the month header
val snackMessage = if (prefix.isNotEmpty())
if (snackBarsPluralFormatting) prefix
else "$prefix $eventCount"
else "-> $eventCount"
// Capitalize the first character
snackMessage.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.ROOT)
else it.toString()
}
return snackMessage
}

/**
* Changes the visual density of the month.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.minar.tasticalendar.utilities

import com.minar.tasticalendar.model.TastiCalendarEvent

// Given a list of events, cumulate in a single string their texts
fun formatEventList(events: List<TastiCalendarEvent>, separator: String? = ""): String {
// Given a list of events, cumulate their texts in a single string
fun formatEventList(events: List<TastiCalendarEvent>, separator: String? = ","): String {
val sb = StringBuilder()
for (event in events) {
if (!event.displayText.isNullOrBlank()) sb.append("${event.displayText}${separator} ")
if (!event.displayText.isNullOrBlank() && events.lastIndex != events.indexOf(event))
sb.append("${event.displayText}${separator} ")
if (!event.displayText.isNullOrBlank() && events.lastIndex == events.indexOf(event))
sb.append(event.displayText)
}
return sb.toString().trim()
}

0 comments on commit def4215

Please sign in to comment.