Create an account menu similar to the wpmudev menu item

I am trying to add an 'account-menu' menu item to my primary menu that includes an avatar and sub menu items like login/out and edit profile links. It's similar to what your own wpmudev site uses, and also what the wordpress admin bar uses.

So far the best I can do is add a login/out item using the following code:

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
    if (is_user_logged_in() && $args->theme_location == 'primary') {
        $items .= '<li>  <a href=&quot;'. wp_logout_url() .'&quot;>Log Out</a></li>';
    }
    elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
        $items .= '<li><a href=&quot;'. site_url('wp-login.php') .'&quot;>Log In</a></li>';
    }
    return $items;
}

But I can't figure out how to show the avatar, and include the login item within that submenu. I don't know much about PHP, so any help with the code would be greatly appreciated!

Thanks so much for the help!

Michael