Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codepath.daggerexample" >

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
35 changes: 24 additions & 11 deletions app/src/main/java/com/codepath/daggerexample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package com.codepath.daggerexample;

import com.codepath.daggerexample.network.interfaces.GitHubApiInterface;
import com.squareup.okhttp.OkHttpClient;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.codepath.daggerexample.network.GitHubApi;

import javax.inject.Inject;

public class MainActivity extends AppCompatActivity {
import retrofit.Retrofit;

@Inject
GitHubApiInterface mGitHubApiInterface;
public class MainActivity extends AppCompatActivity {

@Inject
SharedPreferences mSharedPreferences;

@Inject
OkHttpClient mOkHttpClient;
Retrofit mRetrofit;

private GitHubApi mGitHubApi;


@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -36,14 +38,25 @@ protected void onCreate(Bundle savedInstanceState) {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
public void onClick(final View view) {
mGitHubApi.getRepos("codepath", new GitHubApi.ResponseHandler() {
@Override
public void onResponse(Object data) {
Log.i("(MainActivity.java:45)",data.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks can we kill this line?

Snackbar.make(view,"Data retrieved", Snackbar.LENGTH_LONG)
.setAction("Action",null).show();
}

@Override
public void onFailure() {

}
});
}
});

((MyApp) getApplication()).getGitHubComponent().inject(this);

mGitHubApi = new GitHubApi(mRetrofit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is defeating the purpose of dagger it should be declared as a provider

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import retrofit.http.Path;

public interface GitHubApiInterface {
@GET("/org/{orgName}/repos")
Call<ArrayList<Repository>> getRepository(@Path("orgName") String orgName);
@GET("/users/{user}/repos")
Call<ArrayList<Repository>> getRepository(@Path("user") String userName);

}