Smuggler


Source link: https://github.com/nsk-mironov/smuggler

Smuggler

Makes your data classes Parcelable. Just add AutoParcelable to the class declaration. That's all. No methods need to be implemented.

data class User(
val uuid: String,
val firstName: String,
val lastName: String ) : AutoParcelable  data class Message(
val uuid: String,
val text: String,
val sender: User,
val timestamp: Long,
val seen: Boolean ) : AutoParcelable  data class Chat(
val title: String,
val messages: List<Message>,
val participants: List<User> ) : AutoParcelable

Kotlin objects are supported as well:

interface Command : AutoParcelable  object LoginCommand : Command object LogoutCommand : Command object MenuCommand : Command  data class ProductCommand(val id: String) : Command data class CategoryCommand(val id: String) : Command

Project Setup

buildscript {

repositories {

  mavenCentral()
  jcenter()

}

  dependencies {

  classpath "com.android.tools.build:gradle:2.2.0"
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.0"
  classpath "io.mironov.smuggler:smuggler-plugin:0.12.13"

}
 
}
  repositories {

mavenCentral()
jcenter() 
}
  apply plugin: "com.android.application" apply plugin: "io.mironov.smuggler"

Some important notes:

  • Smuggler plugin must be applied after android plugin.
  • In case you have a mutli-module project and want to use AutoParceable, you have to add smuggler-plugin to each module.

Supported types

  • Primitive types: boolean, byte, char, double, float, int, long, short
  • Boxed types: Boolean, Byte, Char, Double, Float, Int, Long, Short
  • Other types: String, Bundle, SparseBooleanArray, Date, SparseArray
  • All Parcelable subclasses
  • All Enum subclasses
  • All Serializable subclasses
  • Arrays of any supported type, including primitive arrays and multidimensional arrays like: Array<Array<Array<User>>
  • Sets, Lists and Maps of any supported type, including primitive types and complex types like: Map<List<Message>, List<Array<Set<User>>>

Custom types

  • Serialization and deserialization of custom types are supported via TypeAdapter's:

    object BigIntegerTypeAdapter : TypeAdapter<BigInteger> {
    
    override fun fromParcel(parcel: Parcel): BigInteger {
    
      return BigInteger(parcel.createByteArray())
    
    }
    
     override fun toParcel(value: BigInteger, parcel: Parcel, flags: Int) {
    
      parcel.writeByteArray(value.toByteArray())
    
    }
     
    }
    
  • Project-level TypeAdapter can be registered using @GlobalAdapter annotation:

    @GlobalAdapter object BigIntegerTypeAdapter : TypeAdapter<BigInteger> {
    
    ... 
    }
    
  • Class-level TypeAdapter can be registered using @LocalAdapter annotation:

    @LocalAdapter(BigIntegerTypeAdapter::class, CalendarTypeAdapter::class) data class Local(
    val integer: BigInteger,
    val calendar: Calendar ) : AutoParcelable
  • Defining TypeAdapter for a particular type automatically allows to use this type with Lists, Maps, Sets and Arrays:

    data class BigIntegerExample(
    val single: BigInteger,
    val array: Array<BigInteger>,
    val multidimensional: Array<Array<BigInteger>>,
    val list: List<BigInteger>,
    val set: Set<BigInteger>,
    val map: Map<String, BigInteger>,
    val complex: Map<Set<BigInteger>, Array<List<BigInteger>>> ) : AutoParcelable
  • Custom TypeAdapter can be defined both as class or object

  • TypeAdapter defined as class must have a public no-args constructor

How does it work?

Smuggler doesn't use reflection so you don't have to worry about its performance. It isn't an annotation proccessor so you don't have to deal with kapt bugs. Instead, Smuggler built on top of transform api and works by proccessing your compiled bytecode and patching classes that implement AutoParcelable interface.

Known limitations

  • Only data classes and kotlin objects are supported
  • Data classes with type parameters aren't supported at the moment
  • Lists, Maps and Arrays with bounded type parameters aren't supported at the moment
  • The library doesn't work nicely with JVM tests at the moment #12

What does "Smuggler" mean?

A smuggler was an individual who dealt with the secret exchanged shipment of goods to block restrictions or tax fees. The items shipped were often considered contraband, and highly illegal. Notable smugglers included Han Solo, Chewbacca, and Lando Calrissian. © http://starwars.wikia.com

License

Copyright 2016 Vladimir Mironov  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. 

Resources

AndFix is a library that offer hot-fix for Android App. It could help Android developer to fix App bugs online. Andfix is an acronym for "Android hot-fix".

AndFix supports Android 2.3 to 6.0, arm and x86 architecture, dalvik runtime and art runtime.

Android StackBlur with gradle support (only for the native method).

View SQLite file online.

An Android library to show an intro to your users.

A Simple Wrapper Class for Apache-commons FTPClient to Easily Upload/Download Any kind of File over FTP. This Library is targeted for novice developers and provides very minimalistic and easily understandable Interface for FTP usage.

A library to parse XML Gpx files, built for Android.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes