-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0/tercer entregable #50
base: main
Are you sure you want to change the base?
Conversation
…and db models for exchange order books + poc db room + room dependencies + refactor book to exchange boor order + poc dao
… + update primary key for asks and bids + stores ticker to db + item layout for bids and ask
- add book name on bids and orders - moved internet checker to activity viewmodel
…fragment + temp cache strategy for available books call request to avoid multiple calls + fixed exposed mutable live data on view model
…ta a arquitectura MVVM con use case
…xchange order books
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hola Omar,
Te felicito por tu proyecto!! me dio mucho gusto ver tu progreso a lo largo de cada semana. Para este entregable te dejo unos comentarios sobre DI y buenas practicas. Son detalles menores que podrían mejorar tu código, en general es un muy buen trabajo!!
|
||
abstract class HttpConnectionManager<T : Any>(coinApi: CoinApis) { | ||
|
||
abstract fun build(): T | ||
|
||
private val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = if (BuildConfig.DEBUG) { | ||
HttpLoggingInterceptor.Level.BODY | ||
} else { | ||
HttpLoggingInterceptor.Level.NONE | ||
} | ||
} | ||
|
||
val httpClient = when (coinApi) { | ||
CoinApis.BITSO -> { | ||
Retrofit.Builder() | ||
.baseUrl(CoinApis.BITSO.hostUrl) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.client( | ||
OkHttpClient().newBuilder() | ||
.addInterceptor(BitsoInterceptor()) | ||
.addInterceptor(loggingInterceptor) | ||
.build(), | ||
).build() | ||
} | ||
CoinApis.RESTFUL_API -> { | ||
Retrofit.Builder() | ||
.baseUrl(CoinApis.RESTFUL_API.hostUrl) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client( | ||
OkHttpClient().newBuilder() | ||
.addInterceptor(loggingInterceptor) | ||
// .addInterceptor(BitsoInterceptor()) | ||
// .addNetworkInterceptor(GSSCHeadersInterceptorAWSS3()) | ||
.build(), | ||
).build() | ||
} | ||
|
||
else -> { | ||
Retrofit.Builder() | ||
.baseUrl("") | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(OkHttpClient().newBuilder().build()) | ||
.build() | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Podrías mejorar este código creando un modulo y usando inyección de dependencias para obtener la instancia de retrofit, esta seria una propuesta:
@Module
@InstallIn(SingletonComponent::class)
object NetworkingRxModule {
private val loggingInterceptor = HttpLoggingInterceptor().apply {
level = if (BuildConfig.DEBUG) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.NONE
}
}
@Provides
@Singleton
fun provideRetrofitClient(): Retrofit {
return Retrofit.Builder()
.baseUrl(CoinApis.BITSO.hostUrl)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(
OkHttpClient().newBuilder()
.addInterceptor(BitsoInterceptor())
.addInterceptor(loggingInterceptor)
.build(),
).build()
}
}
@Singleton | ||
fun provideBitsoOrderBooksApi(): BitsoOrderBooksApi { | ||
return BitsoOrderBooksApi.Builder().build() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Al usar DI para obtener tu instancia de retrofit, este metodo podría refactorizarse a
@Provides
@Singleton
fun provideBitsoOrderBooksApi(retrofit: Retrofit): BitsoOrderBooksApi {
return retrofit.create(BitsoOrderBooksApi::class.java)
}
private val db: ZeroCoinAppDatabase, | ||
) : LocalOrderBookRepository { | ||
|
||
val scope = CoroutineScope(Dispatchers.IO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Como buena practica convierte tus variables en privadas si solo las usas en ese archivo
val context = LocalContext.current | ||
val listState = rememberLazyListState() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables que no se usan deben eliminarse
if (cryptoCoinsKeys.isEmpty()) CryptoCoinUI.crypto.coinKey else cryptoCoinsKeys[0] | ||
val sellerCryptoCoinKey = | ||
if (cryptoCoinsKeys.size == 2) cryptoCoinsKeys[1] else CryptoCoinUI.crypto.coinKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evita tener "números mágicos" en código, es mas recomendable pasalos a una constante
fun ErrorDialogHandler(show: Boolean) { | ||
val context = LocalContext.current | ||
var showCustomDialog by remember { | ||
mutableStateOf(false) | ||
} | ||
showCustomDialog = show | ||
if (showCustomDialog) { | ||
ErrorDialog({ | ||
showCustomDialog = !showCustomDialog | ||
}, { | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me parece que este componente nunca lo usas en el proy o si?
Se utilizó lint para arreglar codigo.
Añade inyección de dependencias
Cambia a navigation Component la navegación
Agrega la opción de usar RX para el servicio available order books
Agrega opcional mostrar LazyColumn de Compose en lugar de RecyclerView en la primera pantalla