Skip to content

Instantly share code, notes, and snippets.

View shibbirweb's full-sized avatar
💭
Happy Coding

MD. Shibbir Ahmed shibbirweb

💭
Happy Coding
View GitHub Profile
@shibbirweb
shibbirweb / DownloadProgressLiveData.kt
Created May 9, 2021 14:06
Android - Downlaod Progress - Download manager download progress tracker
import android.app.Application
import android.app.DownloadManager
import android.content.Context
import androidx.lifecycle.LiveData
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
data class DownloadItem(val bytesDownloadedSoFar: Long = -1, val totalSizeBytes: Long = -1, val status: Int)
@shibbirweb
shibbirweb / AnyFragment.kt
Created April 30, 2021 16:32
Android - Kotlin - Handle back pressed on Fragment
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// on back pressed call back
val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
// goto dashboard
val action =
SectionChooseRegistrationFragmentDirections.actionSectionChooseRegistrationFragmentToDashboardActivity()
findNavController().navigate(action)
@shibbirweb
shibbirweb / DataStoreManager.kt
Last active April 17, 2023 14:02
Android - Kotlin - Data Store Manager
package com.***.data.dataStoreManager
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.*
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
@shibbirweb
shibbirweb / copy-branch.yml
Created April 26, 2021 05:20
GitHub Action - Duplicates default main branch to the old master branch
# Duplicates default main branch to the old master branch
name: Duplicates main to old master branch
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [ main ]
@shibbirweb
shibbirweb / AnyModel.php
Created April 19, 2021 16:22
Laravel - Order by many many to relationship
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@shibbirweb
shibbirweb / ActivityHelper.kt
Created March 12, 2021 10:47
Android: Context to activity
package me.shibbir.utils.helpers
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
object ActivityHelper {
/**
* Get activity
*/
@shibbirweb
shibbirweb / PermissionHelper.kt
Created March 12, 2021 10:21
Android: PermissionHelper
package me.shibbir.utils.helpers
import android.content.Context
import android.view.View
import com.google.android.material.snackbar.Snackbar
import com.karumi.dexter.Dexter
import com.karumi.dexter.PermissionToken
import com.karumi.dexter.listener.PermissionDeniedResponse
import com.karumi.dexter.listener.PermissionGrantedResponse
import com.karumi.dexter.listener.PermissionRequest
@shibbirweb
shibbirweb / DefaultListRecyclerViewAdapter.kt
Created March 11, 2021 07:41
Android: RecyclerView with Data binding
package me.shibbir.global
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
class DefaultListRecyclerViewAdapter<T>(
@shibbirweb
shibbirweb / BackIconPressHandler.kt
Created March 10, 2021 13:50
Android: View Click to back
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.view.View
object BackIconPressHandler {
/**
@shibbirweb
shibbirweb / DatePickerHelper.kt
Created March 6, 2021 10:59
Show date picker on textview
import android.app.DatePickerDialog
import android.content.Context
import android.widget.TextView
import java.util.*
object DatePickerHelper {
/**
* Show date picker