Migratron


Source link: https://github.com/ffgiraldez/Migratron

Migratron

Android port of MTMigration for Android to execute pieces of code that only need to run once on version updates. This could be anything from data normalization routines, "What's New In This Version" screens, or bug fixes.

Add it to yout project

Include the library in your build.gradle

dependencies{

  compile 'com.github.ffgiraldez.migratron:migratron:1.0' 
}

or to your pom.xml if you are using Maven

<dependency>
  <groupId>com.github.ffgiraldez.migratron</groupId>
  <artifactId>migratron</artifactId>
  <version>1.0</version> </dependency>

Usage

First of all you need create the Migratron object, with a Context recomended the application context and a SharedPreference to store version information needed to handle correctly the diferents Migration

SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, Mode.Private);
 Migratron migratron = new Migration(context.getApplicationContext(), sharedPrefenences)

Migratron provides two kind of migrations, one to use when you need some code that run every time you update your application. Use updateMigrationmethod

When you need a piece of code that runs every time you update your application. Use the applicationUpdateBlock: method.

migratron.updateMigration(new Migration() {

  @Override
  public void migrate(Context context) {

rater.reset();

  
}
 
}
)

the other migratrion is specific to a version, use addMigration(int versionCode,Migration migration) and Migratron will ensure that the Migration passed it's only ever run once for that version

migratron.addMigration(8, new Migration() {

  @Override
  public void migrate(Context context) {

showVersionNotesController.enable();

  
}
 
}
)

Once all your migrations are configured in a Migratron object execute it calling

migratron.migrate();

This allow programers configure the Migratron and execute the migrations in a lazy way only when needed, usualy in the onCreate method of the Application.

Migratron inspect your AndroidManifest.xml for your actual versionCode and keeps track of last migration.

It will migrate all un-migrated Migration inbetween. For example, let's say you had the following migrations:

migratron.addMigration(9, new Migration() {

  @Override
  public void migrate(Context context) {

// Some 9 stuff
  
}
 
}
) migratron.addMigration(10, new Migration() {

  @Override
  public void migrate(Context context) {

// Some 10 stuff
  
}
 
}
)

If a user was at version 8, skipped 9, and upgraded to 10, then both the 9 and 10 migrations would run.

Notes

Migratron assumes version numbers are incremented in a logical way, i.e. 101 -> 102, 110 -> 120, etc.

Version numbers that are past the version specified in your app will not be run. For example, if your AndroidManifest.xml file specifies 120 as versionCode, and you attempt to migrate to 130, the migration will not run.

Migrations are executed on the thread the migration is run on. Background/foreground situations should be considered accordingly.

Contributing

This library does not handle some more intricate migration situations, if you come across intricate use cases from your own app, please add it and submit a pull request. Be sure to add test cases.

Libraries used in this project

Resources

A layout that hide the header when the body is scrolled down and reveal it when the header is scrolled up.

AppIntroAnimation is a set of code snippets to make cool intro screen for your app with special Image Translation and Transformation animation effects. It is very easy to use and customize without adding third party library integrations.

Use Parse REST API for sending Push Notifications.

This project aims to provide a reusable Swipe to Refresh widget for Android.

This project aims to provide a reusable WaveSwipe to Refresh widget for Android.

Akatsuki is an Android library that handles state restoration via annotations. The library automatically generates source files through JSR269 to ensure almost zero performance impact.

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