This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns true if the navigation controller is still pointing at 'this' fragment, or false if it already navigated away. | |
*/ | |
fun Fragment.mayNavigate(): Boolean { | |
val navController = findNavController() | |
val destinationIdInNavController = navController.currentDestination?.id | |
// add tag_navigation_destination_id to your ids.xml so that it's unique: | |
val destinationIdOfThisFragment = view?.getTag(R.id.tag_navigation_destination_id) ?: destinationIdInNavController |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Navigates only if this is safely possible; when this Fragment is still the current destination. | |
*/ | |
fun Fragment.navigateSafe( | |
@IdRes resId: Int, | |
args: Bundle? = null, | |
navOptions: NavOptions? = null, | |
navigatorExtras: Navigator.Extras? = null | |
) { | |
if (mayNavigate()) findNavController().navigate( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bharatpe.nativeloader | |
import android.content.Context | |
import android.graphics.Rect | |
import android.util.AttributeSet | |
import android.util.Log | |
import android.view.GestureDetector | |
import android.view.MotionEvent | |
import android.view.View | |
import android.view.ViewGroup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.fragment.app.DialogFragment | |
import androidx.fragment.app.Fragment | |
import androidx.lifecycle.DefaultLifecycleObserver | |
import androidx.lifecycle.Lifecycle | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.viewbinding.ViewBinding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Target(AnnotationTarget.CLASS) | |
@Retention(AnnotationRetention.SOURCE) | |
/** | |
* Friendly reminder that this might not be the best place to do major changes. Or any changes at all. | |
* Use the [reason] arg to point your teammates and your future-self to some documentation. | |
*/ | |
annotation class HereBeDragons(val reason: String) |
OlderNewer