This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The object we will be fetching from local or remote data source | |
struct Note { | |
var description: String | |
} | |
// Strategy | |
protocol NoteStrategy { | |
func getNote(completion: @escaping (Note) -> Void) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func loadMore(_ pageNumber: Int, _ pageSize: Int, onSuccess: ((Bool) -> Void)?, onError: ((Error) -> Void)?) { | |
// Call your api here | |
// Send true in onSuccess in case new data exists, sending false will disable pagination | |
// If page number is first, reset the list | |
if pageNumber == 1 { self.list = [Model]() } | |
// else append the data to list | |
self.list.append(apiResponseList) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tableView.loadData(refresh: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add paginated delegates only | |
tableView.paginatedDelegate = self | |
tableView.paginatedDataSource = self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assign custom class to table view in storyboard | |
@IBOutlet weak var tableView: PaginatedTableView! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// With thumbnail url | |
Glide.with(context).load(url) | |
.thumbnail(Glide.with(context).load(thumbUrl)) | |
.apply(requestOptions).into(imageView) | |
// Without thumbnail url | |
// If you know thumbnail size | |
Glide.with(context).load(url) | |
.thumbnail(Glide.with(context).load(url).apply(RequestOptions().override(thumbSize))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val requestOptions = RequestOptions() | |
.diskCacheStrategy(DiskCacheStrategy.ALL) | |
.signature(ObjectKey(signature)) | |
.override(100, 100) // resize does not respect aspect ratio | |
Glide.with(context).load(url).apply(requestOptions).into(imageView) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This method must be called on the main thread. | |
Glide.get(context).clearMemory() | |
Thread(Runnable { | |
// This method must be called on a background thread. | |
Glide.get(context).clearDiskCache() | |
}).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val requestOptions = RequestOptions() | |
.diskCacheStrategy(DiskCacheStrategy.ALL) | |
.signature(ObjectKey(signature)) | |
Glide.with(context).load(url).apply(requestOptions).into(imageView) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val requestOptions = RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL) | |
Glide.with(context).load(url).apply(requestOptions).into(imageView) |
NewerOlder