@NonNull @Override public Result doWork() { try { osmQuestChangesUpload.closeOpenChangesets(); } catch(OsmConnectionException e) { // wasn't able to connect to the server (i.e. connection timeout). Oh well, then, // never mind. Could also retry later with Result.retry() but the OSM API closes open // changesets after 1 hour anyway. } catch(OsmAuthorizationException e) { // the user may not be authorized yet (or not be authorized anymore) #283 // nothing we can do about here. He will have to reauthenticate when he next opens the app return Result.failure(); } return Result.success(); } }
} catch (Exception exception) { Log.e(TAG, "Error cleaning up", exception); return Result.failure();
@NonNull @Override public Result doWork() { OkHttpClient client=new OkHttpClient(); Request request=new Request.Builder() .url(getInputData().getString(KEY_URL)) .build(); try (Response response=client.newCall(request).execute()) { File dir=getApplicationContext().getCacheDir(); File downloadedFile= new File(dir, getInputData().getString(KEY_FILENAME)); BufferedSink sink=Okio.buffer(Okio.sink(downloadedFile)); sink.writeAll(response.body().source()); sink.close(); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Exception downloading file", e); return ListenableWorker.Result.failure(); } return ListenableWorker.Result.success(); } }
return Result.failure();
Log.e(getClass().getSimpleName(), "Exception downloading file", e); return ListenableWorker.Result.failure();
@NonNull @Override public Result doWork() { File downloadedFile=new File(getInputData().getString(KEY_ZIPFILE)); File dir=getApplicationContext().getCacheDir(); String resultDirData=getInputData().getString(KEY_RESULTDIR); File resultDir=new File(dir, resultDirData==null ? "results" : resultDirData); try { ZipUtils.unzip(downloadedFile, resultDir, 2048, 1024*1024*16); downloadedFile.delete(); } catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception unZIPing file", e); return ListenableWorker.Result.failure(); } return ListenableWorker.Result.success(); } }
@NonNull @Override public Result doWork() { if (MuzeiUpdateHelper.update(getApplicationContext(), this)) { return Result.success(); } else { return Result.failure(); } }