Skip to content

Instantly share code, notes, and snippets.

Avatar

Ahmad Jailani ajailani4

View GitHub Profile
View MainActivity.kt
@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)
@ajailani4
ajailani4 / activity_main.xml
Created Apr 14, 2021
Final activity_main.xml
View 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"
View activity_main.xml
<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"
View bottom_nav_menu.xml
<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" />
View 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"
View MainRepository.kt
class MainRepository @Inject constructor(
private val apiHelper: ApiHelper
) {
// Do something
}
View ApiHelper.kt
class ApiHelper @Inject constructor(
private val apiService: ApiService
) {
suspend fun getBrands(page: Int, limit: Int) =
apiService.getBrands(page, limit)
suspend fun getPhones(brandSlug: String, page: Int, limit: Int) =
apiService.getPhones(brandSlug, page, limit)
suspend fun getPhonesHome(brandSlug: String) =
View Resource.kt
data class Resource<out T>(val status: Status, val data: T?, val message: String?) {
companion object {
fun <T> loading(data: T?): Resource<T> {
return Resource(Status.LOADING, data, null)
}
fun <T> success(data: T?): Resource<T> {
return Resource(Status.SUCCESS, data, null)
}
View Status.kt
enum class Status {
LOADING,
SUCCESS,
ERROR
}
View PhoneSearch.kt
data class PhoneSearch(
@field:Json(name = "phone_name")
val name: String,
@field:Json(name = "phone_name_slug")
val slug: String,
@field:Json(name = "brand")
val brandName: String,
@field:Json(name = "brand_slug")
val brandSlug: String,
@field:Json(name = "phone_img_url")