Skip to content

Instantly share code, notes, and snippets.

Avatar

Agam Mahajan agammahajan1

View GitHub Profile
View temp.kt
@Composable
fun ApplyButton(
text: String,
modifier: Modifier = Modifier,
applicable: Boolean = false,
spanStyle: SpanStyle,
paragraphStyle: ParagraphStyle,
style: TextStyle,
onClick: () -> Unit
) {
View item_cell.swift
if UIAccessibility.isVoiceOverRunning {
// add cart button in item cell
}
@agammahajan1
agammahajan1 / cutom-actions.swift
Last active Aug 29, 2021
Custom Actions handling in Food item
View cutom-actions.swift
let addItemAction = UIAccessibilityCustomAction(name: "Add one quantity of this item.") { [weak self] _ in
// add 1 quantity of the item selected
UIAccessibility.post(notification: .announcement, argument: "Item added, total number of items in cart now is \(noOfItems) with a subtotal of \(cartTotal) rupees")
}
let removeItemAction = UIAccessibilityCustomAction(name: "Remove one quantity of this item.") { [weak self] _ in
if itemsInCart {
//remove 1 quantity of the item selected
if noOfItems == 0 {
UIAccessibility.post(notification: .announcement, argument: "Item removed, no items in cart now")
View annoucements.swift
UIAccessibility.post(notification: .announcement,
argument: "Location has changed to JP Nagar")
@agammahajan1
agammahajan1 / images.swift
Created Aug 29, 2021
Add alt text to the image view
View images.swift
imageView.isAccessibilityElement = true
imageView.accessibilityLabel = dataSource.accessibility.altText
View grouping.swift
cell.isAccessibilityElement = true
cell.accessibilityLabel = restaurantName + rating + offer
View File_Convert.swift
extension URL {
var attributes: [FileAttributeKey : Any]? {
do {
return try FileManager.default.attributesOfItem(atPath: path)
} catch let error as NSError {
print("FileAttribute error: \(error)")
}
return nil
}
View Logging.swift
static func findCachedVideoURL(forVideoId id: String) -> URL? {
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
if let dirPath = paths.first {
let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(folderPath).appendingPathComponent(id + ".mp4")
let filePath = fileURL.path
let fileManager = FileManager.default
if fileManager.fileExists(atPath: filePath) {
NewRelicService.sendCustomEvent(with: NewRelicEventType.statusCodes,
View MaxNumberOfVideos.swift
func removeVideoIfMaxNumberOfVideosReached() {
if popupVideosDict.count >= maxVideosAllowed {
// remove the least recently used video
let sortedDict = popupVideosDict.keysSortedByValue { (v1, v2) -> Bool in
v1.timeStamp < v2.timeStamp
}
guard let videoId = sortedDict.first else {
return
}
popupVideosDict.removeValue(forKey: videoId)
View TimeStamp_Check.swift
func cleanExpiredVideos() {
let currentTimeStamp = Date().timeIntervalSince1970
var expiredKeys: [String] = []
for videoData in videosDict where currentTimeStamp - videoData.value.timeStamp >= expiryTime {
// video is expired. delete
if let _ = popupVideosDict[videoData.key] {
expiredKeys.append(videoData.key)
}
}
for key in expiredKeys {