Skip to content

Instantly share code, notes, and snippets.

View SurajBahadur's full-sized avatar
🎯
Focusing

Suraj Bahadur SurajBahadur

🎯
Focusing
View GitHub Profile
@SurajBahadur
SurajBahadur / youtube_format_code_itag_list.md
Created November 15, 2022 11:11
YouTube Format Code iTag List

YouTube video stream format codes

Comprehensive list of YouTube format code itags

itag Code Container Content Resolution Bitrate Range VR / 3D
5 flv audio/video 240p - - -
6 flv audio/video 270p - - -
17 3gp audio/video 144p - - -
18 mp4 audio/video 360p - - -
22 mp4 audio/video 720p - - -
@SurajBahadur
SurajBahadur / DoubleClickListener.kt
Created September 21, 2022 06:37
Helper class to get callback for single and double click on a view in android
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
public abstract class DoubleClickListener implements View.OnClickListener {
private static final long DEFAULT_QUALIFICATION_SPAN = 200;
private boolean isSingleEvent;
private final long doubleClickQualificationSpanInMillis;
private long timestampLastClick;
private final Handler handler;
@SurajBahadur
SurajBahadur / Test.kt
Created September 20, 2022 08:01
Smooth Scroll To any position via skipping middle item list in RecyclerView Android
private fun smoothScroll(currentPosition: Int, newPosition: Int) {
Log.d("new_position", "$newPosition")
if (newPosition > currentPosition) {
//scroll top to bottom
binding.upperRecycler.scrollToPosition(newPosition - 2)
binding.upperRecycler.smoothSnapToPosition(newPosition - 1) {
//Reason for adding this is that if RecyclerView height is 0dp or match parent OR more than one items visible on the
// screen then instead of focus on passed position, it scroll down/up depend
binding.upperRecycler.scrollBy(0, -250)
@SurajBahadur
SurajBahadur / Test.kt
Created July 1, 2022 09:29
Scroll to previous saved position in recyclerview
//Create a variable in shared viewmodel to hold the state
var listState: Parcelable? = null
//onDestroyView() in case of fragment, saved the state of layout manager attached to rv
bookMarkViewModel.listState = binding.recyclerViewMain.layoutManager?.onSaveInstanceState()
//Suppose you have move from SCREEN A to SCREEN B and on SCREEN A, you have save the state in the listState variable and when
//you come back to SCREEN A then you need to restore the layoutManager state as below
if(listState!=null){
binding.recyclerViewMain.layoutManager?.onRestoreInstanceState(bookMarkViewModel.listState);
@SurajBahadur
SurajBahadur / TextViewFontAwsome.kt
Created March 22, 2022 07:21
Font Awesome web font in android.
class TextViewFontAwsome : androidx.appcompat.widget.AppCompatTextView {
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context!!, attrs, defStyle) {
init()
}
constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) {
init()
}
constructor(context: Context?) : super(context!!) {
@SurajBahadur
SurajBahadur / MediaUtils.kt
Created March 21, 2022 18:59
Class to handle operation for media files in android
/**
* Class to Handle Operation for Media (Image etc) Files
* */
class MediaUtils {
/* File Size */
interface FILE {
companion object {
const val IMAGE_SIZE = 1000000 //1000 kb
@SurajBahadur
SurajBahadur / MainActivity.kt
Created December 28, 2021 19:50
Fetch current location in kotlin
/*
* Copyright (C) 2020 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@SurajBahadur
SurajBahadur / DynamicHeightViewPager.kt
Created October 28, 2021 19:03
Dynamic height viewpager in android
import android.content.Context
import android.util.AttributeSet
import androidx.viewpager.widget.ViewPager
class DynamicHeightViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
var heightMeasureSpec = heightMeasureSpec
var height = 0
@SurajBahadur
SurajBahadur / Dashboard.kt
Last active July 7, 2021 19:24
Change specific icon of bottom navigation view with with image url.
package com.sway.android.screens.dashboard
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.Menu
@SurajBahadur
SurajBahadur / EmailSender.dart
Created June 24, 2021 18:45
Sending an email without opening the third party app such as Gmail etc in Flutter
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server.dart';
main() async {
String username = '[email protected]';
String password = 'password';
final smtpServer = gmail(username, password);
// Use the SmtpServer class to configure an SMTP server:
// final smtpServer = SmtpServer('smtp.domain.com');