<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.6.2">Jekyll</generator><link href="https://geoffreymetais.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://geoffreymetais.github.io/" rel="alternate" type="text/html" /><updated>2017-12-07T12:28:37+00:00</updated><id>https://geoffreymetais.github.io/</id><title type="html">Android dev blog</title><subtitle>Personal blog about Android dev &amp; VLC</subtitle><author><name>Geoffrey Métais</name></author><entry><title type="html">Announcing VLC 2.5 release!</title><link href="https://geoffreymetais.github.io/features/vlc-25/" rel="alternate" type="text/html" title="Announcing VLC 2.5 release!" /><published>2017-10-02T00:00:00+00:00</published><updated>2017-10-02T00:00:00+00:00</updated><id>https://geoffreymetais.github.io/features/vlc-25</id><content type="html" xml:base="https://geoffreymetais.github.io/features/vlc-25/">&lt;p&gt;VLC is back on Play Store! Version 2.0 is more than 1 year old and will leave room for 2.5 which brings very interesting evolutions!
&lt;!--summary--&gt;&lt;/p&gt;

&lt;p&gt;VLC for Android releases have been trapped in VLC 3.0 preparation and big media library refactoring black holes.
So, there hasn’t been any update for 13 months, but development is still active and cool new stuff is coming!&lt;/p&gt;

&lt;p&gt;This post will focus on features, implementations will be detailed in other blog posts (like the &lt;a href=&quot;/code/diffutil/&quot;&gt;DiffUtil&lt;/a&gt; intro).&lt;/p&gt;

&lt;aside class=&quot;sidebar__right&quot;&gt;
&lt;nav class=&quot;toc&quot;&gt;
    &lt;header&gt;&lt;h4 class=&quot;nav__title&quot;&gt;&lt;i class=&quot;fa fa-gears&quot;&gt;&lt;/i&gt; Incoming features&lt;/h4&gt;&lt;/header&gt;
&lt;ul class=&quot;toc__menu&quot; id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#ux-evolutions&quot; id=&quot;markdown-toc-ux-evolutions&quot;&gt;UX evolutions&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#new-dynamic-ui&quot; id=&quot;markdown-toc-new-dynamic-ui&quot;&gt;New dynamic UI&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#new-audio-player-style&quot; id=&quot;markdown-toc-new-audio-player-style&quot;&gt;New Audio Player Style&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#picture-in-picture-mode&quot; id=&quot;markdown-toc-picture-in-picture-mode&quot;&gt;Picture-In-Picture mode&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#android-tv&quot; id=&quot;markdown-toc-android-tv&quot;&gt;Android TV&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#android-auto&quot; id=&quot;markdown-toc-android-auto&quot;&gt;Android Auto&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#chrome-os-support&quot; id=&quot;markdown-toc-chrome-os-support&quot;&gt;Chrome OS support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#360-videos-support&quot; id=&quot;markdown-toc-360-videos-support&quot;&gt;360° Videos support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#search&quot; id=&quot;markdown-toc-search&quot;&gt;Search&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#miscellaneous-new-features&quot; id=&quot;markdown-toc-miscellaneous-new-features&quot;&gt;Miscellaneous new features&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#under-the-hood&quot; id=&quot;markdown-toc-under-the-hood&quot;&gt;Under the hood&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#medialibrary&quot; id=&quot;markdown-toc-medialibrary&quot;&gt;MediaLibrary&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#playback-performance--formats-support&quot; id=&quot;markdown-toc-playback-performance--formats-support&quot;&gt;Playback performance &amp;amp; formats support&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#future&quot; id=&quot;markdown-toc-future&quot;&gt;Future&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

  &lt;/nav&gt;
&lt;/aside&gt;

&lt;p&gt;For now, let me introduce you to the new VLC for Android.&lt;/p&gt;

&lt;p&gt;Minimum Android version is now &lt;strong&gt;Gingerbread&lt;/strong&gt;.&lt;br /&gt;
FroYo support has been abandonned, these devices cannot access Google Play Store anymore.&lt;/p&gt;

&lt;h1 id=&quot;ux-evolutions&quot;&gt;UX evolutions&lt;/h1&gt;

&lt;h2 id=&quot;new-dynamic-ui&quot;&gt;New dynamic UI&lt;/h2&gt;

&lt;p&gt;Video cards have been refactored, we now show you video details over its cover picture. This is a nicer presentation and gives room for displaying more videos at once.&lt;/p&gt;

&lt;p&gt;Audio lists have been slightly lifted too.
Others lists view have been reworked, like audio media, browsers and history. We got rid of cardview pattern, and got back to a more flat and clean design.&lt;/p&gt;

&lt;p&gt;You can now select multiple items at the same time, to start a playlist for example.&lt;/p&gt;

&lt;p&gt;Sort options have been spread to Audio and Browser sections.&lt;/p&gt;

&lt;p&gt;Info page has also been redesigned with a fancy collapse effect for thumbnail or cover.&lt;/p&gt;

&lt;p&gt;According to Material design principles, application has also become a bit more dynamic.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/video_sort.gif&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/dynamic_ui.gif&quot; alt=&quot;songs scrolling&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;new-audio-player-style&quot;&gt;New Audio Player Style&lt;/h2&gt;

&lt;p&gt;Audio player background is now a blurred version of current art cover if available.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/player_list.png&quot; alt=&quot;player list&quot; /&gt;
&lt;img src=&quot;/assets/images/v2.5/player_cover.png&quot; alt=&quot;player cover&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;picture-in-picture-mode&quot;&gt;Picture-In-Picture mode&lt;/h2&gt;

&lt;p&gt;VLC implements PiP support for Oreo devices and even Nougat Android TVs. You can activate it from video advanced options during playback.&lt;/p&gt;

&lt;p&gt;We also added an option to automatically continue video playback in PiP or background mode (audio only) while multitasking.&lt;br /&gt;
Go in VLC settings to activate it and video playback will switch to PiP when you’ll press HOME button.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/pip.png&quot; alt=&quot;player cover&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;android-tv&quot;&gt;Android TV&lt;/h2&gt;

&lt;p&gt;TV interface had its own minor lifting too.
Background is filled with blurred covers and colors are warmer. Also I made long media titles scroll, I heard your (justified) frustration :)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/tv_main.png&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/tv_music_player.png&quot; alt=&quot;audio player&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;android-auto&quot;&gt;Android Auto&lt;/h1&gt;

&lt;p&gt;This release will bring Android Auto compatibility.&lt;br /&gt;
You’ll be able to use VLC as your travel music player with easy browsing into you audio library, with the minimum possible distraction from driving.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/auto_playing.png&quot; alt=&quot;auto player&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/auto_menu.png&quot; alt=&quot;auto menu&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;VLC also supports voice actions on Android Auto:&lt;br /&gt;
You can ask “&lt;em&gt;play Daft Punk&lt;/em&gt; (with VLC)” and Google Assistant will recognize whether it’s an artist, an album or a song you’re asking for and command VLC to play it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/auto_voice_landscape.gif&quot; alt=&quot;auto voice&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;chrome-os-support&quot;&gt;Chrome OS support&lt;/h1&gt;

&lt;p&gt;VLC has been tested and adapted for latest Chrome OS running Android apps. You now have an awesome media application ready for your chromebook!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/chromeos.png&quot; alt=&quot;Chrome OS&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;360-videos-support&quot;&gt;360° Videos support&lt;/h1&gt;

&lt;p&gt;VLC now supports 360° videos, you can change viewpoint by swiping or with remote control arrows.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/360.png&quot; alt=&quot;video 360&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cardboard/VR mode is not available yet but we are working on it.&lt;/p&gt;

&lt;h1 id=&quot;search&quot;&gt;Search&lt;/h1&gt;

&lt;p&gt;Search has been split in two modes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;First step, the text you type in triggers a &lt;strong&gt;filtering&lt;/strong&gt; in the current view. Exactly like in current playlist view.&lt;/li&gt;
  &lt;li&gt;If you want to do a global search, click on the &lt;code class=&quot;highlighter-rouge&quot;&gt;SEARCH IN ALL MEDIALIBRARY&lt;/code&gt; button to show the new search view. This will bring detailed results grouped by video/artist/album/songs/genres/playlist.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/search.gif&quot; alt=&quot;search global&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Bonus:
VLC is now compatible with voice search.&lt;br /&gt;
Asking Google Now &lt;em&gt;“Search Artic Monkeys in VLC”&lt;/em&gt; will trigger a &lt;em&gt;Arctic Monkeys&lt;/em&gt; search and show you this new search result screen.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.5/voice_search.gif&quot; alt=&quot;search voice&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;miscellaneous-new-features&quot;&gt;Miscellaneous new features&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;DayNight mode integration&lt;/li&gt;
  &lt;li&gt;Audio boost in video&lt;/li&gt;
  &lt;li&gt;Equalizer custom presets&lt;/li&gt;
  &lt;li&gt;Save and resume position for podcasts &amp;amp; audiobooks&lt;/li&gt;
  &lt;li&gt;Restored double/long click on remote play to skip songs&lt;/li&gt;
  &lt;li&gt;Removed sound lowering on notification&lt;/li&gt;
  &lt;li&gt;Force previous song on audioplayer swipe&lt;/li&gt;
  &lt;li&gt;Fix audioplayer layout for black theme and RTL&lt;/li&gt;
  &lt;li&gt;Save subtitles delay and optionally audio delay for each file.&lt;/li&gt;
  &lt;li&gt;Support for devices with large aspect ratio, like G6 and S8 phones&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;under-the-hood&quot;&gt;Under the hood&lt;/h1&gt;

&lt;h2 id=&quot;medialibrary&quot;&gt;MediaLibrary&lt;/h2&gt;

&lt;p&gt;That’s the most important change in this update, because it affects the whole application, but you should barely notice it…&lt;/p&gt;

&lt;p&gt;VLC now uses &lt;a href=&quot;https://code.videolan.org/videolan/medialibrary&quot;&gt;medialibrary&lt;/a&gt; like VLC for Tizen (other VLC ports will follow).&lt;br /&gt;
It’s a C++ library, written by &lt;a href=&quot;http://www.beauzee.fr/&quot;&gt;Hugo Beauzée-Luyssen&lt;/a&gt;, which parses storages for video/audio files and manages a sqlite database to model your media library (with album, artist, genre classification, etc..). It replaces the old system we had on Android which just saved media files with their metadata, we had no proper structure for media library.&lt;br /&gt;
Categories lists are now faster to show up, we don’t have to generate them at runtime. And this is all native code, which is faster than Java.&lt;br /&gt;
Beside this speed improvement, one of the main benefits of this medialibrary is to provide better &lt;a href=&quot;#search&quot;&gt;search results&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For now we are focusing on the first scan performance to make it at least as fast as the previous system.&lt;/p&gt;

&lt;p&gt;So, this library is aimed to be a common module of all VLC ports, wich means all debugging, performance and any improvement will benefit other platforms.&lt;/p&gt;

&lt;p&gt;Next steps for this library will be media scrapping, and network scan:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Medialibrary will get information and illustrations for your media, so we’ll be able to present you a nice collection instead of an uncheerful files list. We will also group media by shows/seasons et genre/release year/whatever&lt;/li&gt;
  &lt;li&gt;You will be able to scan your NAS content to access your media easily.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will make VLC a fully featured media center!&lt;/p&gt;

&lt;h2 id=&quot;playback-performance--formats-support&quot;&gt;Playback performance &amp;amp; formats support&lt;/h2&gt;

&lt;p&gt;VLC core team worked hard too to bring performance improvements and some new features. Here are some highlights:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Adaptive (HLS/Dash) &amp;amp; TS playback improved&lt;/li&gt;
  &lt;li&gt;OpenGLES 2.0 is now used to render video (for software decoders &amp;amp; mediacodec)&lt;/li&gt;
  &lt;li&gt;Support for VP8/9/10 in MP4&lt;/li&gt;
  &lt;li&gt;HDMI passthrough&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;future&quot;&gt;Future&lt;/h1&gt;

&lt;p&gt;We also plan to implement a feature to &lt;strong&gt;download media on your device&lt;/strong&gt;, in order to sync your series episodes or songs from your NAS to your device.&lt;/p&gt;

&lt;p&gt;We’d like to support videos playlists like we do with videos grouped by their common name prefix.&lt;/p&gt;

&lt;p&gt;As previously stated, medialibrary will help VLC to turn into a real &lt;strong&gt;media center&lt;/strong&gt; with fancy movies/tv shows presentation, and better artists/albums artworks.&lt;/p&gt;

&lt;p&gt;At last, I started an &lt;strong&gt;extension API&lt;/strong&gt; to help everyone eager to develop android applications that can provide content to VLC, and benefit from VLC Auto and TV implementation.
As a start, we will release (with sources of course) extensions for podcasts subscriptions and Google Drive access.&lt;/p&gt;</content><author><name>Geoffrey Métais</name></author><category term="vlc" /><category term="android" /><summary type="html">VLC is back on Play Store! Version 2.0 is more than 1 year old and will leave room for 2.5 which brings very interesting evolutions!</summary></entry><entry><title type="html">Signing android releases with yubikey</title><link href="https://geoffreymetais.github.io/code/key-signing/" rel="alternate" type="text/html" title="Signing android releases with yubikey" /><published>2017-06-01T00:00:00+00:00</published><updated>2017-06-01T00:00:00+00:00</updated><id>https://geoffreymetais.github.io/code/key-signing</id><content type="html" xml:base="https://geoffreymetais.github.io/code/key-signing/">&lt;p&gt;At VideoLAN, we recently changed our signing procedure to leverage our security keys.
As explained on &lt;a href=&quot;https://developers.yubico.com/PIV/Guides/Android_code_signing.html&quot;&gt;Yubico website&lt;/a&gt;, Android signing is quite easy.&lt;/p&gt;

&lt;aside class=&quot;sidebar__right&quot;&gt;
&lt;nav class=&quot;toc&quot;&gt;
    &lt;header&gt;&lt;h4 class=&quot;nav__title&quot;&gt;&lt;i class=&quot;fa fa-gears&quot;&gt;&lt;/i&gt; On This Page&lt;/h4&gt;&lt;/header&gt;
&lt;ul class=&quot;toc__menu&quot; id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#setup&quot; id=&quot;markdown-toc-setup&quot;&gt;Setup&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#install-dependencies&quot; id=&quot;markdown-toc-install-dependencies&quot;&gt;Install dependencies&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#prepare-configuration-file&quot; id=&quot;markdown-toc-prepare-configuration-file&quot;&gt;Prepare configuration file&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#set-up-your-own-management-key&quot; id=&quot;markdown-toc-set-up-your-own-management-key&quot;&gt;Set up your own management key&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#change-your-pin&quot; id=&quot;markdown-toc-change-your-pin&quot;&gt;Change your PIN&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#keystore-import&quot; id=&quot;markdown-toc-keystore-import&quot;&gt;Keystore import&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#app-signature&quot; id=&quot;markdown-toc-app-signature&quot;&gt;App signature&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#scripting&quot; id=&quot;markdown-toc-scripting&quot;&gt;Scripting&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#jarsigner&quot; id=&quot;markdown-toc-jarsigner&quot;&gt;Jarsigner&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

  &lt;/nav&gt;
&lt;/aside&gt;

&lt;p&gt;With this method, I can now sign the VLC releases on any of my computers without duplicating the keystore file. And keystore password is replaced by my Yubikey PIN.&lt;/p&gt;

&lt;p&gt;Here is the precise process we went through to get this done.&lt;/p&gt;

&lt;h1 id=&quot;setup&quot;&gt;Setup&lt;/h1&gt;

&lt;h3 id=&quot;install-dependencies&quot;&gt;Install dependencies&lt;/h3&gt;
&lt;p class=&quot;notice--info&quot;&gt;I am considering a Debian based distribution with open JDK 8 installed for this post.&lt;/p&gt;

&lt;p&gt;First of all, we need to install the pkcs11 opensc lib and the zipalign tool&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get install opensc-pkcs11 zipalign
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;notice--info&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;zipalign&lt;/code&gt; can also be found in &lt;em&gt;android_sdk_path&lt;/em&gt;/build-tools/&lt;em&gt;version&lt;/em&gt;/&lt;/p&gt;

&lt;h3 id=&quot;prepare-configuration-file&quot;&gt;Prepare configuration file&lt;/h3&gt;
&lt;p&gt;Then, we prepare the pkcs11 configuration. Let’s create file &lt;code class=&quot;highlighter-rouge&quot;&gt;pkcs11_java.cfg&lt;/code&gt; and fill it with:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;name = OpenSC-PKCS11
description = SunPKCS11 via OpenSC
library = /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so
slotListIndex = 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;notice--info&quot;&gt;Yubico How-To advises &lt;code class=&quot;highlighter-rouge&quot;&gt;slotListIndex = 1&lt;/code&gt;, but I had to set it to 0 to make it work with my Yubikey 4.&lt;/p&gt;

&lt;p&gt;Let’s assume we save it in: &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.pkcs11_java.cfg&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;set-up-your-own-management-key&quot;&gt;Set up your own management key&lt;/h3&gt;
&lt;p&gt;If you did not set your management key, you have to do it now:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;key=`dd if=/dev/random bs=1 count=24 2&amp;gt;/dev/null | hexdump -v -e '/1 &quot;%02X&quot;'`
echo $key
yubico-piv-tool -a set-mgm-key -n $key
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;change-your-pin&quot;&gt;Change your PIN&lt;/h3&gt;
&lt;p&gt;Same for PIN setting, default one is &lt;em&gt;123456&lt;/em&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;yubico-piv-tool -a change-pin -P 123456 -N &amp;lt;NEW PIN&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;keystore-import&quot;&gt;Keystore import&lt;/h1&gt;

&lt;p&gt;Now it’s time to import our keystore to the key PIV slot.&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;keytool -importkeystore -srckeystore mykeystore.keystore -destkeystore mykeystorey.p12 -srcstoretype jks -deststoretype pkcs12
yubico-piv-tool -s 9a -a import-key -a import-cert -i mykeystorey.p12 -K PKCS12 -k
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You will be asked to type in the keystore password, then the certificate management key.&lt;/p&gt;

&lt;p class=&quot;notice--info&quot;&gt;Starting from now, you won’t have to type the keystore password anymore but your Yubikey PIN.&lt;/p&gt;

&lt;p&gt;We can check that our key is ready to sign apps:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;keytool -providerClass sun.security.pkcs11.SunPKCS11 -providerArg ~/.pkcs11_java.cfg -keystore NONE -storetype PKCS11 -list -J-Djava.security.debug=sunpkcs11
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;notice--warning&quot;&gt;This is the Yubikey PIN you have to type-in now.&lt;br /&gt;
And don’t forget to touch it if you enabled the ‘touch-to-sign’ option.&lt;/p&gt;

&lt;h1 id=&quot;app-signature&quot;&gt;App signature&lt;/h1&gt;
&lt;p&gt;In build tools 24.0.3 Google has released &lt;a href=&quot;https://developer.android.com/studio/command-line/apksigner.html&quot;&gt;apksigner&lt;/a&gt;, a new signature tool with convenient arguments like &lt;code class=&quot;highlighter-rouge&quot;&gt;--min-sdk-version&lt;/code&gt; to get sure the application signature is correct.&lt;/p&gt;

&lt;p class=&quot;notice--warning&quot;&gt;Until release (26.0.1) apksigner doesn’t handle pkcs11 protocol correctly. So, &lt;strong&gt;you need to use build-tools 26.0.1+&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We now have to get an &lt;strong&gt;unsigned&lt;/strong&gt; apk, so we must tell gradle to not apply any signing config for release builds&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; buildTypes {
        release {
            signingConfig null
            //…
        }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally we can sign an apk without our keystore, we just need the Yubikey to be plugged and fire up &lt;em&gt;apksigner&lt;/em&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ANDROID_SDK_PATH/build-tools/BUILD_TOOLS_VERSION/apksigner sign --ks NONE --ks-pass &quot;pass:$YUBI_PIN&quot; \
--min-sdk-version 9 --provider-class sun.security.pkcs11.SunPKCS11 \
--provider-arg pkcs11_java.cfg --ks-type PKCS11 app.apk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can now verify the package is signed:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apksigner verify --verbose app.apk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;verify&lt;/code&gt; accepts &lt;code class=&quot;highlighter-rouge&quot;&gt;--min-sdk-version&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;--max-sdk-version&lt;/code&gt; to ensure your users won’t get &lt;code class=&quot;highlighter-rouge&quot;&gt;103&lt;/code&gt; Play Store error code once the app is released.&lt;/p&gt;

&lt;h1 id=&quot;scripting&quot;&gt;Scripting&lt;/h1&gt;

&lt;p&gt;Here is the full bash script I use to sign all my apks at once:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#! /bin/sh&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Please enter Yubikey PIN code &quot;&lt;/span&gt;
stty &lt;span class=&quot;nt&quot;&gt;-echo&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;trap&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'stty echo'&lt;/span&gt; EXIT
&lt;span class=&quot;nb&quot;&gt;read&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'PIN: '&lt;/span&gt; YUBI_PIN
stty &lt;span class=&quot;nb&quot;&gt;echo
trap&lt;/span&gt; - EXIT

&lt;span class=&quot;nv&quot;&gt;BT_VERSION&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;26.0.1&quot;&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Signing apks&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;i &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;ls&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;.apk&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ANDROID_SDK&lt;/span&gt;/build-tools/&lt;span class=&quot;nv&quot;&gt;$BT_VERSION&lt;/span&gt;/zipalign 4 &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt;.tmp &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; mv &lt;span class=&quot;nt&quot;&gt;-vf&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt;.tmp &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ANDROID_SDK&lt;/span&gt;/build-tools/&lt;span class=&quot;nv&quot;&gt;$BT_VERSION&lt;/span&gt;/apksigner sign &lt;span class=&quot;nt&quot;&gt;--ks&lt;/span&gt; NONE &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;--ks-pass&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;pass:&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$YUBI_PIN&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--min-sdk-version&lt;/span&gt; 9 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;--max-sdk-version&lt;/span&gt; 26 &lt;span class=&quot;nt&quot;&gt;--provider-class&lt;/span&gt; sun.security.pkcs11.SunPKCS11 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;--provider-arg&lt;/span&gt; ~/.pkcs11_java.cfg &lt;span class=&quot;nt&quot;&gt;--ks-type&lt;/span&gt; PKCS11 &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;done
&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;unset &lt;/span&gt;YUBI_PIN
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;jarsigner&quot;&gt;Jarsigner&lt;/h1&gt;

&lt;p&gt;We can also use jarsigner to sign your apk:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;jarsigner -providerClass sun.security.pkcs11.SunPKCS11 -providerArg ~/.pkcs11_java.cfg \
  -keystore NONE -storetype PKCS11 -sigalg SHA1withRSA -digestalg SHA1 \
  app.apk &quot;Certificate for PIV Authentication&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;notice--info&quot;&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;-sigalg SHA1withRSA -digestalg SHA1&lt;/code&gt; parameters are needed because we support old devices. If you don’t support Android 4.2 and older you can rip it off.&lt;/p&gt;
&lt;p class=&quot;notice--warning&quot;&gt;With jarsigner, we need to zipalign the apk &lt;strong&gt;after&lt;/strong&gt; signing them.&lt;/p&gt;

&lt;p&gt;And verify the package is signed:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;jarsigner -verify app.apk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Geoffrey Métais</name></author><category term="vlc" /><category term="android" /><summary type="html">Use a security USB Key to embed your Play Store Keystore and sign your releases on the go</summary></entry><entry><title type="html">DiffUtil off the UI thread</title><link href="https://geoffreymetais.github.io/code/diffutil-threading/" rel="alternate" type="text/html" title="DiffUtil off the UI thread" /><published>2017-03-13T00:00:00+00:00</published><updated>2017-03-13T00:00:00+00:00</updated><id>https://geoffreymetais.github.io/code/diffutil-threading</id><content type="html" xml:base="https://geoffreymetais.github.io/code/diffutil-threading/">&lt;aside class=&quot;sidebar__right&quot;&gt;
&lt;nav class=&quot;toc&quot;&gt;
    &lt;header&gt;&lt;h4 class=&quot;nav__title&quot;&gt;&lt;i class=&quot;fa fa-code-fork&quot;&gt;&lt;/i&gt; DiffUtil steps&lt;/h4&gt;&lt;/header&gt;
&lt;ul class=&quot;toc__menu&quot; id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#threading&quot; id=&quot;markdown-toc-threading&quot;&gt;Threading&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#skip-queued-updates&quot; id=&quot;markdown-toc-skip-queued-updates&quot;&gt;Skip queued updates&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#code-factorization&quot; id=&quot;markdown-toc-code-factorization&quot;&gt;Code factorization&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#the-kotlin-way&quot; id=&quot;markdown-toc-the-kotlin-way&quot;&gt;The Kotlin way&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

  &lt;/nav&gt;
&lt;/aside&gt;
&lt;p&gt;As stated in the &lt;a href=&quot;/code/diffutil/&quot;&gt;previous post&lt;/a&gt;, we do process all &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.DiffResult.html&quot;&gt;DiffUtil.DiffResult&lt;/a&gt; calculations in main thread to preserve adapter state consistency.&lt;br /&gt;
But in VLC, we have to deal with potentially HUGE datasets, so calculation could take some time.&lt;/p&gt;

&lt;p&gt;Background calculation is mandatory then, and we have to preserve dataset consistency. I lost a few days trying different techniques then finally chose to stack updates within a queue and use it for all dataset operations, because it provides consistency safetyness.&lt;br /&gt;
I’ve been inspired by &lt;a href=&quot;https://medium.com/@jonfhancock/get-threading-right-with-diffutil-423378e126d2&quot;&gt;Jon F Hancock blog post&lt;/a&gt; to get this right.&lt;/p&gt;

&lt;p class=&quot;notice--warning&quot;&gt;To achieve background calculation and preserve data consistency, we now have to use our &lt;code class=&quot;highlighter-rouge&quot;&gt;update()&lt;/code&gt; method for &lt;strong&gt;all&lt;/strong&gt; dataset updates or manage the pending queue state manually.&lt;/p&gt;

&lt;h2 id=&quot;threading&quot;&gt;Threading&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;update(list)&lt;/code&gt; method is now splitted in two, in order to allow queueing and recursivity:&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;update(list)&lt;/code&gt; which is now limited to queueing the new list and triggering &lt;code class=&quot;highlighter-rouge&quot;&gt;internalUpdate(list)&lt;/code&gt; to do the actual job.&lt;/p&gt;

&lt;p class=&quot;notice--info&quot;&gt;Notice all queue accesses or modifications are done in the main thread (for the same reasons that for dataset changes).&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Our queue with next dataset&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayDeque&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayDeque&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

&lt;span class=&quot;nd&quot;&gt;@MainThread&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//no pending update, let's go&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//private method, called exclusively by update()&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;VLCApplication&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;runBackground&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Runnable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;DiffResult&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;calculateDiff&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MediaItemDiffCallback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//back to main thread for the update&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;VLCApplication&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;runOnMainThread&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Runnable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
                &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;dispatchUpdatesTo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseBrowserAdapter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                    &lt;span class=&quot;c1&quot;&gt;//We are done with this dataset&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
                    &lt;span class=&quot;c1&quot;&gt;//Process the next queued dataset if any&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;});&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For simple actions, like item insertion/removal, we must check the &lt;code class=&quot;highlighter-rouge&quot;&gt;mPendingUpdates&lt;/code&gt; state. Either we handle it, either we use &lt;code class=&quot;highlighter-rouge&quot;&gt;update(list)&lt;/code&gt; in order to respect the queue process we just set. So, we have to copy the most recent dataset, add/remove the item then call &lt;code class=&quot;highlighter-rouge&quot;&gt;update(list)&lt;/code&gt;.&lt;/p&gt;

&lt;p class=&quot;notice--warning&quot;&gt;Using &lt;code class=&quot;highlighter-rouge&quot;&gt;mDataset&lt;/code&gt; as the current reference state can be a mistake, if &lt;code class=&quot;highlighter-rouge&quot;&gt;mPendingUpdates&lt;/code&gt; is not empty, another dataset will be processed between &lt;code class=&quot;highlighter-rouge&quot;&gt;mDataset&lt;/code&gt; and our new list with item added or removed. In this case, we have to peek the last list from &lt;code class=&quot;highlighter-rouge&quot;&gt;mPendingUpdates&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@MainThread&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;addItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peekLast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For item removal, I’d recommend to just avoid calling it with position only, prefer to pass the item reference. Because the position value is likely to be wrong if there is a pending update at this time.&lt;/p&gt;

&lt;h2 id=&quot;skip-queued-updates&quot;&gt;Skip queued updates&lt;/h2&gt;

&lt;p&gt;In case you can receive a bunch of updates while &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.html&quot;&gt;DiffUtil&lt;/a&gt; is calculating the &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.DiffResult.html&quot;&gt;DiffUtil.DiffResult&lt;/a&gt;, you get a stack of new datasets to process. Let’s skip to the last one: as we made sure they are consistent we can do it. That’s just factorizing the updates.&lt;br /&gt;
We have to clear the &lt;code class=&quot;highlighter-rouge&quot;&gt;mPendingUpdates&lt;/code&gt; queue from all its elements but the last one.&lt;/p&gt;

&lt;p&gt;Here is our current queue processing:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Which becomes:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// more than one update queued&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lastList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peekLast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;clear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lastList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;code-factorization&quot;&gt;Code factorization&lt;/h2&gt;

&lt;p&gt;Here is my base adapter class, dedicated to pending queue management. Children classes just need to call &lt;code class=&quot;highlighter-rouge&quot;&gt;update(newList)&lt;/code&gt; for any update.&lt;br /&gt;
(I chose to not specify &lt;code class=&quot;highlighter-rouge&quot;&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; because I also use arrays)&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BaseQueuedAdapter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VH&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RecyclerView&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ViewHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RecyclerView&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Adapter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;VH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayDeque&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayDeque&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Handler&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mHandler&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Handler&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Looper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getMainLooper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@MainThread&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hasPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@MainThread&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;peekLast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peekLast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@MainThread&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;thread&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Runnable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;DiffResult&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;calculateDiff&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ItemDiffCallback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mDataList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;mHandler&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Runnable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
                    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;dispatchUpdatesTo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseQueuedAdapter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;processQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;});&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@MainThread&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;processQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lastList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peekLast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;clear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lastList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mPendingUpdates&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;My adapter class becomes:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MyAdapter&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BaseQueuedAdapter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MyAdapter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ViewHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s it, we now have asynchronous and classy RecyclerView updates without extra boilerplate 😎&lt;/p&gt;

&lt;h2 id=&quot;the-kotlin-way&quot;&gt;The Kotlin way&lt;/h2&gt;

&lt;p&gt;Because we can do better with Kotlin!&lt;/p&gt;

&lt;p&gt;First of all, we use an &lt;a href=&quot;https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#actors&quot;&gt;Actor&lt;/a&gt;, to easily operate a &lt;a href=&quot;https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#channels&quot;&gt;Channel&lt;/a&gt;, so we can send this one every single update we want.  It’s capacity is set to &lt;code class=&quot;highlighter-rouge&quot;&gt;CONFLATED&lt;/code&gt; which means that the channel will bufffer at most one element: when busy, it will just replace the buffered element by the new one we provided. That’s a smarter way to process our waiting queue.&lt;/p&gt;

&lt;p&gt;When ready, &lt;code class=&quot;highlighter-rouge&quot;&gt;eventActor&lt;/code&gt; will call &lt;code class=&quot;highlighter-rouge&quot;&gt;internalUpdate&lt;/code&gt; in the &lt;code class=&quot;highlighter-rouge&quot;&gt;CommonPool&lt;/code&gt;, in which we still do the calculation.&lt;br /&gt;
UI dispatch is done in &lt;code class=&quot;highlighter-rouge&quot;&gt;launch&lt;/code&gt; higher-order function with &lt;code class=&quot;highlighter-rouge&quot;&gt;UI&lt;/code&gt; as parameter so we can &lt;code class=&quot;highlighter-rouge&quot;&gt;join()&lt;/code&gt; it:&lt;br /&gt;
In Kotlin, &lt;code class=&quot;highlighter-rouge&quot;&gt;join()&lt;/code&gt; doesn’t block the current thread but it &lt;em&gt;suspends&lt;/em&gt; it while UI job is done, so no thread blocking!&lt;/p&gt;

&lt;p&gt;And as a bonus, we gained thread safety! We can call &lt;code class=&quot;highlighter-rouge&quot;&gt;update(list)&lt;/code&gt; from any thread now.&lt;/p&gt;

&lt;div class=&quot;language-kotlin highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DiffUtilAdapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VH&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RecyclerView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ViewHolder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RecyclerView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Adapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;VH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;mDataset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;listOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;diffCallback&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lazy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LazyThreadSafetyMode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NONE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffCallback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;eventActor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;actor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;capacity&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CONFLATED&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;list&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventActor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;offer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;suspend&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;internalUpdate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calculateDiff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;diffCallback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;apply&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;list&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;launch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dispatchUpdatesTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;@DiffUtilAdapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DiffCallback&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;lateinit&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getOldListSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getNewListSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;areContentsTheSame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;areItemsTheSame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Geoffrey Métais</name></author><category term="vlc" /><category term="android" /><summary type="html">Now we have superb RecyclerView updates with DiffUtil, we want to preserve UI thread from being blocked by potentially heavy calculations</summary></entry><entry><title type="html">Recyclerview++ with DiffUtil</title><link href="https://geoffreymetais.github.io/code/diffutil/" rel="alternate" type="text/html" title="Recyclerview++ with DiffUtil" /><published>2017-03-03T00:00:00+00:00</published><updated>2017-03-03T00:00:00+00:00</updated><id>https://geoffreymetais.github.io/code/diffutil</id><content type="html" xml:base="https://geoffreymetais.github.io/code/diffutil/">&lt;p&gt;&lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.html&quot;&gt;DiffUtil&lt;/a&gt; is an AppCompat utility class developed to ease Recyclerview updates.&lt;/p&gt;

&lt;p&gt;You just pass it the new dataset and current one and it automagically handles all the &lt;code class=&quot;highlighter-rouge&quot;&gt;notifyItemRange*&lt;/code&gt; events to provide cool RecyclerView animations or subtle item updates (like a single progressbar update instead of the whole item layout rebinding).&lt;/p&gt;

&lt;aside class=&quot;sidebar__right&quot;&gt;
&lt;nav class=&quot;toc&quot;&gt;
    &lt;header&gt;&lt;h4 class=&quot;nav__title&quot;&gt;&lt;i class=&quot;fa fa-code-fork&quot;&gt;&lt;/i&gt; DiffUtil steps&lt;/h4&gt;&lt;/header&gt;
&lt;ul class=&quot;toc__menu&quot; id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#principles&quot; id=&quot;markdown-toc-principles&quot;&gt;Principles&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#basic-usage&quot; id=&quot;markdown-toc-basic-usage&quot;&gt;Basic usage&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#finer-items-updates&quot; id=&quot;markdown-toc-finer-items-updates&quot;&gt;Finer items updates&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#diffutil-process-scheme&quot; id=&quot;markdown-toc-diffutil-process-scheme&quot;&gt;DiffUtil process scheme&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#moves-detection&quot; id=&quot;markdown-toc-moves-detection&quot;&gt;Moves detection&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#going-further&quot; id=&quot;markdown-toc-going-further&quot;&gt;Going further&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

  &lt;/nav&gt;
&lt;/aside&gt;

&lt;h2 id=&quot;principles&quot;&gt;Principles&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;Provide your custom &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback.html&quot;&gt;DiffUtil.Callback&lt;/a&gt; fed with the old and new datasets to the &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.html#calculateDiff(android.support.v7.util.DiffUtil.Callback&quot;&gt;DiffUtil.calculateDiff&lt;/a&gt; method, and obtain a &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.DiffResult.html&quot;&gt;DiffUtil.DiffResult&lt;/a&gt; which contains all the necessary operations (additions, deletions and optionnally moves) to get from old list to the new one.&lt;/li&gt;
  &lt;li&gt;Update your dataset&lt;/li&gt;
  &lt;li&gt;Call &lt;code class=&quot;highlighter-rouge&quot;&gt;diffResult.dispatchUpdatesTo(recyclerviewAdapter)&lt;/code&gt;, your recyclerviewAdapter will receive all the corresponding &lt;em&gt;notifyItemRange*&lt;/em&gt; events and benefit from shiny recyclerview animations!&lt;/li&gt;
&lt;/ol&gt;

&lt;p class=&quot;notice--warning&quot;&gt;It is strongly advised to run &lt;strong&gt;all dataset operations in the main thread, to ensure consistency&lt;/strong&gt;. And for now (until next post), DiffUtil calculations will also be run in the main thread for consistency concern.&lt;/p&gt;

&lt;h2 id=&quot;basic-usage&quot;&gt;Basic usage&lt;/h2&gt;

&lt;p&gt;Here is a simple example of DiffUtil powered recyclerview update method in browsers adapter:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@MainThread&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;DiffResult&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;calculateDiff&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MediaItemDiffCallback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mDataset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;dispatchUpdatesTo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MyAdapter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You can see we only have these 3 basic steps.&lt;br /&gt;
With &lt;code class=&quot;highlighter-rouge&quot;&gt;mDataset&lt;/code&gt; the current dataset, &lt;code class=&quot;highlighter-rouge&quot;&gt;newList&lt;/code&gt; the new one, and &lt;code class=&quot;highlighter-rouge&quot;&gt;false&lt;/code&gt; the parameter value for &lt;a href=&quot;#moves-detection&quot;&gt;moves detection&lt;/a&gt;, we don’t handle it for now.&lt;/p&gt;

&lt;p&gt;The base &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback.html&quot;&gt;DiffUtil.Callback&lt;/a&gt; implementation we use:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MediaItemDiffCallback&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Callback&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MediaItemDiffCallback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;oldList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;newList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getOldListSize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getNewListSize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;areItemsTheSame&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;areContentsTheSame&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For now, &lt;code class=&quot;highlighter-rouge&quot;&gt;areContentsTheSame&lt;/code&gt; always returns &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt;, we’ll see later how to use it for smarter updates.
Let’s focus on &lt;code class=&quot;highlighter-rouge&quot;&gt;areItemsTheSame&lt;/code&gt;: this is simply a equals&lt;em&gt;-ish&lt;/em&gt; method to determine if two instances correspond to the same model view.&lt;/p&gt;

&lt;p&gt;Now, with this diffResult, for every item insertion and deletion we get the precise adapter notification.&lt;br /&gt;
Typical application is list feeding, all new items are nicely inserted or removed which makes fancy animations to happen, like if we had set all the &lt;code class=&quot;highlighter-rouge&quot;&gt;notifyItemInserted&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;notifyItemDeleted&lt;/code&gt; one by one.&lt;/p&gt;

&lt;p&gt;A nicer use case is list/grid filtering. Here’s the result, with that simple &lt;code class=&quot;highlighter-rouge&quot;&gt;update(newList)&lt;/code&gt; call:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/filter.gif&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;finer-items-updates&quot;&gt;Finer items updates&lt;/h2&gt;

&lt;p&gt;In video section, we want to update an item view if media progress or thumbnail has changed, but we don’t want to completely rebind its view.&lt;br /&gt;
Until VLC 2.0.6, you could experience a flicker of the video you were watching once getting back from video player.
That’s because media progress had changed and we blindly updated the whole view (which triggered thumbnail reloading).&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href=&quot;https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback.html&quot;&gt;DiffUtil.Callback&lt;/a&gt; specific to video grid which not only checks if items are the same, but if their content has changed also:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VideoItemDiffCallback&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Callback&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;VideoItemDiffCallback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;oldList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;newList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getOldListSize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getNewListSize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;areItemsTheSame&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;areContentsTheSame&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
              &lt;span class=&quot;n&quot;&gt;TextUtils&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getArtworkMrl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getArtworkMrl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Nullable&lt;/span&gt;
        &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getChangePayload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Item&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newItemPosition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UPDATE_TIME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UPDATE_THUMB&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If &lt;code class=&quot;highlighter-rouge&quot;&gt;areItemsTheSame&lt;/code&gt; returns &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;areContentsTheSame&lt;/code&gt; is called for the same items. &lt;code class=&quot;highlighter-rouge&quot;&gt;areContentsTheSame&lt;/code&gt; returns &lt;code class=&quot;highlighter-rouge&quot;&gt;false&lt;/code&gt; if we detect small changes we want to propagate to the UI without totally rebinding the concerned item view.
In our case this is two &lt;code class=&quot;highlighter-rouge&quot;&gt;Item&lt;/code&gt; instances representing the same video file but artwork URL or time value has changed.&lt;/p&gt;

&lt;p&gt;If &lt;code class=&quot;highlighter-rouge&quot;&gt;areContentsTheSame&lt;/code&gt; returns &lt;code class=&quot;highlighter-rouge&quot;&gt;false&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;getChangePayload&lt;/code&gt; is called for the same items. We define here the updated value and return it. The dispatch util will call &lt;code class=&quot;highlighter-rouge&quot;&gt;notifyItemChanged(position, payload)&lt;/code&gt; with this value. Then it’s up to the adapter to manage the update:&lt;/p&gt;

&lt;p&gt;In the adapter, we override &lt;code class=&quot;highlighter-rouge&quot;&gt;onBindViewHolder(holder, position, payload)&lt;/code&gt; to achieve this:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;onBindViewHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ViewHolder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;holder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payloads&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloads&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;onBindViewHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;holder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;MediaWrapper&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mVideos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payloads&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;UPDATE_THUMB:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;AsyncImageLoader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;loadPicture&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;holder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;thumbView&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nl&quot;&gt;UPDATE_TIME:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;fillView&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;holder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;onBindViewHolder(holder, position, payloads)&lt;/code&gt; makes the smart move and updates the related view(s), instead of rebinding the whole item view. In our case, we load the thumb in the &lt;code class=&quot;highlighter-rouge&quot;&gt;ImageView&lt;/code&gt; or we regenerate the progress string and update the progress bar with &lt;code class=&quot;highlighter-rouge&quot;&gt;fillView()&lt;/code&gt;.&lt;br /&gt;
As the dataSet is already updated, we don’t need to pass the values here, so I opted for constants refering to the different actions.&lt;/p&gt;

&lt;h2 id=&quot;diffutil-process-scheme&quot;&gt;DiffUtil process scheme&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/diffutil/Diffutil_flow.png&quot; alt=&quot;flaw chart&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;moves-detection&quot;&gt;Moves detection&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;DiffUtil.calculateDiff&lt;/code&gt; algorithm can optionnally do a second pass to look for items movements between the old and new lists. If the sort order doesn’t change, it is useless to do it.&lt;br /&gt;
In VLC it’s only interesting in video grid for now, so we call:&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;DiffUtil&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;calculateDiff&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VideoItemDiffCallback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detectMoves&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Where &lt;code class=&quot;highlighter-rouge&quot;&gt;detectMoves&lt;/code&gt; variable is a boolean which is set to &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt; only in case of video resorting call, in other cases we spare the second pass. Thanks to it, animations are fancier with only moving cards. Without this moves detection we’d get disappearing and reappearing cards.&lt;/p&gt;

&lt;p&gt;Resorting videos with moves detection:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/sort.gif&quot; alt=&quot;sort no move&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Without moves detection:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/diffutil/sort_no_detection.gif&quot; alt=&quot;sort moves&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;going-further&quot;&gt;Going further&lt;/h2&gt;

&lt;p&gt;We now master diffutil, but we can do better and get calculation out of UI thread.&lt;br /&gt;
Rendez-vous to the second part of this post to check it out.&lt;/p&gt;</content><author><name>Geoffrey Métais</name></author><category term="vlc" /><category term="android" /><summary type="html">DiffUtil tool allowed greatly improving lists/grids updates in VLC, here is how we implemented it.</summary></entry><entry><title type="html">Announcing VLC 2.1 beta release!</title><link href="https://geoffreymetais.github.io/features/vlc-21-beta/" rel="alternate" type="text/html" title="Announcing VLC 2.1 beta release!" /><published>2017-02-23T00:00:00+00:00</published><updated>2017-02-23T00:00:00+00:00</updated><id>https://geoffreymetais.github.io/features/vlc-21-beta</id><content type="html" xml:base="https://geoffreymetais.github.io/features/vlc-21-beta/">&lt;p&gt;Not so much activity on Play Store since v2.0.6 release.&lt;br /&gt;
I’ve been quite busy but VLC keeps going on with very interesting evolutions!&lt;br /&gt;
&lt;!--summary--&gt;
This post will only deal with features, not their implementation. I will later publish other posts, more interesting for developers, about it.&lt;/p&gt;

&lt;aside class=&quot;sidebar__right&quot;&gt;
&lt;nav class=&quot;toc&quot;&gt;
    &lt;header&gt;&lt;h4 class=&quot;nav__title&quot;&gt;&lt;i class=&quot;fa fa-gears&quot;&gt;&lt;/i&gt; Incoming features&lt;/h4&gt;&lt;/header&gt;
&lt;ul class=&quot;toc__menu&quot; id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#ux-evolutions&quot; id=&quot;markdown-toc-ux-evolutions&quot;&gt;UX evolutions&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#presentation&quot; id=&quot;markdown-toc-presentation&quot;&gt;Presentation&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#new-audio-player-style&quot; id=&quot;markdown-toc-new-audio-player-style&quot;&gt;New Audio Player Style&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#dynamic-ui&quot; id=&quot;markdown-toc-dynamic-ui&quot;&gt;Dynamic UI&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#scrolling&quot; id=&quot;markdown-toc-scrolling&quot;&gt;Scrolling&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#updating-content&quot; id=&quot;markdown-toc-updating-content&quot;&gt;Updating content&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#tv-design&quot; id=&quot;markdown-toc-tv-design&quot;&gt;TV design&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#360-videos-support&quot; id=&quot;markdown-toc-360-videos-support&quot;&gt;360° Videos support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#search&quot; id=&quot;markdown-toc-search&quot;&gt;Search&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#android-auto&quot; id=&quot;markdown-toc-android-auto&quot;&gt;Android Auto&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#action-mode&quot; id=&quot;markdown-toc-action-mode&quot;&gt;Action mode&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#miscellaneous-new-features&quot; id=&quot;markdown-toc-miscellaneous-new-features&quot;&gt;Miscellaneous new features&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#under-the-hood&quot; id=&quot;markdown-toc-under-the-hood&quot;&gt;Under the hood&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#medialibrary&quot; id=&quot;markdown-toc-medialibrary&quot;&gt;MediaLibrary&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#playback-performance--formats-support&quot; id=&quot;markdown-toc-playback-performance--formats-support&quot;&gt;Playback performance &amp;amp; formats support&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#future&quot; id=&quot;markdown-toc-future&quot;&gt;Future&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

  &lt;/nav&gt;
&lt;/aside&gt;

&lt;p&gt;2.1.x version name will be used for beta only, we’ll decide later which version the stable release will be.&lt;/p&gt;

&lt;p&gt;To get it you need to &lt;a href=&quot;/vlc/testing/&quot;&gt;join the beta program&lt;/a&gt;, and you’ll receive it like a normal update.&lt;/p&gt;

&lt;p&gt;For now, let me introduce you to the new VLC for Android.&lt;/p&gt;

&lt;h2 id=&quot;ux-evolutions&quot;&gt;UX evolutions&lt;/h2&gt;

&lt;h3 id=&quot;presentation&quot;&gt;Presentation&lt;/h3&gt;
&lt;p&gt;Video cards have been refactored, we now show you video informations over its cover picture. This is a nicer presentation and gives room for displaying more videos at once.
Others lists view have been reworked too, like audio media, browsers and history. We got rid of cardview pattern, and got back to a more flat and clean design.&lt;/p&gt;

&lt;p&gt;Audio lists have been a bit lifted too but this change is lighter.&lt;/p&gt;

&lt;p&gt;Info page has also been redesigned with a fancy collapse effect for thumbnail or cover.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/video_grid.png&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/songs_list.png&quot; alt=&quot;info panel&quot; /&gt;
&lt;img src=&quot;/assets/images/v2.1/screen_info.png&quot; alt=&quot;info panel&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;new-audio-player-style&quot;&gt;New Audio Player Style&lt;/h3&gt;

&lt;p&gt;Audio player background is now a blurred version of current art cover if available.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/screen_player_list.png&quot; alt=&quot;player list&quot; /&gt;
&lt;img src=&quot;/assets/images/v2.1/screen_player_cover.png&quot; alt=&quot;player cover&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;dynamic-ui&quot;&gt;Dynamic UI&lt;/h3&gt;

&lt;h4 id=&quot;scrolling&quot;&gt;Scrolling&lt;/h4&gt;

&lt;p&gt;The action bar will now hide when your scroll your media lists, to save the more useful space possible while you’re looking for your media.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/scroll.gif&quot; alt=&quot;list scroll&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Album view has been revamped to become more #Material and now serves for playlists too&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/album.gif&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;updating-content&quot;&gt;Updating content&lt;/h4&gt;

&lt;p&gt;Thanks to the &lt;em&gt;DiffUtil&lt;/em&gt; tool from Appcompat library, grids/lists updates are now animated and more efficient.&lt;br /&gt;
One disturbing side effect is when you refresh and there’s no change in your media library. You won’t see any update, not even any flickering.&lt;br /&gt;
But the cool thing is whith actual content update, like during media scan or filtering the current view with &lt;a href=&quot;#search&quot;&gt;the new search UX&lt;/a&gt;, insertions/deletions and position changes are animated:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/sort.gif&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;tv-design&quot;&gt;TV design&lt;/h3&gt;

&lt;p&gt;TV interface had its own lifting too, nothing really impressive here.
Colors are less depressive and we make long media titles scroll, I heard your (justified) frustration :)&lt;/p&gt;

&lt;p&gt;The interesting new feature on TV is the Picture-In-Picture (aka PIP) mode, available for all Android TVs powered by Android 7+.&lt;br /&gt;
It’s really like our popup mode in classic phone/tablet interface (so we used the very same icon in &lt;em&gt;video advanced options&lt;/em&gt; for PIP).&lt;br /&gt;
You can still watch your video while using another application.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/tv_pip.png&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/tv_audio_player.png&quot; alt=&quot;audio player&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;360-videos-support&quot;&gt;360° Videos support&lt;/h2&gt;

&lt;p&gt;VLC now supports 360° videos, you can change viewpoint by swiping or with remote control arrows.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/360.png&quot; alt=&quot;video 360&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cardboard/VR mode is not available yet but we are working on it.&lt;/p&gt;

&lt;h2 id=&quot;search&quot;&gt;Search&lt;/h2&gt;
&lt;p&gt;Search has been splitted in two modes:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;First step, the text you type in triggers a &lt;strong&gt;filtering&lt;/strong&gt; in the current view. Exaclty like in current playlist view.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/filter.gif&quot; alt=&quot;search filter&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Then, if you want to do a global search, click on the &lt;code class=&quot;highlighter-rouge&quot;&gt;SEARCH IN ALL MEDIALIBRARY&lt;/code&gt; button to show the new search activity. Which will bring detailed results grouped by video/artist/album/songs/genres/playlist&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/search.gif&quot; alt=&quot;search global&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Bonus:
VLC will now be compatible with voice search.&lt;br /&gt;
Asking Google Now &lt;em&gt;“Search game in VLC”&lt;/em&gt; will trigger a &lt;em&gt;game&lt;/em&gt; search and show you this new search result screen.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/voice_search.gif&quot; alt=&quot;search voice&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;android-auto&quot;&gt;Android Auto&lt;/h2&gt;

&lt;p&gt;This release will bring Android Auto compatibility.&lt;br /&gt;
You’ll be able to use VLC as your travel music player with easy browsing into you audio library, with the minimum possible distraction from driving.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/auto_list.png&quot; alt=&quot;auto list&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/auto_main.png&quot; alt=&quot;auto main&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/auto_menu.png&quot; alt=&quot;auto menu&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/auto_playing.png&quot; alt=&quot;auto player&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;VLC also supports voice actions on Android Auto:&lt;br /&gt;
You can ask “&lt;em&gt;play Daft Punk&lt;/em&gt;” and Google Assistant will recognize whether it’s an artist, an album or a song you’re asking for and trigger VLC to play it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/voice_action.gif&quot; alt=&quot;auto voice&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;action-mode&quot;&gt;Action mode&lt;/h2&gt;

&lt;p&gt;You can now select multiple items by long press on them (classic context menu is still available with the three dots icon) and enjoy actions like &lt;em&gt;play it all&lt;/em&gt; or &lt;em&gt;add selection to playlist&lt;/em&gt;&lt;br /&gt;
Actions available depend on media type and selection count.&lt;/p&gt;

&lt;p&gt;This is very handy for starting or creating a playlist.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/v2.1/actionmode.png&quot; alt=&quot;video grid&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;miscellaneous-new-features&quot;&gt;Miscellaneous new features&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DayNight mode integration&lt;/li&gt;
  &lt;li&gt;Restored double/long click on remote play to skip songs&lt;/li&gt;
  &lt;li&gt;Removed sound lowering on notification&lt;/li&gt;
  &lt;li&gt;Force previous song on audioplayer swipe&lt;/li&gt;
  &lt;li&gt;Fix audioplayer layout for black theme and RTL&lt;/li&gt;
  &lt;li&gt;Save subtitles delay and optionally audio delay for each file.&lt;/li&gt;
  &lt;li&gt;Support for LG devices with 18:9 aspect ratio&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;under-the-hood&quot;&gt;Under the hood&lt;/h2&gt;

&lt;h3 id=&quot;medialibrary&quot;&gt;MediaLibrary&lt;/h3&gt;

&lt;p&gt;That’s the most important change in this update, because it affects the whole application, but you should barely notice it…&lt;/p&gt;

&lt;p&gt;VLC now uses &lt;a href=&quot;https://code.videolan.org/videolan/medialibrary&quot;&gt;medialibrary&lt;/a&gt; like VLC for Tizen, others VLC ports will follow.&lt;br /&gt;
It’s a C++ library, written by &lt;a href=&quot;http://www.beauzee.fr/&quot;&gt;Hugo Beauzée-Luyssen&lt;/a&gt;, which parses storages for video/audio files and manages a sqlite database to model your media library (with album, artist, genre classification, etc..). It replaces the old system we had on Android which just saved media files with their metadata, we had no proper structure for media library.&lt;br /&gt;
So these categories listing are now faster, we don’t have to generate categories at runtime. And this is all native code, which is faster than Java.&lt;br /&gt;
Beside this speed improvement, one of the main benefits of this medialibrary is to provide better &lt;a href=&quot;#search&quot;&gt;search results&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For now we are focusing on the first scan performance to make it at least as fast as the previous system.&lt;/p&gt;

&lt;p&gt;So, this library is aimed to be a common module of all VLC ports, wich means all debugging, performance and any improvement will benefit other platforms.&lt;/p&gt;

&lt;p&gt;Next steps for this library will be media scrapping, and network scan:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Medialibrary will get informations and illustrations for your media, so we’ll be able to present you a nice collection, and not files list anymore. We will also group media by shows/seasons et genre/release year/whatever&lt;/li&gt;
  &lt;li&gt;You will be able to scan your NAS content to access your media easily.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;playback-performance--formats-support&quot;&gt;Playback performance &amp;amp; formats support&lt;/h3&gt;

&lt;p&gt;VLC core team worked hard too to bring performance improvements and some new features. Here are some highlights:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;360° videos support&lt;/li&gt;
  &lt;li&gt;Adaptive (HLS/Dash) &amp;amp; TS playback improved&lt;/li&gt;
  &lt;li&gt;OpenGLES 2.0 is now used to render video (for software decoders &amp;amp; mediacodec)&lt;/li&gt;
  &lt;li&gt;Support for VP8/9/10 in MP4&lt;/li&gt;
  &lt;li&gt;e-AC3 HDMI passthrough&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;future&quot;&gt;Future&lt;/h2&gt;

&lt;p&gt;We also plan to implement a feature to &lt;strong&gt;download media on your device&lt;/strong&gt;, in order to sync your series episodes or songs from your NAS to your device.&lt;/p&gt;

&lt;p&gt;We’d like to support videos playlists like we do with videos grouped by their common name prefix.&lt;/p&gt;

&lt;p&gt;As previously stated, medialibrary will allow to make VLC a real &lt;strong&gt;media center&lt;/strong&gt; with fancy movies/tv shows presentation, and better artists/albums illustrations.&lt;/p&gt;

&lt;p&gt;At last, I started an &lt;strong&gt;extension API&lt;/strong&gt; in order for everyone to develop android applications which will provide content to VLC.
For example, we will release (with sources of course) extensions bringing support of podcasts subscriptions and Google Drive access.&lt;/p&gt;</content><author><name>Geoffrey Métais</name></author><category term="vlc" /><category term="android" /><summary type="html">Not so much activity on Play Store since v2.0.6 release. I’ve been quite busy but VLC keeps going on with very interesting evolutions!</summary></entry><entry><title type="html">Tips for VLC</title><link href="https://geoffreymetais.github.io/features/tips/" rel="alternate" type="text/html" title="Tips for VLC" /><published>2017-02-22T00:00:00+00:00</published><updated>2017-02-22T00:00:00+00:00</updated><id>https://geoffreymetais.github.io/features/tips</id><content type="html" xml:base="https://geoffreymetais.github.io/features/tips/">&lt;p&gt;Here are some hidden features of VLC on Android.
&lt;!--summary--&gt;&lt;/p&gt;
&lt;aside class=&quot;sidebar__right&quot;&gt;
&lt;nav class=&quot;toc&quot;&gt;
    &lt;header&gt;&lt;h4 class=&quot;nav__title&quot;&gt;&lt;i class=&quot;fa fa-thumbs-o-up&quot;&gt;&lt;/i&gt; Tips&lt;/h4&gt;&lt;/header&gt;
&lt;ul class=&quot;toc__menu&quot; id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#play-video-on-your-chromecast&quot; id=&quot;markdown-toc-play-video-on-your-chromecast&quot;&gt;Play video on your Chromecast&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#stop-playback-service&quot; id=&quot;markdown-toc-stop-playback-service&quot;&gt;STOP playback service&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#repeat-video&quot; id=&quot;markdown-toc-repeat-video&quot;&gt;Repeat video&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#reorder-media-in-current-playlist&quot; id=&quot;markdown-toc-reorder-media-in-current-playlist&quot;&gt;Reorder media in current playlist&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#load-last-playlist&quot; id=&quot;markdown-toc-load-last-playlist&quot;&gt;Load last playlist&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#nextprevious-by-swipe&quot; id=&quot;markdown-toc-nextprevious-by-swipe&quot;&gt;Next/previous by swipe&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#video-player-bindings&quot; id=&quot;markdown-toc-video-player-bindings&quot;&gt;Video player bindings&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

  &lt;/nav&gt;
&lt;/aside&gt;

&lt;h2 id=&quot;play-video-on-your-chromecast&quot;&gt;Play video on your Chromecast&lt;/h2&gt;

&lt;p&gt;VLC does not yet support Chromecast, but you already can use it!&lt;/p&gt;

&lt;p&gt;Android can cast its screen content and audio to it.
Here are some ways to access this option:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;With the &lt;a href=&quot;/assets/images/tips/shortcut_cast.png&quot;&gt;quick toggle&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;In &lt;a href=&quot;/assets/images/tips/settings_cast.png&quot;&gt;Display settings&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;In Google Home &lt;a href=&quot;/assets/images/tips/home_cast.png&quot;&gt;app menu&lt;/a&gt;&lt;br /&gt;
  You can &lt;a href=&quot;https://play.google.com/store/apps/details?id=com.google.android.apps.chromecast.app&quot;&gt;find Google Home here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;VLC detects the secondary display (your Chromecast) like it does if you plug your device to your TV with a HDMI cable, and video player will show you this screen:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/tips/remote_controls.png&quot; alt=&quot;video remote&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You have normal controls like swipe to seek and go to advanced options while you watch your movie on TV 📺 😃&lt;/p&gt;

&lt;h2 id=&quot;stop-playback-service&quot;&gt;STOP playback service&lt;/h2&gt;
&lt;p&gt;There are 2 ways to completely stop vlc player service (and not just pause playback), but this action has no explicit button.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;With mini player&lt;/strong&gt;: long press on play/pause button
&lt;img src=&quot;/assets/images/tips/stop.gif&quot; alt=&quot;stop player&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;With playback icon&lt;/strong&gt;: &lt;strong&gt;only when playback is paused&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;on Android 5+: you can swipe the notification.&lt;/li&gt;
      &lt;li&gt;on Android 4.x: you should have a ‘x’ button on top-right corner.
&lt;img src=&quot;/assets/images/tips/stop_notification.gif&quot; alt=&quot;stop notification&quot; /&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;repeat-video&quot;&gt;Repeat video&lt;/h2&gt;
&lt;p&gt;With version 2.1 you’ll have the repeat button available in the video player advanced options, but you can already do that with version 2.0.x:&lt;br /&gt;
&lt;strong&gt;Long press on play/pause&lt;/strong&gt; button to switch playback to &lt;em&gt;repeat&lt;/em&gt; mode so your video playback will loop&lt;/p&gt;

&lt;h2 id=&quot;reorder-media-in-current-playlist&quot;&gt;Reorder media in current playlist&lt;/h2&gt;
&lt;p&gt;Simply &lt;strong&gt;drag&lt;/strong&gt; media within current playlist to reorder it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/tips/drag.gif&quot; alt=&quot;reorder playlist&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;load-last-playlist&quot;&gt;Load last playlist&lt;/h2&gt;
&lt;p&gt;In action bar, the circled &lt;em&gt;play&lt;/em&gt; button triggers loading of last playlist from the current category: In video view it will load last video(s) played, in Audio view it will load last audio playlist.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/tips/load_last.gif&quot; alt=&quot;load last audio playlist&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;p&gt;With remote play/pause control (wired headset or bluetooth ad2p device) when VLC is not playing, you can load last audio playlist and continue playback where you stopped it.&lt;/p&gt;

&lt;h2 id=&quot;nextprevious-by-swipe&quot;&gt;Next/previous by swipe&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Swipe miniplayer&lt;/strong&gt; on left/right triggers skip to previous/next media.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/tips/next.gif&quot; alt=&quot;swipe next&quot; class=&quot;align-center&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;video-player-bindings&quot;&gt;Video player bindings&lt;/h2&gt;

&lt;p&gt;If you have a keyboard or a gamepad connected to your Android device, here are the key bindings in video player:&lt;/p&gt;

&lt;p&gt;within DVD menu:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Key(s)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Action&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;↓↑←→&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;navigate&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Gamepad A or X /play/pause/space/OK/enter&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;click on focused item&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;in 360° video playback (version 2.1.0+):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Key(s)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Action&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;↓↑←→&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;change viewpoint&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;normal case:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Key(s)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Action&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;F/fast_forward/→&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;seek (+10 seconds)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;R/rewind/←&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;seek (-10 seconds)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;R1&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;seek (+1 minute)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;L1&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;seek (-1 minute)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;A(gamepad)/play/pause/space/OK&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;toggle play/pause&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;O/Y(gamepad)/menu/↑&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;show advanced options&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;V/audio-track/X(gamepad)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;open subtitles options&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;N&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;show DVD navigation menu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;A&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;resize video&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;M/mute&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;toggle sound mute&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;S/STOP&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;stop playback &amp;amp; exit player&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;captions&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;select subtitles&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;J&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;delay audio (-50ms)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;K&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;delay audio (+50ms)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;G&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;delay subtitles (-50ms)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;H&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;delay subtitles (+50ms)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;</content><author><name>Geoffrey Métais</name></author><category term="vlc" /><category term="android" /><summary type="html">Here are some hidden features of VLC on Android.</summary></entry></feed>