Estoy intentando hacer una aplicaciòn con clean architecture y MVP y patròn repository,(debo aclarar que soy nuevo en esto) tengo 5 clases la de la vista, presenter, interactor, repositorio, y el adapter les adjunto el còdigo de cada clase necesito mostrar en pantalla una lista con un recyclerview pero sigo recibiendo el error E/RecyclerView: No adapter attached; skipping layout y no muestra la lista de ante mano muchas gracias
Vista Dashboard()
@SuppressLint("WrongConstant")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapter = DashboardAdapter(context!!)
recycler_accountant.layoutManager = LinearLayoutManager(context, OrientationHelper.VERTICAL, false)
recycler_accountant.adapter = adapter
}
override fun SendDataAccountantToPresenter() {
presenter.getDataAccountantToInteractor()
}
override fun SendDataAccountantToAdapter(mutableList: MutableList<Accountant>) {
Log.d(ContentValues.TAG, "datos obtenidos en la vista $mutableList")
adapter.setDataList(mutableList)
adapter.notifyDataSetChanged()
}
Presenter DashboardPresenter()
class DashboardPresenter(dashboardInteactor: DashboardAccountantInteractor) : DashboardContract.DashboardPresenter {
var dashboardInt: DashboardAccountantInteractor? = null
var viewdp: DashboardContract.DashboardView? = null
init {
dashboardInt = dashboardInteactor
}
override fun getDataAccountantToInteractor() {
Log.d(ContentValues.TAG, "entro en el metodo getDataAccountantToInteractor() del presenter ")
dashboardInt?.getAccountantDataToRepository()?.observe(Dashboard(), Observer {
viewdp?.SendDataAccountantToAdapter(it)
})
}
Interactor DashboardAccountantImpl()
class DashboardAcoountantImpl : DashboardAccountantInteractor {
override fun getAccountantDataToRepository(): MutableLiveData<MutableList<Accountant>> {
val accountantRepository = AccountRepositoryImpl()
val user = FirebaseAuth.getInstance().currentUser
val exception = FirebaseAuthException("002", "user don't Auth")
val mutableListData = MutableLiveData<MutableList<Accountant>>()
if (user != null) {
accountantRepository.getAccountantData().observeForever { accountantlist ->
mutableListData.value = accountantlist
Log.d(ContentValues.TAG, "datos obtenidos en el interactor ${mutableListData.value}")
}
} else {
Log.d(ContentValues.TAG, "Para ingresar sus datos debe ser un usuario registrado", exception)
}
return mutableListData
}
}
Repositorio AccountRepositoryImpl()
override fun getAccountantData():LiveData<MutableList<Accountant>> {
val mutableData = MutableLiveData<MutableList<Accountant>>()
val listData = mutableListOf<Accountant>()
db.collection("accountant").get().addOnSuccessListener { querySnapshot ->
if (querySnapshot.isEmpty) {
Log.w(TAG, "Error obteniendo datos de los documentos")
} else {
Log.w(TAG, "datos obtenidos con exito desde firestore al repositorio")
for (document in querySnapshot) {
val name = document.getString("name")
val lastname = document.getString("lastname")
val city = document.getString("city")
val accountant = Accountant(document.getString("id")!!, "$name","$lastname",
document.getString("email")!!,document.getString("phone")!!,city!!,
document.getString("address")!!,document.getString("professional_card")!!)
listData.add(accountant)
}
}
mutableData.value = listData
}
return mutableData
}
Adapter DashboardAdapter()
class DashboardAdapter(private val context:Context) : RecyclerView.Adapter<DashboardAdapter.Viewholder>() {
private var datalist: MutableList<Accountant> = mutableListOf()
fun setDataList(data:MutableList<Accountant>){
datalist = data
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Viewholder {
val view: View = LayoutInflater.from(context).inflate(R.layout.item_accountant, parent, false)
return Viewholder(view)
}
override fun getItemCount(): Int {
return if (datalist.size > 0) datalist.size else 0
}
override fun onBindViewHolder(holder: Viewholder, position: Int) {
val accountant = datalist[position]
holder.bindView(accountant)
}
inner class Viewholder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindView(accountant: Accountant) {
val fullname = accountant.name + accountant.lastname
itemView.labl_name.text = fullname
itemView.txt_city.text = accountant.city
}
}
}