Skip to content

Instantly share code, notes, and snippets.

View bmoliveira's full-sized avatar
🏠

Bruno Oliveira bmoliveira

🏠
View GitHub Profile
@bmoliveira
bmoliveira / Fresco+SVG.kt
Created November 29, 2018 11:35
Fresco setup with SVG
class Usage {
companion object {
fun loadStuff(image: SimpleDraweeView, imageURI: String) {
image.setImageURI(imageURI)
}
}
}
class SetupExample {
companion object {
@bmoliveira
bmoliveira / Dependencies.kt
Created February 16, 2018 13:22
Android gradle Kotlin dependencies file example
object Versions {
val kotlin = "1.2.21"
val supportLib = "27.0.2"
val buildTools = "27.0.2"
val minSDK = 19
val targetSDK = 26
val compileSDK = 26
val versionCode = 1
val versionName = "1.0"
@bmoliveira
bmoliveira / bintray-deploy.gradle
Last active February 16, 2018 13:30
BintrayUpload via providing properties
// This script will configure the deploy to bintray with aar
// Of an android-library using kotlin project
// Simply by providing the .property files
// all boilerplate code is here.
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'maven-publish'
class ExampleViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
// the compiler will now complain if you don't have this implemented
// you need this to conform to SegueHandlerType
enum SegueIdentifier: String {
case TheRedPillExperience
case TheBluePillExperience
}
protocol SegueHandlerType {
associatedtype SegueIdentifier: RawRepresentable
}
// notice the cool use of where here to narrow down
// what could use these methods.
extension SegueHandlerType where Self: UIViewController,
SegueIdentifier.RawValue == String
{
class ExampleViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
title = "Example title".localized()
collectionView.registerCell(ExampleCell)
}
}
Localization files example:
public class Localize: NSObject {
/**
List available languages
- Returns: Array of available languages.
*/
public class func availableLanguages() -> [String] {
return NSBundle.mainBundle().localizations
}
/**
@bmoliveira
bmoliveira / String+Localizable.swift
Last active May 10, 2016 10:38
String Localization extension
public extension String {
/**
Swift 2 friendly localization syntax, replaces NSLocalizedString
- Returns: The localized string.
*/
func localized() -> String {
if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) {
return bundle.localizedStringForKey(self, value: nil, table: nil)
}
else if let path = NSBundle.mainBundle().pathForResource(LCLBaseBundle, ofType: "lproj"), bundle = NSBundle(path: path) {
@bmoliveira
bmoliveira / ExampleCell+ExampleViewController.swift
Last active May 10, 2016 10:36
ExampleCell + ExampleViewController
class ExampleCell: UICollectionViewCell, ReusableCell {
func updateCellUI() {
print("Here you should do something")
}
}
class ExampleViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
@bmoliveira
bmoliveira / UICollectionView+Reusable.swift
Last active May 10, 2016 14:23
UICollectionView reusable
extension UICollectionView {
func registerCell<T: ReusableCell>(cellType: T.Type) {
if let identifier = T.reuseIdentifier() {
self.registerNib(T.uiNibFromClass(), forCellWithReuseIdentifier: identifier)
}
}
func dequeueReusableCell<T: UICollectionViewCell>(index: Int) -> T {
return dequeueReusableCell(NSIndexPath(forItem: index, inSection: 0))