Skip to content

Instantly share code, notes, and snippets.

@raxhaxor
raxhaxor / commitAllowingStateLoss on DialogFragment
Created December 31, 2020 06:10
commitAllowingStateLoss on DialogFragment
override fun show(manager: FragmentManager, tag: String?) {
try {
val superClass = this::class.java.superclass
val dismissedField = superClass?.getDeclaredField("mDismissed")
val isShownByMeField = superClass?.getDeclaredField("mShownByMe")
dismissedField?.isAccessible = true
isShownByMeField?.isAccessible = true
dismissedField?.setBoolean(this, false)
isShownByMeField?.setBoolean(this, true)
dismissedField?.isAccessible = false
@raxhaxor
raxhaxor / Pause audio and video in android WebView
Created January 5, 2021 14:12
Pause audio and video in android WebView
val audioPauseJavascipt = "function pauseAudioAndVideo(windowA){" +
" for(var i = 0; i < windowA.document.getElementsByTagName('video').length; i++){" +
" var media = windowA.document.getElementsByTagName('video')[i];" +
" media.pause(); " +
" media.currentTime = -1; " +
" media.volume = 0; " +
" }" +
" for(var i = 0; i < windowA.document.getElementsByTagName('audio').length; i++){" +
" var media = windowA.document.getElementsByTagName('audio')[i];" +
" media.pause(); " +
// DrwableMaker.kt
class DrawableMaker {
var shape: DrawableShape = DrawableShape.RECTANGLE
@ColorInt
var color: Int = 0
var cornerRadius: Int = 0
var cornerRadii: CornerRadii? = null
var gradientOrientation: GradientDrawable.Orientation = GradientDrawable.Orientation.TOP_BOTTOM
var gradientColors: IntArray? = null
@raxhaxor
raxhaxor / Set startDestination & startDestinationArgs in Navigation component programmatically
Last active March 27, 2021 16:00
Set startDestination & startDestinationArgs in Navigation component programmatically
val finalHost = navHostFragment as NavHostFragment
val navController = finalHost.navController
val graphInflater = navController.navInflater
val navGraph = graphInflater.inflate(R.navigation.my_subscription_nav_graph).apply {
val destination = if (isBeautySubscription) R.id.beautyServiceSubscriptionDetailsFragment else R.id.activeSubscriptionDetailFragment
startDestination = destination
}
navController.setGraph(navGraph, Bundle().apply {
putString("subscriptionId", intent.getStringExtra("subscriptionId"))