Skip to content

Instantly share code, notes, and snippets.

View anibalbastiass's full-sized avatar
🇺🇸
Working and learning every day

Anibal Bastias Soto anibalbastiass

🇺🇸
Working and learning every day
View GitHub Profile
@anibalbastiass
anibalbastiass / AndroidManifest.xml
Last active July 27, 2023 21:52
[Android] Force enable Animation using Accessibiity Service
<service
android:name=".ui.home.GCAccessibilityService"
android:exported="false"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
>
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
@anibalbastiass
anibalbastiass / JSONParserChallenge.kt
Created March 23, 2022 15:54
JSONParserChallenge (Using Gson Library)
import CharterChallenge.Order.OrderItem.SizePrice
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import java.net.URL
class CharterChallenge {
companion object {
private const val GET_ORDER_URL = "https://raw.githubusercontent.com/pgiani/KotlinTask/main/order.json"
import java.io.BufferedReader
import java.io.FileReader
fun main() {
getRepeatedCode(fileName = "data.txt")
}
private fun getRepeatedCode(fileName: String) {
var line: String
@anibalbastiass
anibalbastiass / CurrenciesRepositoryImplTest.kt
Last active January 3, 2020 19:26
CurrenciesRepositoryImplTest.kt
@ExperimentalCoroutinesApi
@RunWith(JUnit4::class)
class CurrenciesRepositoryImplTest {
private val restApi = mock<ForeignExchangeApiService>()
private val mapper = mock<CurrenciesUiMapper>()
private val testDispatcher = TestCoroutineDispatcher()
private val currenciesRemoteImpl = CurrenciesRepositoryImpl(restApi, mapper)
private val managedCoroutineScope: ManagedCoroutineScope =
@anibalbastiass
anibalbastiass / Extension.kt
Created January 3, 2020 19:24
Extension.kt
@BindingAdapter(
value = ["loadAdapterData", "loadAdapterLayout", "loadAdapterListener", "filter"],
requireAll = false
)
fun <T> RecyclerView.loadAdapterData(
list: MutableList<T>?,
layout: Int?,
callback: BaseBindClickHandler<T>? = null,
filter: FilterWordListener<T>? = null
) {
@anibalbastiass
anibalbastiass / fragment_currencies_list.xml
Created January 3, 2020 19:22
fragment_currencies_list.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
@anibalbastiass
anibalbastiass / CurrenciesFragment.kt
Created January 3, 2020 19:19
CurrenciesFragment.kt
private fun initViewModel() {
// Fetch Latest Currencies
with(currenciesViewModel) {
observe(getLatestCurrenciesLiveData(), ::observeCurrencies)
fetchCurrencies()
}
}
private fun observeCurrencies(result: Result<UiCurrencies>?) {
when (result) {
@anibalbastiass
anibalbastiass / CurrenciesViewModel.kt
Created January 3, 2020 19:15
CurrenciesViewModel.kt
open class CurrenciesViewModel @Inject constructor(
private val getLatestCurrenciesUseCase: GetLatestCurrenciesUseCase
) : BaseViewModel() {
//region Observables
var isLoading: ObservableBoolean = ObservableBoolean(false)
//endregion
//region Live Data
typealias LiveResult<T> = MutableLiveData<Result<T>>
@anibalbastiass
anibalbastiass / Result.kt
Created January 3, 2020 19:13
Result.kt
sealed class Result<T> {
data class OnSuccess<T>( val value: T) : Result<T>()
data class OnError<T>(val throwable: Throwable) : Result<T>()
class OnLoading<T> : Result<T>()
class OnCancel<T> : Result<T>()
class OnEmpty<T> : Result<T>()
}
@anibalbastiass
anibalbastiass / GetLatestCurrenciesUseCase.kt
Created January 3, 2020 19:07
GetLatestCurrenciesUseCase.kt
open class GetLatestCurrenciesUseCase @Inject constructor(private val currenciesRepository: ICurrenciesRepository) :
ResultUseCase<String, UiCurrencies>(
backgroundContext = Dispatchers.IO,
foregroundContext = Dispatchers.Main
) {
override suspend fun executeOnBackground(params: String): UiCurrencies? =
currenciesRepository.getLatestCurrencies(params)
}