Les surcouches constructeur sur Android

Les surcouches constructeur sur Android

Android Maker 2018

Mathieu Hausherr

April 23, 2018

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

58 slides
  1. public static boolean isResponseFromCache(Headers headers) { if (CollectionUtils.isNotEmpty(headers.names())) { for

    (String headerName : headers.names()) { if (TextUtils.equals(headerName, HEADER_CACHE)) { return true; } } } return false; }
  2. public static boolean isResponseFromCache(Headers headers) { if (CollectionUtils.isNotEmpty(headers.names())) { for

    (String headerName : headers.names()) { if (TextUtils.equals(headerName, HEADER_CACHE)) { return true; } } } return false; }
  3. public static boolean isResponseFromCache(Headers headers) { if (CollectionUtils.isNotEmpty(headers.names())) { for

    (String headerName : headers.names()) { if (TextUtils.equals(headerName, HEADER_CACHE)) { return true; } } } return false; }
  4. Caused by java.lang.NoSuchMethodError: No static method b(Ljava/lang/ CharSequence;)Z in class

    Lorg/apache/commons/lang3/StringUtils; or its super classes (declaration of 'org.apache.commons.lang3.StringUtils' appears in /system/framework/framework.jar:classes2.dex)
  5. Pas reproductible sur une app HelloWorld L’app de l’époque crash

    toujours Le code de l’époque avec les nouveaux build tools crash encore Fonctionne si je désactive l’optimisation proguard
  6. Caused by java.lang.NoSuchMethodError: No static method b(Ljava/lang/ CharSequence;)Z in class

    Lorg/apache/commons/lang3/StringUtils; or its super classes (declaration of 'org.apache.commons.lang3.StringUtils' appears in /system/framework/framework.jar:classes2.dex)
  7. public class VirtuoCollectionUtils { private VirtuoCollectionUtils() { } public static

    <T> boolean isEmpty(Collection<T> collection) { return collection == null || collection.size() == 0; } public static <T> boolean isNotEmpty(Collection<T> collection) { return !isEmpty(collection); } }
  8. enum class ImageType constructor(val code: Int) { ID_FRONT(1), ID_BACK(2), DRIVING_LICENCE_FRONT(3),

    DRIVING_LICENCE_BACK(4), SELFIE(5); } private var images: HashMap<ImageType, String?> = HashMap()
  9. enum class ImageType constructor(val code: Int) { ID_FRONT(1), ID_BACK(2), DRIVING_LICENCE_FRONT(3),

    DRIVING_LICENCE_BACK(4), SELFIE(5); } private var images: HashMap<ImageType, String?> = HashMap()
  10. edit.putString(PREF_UPLOADED_IMAGES, gson.toJson(images)) val json = preferences.getString(PREF_UPLOADED_IMAGES, null) val type =

    object : TypeToken<HashMap<ImageType, String>>() {}.type images = gson.fromJson<HashMap<ImageType, String?>>(json, type)
  11. edit.putString(PREF_UPLOADED_IMAGES, gson.toJson(images)) val json = preferences.getString(PREF_UPLOADED_IMAGES, null) val type =

    object : TypeToken<HashMap<ImageType, String>>() {}.type images = gson.fromJson<HashMap<ImageType, String?>>(json, type)
  12. var images: MutableMap<ImageType, String?> = HashMap() fun imagesRepresentation(): String? {

    return gson.toJson(images.entries.associate { it.key.code to it.value }) } fun parseImages(json: String?): Map<ImageType, String?> { val type = object : TypeToken<HashMap<Int, String>>() {}.type return gson.fromJson<…>(json, type).entries.associate { ImageType.getImageTypeByCode(it.key) to it.value } }
  13. var images: MutableMap<ImageType, String?> = HashMap() fun imagesRepresentation(): String? {

    return gson.toJson(images.entries.associate { it.key.code to it.value }) } fun parseImages(json: String?): Map<ImageType, String?> { val type = object : TypeToken<HashMap<Int, String>>() {}.type return gson.fromJson<…>(json, type).entries.associate { ImageType.getImageTypeByCode(it.key) to it.value } }
  14. var images: MutableMap<ImageType, String?> = HashMap() fun imagesRepresentation(): String? {

    return gson.toJson(images.entries.associate { it.key.code to it.value }) } fun parseImages(json: String?): Map<ImageType, String?> { val type = object : TypeToken<HashMap<Int, String>>() {}.type return gson.fromJson<…>(json, type).entries.associate { ImageType.getImageTypeByCode(it.key) to it.value } }
  15. val preferences = mock(SharedPreferences::class.java) @Test fun testSaveImageType() { val identityDP

    = IdentityDP(preference, Gson()) identityDP.images[IdentityDP.ImageType.ID_FRONT] = "foo" val encodedJson = identityDP.imagesRepresentation() val result = identityDP.parseImages(encodedJson) assertEquals("foo", result[IdentityDP.ImageType.ID_FRONT]) }

More Decks by Mathieu Hausherr

Other Decks in Technology