|
2 | 2 |
|
3 | 3 | import android.app.Activity; |
4 | 4 | import android.app.Application; |
| 5 | +import android.content.pm.ApplicationInfo; |
| 6 | +import android.content.pm.PackageInfo; |
| 7 | +import android.content.pm.PackageManager; |
5 | 8 |
|
6 | 9 | import com.google.gson.JsonObject; |
7 | 10 |
|
@@ -236,22 +239,43 @@ private void init(final Application app, |
236 | 239 |
|
237 | 240 | userPreferences = new UserPreferences(application); |
238 | 241 |
|
239 | | - if (config.endpointBaseUrl.startsWith("http://") |
| 242 | + projectId = config.projectId; |
| 243 | + |
| 244 | + if (projectId == null || application == null) { |
| 245 | + setupCompletionListener.onError(Error.CONFIG_PARAMETER_MISSING); |
| 246 | + return; |
| 247 | + } |
| 248 | + |
| 249 | + if(config.endpointBaseUrl == null){ |
| 250 | + endpointBaseUrl = "https://api.snabble.io"; |
| 251 | + } else if (config.endpointBaseUrl.startsWith("http://") |
240 | 252 | || config.endpointBaseUrl.startsWith("https://")) { |
241 | 253 | endpointBaseUrl = config.endpointBaseUrl; |
242 | 254 | } else { |
243 | 255 | endpointBaseUrl = "https://" + config.endpointBaseUrl; |
244 | 256 | } |
245 | 257 |
|
246 | | - projectId = config.projectId; |
| 258 | + if(config.metadataUrl == null){ |
| 259 | + ApplicationInfo applicationInfo = app.getApplicationInfo(); |
| 260 | + int stringId = applicationInfo.labelRes; |
| 261 | + String label = stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : app.getString(stringId); |
| 262 | + String version; |
| 263 | + |
| 264 | + try { |
| 265 | + PackageInfo pInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0); |
| 266 | + version = pInfo.versionName; |
| 267 | + } catch (PackageManager.NameNotFoundException e) { |
| 268 | + version = ""; |
| 269 | + } |
247 | 270 |
|
248 | | - if (endpointBaseUrl == null || projectId == null |
249 | | - || application == null || config.metadataUrl == null) { |
250 | | - setupCompletionListener.onError(Error.CONFIG_PARAMETER_MISSING); |
251 | | - return; |
| 271 | + label = label.toLowerCase().replace(" ", ""); |
| 272 | + version = version.toLowerCase().replace(" ", ""); |
| 273 | + |
| 274 | + metadataUrl = "/" + config.projectId + "/metadata/app/android/" + label + "-" + version; |
| 275 | + } else { |
| 276 | + metadataUrl = absoluteUrl(config.metadataUrl); |
252 | 277 | } |
253 | 278 |
|
254 | | - metadataUrl = absoluteUrl(config.metadataUrl); |
255 | 279 | metadataDownloader = new MetadataDownloader(this, config.bundledMetadataAssetPath); |
256 | 280 |
|
257 | 281 | roundingMode = config.roundingMode != null ? config.roundingMode : RoundingMode.HALF_UP; |
|
0 commit comments