Git Product home page Git Product logo

android-prince-of-versions's Introduction

Prince of versions

CircleCI Download

Library checks for updates using configuration from some resource.

Features

  • Load update configuration from network resource or from input stream resource
  • Accept custom loader for loading update configuration resource
  • Use predefined parser for parsing update configuration in JSON format
  • Accept custom parser for parsing update configuration
  • Make asynchronous loading and use callback for notifying result
  • Loading and verifying versions happen outside of UI thread
  • Use thread pool to cap concurrent resource usage.
  • Provide functionality for canceling once started verifications

Default parser and JSON file

If you are using a default parser, version in your application and the JSON file has to follow Semantic Versioning.JSON file has to look like this:

{
	"ios": {
		"minimum_version": "1.2.3",
		"optional_update": {
			"version": "2.4.5",
			"notification_type": "ALWAYS"
		}
	},
	"android": {
		"minimum_version": "1.2.3",
		"optional_update": {
			"version": "2.4.5",
			"notification_type": "ONCE"
		}
	},
	"meta": {
		"key1": "value1",
		"key2": "value2"
	}
}

Depending on notification_type property, the user can be notified ONCE or ALWAYS. The library handles this for you, and if notification type is set to ONCE, it will notify you via onNewUpdate(String version, boolean isMandatory) method only once. Every other time the library will return onNoUpdate for that specific version. Key-value pairs under "meta" key are optional metadata of which any amount can be sent accompanying the required fields.

Examples

Full example application is available here.

Most common usage - loading from network resource

  1. Create new instance of updater associated with application context.

      PrinceOfVersions updater = new PrinceOfVersions(this);
  2. Create loader factory for loading from network passing resource URL.

      LoaderFactory loaderFactory = new NetworkLoaderFactory("http://pastebin.com/raw/41N8stUD");
  3. Create concrete callback for result implementing co.infinum.princeofversions.callbacks.UpdaterCallback interface.

    UpdaterCallback callback = new UpdaterCallback() {
            @Override
            public void onNewUpdate(String version, boolean isMandatory, Map<String, String> metadata) {
            }
    
            @Override
            public void onNoUpdate(Map<String, String> metadata) {
            }
    
            @Override
            public void onError(@ErrorCode int error) {
            }
        };
  4. Use updater with previously created loader factory and callback. Call checkForUpdates method to start update check.

      UpdaterResult result = updater.checkForUpdates(loaderFactory, callback);
  5. To cancel update check, call cancel method on UpdaterResult object.

Writing tests

For testing purposes you can create your own LoaderFactory. For ease of use, StreamLoader object exists in the library. Here is an example of loading a JSON file from raw.

  1. Create new instance of updater associated with application context.

      PrinceOfVersions updater = new PrinceOfVersions(this);
  2. Create loader factory for creating stream loader by passing new input stream in its constructor.

      LoaderFactory loaderFactory = new LoaderFactory() {
            @Override
            public UpdateConfigLoader newInstance() {
                  return new StreamLoader(getResources().openRawResource(R.raw.update));
            }
      };

Note: Be aware that once used input stream in StreamLoader is read and closed. For that purpose always create new stream in newInstance method of LoaderFactory.

3rd, 4th and 5th step are same as in previous example.

Contributing

Feedback and code contributions are very much welcome. Just make a pull request with a short description of your changes. By making contributions to this project you give permission for your code to be used under the same license.

android-prince-of-versions's People

Contributors

ikocijan avatar antunflas avatar reisub avatar pejna avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.