Skip to content
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

Tercer entregable #39

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

AldoCrono
Copy link

-Fix to get Asks and Bids from Api
-Add Ktlint to be able to analize code.
-Navigation controller and RxJava2.
-Pruebas unitarias
-Modificaciones de diseño
-Corutinas
-Change RecyclerView.Adapter to ListAdapter on AvailableBooksAdapter and OpenOrdersAdapter.
-Move setonClickListener on ListAdapter Item to init on ViewHolder instead of bindItem

Copy link

@diego-parra-robayo diego-parra-robayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buenas noches Aldo,
Felicitaciones, creo que mejoró mucho el código en comparación con la segunda entrega. Para esta última entrega te dejo algunos detalles que puedes mejorar.


override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val context: Context = holder.itemView.context
holder.bindItem(data[position], context)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muy bien, ya cambiaste el RecyclerView.Adapter a ListAdapter. El único cambio necesario ahora es que el ListAdapter no necesita una referencia a una lista, y por tanto, no es necesario el método getItemCount ni la lista 'data' en el constructor.
Para obtener la info en onBindViewHolder se puede cambiar data[position por getItem(position).

}
availableBooksVM.availableOrderBookList.observe(viewLifecycleOwner) {

rvBooks.adapter = AvailableBooksListAdapter(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La instancia del adapter no se debe crear dentro de un observer ya que es costoso y puede generar memory leaks. Esta instancia va por fuera del observe, y para actualizar la lista puedes utilizar adapter.submitList(it ?: emptyList())

}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bindItem(data[position])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mismo comentario que en AvailableBooksListAdapter. Puedes cambiar data[position por getItem(position) y eliminar la referencia 'data', eliminar data del constructor y eliminar la implementación de getItemCount

): OrderBookResponse

@GET("available_books")
fun getAvailableBooksRxJava(): Observable<Response<AvailableBooksResponse>>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar a como se hizo en corutines, no es necesario tener Response<> alrededor de la respuesta. El tipo puede cambiarse simplemente a Observable

bookList
} else {
Log.i("LocalDataBase", "Getting availableBooks from local database.")
withContext(Dispatchers.IO) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este withContext puede quedar a nivel más general cubriendo toda la función, es decir:
getAvailableBooks(): List = withContext(Dispatchers.IO) { ... }
Esto porque tanto consultas locales como consultas a Retrofit deben ejecutarse en el hilo IO.

*Aplica también para los otros métodos en esta clase como getTicker() y getOrderBook()

private var _selectedOrderBookName = MutableLiveData<String>()
private var _selectedCoinName = MutableLiveData<String>()

private var _ticker = MutableLiveData<Ticker>()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Estas variables deben ser 'val' en lugar de 'var'


private val defaultScheduler: Scheduler = Schedulers.io()

suspend fun getAvailableBooksRxJava() = MutableLiveData<List<AvailableBook>>().apply {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No deberías crear un MutableLiveData aqui.

loadFragment(AvailableBooksFragment())
}

private fun loadFragment(fragment: Fragment) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Con la implementación de navigation component, este método ya no es necesario

app:layout_constraintStart_toEndOf="@id/img_down"
app:layout_constraintBottom_toTopOf="@id/ll_bids_asks"/>

<LinearLayout

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como te había comentado previamente, el objetivo de ConstraintLayout es, en la medida de lo posible, evitar layouts internos. Algunos de los LinearLayout que tienes en este archivo se pueden evitar, y colocar las vistas directamente en el constraintLayout.

import org.junit.Rule
import org.junit.Test

class BitsoRepositoryImpTest {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revisa los tests en este archivo. Algunos están fallando por distintas razones, por ejemplo, algunos logs que colocaste en BitsoRepositoryImp (que no se pueden reconocer en un unit test), y algunos métodos que no están mockeados como deleteOpenOrdersFromDatabase(_) en tests como insert order books ...

-Instance adapter outside observer.
-Delete Response <> from BitsoApi.
-withContext() now covers the entire function.
-Delete method with blocking prefix.
-AsksEntity and BidsEntity changed forEach to map.
-Delete suspend when using RxJava.
-Cleaning CompositeDisposable with dispose() on onCleared() method.
-Change var to val on ViewModels.
-Delete MutableLiveData on AvailableBooksViewModel line 29.
-Delete loadFragment function because the navigation component already does the job.
-Change LinearLayouts to ConstraintLayouts.
@AldoCrono
Copy link
Author

Buenas tardes Diego. Subí 2 commits con las correcciones que mencionas.

Para que sea mas facil ubicarlas, van corregidas las observaciones a las que les puse un pulgar arriba en tus comentarios.

De antemano gracias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants