Skip to content

Instantly share code, notes, and snippets.

View Foso's full-sized avatar
👨‍💻
Break stuff, fix stuff

Jens Klingenberg Foso

👨‍💻
Break stuff, fix stuff
View GitHub Profile
SampleRetrofitInterface api = SampleRetrofitInterface.retrofit.create(SampleRetrofitInterface.class);
Call<List<Post>> call = api.getPostList();
call.enqueue(new Callback<List<Post>>() {
@Override
public void onResponse(Call<List<Post>>call, Response<List<Post>> response) {
Log.i("INFO", String.valueOf(response.body().size()));
}
@Foso
Foso / post.java
Last active August 27, 2016 08:41
public class Post {
int userId;
int id;
String title;
String body;
public Post(int userId, int id, String title, String body) {
this.userId = userId;
this.id = id;
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
public interface SampleRetrofitInterface {
@GET("/posts")
Call<List<Post>> getPostList();
@GET("/posts/{id}")
Call<Post> getSinglePost(@Path("id") int postId);
@GET("/posts/")
Call<Post> getSinglePostQuery(@Query("userId") int userId);
dependencies {
...
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation "com.jakewharton:butterknife:8.8.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
}
project.ext {
applicationId = "jensklingenberg.de.exampleexoplayer"
compileSdk = 27
targetSdk = 27
minSdk = 21
versionCode = 1
versionName = "1.0"
buildTools = '27.0.1'
junitVersion = '4.12'
appVersion = '1.0'
dependencies {
...
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.google.android.exoplayer:exoplayer:${exoplayerVersion}"
implementation "com.jakewharton:butterknife:${butterknifeVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${butterknifeVersion}"}
compileSdkVersion compileSdk
defaultConfig {
applicationId applicationId
...
}
buildTypes {
debug {
buildConfigField "String", "API_BASE_URL", '"https://test.de/testing/api/v1/"'
...
}
release {
buildConfigField "String", "API_BASE_URL", '"https://test.de/prod/api/v1/"'
...
}
new Retrofit.Builder().addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(new LiveDataCallAdapterFactory())
.baseUrl(BuildConfig.API_BASE_URL)
.client(App.getInstance().getOkHttpClient())
.build();