|
| 1 | +# Installation |
| 2 | + |
| 3 | +## Requirements |
| 4 | + |
| 5 | +minSdkVersion = 21 |
| 6 | +compileSdkVersion = 29 |
| 7 | +java 8 |
| 8 | +androidx |
| 9 | + |
| 10 | +### Using the snabble GitHub Repository |
| 11 | + |
| 12 | +Add the snabble maven repository for out and the Datatrans SDK: |
| 13 | + |
| 14 | +``` groovy |
| 15 | +repositories { |
| 16 | + maven { |
| 17 | + url 'https://raw.githubusercontent.com/snabble/maven-repository/releases' |
| 18 | + } |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +Then add the library to your dependencies. |
| 23 | + |
| 24 | +``` groovy |
| 25 | +dependencies { |
| 26 | + // core library |
| 27 | + implementation 'io.snabble.sdk:core:{{ extra.sdk_version }}' |
| 28 | + |
| 29 | + // user interface library |
| 30 | + implementation 'io.snabble.sdk:ui:{{ extra.sdk_version }}' |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +### Locally |
| 35 | + |
| 36 | +The library can be installed to the local maven repository using: |
| 37 | + |
| 38 | +``` sh |
| 39 | +./gradlew publishToMavenLocal |
| 40 | +``` |
| 41 | + |
| 42 | +Make sure you add maven local to your repositories in your gradle script. |
| 43 | + |
| 44 | +``` groovy |
| 45 | +repositories { |
| 46 | + mavenLocal() |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +Then add the library to your dependencies. (Note: The + means it always uses the latest version) |
| 51 | + |
| 52 | +``` groovy |
| 53 | +dependencies { |
| 54 | + implementation 'io.snabble.sdk:core:{{ extra.sdk_version }}' |
| 55 | + implementation 'io.snabble.sdk:ui:{{ extra.sdk_version }}' |
| 56 | + implementation 'io.snabble.sdk:ui-integration:{{ extra.sdk_version }}' |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +## Usage |
| 61 | +``` java |
| 62 | +//you may enable debug logging to see requests made by the sdk, and other various logs |
| 63 | +Snabble.setDebugLoggingEnabled(true); |
| 64 | + |
| 65 | +Snabble.Config config = new Snabble.Config(); |
| 66 | +config.appId = <your app id> |
| 67 | +config.secret = <your secret> |
| 68 | + |
| 69 | +// optional: provide a metadata file, store in the assets. That allows the sdk |
| 70 | +// init without requiring a network connection. |
| 71 | +config.bundledMetadataAssetPath = "metadata.json"; |
| 72 | + |
| 73 | +final Snabble snabble = Snabble.getInstance(); |
| 74 | +snabble.setup(this, config, new Snabble.SetupCompletionListener() { |
| 75 | + @Override |
| 76 | + public void onReady() { |
| 77 | + // get the first project, there can be multiple projects per app |
| 78 | + project = snabble.getProjects().get(0); |
| 79 | + |
| 80 | + // registers this project globally for use with ui components |
| 81 | + SnabbleUI.setProject(project); |
| 82 | + |
| 83 | + // select the first shop for demo purposes, ideally this should be done with |
| 84 | + // geofencing or a manual user selection |
| 85 | + if (project.getShops().length > 0) { |
| 86 | + project.getCheckout().setShop(project.getShops()[0]); |
| 87 | + } |
| 88 | + |
| 89 | + // optional: set a loyalty card id for identification, for demo purposes |
| 90 | + // we invent one here |
| 91 | + project.setLoyaltyCardId("testAppUserLoyaltyCardId"); |
| 92 | + |
| 93 | + // optional: load a bundled database file from the assets folder |
| 94 | + // this lowers the download size of database updates and the database is immediatly |
| 95 | + // available offline |
| 96 | + project.getProductDatabase().loadDatabaseBundle("db.sqlite3", revision, major, minor); |
| 97 | + |
| 98 | + // recommended: download the latest product database for offline availability |
| 99 | + // it is highly recommended to call this in shorter time frames than config.maxProductDatabaseAge is set at |
| 100 | + // since the local database is only used if the time since the last update is smaller than |
| 101 | + // config.maxProductDatabaseAge, which defaults to 1 hour |
| 102 | + // |
| 103 | + // a good place for this is the onStart() method of your activity |
| 104 | + // database updates are usually very small since we are using delta updates for updating the database |
| 105 | + // |
| 106 | + // also a good place for database updates are background schedulers like |
| 107 | + // https://developer.android.com/topic/libraries/architecture/workmanager |
| 108 | + project.getProductDatabase().update(); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public void onError(Snabble.Error error) { |
| 113 | + // connecton error if no metadata file is bundled or config error |
| 114 | + // if no appId or secret is provided |
| 115 | + } |
| 116 | +}); |
| 117 | +``` |
0 commit comments