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
Open App | |
from home screen -> Is user authorized? | |
from email or deep link -> Email link type | |
Root | |
Logged Out | |
Is user authorized? | |
Yes -> Logged In | |
No -> Splash |
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
@propertyWrapper | |
struct Lateinit<T> { | |
private var _value: T? | |
var wrappedValue: T { | |
get { | |
guard let value = _value else { | |
fatalError("Property being accessed without initialization") | |
} | |
return value |
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
class Activity { | |
lateinit var notificationManager: NotificationManager | |
override fun onCreate() { | |
super.onCreate() | |
// lateinit allows to access property without initialization and check for null | |
// this will cause a crash | |
notificationManager.readNotification() |
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
// Inject or instantiate the manager | |
lateinit var environmentManager: EnvironmentManager | |
// url address depending on DEFAULT_ENV | |
val serverAddress = environmentManager.get(EnvironmentVariables::baseUrl) | |
// change env | |
environmentManager.currentEnvironment = Environment.PRODUCTION | |
// Now you got the prod adrress |
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
class EnvironmentManager( | |
// We use shared prefs to save currently selected env between app launches | |
private val store: SharedPreferences | |
) { | |
// This is a key for saving env in prefs | |
private val currentEnvironmentKey = "current_environment" | |
/* | |
* Here we need to describe all our strings | |
* for all of the supported environments. |
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
enum class Environment(val id: String) { | |
DEVELOPMENT("development"), | |
PRODUCTION("production"); | |
companion object { | |
fun create(env: String): Environment = | |
when (env) { | |
"development" -> DEVELOPMENT | |
"production" -> PRODUCTION | |
else -> throw Exception("Unsupported environment $env") |
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
data class EnvironmentVariables( | |
val baseUrl: String, | |
val algoliaSearchKey: String | |
) |
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
android { | |
buildTypes { | |
debug { | |
buildConfigField("String", "BASE_URL", "\"https://api-dev.myproject.com/\"") | |
} | |
release { | |
buildConfigField("String", "BASE_URL", "\"https://api.myproject.com/\"") | |
} | |
} | |
} |
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
import Foundation | |
let date1Timestamp = Double(1545648417) // This is our date since 1970 | |
let date2Str = "2018-12-07 05:32:54" // This is our date in String | |
// Here we create a `DateFormatter` which will allow us to parse our String | |
// Since we don't have a timezone data in our String, we indicate that this String in UTC | |
let date2Formatter = DateFormatter() | |
date2Formatter.dateFormat = "yyyy-MM-dd hh:mm:ss" | |
date2Formatter.timeZone = TimeZone(abbreviation: "UTC")! |
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
fun loadPosts() { | |
retrofitService.getPosts() | |
.filter { post -> post.author == me } | |
.map { post -> createViewablePost(post) } | |
.onComplete { posts -> view.showData(posts) } | |
.onError { e -> view.showError(e) } | |
} |