Skip to content

Instantly share code, notes, and snippets.

View ajailani4's full-sized avatar

Ahmad Jailani ajailani4

View GitHub Profile
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/homeFragment"
android:enabled="true"
android:icon="@drawable/ic_home"
android:title="@string/home"
app:showAsAction="ifRoom" />
@ajailani4
ajailani4 / activity_main.xml
Created April 14, 2021 03:13
With BottomAppBar
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabAlignmentMode="center"
app:fabCradleRoundedCornerRadius="20dp"
app:fabCradleMargin="8dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
@ajailani4
ajailani4 / activity_main.xml
Created April 14, 2021 03:15
Final activity_main.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout 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.view.activity.MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
<androidx.core.widget.NestedScrollView 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.view.fragment.HomeFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="230dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:clickable="true"
class BrandsHomeDataSource @Inject constructor(
private val apiHelper: ApiHelper
) : PagingSource<Int, Brand>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Brand> {
val currentLoadingPageKey = params.key ?: 1
return try {
val response = apiHelper.getBrands(currentLoadingPageKey, 5)
val data = response.body()?.data?.brands ?: emptyList()
class BrandsHomeAdapter(
private val moreListener: (Brand) -> Unit,
private val phoneListener: (String, String) -> Unit
) : PagingDataAdapter<Brand, BrandsHomeAdapter.ViewHolder>(DataDifferentiator) {
private lateinit var binding: ItemBrandHomeBinding
private lateinit var phonesHomeAdapter: PhonesHomeAdapter
private val rvViewPool = RecyclerView.RecycledViewPool()
object DataDifferentiator : DiffUtil.ItemCallback<Brand>() {
override fun areItemsTheSame(oldItem: Brand, newItem: Brand): Boolean {
class PhonesHomeAdapter(
private val phonesHomeList: List<Phone>?,
private val listener: (String) -> Unit
) : RecyclerView.Adapter<PhonesHomeAdapter.ViewHolder>() {
private lateinit var binding: ItemPhoneHomeBinding
class ViewHolder(private val binding: ItemPhoneHomeBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(phone: Phone?, listener: (String) -> Unit) {