• Stars
    star
    209
  • Rank 188,325 (Top 4 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android sample app in Kotlin showing usage of DiffUtil class.

DiffUtil Android Sample - Kotlin

Example of usage DiffUtil utility class added originally in Support Library 24.2.0.

Demo

Demo

Implementation

calculateDiff method from DiffUtill class requires DiffUtil.Callback object as parameter.

DiffUtil callback - ActorDiffCallback.kt

Implements 4 methods:

  • getOldListSize - returns size of the old list
  • getNewListSize - returns size of the new list
  • areItemsTheSame - returns true if two items are the same, e.g. have the same ids
  • areContentsTheSame - returns true if displayed content was not changed. In our case we only display actor's name so we're detecing name's change.

Applying diff result - ActorAdapter.swap()

DiffResult can be applied to adapter by calling diffResult.dispatchUpdatesTo(adapter).

    fun swap(actors: List<Actor>) {
            val diffCallback = ActorDiffCallback(this.actors, actors)
            val diffResult = DiffUtil.calculateDiff(diffCallback)

            this.actors.clear()
            this.actors.addAll(actors)
            diffResult.dispatchUpdatesTo(this)
    }

Resources

License

Copyright 2016 MichaΕ‚ Moczulski

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

Ok2Curl

Convert OkHttp requests into curl logs.
Kotlin
432
star
2

fix-android-emulator-audio

πŸ”Š Script for fixing Bluetooth issue when running Android Emulator on macOS
Shell
59
star
3

AndroidLiveTemplates

Live Templates set for Android Studio / Intellij IDEA.
52
star
4

RenderScriptPlayground

Example of using RenderScript with Gradle and Android Studio. Works with Android API >= 8.
Java
37
star
5

Simple-Android-Notepad

Simple Android Notepad
Java
15
star
6

EspressoShowcase

Sample Android Espresso UI Tests
Java
9
star
7

AutoValueSample

Sample project showing usage of AutoValue library. Prepared for ADG PoznaΕ„ meetup.
Java
6
star
8

SimpleAndroidDocker

Docker image containing tools for building Android applications.
3
star
9

android-resmaker

Simple Ruby tool to creates scaled Android resources.
Ruby
3
star
10

android-ci-sample

Android continuous integration with Docker.
Kotlin
3
star
11

kotlin-training

Introduction to Kotlin - training
Kotlin
2
star
12

att-sample

Mobile backend with Firebase
JavaScript
1
star
13

Android-RSS-Reader

Java
1
star
14

homebrew-fix-android-emulator-audio

Hombrew repository for fix-android-emulator-audio script
Ruby
1
star
15

j-backtester

Strategy backtesting tool.
Java
1
star
16

mobilizacja-android-loader

Java
1
star
17

Dropdown-Menu

Simple dropdown menu with some css3 features
1
star
18

everyday-android

My collections of tips and tools useful in everyday Android development
1
star
19

kotlin-loader-sample

Sample android app written in Kotlin
Kotlin
1
star
20

stock-distance-abacus

Program helps to determine the best pair of stock for pairs trading purpose. Algorithm is based on distance method used by Gatev(1999)
Java
1
star