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 { | |
splits { | |
// Configures multiple APKs based on ABI. | |
abi { | |
// Enables building multiple APKs per ABI. | |
enable true | |
// By default all ABIs are included, so use reset() and include to specify that we only | |
// want APKs for x86, armeabi-v7a, and mips. | |
reset() |
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 { | |
splits { | |
abi { | |
def isReleaseBuild = false | |
gradle.startParameter.taskNames.find { | |
// Enable split for release builds in different build flavors | |
// (assemblePaidRelease, assembleFreeRelease, etc.). | |
if (it ==~ /:app:assemble.*Release/) { | |
isReleaseBuild = 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
class AccessTokenInterceptor : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response = chain | |
.request() | |
.newBuilder() | |
.let { builder -> | |
val accessToken = accountRepository.accessToken ?: "" | |
builder.setAuthHeader(builder, accessToken) | |
} | |
.build() |
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 okHttpClient = OkHttpClient.Builder() | |
.addInterceptor(AuthInterceptor()) | |
.build() | |
val retrofit = Retrofit.Builder() | |
.baseUrl("https://igor.wojda.com/app") | |
.client(okHttpClient) | |
.build() |
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 AccountRepository(context: Context) { | |
companion object { | |
const val ACCOUNT_NAME = "ABC app account" | |
const val ACCOUNT_TYPE = "com.igorwojda.abc" | |
const val REFRESH_TOKEN = "refreshToken" | |
} | |
private val accountManager: AccountManager = AccountManager.get(context) |
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 retrofit = Retrofit.Builder() | |
.baseUrl("https://igorwojda.com/app") | |
.build() | |
val userService = retrofit.create(UserService::class.java) | |
val accountRepository = AccountRepository(context) | |
// Wee need this because userService.login function is suspended | |
CoroutineScope(Dispatchers.IO).launch { | |
val response = userService.login("email", "password") |
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
// EVOLUTION OF CLASS PROPERTY | |
// The presented code is in Kotlin, but the problem itself is not language-specific | |
// Client usage | |
fun main() { | |
Evolution1().setName("Igor") | |
Evolution2().name = "Igor" | |
Evolution3().name = "Igor" | |
Evolution4().name = "Igor" | |
} |
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 patient:Patient? = null | |
fun setPatient(patient:Patient) { | |
this.patient = patient | |
} |
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 RegisterViewModelFactory @Inject constructor( | |
private val repository: UserRepository | |
): ViewModelProvider.Factory { | |
@Suppress("UNCHECKED_CAST") | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
return if (modelClass.isAssignableFrom(RegisterViewModel::class.java!!)) { | |
RegisterViewModel(repository) as T | |
} else { | |
throw IllegalArgumentException("ViewModel Not Found") |
NewerOlder