Skip to content

Instantly share code, notes, and snippets.

View qamarelsafadi's full-sized avatar

Qamar A. Safadi qamarelsafadi

View GitHub Profile
@qamarelsafadi
qamarelsafadi / BaseBottomSheet.kt
Last active August 2, 2023 04:56
This class is a generic class for BottomSheetDialogFragment using Kotlin, it will helps you to use one class for all ur bottom sheets on your app.
/*
* Copyright (c) 2022. Qamar A. Safadi
*/
package com.qamar.test.base
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
@qamarelsafadi
qamarelsafadi / NavgationComponentExtensions.kt
Last active June 14, 2022 07:38
This gist file will include all Navigation Component usefull Extensions.
/*
Qamar A. Safadi
*/
fun NavController.safeNavigateWithClearBackStack(
@IdRes currentDestinationId: Int,
@IdRes id: Int,
args: Bundle? = null
) {
if (currentDestinationId == currentDestination?.id) {
@qamarelsafadi
qamarelsafadi / BaseDialog.kt
Last active August 2, 2024 06:04
This class is generic class for creating your custom dialogs, it will helps you to use one class for all ur custom dialogs.
/*
* Created by Qamar A. Safadi on 6/13/22, 9:50 PM
* Copyright (c) 2022 .
*/
package com.example.qamar.ui.base
import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
@qamarelsafadi
qamarelsafadi / LocalData.kt
Last active July 28, 2022 05:41
this class is a generic class for your shared prefernces api.
object LocalData {
/**
* Set any type of shared preferences value
* @param key of the shared preferences which the caller is desire to set
* @param value any type
*/
operator fun<T> set(key: String?, value: T) {
/* below you can put whatever shared preferences api you use, I prefer Hawk
* it helps to store objects immediately without need to use GSON in shared preferences
* */
@qamarelsafadi
qamarelsafadi / NewMenuApiImplementation.kt
Last active January 19, 2024 12:52
This gist will help you to get started with the new menu implementation way, you can find 2 extensions that will help you not repeat a huge code, Enjoy it.
// Step 1 : implement the new activity dependency in you gradle
implementation 'androidx.activity:activity-ktx:1.5.1'
// if you are using compose
implementation 'androidx.activity:activity-compose:1.5.1'
/* ---------------------------------------------- Activity Extension -------------------------------------------------------*/
fun AppCompatActivity.bindMenu(
@MenuRes menuRes: Int,
@qamarelsafadi
qamarelsafadi / OnBackPressedAlternativeWay.kt
Last active April 4, 2023 10:09
OnBackPressed Alternative way for fragments and activities
/* ----------------------------------------- Activity ------------------------------------------ */
/* make sure you have at least 'androidx.activity:activity-ktx:1.6.0-rc01' at your dependencies
(just to let you know this dependency is not stable yet )
*/
implementation 'androidx.activity:activity-ktx:1.6.0-rc01'
fun AppCompatActivity.onBackPressed(isEnabled: Boolean, callback: () -> Unit) {
onBackPressedDispatcher.addCallback(this,
@qamarelsafadi
qamarelsafadi / BottomNavItem.kt
Created September 14, 2022 15:22
BottomNaviagtionCompose Naviagtion
sealed class BottomNavItem(var title: String, var icon: Int, val route: String) {
object Home : BottomNavItem("Home", R.drawable.home_icon, "home")
object Bookmarks : BottomNavItem("Bookmarks", R.drawable.home_icon, "bookmarks")
object Notification : BottomNavItem("Notification", R.drawable.home_icon, "notification")
}
@qamarelsafadi
qamarelsafadi / ProgressButton.kt
Created September 15, 2022 05:56
This gist will help ypu doing ypur progress button via Compose
@Composable
fun ProgressButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
loading: Boolean = false,
color: Int,
progressColor: Int,
content: @Composable () -> Unit,
) {
val contentAlpha by animateFloatAsState(targetValue = if (loading) 0f else 1f)
import android.app.LocaleManager
import android.content.Context
import android.os.Build
import android.os.LocaleList
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import java.util.Locale
/// Change Langauage Extenstion
// update your activity version
implementation 'androidx.activity:activity-ktx:1.7.1'
val pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
// Callback is invoked after the user selects a media item or closes the
// photo picker.
if (uri != null) {
// do what you want with pic
} else {