View build.gradle
This file contains 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
dependencies { | |
implementation 'io.github.ahmad-hamwi:tabsync:1.0.1' | |
} |
View MainActivity.kt
This file contains 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
private fun initMediator() { | |
TabbedListMediator( | |
recyclerView, | |
tabLayout, | |
categories.indices.toList(), | |
true // NEW | |
).attach() | |
} |
View build.gradle
This file contains 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
allprojects { | |
repositories { | |
... | |
mavenCentral() | |
} | |
} |
View activity_main.xml
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".ui.MainActivity"> | |
<com.google.android.material.tabs.TabLayout | |
android:id="@+id/tabLayout" |
View MainActivity.kt
This file contains 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
initViews() | |
initTabLayout() | |
initRecycler() | |
initMediator() // NEW | |
} |
View MainActivity.kt
This file contains 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
initViews() | |
initTabLayout() | |
initRecycler() | |
} | |
private fun initViews() { |
View MainActivity.kt
This file contains 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
private val categories = mutableListOf( | |
Category( | |
"Category 1", | |
Item("Item 1"), | |
Item("Item 2"), | |
Item("Item 3"), | |
Item("Item 4"), | |
Item("Item 5"), | |
Item("Item 6") | |
), |
View CategoriesAdapter.kt
This file contains 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 CategoriesAdapter( | |
private val context: Context, | |
private val listOfCategories: List<Category> | |
) : RecyclerView.Adapter<CategoriesAdapter.CategoryViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder { | |
return CategoryViewHolder( | |
LayoutInflater.from(context).inflate(R.layout.item_category, parent, false) | |
) | |
} |
View ItemsAdapter.kt
This file contains 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 ItemsAdapter( | |
private val context: Context, | |
private var items: List<Item> | |
) : | |
RecyclerView.Adapter<ItemsAdapter.ItemViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { | |
return ItemViewHolder( | |
LayoutInflater.from(context).inflate(R.layout.item_item, parent, false) | |
) |
View Category.kt
This file contains 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 Category(val name: String, vararg item: Item) { | |
val listOfItems: List<Item> = item.toList() | |
} |
NewerOlder