<commit_before>package com.mikepenz.materialdrawer.util

import android.os.Bundle
import android.view.View
import androidx.annotation.IdRes
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import com.mikepenz.materialdrawer.model.NavigationDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
import java.lang.ref.WeakReference

/**
 * Sets up a {@link Drawer} for use with a {@link NavController}.
 * The selected item in the Drawer will automatically be updated when the destination
 * changes.
 *
 * @param navController The NavController that hosts the destination
 * @param fallBackListener the listener to handle no navigationDrawerItems
 * @return
 */
fun MaterialDrawerSliderView.setupWithNavController(
        navController: NavController,
        successListener: ((v: View?, item: IDrawerItem<*>, position: Int) -> Boolean)? = null,
        fallBackListener: ((v: View?, item: IDrawerItem<*>, position: Int) -> Boolean)? = null,
) {
    DrawerNavigationUI.setupWithNavController(this, navController, successListener, fallBackListener)
}

/**
 * Created by petretiandrea on 19.07.19.
 */
object DrawerNavigationUI {

    /**
     * Sets up a {@link Drawer} for use with a {@link NavController}. It allow to navigate
     * to a destination when an item {@link NavigationDrawerItem} of drawer is selected.
     * The selected item in the Drawer will automatically be updated when the destination
     * changes.
     *
     * It automatically close the Drawer.
     *
     * @param drawer The drawer that should be kept in sync with changes to the NavController.<commit_msg>- keep backwards compatibility, add deprecation notice<commit_after>package com.mikepenz.materialdrawer.util

import android.os.Bundle
import android.view.View
import androidx.annotation.IdRes
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import com.mikepenz.materialdrawer.model.NavigationDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
import java.lang.ref.WeakReference

/**
 * Sets up a {@link Drawer} for use with a {@link NavController}.
 * The selected item in the Drawer will automatically be updated when the destination
 * changes.
 *
 * @param navController The NavController that hosts the destination
 * @param fallBackListener the listener to handle no navigationDrawerItems
 * @return
 */
@Deprecated("Added new successListener", ReplaceWith("setupWithNavController(navController, null, fallBackListener)"))
fun MaterialDrawerSliderView.setupWithNavController(
    navController: NavController,
    fallBackListener: ((v: View?, item: IDrawerItem<*>, position: Int) -> Boolean)? = null,
) {
    setupWithNavController(navController, null, fallBackListener)
}

/**
 * Sets up a {@link Drawer} for use with a {@link NavController}.
 * The selected item in the Drawer will automatically be updated when the destination
 * changes.
 *
 * @param navController The NavController that hosts the destination
 * @param successListener listener to retrieve a notification on successful navigation
 * @param fallBackListener the listener to handle no navigationDrawerItems
 * @return
 */
fun MaterialDrawerSliderView.setupWithNavController(
        navController: NavController,
        successListener: ((v: View?, item: IDrawerItem<*>, position: Int) -> Boolean)? = null,
        fallBackListener: ((v: View?, item: IDrawerItem<*>, position: Int) -> Boolean)? = null,
) {
    DrawerNavigationUI.setupWithNavController(this, navController, successListener, fallBackListener)
}

/**
 * Created by petretiandrea on 19.07.19.
 */
object DrawerNavigationUI {

    /**
     * Sets up a {@link Drawer} for use with a {@link NavController}. It allow to navigate
     * to a destination when an item {@link NavigationDrawerItem} of drawer is selected.
     * The selected item in the Drawer will automatically be updated when the destination
     * changes.
     *
     * It automatically close the Drawer.
     *
     * @param drawer The drawer that should be kept in sync with changes to the NavController.
{'fraction_non_alphanumeric': 0.08366721659203394, 'fraction_numerical': 0.0028281876031110063, 'mean_word_length': 4.576872536136662, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7325174', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1119, 'n_words': 391}