mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-01 07:57:01 +00:00
Fix calendar
This commit is contained in:
parent
2b2d14f53f
commit
dbfcf2790c
@ -296,13 +296,13 @@
|
|||||||
"Weekday.Today" = "Today";
|
"Weekday.Today" = "Today";
|
||||||
"Weekday.Yesterday" = "Yesterday";
|
"Weekday.Yesterday" = "Yesterday";
|
||||||
|
|
||||||
"Calendar.ShortMonday" = "M";
|
"Calendar.ShortMon" = "M";
|
||||||
"Calendar.ShortTuesday" = "T";
|
"Calendar.ShortTue" = "T";
|
||||||
"Calendar.ShortWednesday" = "W";
|
"Calendar.ShortWed" = "W";
|
||||||
"Calendar.ShortThursday" = "T";
|
"Calendar.ShortThu" = "T";
|
||||||
"Calendar.ShortFriday" = "F";
|
"Calendar.ShortFri" = "F";
|
||||||
"Calendar.ShortSaturday" = "S";
|
"Calendar.ShortSat" = "S";
|
||||||
"Calendar.ShortSunday" = "S";
|
"Calendar.ShortSun" = "S";
|
||||||
|
|
||||||
"Time.TodayAt" = "today at %@";
|
"Time.TodayAt" = "today at %@";
|
||||||
"Time.YesterdayAt" = "yesterday at %@";
|
"Time.YesterdayAt" = "yesterday at %@";
|
||||||
|
@ -120,22 +120,51 @@ private final class MediaPreviewView: UIView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func dayName(index: Int, strings: PresentationStrings) -> String {
|
private func normalizeDayIndex(index: Int) -> Int {
|
||||||
switch index {
|
switch index {
|
||||||
case 0:
|
|
||||||
return strings.Calendar_ShortMonday
|
|
||||||
case 1:
|
case 1:
|
||||||
return strings.Calendar_ShortTuesday
|
return 6
|
||||||
case 2:
|
case 2:
|
||||||
return strings.Calendar_ShortWednesday
|
return 0
|
||||||
case 3:
|
case 3:
|
||||||
return strings.Calendar_ShortThursday
|
return 1
|
||||||
case 4:
|
case 4:
|
||||||
return strings.Calendar_ShortFriday
|
return 2
|
||||||
case 5:
|
case 5:
|
||||||
return strings.Calendar_ShortSaturday
|
return 3
|
||||||
case 6:
|
case 6:
|
||||||
return strings.Calendar_ShortSunday
|
return 4
|
||||||
|
case 7:
|
||||||
|
return 5
|
||||||
|
default:
|
||||||
|
preconditionFailure()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func gridDayOffset(firstDayOfWeek: Int, firstWeekdayOfMonth: Int) -> Int {
|
||||||
|
let monthStartsWithDay = normalizeDayIndex(index: firstWeekdayOfMonth)
|
||||||
|
let weekStartsWithDay = normalizeDayIndex(index: firstDayOfWeek)
|
||||||
|
|
||||||
|
return (monthStartsWithDay - weekStartsWithDay + 7) % 7
|
||||||
|
}
|
||||||
|
|
||||||
|
private func gridDayName(index: Int, firstDayOfWeek: Int, strings: PresentationStrings) -> String {
|
||||||
|
let adjustedIndex = (index + firstDayOfWeek) % 7
|
||||||
|
switch adjustedIndex {
|
||||||
|
case 1:
|
||||||
|
return strings.Calendar_ShortSun
|
||||||
|
case 2:
|
||||||
|
return strings.Calendar_ShortMon
|
||||||
|
case 3:
|
||||||
|
return strings.Calendar_ShortTue
|
||||||
|
case 4:
|
||||||
|
return strings.Calendar_ShortWed
|
||||||
|
case 5:
|
||||||
|
return strings.Calendar_ShortThu
|
||||||
|
case 6:
|
||||||
|
return strings.Calendar_ShortFri
|
||||||
|
case 0:
|
||||||
|
return strings.Calendar_ShortSat
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -670,7 +699,7 @@ private final class MonthComponent: CombinedComponent {
|
|||||||
let updatedWeekdayTitles = (0 ..< 7).map { index in
|
let updatedWeekdayTitles = (0 ..< 7).map { index in
|
||||||
return weekdayTitles[index].update(
|
return weekdayTitles[index].update(
|
||||||
component: AnyComponent(Text(
|
component: AnyComponent(Text(
|
||||||
text: dayName(index: index, strings: context.component.strings),
|
text: gridDayName(index: index, firstDayOfWeek: context.component.model.firstWeekday, strings: context.component.strings),
|
||||||
font: Font.regular(10.0),
|
font: Font.regular(10.0),
|
||||||
color: context.component.foregroundColor
|
color: context.component.foregroundColor
|
||||||
)),
|
)),
|
||||||
@ -761,7 +790,7 @@ private final class MonthComponent: CombinedComponent {
|
|||||||
var selectionsByLine: [Int: LineSelection] = [:]
|
var selectionsByLine: [Int: LineSelection] = [:]
|
||||||
|
|
||||||
for i in 0 ..< updatedDays.count {
|
for i in 0 ..< updatedDays.count {
|
||||||
let gridIndex = (context.component.model.firstDayWeekday - 1) + i
|
let gridIndex = gridDayOffset(firstDayOfWeek: context.component.model.firstWeekday, firstWeekdayOfMonth: context.component.model.firstDayWeekday) + i
|
||||||
let rowIndex = gridIndex % 7
|
let rowIndex = gridIndex % 7
|
||||||
let lineIndex = gridIndex / 7
|
let lineIndex = gridIndex / 7
|
||||||
|
|
||||||
@ -828,7 +857,7 @@ private final class MonthComponent: CombinedComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i in 0 ..< updatedDays.count {
|
for i in 0 ..< updatedDays.count {
|
||||||
let gridIndex = (context.component.model.firstDayWeekday - 1) + i
|
let gridIndex = gridDayOffset(firstDayOfWeek: context.component.model.firstWeekday, firstWeekdayOfMonth: context.component.model.firstDayWeekday) + i
|
||||||
let rowIndex = gridIndex % 7
|
let rowIndex = gridIndex % 7
|
||||||
let lineIndex = gridIndex / 7
|
let lineIndex = gridIndex / 7
|
||||||
|
|
||||||
@ -865,6 +894,7 @@ private struct MonthModel: Equatable {
|
|||||||
var numberOfDays: Int
|
var numberOfDays: Int
|
||||||
var firstDay: Date
|
var firstDay: Date
|
||||||
var firstDayWeekday: Int
|
var firstDayWeekday: Int
|
||||||
|
var firstWeekday: Int
|
||||||
var currentYear: Int
|
var currentYear: Int
|
||||||
var currentMonth: Int
|
var currentMonth: Int
|
||||||
var currentDayOfMonth: Int
|
var currentDayOfMonth: Int
|
||||||
@ -876,6 +906,7 @@ private struct MonthModel: Equatable {
|
|||||||
numberOfDays: Int,
|
numberOfDays: Int,
|
||||||
firstDay: Date,
|
firstDay: Date,
|
||||||
firstDayWeekday: Int,
|
firstDayWeekday: Int,
|
||||||
|
firstWeekday: Int,
|
||||||
currentYear: Int,
|
currentYear: Int,
|
||||||
currentMonth: Int,
|
currentMonth: Int,
|
||||||
currentDayOfMonth: Int,
|
currentDayOfMonth: Int,
|
||||||
@ -886,6 +917,7 @@ private struct MonthModel: Equatable {
|
|||||||
self.numberOfDays = numberOfDays
|
self.numberOfDays = numberOfDays
|
||||||
self.firstDay = firstDay
|
self.firstDay = firstDay
|
||||||
self.firstDayWeekday = firstDayWeekday
|
self.firstDayWeekday = firstDayWeekday
|
||||||
|
self.firstWeekday = firstWeekday
|
||||||
self.currentYear = currentYear
|
self.currentYear = currentYear
|
||||||
self.currentMonth = currentMonth
|
self.currentMonth = currentMonth
|
||||||
self.currentDayOfMonth = currentDayOfMonth
|
self.currentDayOfMonth = currentDayOfMonth
|
||||||
@ -901,6 +933,7 @@ private func monthMetadata(calendar: Calendar, for baseDate: Date, currentYear:
|
|||||||
let year = calendar.component(.year, from: firstDayOfMonth)
|
let year = calendar.component(.year, from: firstDayOfMonth)
|
||||||
let month = calendar.component(.month, from: firstDayOfMonth)
|
let month = calendar.component(.month, from: firstDayOfMonth)
|
||||||
let firstDayWeekday = calendar.component(.weekday, from: firstDayOfMonth)
|
let firstDayWeekday = calendar.component(.weekday, from: firstDayOfMonth)
|
||||||
|
let firstWeekday = calendar.firstWeekday
|
||||||
|
|
||||||
return MonthModel(
|
return MonthModel(
|
||||||
year: year,
|
year: year,
|
||||||
@ -908,6 +941,7 @@ private func monthMetadata(calendar: Calendar, for baseDate: Date, currentYear:
|
|||||||
numberOfDays: numberOfDaysInMonth,
|
numberOfDays: numberOfDaysInMonth,
|
||||||
firstDay: firstDayOfMonth,
|
firstDay: firstDayOfMonth,
|
||||||
firstDayWeekday: firstDayWeekday,
|
firstDayWeekday: firstDayWeekday,
|
||||||
|
firstWeekday: firstWeekday,
|
||||||
currentYear: currentYear,
|
currentYear: currentYear,
|
||||||
currentMonth: currentMonth,
|
currentMonth: currentMonth,
|
||||||
currentDayOfMonth: currentDayOfMonth,
|
currentDayOfMonth: currentDayOfMonth,
|
||||||
@ -1057,7 +1091,7 @@ public final class CalendarMessageScreen: ViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let calendar = Calendar(identifier: .gregorian)
|
let calendar = Calendar.current
|
||||||
|
|
||||||
let baseDate = Date()
|
let baseDate = Date()
|
||||||
let currentYear = calendar.component(.year, from: baseDate)
|
let currentYear = calendar.component(.year, from: baseDate)
|
||||||
|
@ -244,7 +244,7 @@ public final class DirectMediaImageCache {
|
|||||||
let progressiveSizes = representation.progressiveSizes
|
let progressiveSizes = representation.progressiveSizes
|
||||||
if progressiveSizes.count > 0 && width <= 64 {
|
if progressiveSizes.count > 0 && width <= 64 {
|
||||||
selectedSize = progressiveSizes[0]
|
selectedSize = progressiveSizes[0]
|
||||||
} else if progressiveSizes.count > 1 && width <= 160 {
|
} else if progressiveSizes.count > 2 && width <= 160 {
|
||||||
selectedSize = progressiveSizes[2]
|
selectedSize = progressiveSizes[2]
|
||||||
} else if progressiveSizes.count > 4 && width <= 400 {
|
} else if progressiveSizes.count > 4 && width <= 400 {
|
||||||
selectedSize = progressiveSizes[4]
|
selectedSize = progressiveSizes[4]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user