BOILING OUT BOILERPLATE
Hi, I'm Maciej
BOILERPLATE
NETWORKING
HttpURLConnection urlConnection = null;BufferedReader reader = null;String forecastJsonStr = null; try { URL url = new URL("http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7");urlConnection = (HttpURLConnection) url.openConnection();urlConnection.setRequestMethod("GET");urlConnection.connect();InputStream inputStream = urlConnection.getInputStream();StringBuffer buffer = new StringBuffer();if (inputStream == null) {forecastJsonStr = null;}reader = new BufferedReader(new InputStreamReader(inputStream));String line;while ((line = reader.readLine()) != null) {buffer.append(line + "\n");}
NETWORKING
if (buffer.length() == 0) {forecastJsonStr = null;}forecastJsonStr = buffer.toString();} catch (IOException e) {Log.e("PlaceholderFragment", "Error ", e);forecastJsonStr = null;} finally{if (urlConnection != null) {urlConnection.disconnect();}if (reader != null) {try {reader.close();} catch (final IOException e) {Log.e("PlaceholderFragment", "Error closing stream", e);}}}
NETWORKING
JSONObject forecastJson = new JSONObject(forecastJsonStr);JSONArray weatherArray = forecastJson.getJSONArray("list");String[] resultStrs = new String[numDays];for(int i = 0; i < weatherArray.length(); i++) {JSONObject dayForecast = weatherArray.getJSONObject(i);long dateTime = dayForecast.getLong("dt");String day = getReadableDateString(dateTime);JSONObject weatherObject = dayForecast.getJSONArray("weather").getJSONObject(0);String description = weatherObject.getString("main");JSONObject temperatureObject = dayForecast.getJSONObject("temp");double high = temperatureObject.getDouble("max");double low = temperatureObject.getDouble("min");String highAndLow = formatHighLows(high, low);resultStrs[i] = day + " - " + description + " - " + highAndLow;}return resultStrs;
Networking
- Retrofit
- Picasso
JSR 269
WHO?
- Dagger
- AndroidAnnotations
- ButterKnife
- Parceler
- AndroidAutoValue
- Lombok
LOMBOK
LOMBOK
LOMBOK
- @Getter and @Setter
- @EqualsAndHashCode
- @ToString
- @Value and @Data
- @Builder
- @Wither
- @Delegate
LOMBOK +?
HRISEY
HRISEY
- @Parcelable
- @Preferences
- @InstanceState
PROS AND CONS
- (-) generates code in your classes
- (-) no Eclipse support
- (+) generates code in your classes
- (+) can be removed within minutes
TALK IS CHEAP,
SHOW ME THE CODE
THE FUTURE
- @Argument
- @Extra
- @DatabaseTable
- @ContentProvider
- @MagicViews
- ...
CONTRIBUTING
BONUS
Vielen Games ANDROID CLIENT
Q || A
THANKS!
LINKS
Boiling out Boilerplate / MobileWarsaw July 2014
By Maciej Górski
Boiling out Boilerplate / MobileWarsaw July 2014
- 2,076