-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68c0167
commit 94298d9
Showing
24 changed files
with
343 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,5 @@ proguard/ | |
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the Dalvik VM | ||
*.dex | ||
|
||
*.idea | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'me.tatarka.retrolambda' | ||
apply plugin: 'realm-android' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.3" | ||
|
||
defaultConfig { | ||
applicationId "io.fabianterhorst.apiclient.app" | ||
minSdkVersion 14 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:2.3.0' | ||
compile 'com.android.support:appcompat-v7:23.3.0' | ||
compile 'com.android.support:recyclerview-v7:23.3.0' | ||
compile 'com.trello:rxlifecycle-components:0.6.0' | ||
compile project (':apiclient') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/fabianterhorst/Desktop/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 *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.fabianterhorst.apiclient.app"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:name=".MyApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<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> |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/io/fabianterhorst/apiclient/app/Github.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.fabianterhorst.apiclient.app; | ||
|
||
import java.util.List; | ||
|
||
import io.fabianterhorst.apiclient.ApiClient; | ||
import retrofit2.http.Path; | ||
import rx.Observable; | ||
|
||
public class Github extends ApiClient<GithubApi> implements GithubApi { | ||
|
||
public Github() { | ||
super(GithubApi.class, GithubApi.END_POINT); | ||
} | ||
|
||
public static void init() { | ||
init(new Github()); | ||
} | ||
|
||
@Override | ||
public Observable<List<Repository>> getRepositories(@Path("user") String user) { | ||
return getApiObservable(getApi().getRepositories(user), Repository.class); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/io/fabianterhorst/apiclient/app/GithubApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.fabianterhorst.apiclient.app; | ||
|
||
import java.util.List; | ||
|
||
import retrofit2.http.GET; | ||
import retrofit2.http.Path; | ||
import rx.Observable; | ||
|
||
public interface GithubApi { | ||
|
||
String END_POINT = "https://api.github.com"; | ||
|
||
@GET("/users/{user}/repos") | ||
Observable<List<Repository>> getRepositories(@Path("user") String user); | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/io/fabianterhorst/apiclient/app/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.fabianterhorst.apiclient.app; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import com.trello.rxlifecycle.components.support.RxAppCompatActivity; | ||
|
||
public class MainActivity extends RxAppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.repositories); | ||
RepositoriesAdapter adapter = new RepositoriesAdapter(); | ||
if(recyclerView != null) { | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
recyclerView.setAdapter(adapter); | ||
} | ||
//Github github = Github.getInstance(); is also working, but does not un subscribe on orientation change for example | ||
Github github = Github.getInstance(bindToLifecycle()); | ||
github.getRepositories("realm").subscribe(adapter::setRepositories); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/io/fabianterhorst/apiclient/app/MyApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.fabianterhorst.apiclient.app; | ||
|
||
import android.app.Application; | ||
|
||
import io.realm.Realm; | ||
import io.realm.RealmConfiguration; | ||
|
||
public class MyApplication extends Application { | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this) | ||
.deleteRealmIfMigrationNeeded() | ||
.build(); | ||
Realm.setDefaultConfiguration(realmConfiguration); | ||
Github.init(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/io/fabianterhorst/apiclient/app/RepositoriesAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.fabianterhorst.apiclient.app; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RepositoriesAdapter extends RecyclerView.Adapter<RepositoriesAdapter.ViewHolder> { | ||
|
||
private List<Repository> repositories; | ||
|
||
public static class ViewHolder extends RecyclerView.ViewHolder { | ||
public TextView name; | ||
public ViewHolder(View view) { | ||
super(view); | ||
name = (TextView) view.findViewById(R.id.repository_name); | ||
} | ||
} | ||
|
||
public RepositoriesAdapter() { | ||
setHasStableIds(true); | ||
repositories = new ArrayList<>(); | ||
} | ||
|
||
public void setRepositories(List<Repository> repositories) { | ||
this.repositories = repositories; | ||
notifyDataSetChanged(); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return repositories.get(position).getId(); | ||
} | ||
|
||
@Override | ||
public RepositoriesAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, | ||
int viewType) { | ||
View v = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.item_repository, parent, false); | ||
return new ViewHolder(v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, int position) { | ||
holder.name.setText(repositories.get(position).getName()); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return repositories.size(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/io/fabianterhorst/apiclient/app/Repository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.fabianterhorst.apiclient.app; | ||
|
||
import io.realm.RealmObject; | ||
import io.realm.annotations.PrimaryKey; | ||
import io.realm.annotations.RealmClass; | ||
|
||
@RealmClass | ||
public class Repository extends RealmObject { | ||
|
||
@PrimaryKey | ||
private long id; | ||
|
||
private String name; | ||
|
||
public Repository() { | ||
|
||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="io.fabianterhorst.apiclient.app.MainActivity"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/repositories" | ||
android:scrollbars="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<TextView | ||
android:id="@+id/repository_name" | ||
android:layout_width="wrap_content" | ||
android:textColor="#000000" | ||
android:layout_height="wrap_content"/> | ||
|
||
</LinearLayout> |
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">App</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':apiclient', ':apiclient-components', ':apiclient-accountmanager' | ||
include ':apiclient', ':apiclient-components', ':apiclient-accountmanager', ':app' |