Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
florent champigny committed Jul 11, 2017
1 parent 5df9874 commit 2bd15e6
Show file tree
Hide file tree
Showing 50 changed files with 1,146 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
35 changes: 35 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "florent37.github.com.rxgraphql"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"

jackOptions.enabled = true
}

compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'

compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.facebook.stetho:stetho:1.5.0'
compile 'com.facebook.stetho:stetho-okhttp3:1.5.0'
compile 'com.jakewharton:butterknife:7.0.1'

compile project(':rxgraphql')
compile 'io.reactivex.rxjava2:rxjava:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.google.code.gson:gson:2.8.0'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/florentchampigny/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="florent37.github.com.rxgraphql">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".MainApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
92 changes: 92 additions & 0 deletions app/src/main/java/florent37/github/com/rxgraphql/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package florent37.github.com.rxgraphql;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.github.florent37.rxgraphql.RxGraphQl;
import com.github.florent37.rxgraphql.converter.GsonConverter;
import com.google.gson.Gson;

import butterknife.Bind;
import butterknife.ButterKnife;
import florent37.github.com.rxgraphql.model.WeatherForecastResponse;
import io.reactivex.android.schedulers.AndroidSchedulers;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";

private RxGraphQl rxGraphQl;

@Bind(R.id.text)
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);

this.rxGraphQl = new RxGraphQl.Builder()
.okClient(((MainApplication) getApplication()).getOkHttpClient())
.baseUrl("http://192.168.1.16:8888/graphql")
.converter(new GsonConverter(new Gson()))
.build();

query();
//mutation();
}

private void enqueue() {
rxGraphQl.query(
"weatherForecast(city:@city) {" +
"city {" +
" id," +
" population," +
" name," +
" country," +
" coord{" +
" lon," +
" lat" +
" }" +
" }" +
"}"
)
.cast(WeatherForecastResponse.class)
.field("city", "Seattle")
.enqueue(data -> {
Log.d(TAG, data.toString());
textView.setText(data.toString());
}, error -> {

});
}

private void query() {
rxGraphQl.query(
"weatherForecast(city:@city) {" +
"city {" +
" id," +
" population," +
" name," +
" country," +
" coord{" +
" lon," +
" lat" +
" }" +
" }" +
"}"
)
.cast(WeatherForecastResponse.class)
.field("city", "Seattle")
.toSingle()
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess(data -> Log.d(TAG, data.toString()))
.subscribe(
data -> textView.setText(data.toString()),
throwable -> textView.setText(throwable.getLocalizedMessage())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package florent37.github.com.rxgraphql;

import android.app.Application;

import com.facebook.stetho.Stetho;
import com.facebook.stetho.okhttp3.StethoInterceptor;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

/**
* Created by florentchampigny on 10/07/2017.
*/

public class MainApplication extends Application {

private OkHttpClient okHttpClient;

@Override
public void onCreate() {
super.onCreate();

Stetho.initializeWithDefaults(getApplicationContext());
okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new StethoInterceptor())
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
}

public OkHttpClient getOkHttpClient() {
return okHttpClient;
}
}
54 changes: 54 additions & 0 deletions app/src/main/java/florent37/github/com/rxgraphql/model/City.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package florent37.github.com.rxgraphql.model;

/**
* Created by florentchampigny on 10/07/2017.
*/

public class City {
private String id;
private String name;
private String country;
private Coord coord;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public Coord getCoord() {
return coord;
}

public void setCoord(Coord coord) {
this.coord = coord;
}

@Override
public String toString() {
return "City{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", country='" + country + '\'' +
", coord=" + coord +
'}';
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/florent37/github/com/rxgraphql/model/Coord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package florent37.github.com.rxgraphql.model;

/**
* Created by florentchampigny on 10/07/2017.
*/

public class Coord {
private String lon;
private String lat;

public String getLon() {
return lon;
}

public void setLon(String lon) {
this.lon = lon;
}

public String getLat() {
return lat;
}

public void setLat(String lat) {
this.lat = lat;
}

@Override
public String toString() {
return "Coord{" +
"lon='" + lon + '\'' +
", lat='" + lat + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package florent37.github.com.rxgraphql.model;

/**
* Created by florentchampigny on 10/07/2017.
*/

public class WeatherForecast {
private City city;

public City getCity() {
return city;
}

public void setCity(City city) {
this.city = city;
}

@Override
public String toString() {
return "WeatherForecast{" +
"city=" + city +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package florent37.github.com.rxgraphql.model;

/**
* Created by florentchampigny on 10/07/2017.
*/

public class WeatherForecastResponse {
WeatherForecast weatherForecast;

public WeatherForecast getWeatherForecast() {
return weatherForecast;
}

public void setWeatherForecast(WeatherForecast weatherForecast) {
this.weatherForecast = weatherForecast;
}

@Override
public String toString() {
return "WeatherForecastResponse{" +
"weatherForecast=" + weatherForecast +
'}';
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="florent37.github.com.rxgraphql.MainActivity">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center" />

</FrameLayout>
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">RxGraphQl</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Loading

0 comments on commit 2bd15e6

Please sign in to comment.