• Stars
    star
    711
  • Rank 63,679 (Top 2 %)
  • Language
    Java
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sample Android project demonstrating the use of Retrofit and RxJava to interact with web services

RexWeather

RexWeather is a sample Android Studio project demonstrating the use of Retrofit and RxJava to interact with web services. Link to the blog post.

RexWeather Screenwhot

Retrofit, by Square

Retrofit is a REST client for Android and Java. It allows you to turn a REST API into a Java interface by using annotations to describe the HTTP requests. It can then generate an implementation of the interface for you. This means that you can go from GET /users/{userId}/posts to webService.fetchUserPosts(userId) in a few lines of code. Retrofit is very easy to use and it integrates well with RxJava.

RxJava, by Netflix

RxJava is a Java implementation of Rx, the Reactive Extensions library from the .NET world. It allows you to compose asynchronous and event-based programs in a declarative manner. Let's say that you want to implement something like this:

  • Start observing our current location. When a location change happens, in parallel,
    • Send a web service request A
    • Send a web service request B
      • Using the result from B, send a web service request C
  • When the results for both A and C are back, update the UI

RxJava allows you to write out your program pretty much as above. It abstracts out concerns about things like threading, synchronization, thread-safety, concurrent data structures, and non-blocking I/O. You can tell RxJava to observe the location changes and perform the web service requests in a background thread, and pass you the final results in the UI thread. If any exceptions are thrown at any point in the chain of events, you get told about it in one convenient place. You're not drowning in a spaghetti of onSuccess and onError callbacks. You're building pipelines.

Web Service Calls

The app uses OpenWeatherMap to fetch the current weather as well as the seven day forecast.

Because of the new policy of OpenWeatherMap, we need to provide API key to the requests we made. You can see the detailed information in here. Please insert your API key that you get after register from OpenWeatherMap to WeatherService.java

Current Weather

The current weather can be obtained by making a call similar to the following:

http://api.openweathermap.org/data/2.5/weather?lat=-31.9522&lon=115.8589&units=metric

The returned JSON looks like this:

{
  "coord": {
    "lon": 115.86,
    "lat": -31.95
  },
  "sys": {
    "message": 0.1843,
    "country": "AU",
    "sunrise": 1404602233,
    "sunset": 1404638729
  },
  "weather": [
    {
      "id": 802,
      "main": "Clouds",
      "description": "scattered clouds",
      "icon": "03n"
    }
  ],
  "base": "cmc stations",
  "main": {
    "temp": 13,
    "pressure": 1015,
    "humidity": 71,
    "temp_min": 13,
    "temp_max": 13
  },
  "wind": {
    "speed": 3.1,
    "deg": 300
  },
  "rain": {
    "3h": 0
  },
  "clouds": {
    "all": 40
  },
  "dt": 1404657000,
  "id": 6692202,
  "name": "South Perth",
  "cod": 200
}

7 Day Forecast

The 7 day forecast can be obtained like so:

http://api.openweathermap.org/data/2.5/forecast/daily?lat=-31.9522&lon=115.8589&mode=json&units=metric&cnt=7

And the returned JSON looks like this:

{
  "cod": "200",
  "message": 0.0094,
  "city": {
    "id": 2063523,
    "name": "South Perth",
    "coord": {
      "lon": 115.833328,
      "lat": -31.933331
    },
    "country": "AU",
    "population": 0
  },
  "cnt": 7,
  "list": [
    {
      "dt": 1404619200,
      "temp": {
        "day": 13,
        "min": 13,
        "max": 13.31,
        "night": 13.31,
        "eve": 13,
        "morn": 13
      },
      "pressure": 1016.99,
      "humidity": 100,
      "weather": [
        {
          "id": 501,
          "main": "Rain",
          "description": "moderate rain",
          "icon": "10d"
        }
      ],
      "speed": 7.25,
      "deg": 225,
      "clouds": 92,
      "rain": 4
    },
  ]

  // Six more entries ...

}

More Repositories

1

docker-compose-kubernetes

Launch a local Kubernetes cluster via Docker Compose
Shell
156
star
2

kid

Utility to launch Kubernetes in Docker
Shell
141
star
3

grpc-swift-combine

Combine framework integration for Swift gRPC
Swift
74
star
4

klusterd

Akka Clustering with Kubernetes: A Sample Project
Scala
66
star
5

cassandra-kubernetes

Easily launch a Cassandra cluster on Kubernetes
Shell
60
star
6

grpc-scala-microservice-kit

A starter kit for building microservices using gRPC and Scala
Scala
24
star
7

concourse-kubernetes

Concourse CI on Kubernetes
Shell
14
star
8

grpc-oidc

A Scala library that provides OpenID Connect integration for gRPC
Scala
8
star
9

cleanroom-vim-color

A light, minimal Vim colour scheme that stays out of your way and gives you room to think.
Vim Script
7
star
10

vydark-vim-color

A comfortable, dark Vim colour scheme for everyday use.
Vim Script
6
star
11

darculash

IntelliJ IDEA colour scheme based on Darcula
4
star
12

vyterm-vim-color

Vim Script
2
star
13

geohash-tool

A Cocoa application for working with Geohashes
Swift
2
star
14

elixir-weather

Simple command line weather utility written in Elixir
Elixir
2
star
15

homelab

Home Kubernetes Cluster
Makefile
1
star
16

concourse-web-docker

Docker image for running the web component of the Concourse CI binary distribution
Shell
1
star
17

concourse-worker-docker

Docker image for running the worker component of the Concourse CI binary distribution
Shell
1
star
18

reverse-geocoder

Reverse geocoding served over gRPC, written in Scala
Scala
1
star
19

healthttpd

A tiny Scala library that provides a lightweight health and readiness status server
Scala
1
star
20

here-and-now

iOS Weather App with experimental architecture based on nestable components and RxSwift
Swift
1
star