This file contains hidden or 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
| abstract class BaseConcatHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
| abstract fun bind(adapter: T) | |
| } |
This file contains hidden or 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 animalAdapter = AnimalAdapter(this) | |
| animalAdapter.setAnimals(mutableListOf(Animal("Dog","DogImgUrl"),Animal("Cat","CatImgUrl"),Animal("Hamster","HamsterImgUrl"),Animal("Shark","SharkImgUrl")) | |
| val breedAdapter = DogBreedAdapter(this) | |
| breedAdapter.setBreeds(mutableListOf(Breed("Bulldog"),Breed("Beagle"),Breed("Bulldog"),Breed("Golden retriever")) | |
| //Lets create now the ConcatAdapter with these adapters ready | |
| val concatAdapter = ConcatAdapter(GridConcatAdapter(this,animalAdapter,4),breedAdapter) | |
| animal_rv.layoutManager = LinearLayoutManager(requireContext()) | |
| animal_rv.adapter = concatAdapter |
This file contains hidden or 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 BaseGridConcatAdapter(private val context: Context, private val animalAdapter: AnimalAdapter,private val spanCount:Int) : | |
| RecyclerView.Adapter<BaseConcatHolder<*>>() { | |
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseConcatHolder<*> { | |
| val view = LayoutInflater.from(context).inflate(R.layout.animal_concat_row,parent,false) | |
| view.rv_animal_concat.layoutManager = GridLayoutManager(context, spanCount) | |
| return ConcatViewHolder(view) | |
| } | |
| override fun getItemCount(): Int = 1 |
This file contains hidden or 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 animalAdapter = AnimalAdapter(this) | |
| animalAdapter.setAnimals(mutableListOf(Animal("Dog","DogImgUrl"),Animal("Cat","CatImgUrl"),Animal("Hamster","HamsterImgUrl"),Animal("Shark","SharkImgUrl")) | |
| val breedAdapter = DogBreedAdapter(this) | |
| breedAdapter.setBreeds(mutableListOf(Breed("Bulldog"),Breed("Beagle"),Breed("Bulldog"),Breed("Golden retriever")) | |
| //Lets create now the ConcatAdapter with these adapters ready | |
| val concatAdapter = ConcatAdapter(animalAdapter,breedAdapter) | |
| animal_rv.layoutManager = LinearLayoutManager(requireContext()) | |
| animal_rv.adapter = concatAdapter |
This file contains hidden or 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 DogBreedAdapter( | |
| val context: Context, | |
| ) : RecyclerView.Adapter<BaseViewHolder<*>>() { | |
| private var dogBreedList = mutableListOf<Breed>() | |
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<*> { | |
| return DogBreedViewHolder( | |
| LayoutInflater.from(context).inflate(R.layout.breeds_row, parent, false) | |
| ) |
This file contains hidden or 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
| abstract class BaseViewHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
| abstract fun bind(item: T,position:Int) | |
| } |
This file contains hidden or 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 AnimalAdapter(private val context: Context) : | |
| RecyclerView.Adapter<BaseViewHolder<*>>() { | |
| private var animalList = mutableListOf<Animal>() | |
| companion object { | |
| const val ITEMS_PER_PAGE = 4 | |
| } | |
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<*> { |
This file contains hidden or 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
| sharedViewModel.getCart.observe(viewLifecycleOwner, Observer { cart -> | |
| navigateToCart(cart) | |
| }) |
This file contains hidden or 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
| //ViewModel | |
| fun getHashMapData():LiveData<HashMap<String,Cart>>{ | |
| return cartHashMap | |
| } | |
| //UI that gets this hashmap | |
| sharedViewModel.getHashMapData().observe(viewLifecycleOwner, Observer { dataHashMap -> | |
| //Here I need to transform this HashMap into a MutableList<Cart> |
NewerOlder