-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit b128fd7
Showing
33 changed files
with
822 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
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,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
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 @@ | ||
/build |
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,32 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "com.faladinojames.andela" | ||
minSdkVersion 15 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
ext { | ||
libSupportVersion = '25.1.0' | ||
} | ||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile "com.android.support:appcompat-v7:${libSupportVersion}" | ||
compile "com.android.support:design:${libSupportVersion}" | ||
compile "com.android.support:recyclerview-v7:${libSupportVersion}" | ||
compile "com.android.support:cardview-v7:${libSupportVersion}" | ||
compile "com.android.support:support-v4:${libSupportVersion}" | ||
|
||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 C:\Users\Falade James\AppData\Local\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 *; | ||
#} |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/faladinojames/andela/ExampleInstrumentedTest.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,26 @@ | ||
package com.faladinojames.andela; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.faladinojames.andela", appContext.getPackageName()); | ||
} | ||
} |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.faladinojames.andela"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<application | ||
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/com/faladinojames/andela/AndelaActivity.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 com.faladinojames.andela; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* Created by Falade James on 3/6/2017 All Rights Reserved. | ||
*/ | ||
|
||
public class AndelaActivity extends AppCompatActivity { | ||
|
||
|
||
protected void shortToast(String t) | ||
{ | ||
Toast.makeText(this,t,Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
protected void log(String l) | ||
{ | ||
Log.d("Andela",l); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/faladinojames/andela/GithubUser.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,51 @@ | ||
package com.faladinojames.andela; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Created by Falade James on 3/6/2017 All Rights Reserved. | ||
*/ | ||
|
||
public class GithubUser { | ||
JSONObject object; | ||
public GithubUser(JSONObject o) | ||
{ | ||
this.object=o; | ||
} | ||
|
||
public String getUsername(){ | ||
try { | ||
return object.getString("login"); | ||
} | ||
catch (JSONException e) | ||
{ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
public String getAvatarUrl(){ | ||
try { | ||
return object.getString("avatar_url"); | ||
} | ||
catch (JSONException e) | ||
{ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
|
||
} | ||
|
||
public String getURL(){ | ||
try { | ||
return object.getString("html_url"); | ||
} | ||
catch (JSONException e) | ||
{ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
|
||
} | ||
} |
187 changes: 187 additions & 0 deletions
187
app/src/main/java/com/faladinojames/andela/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,187 @@ | ||
package com.faladinojames.andela; | ||
|
||
import android.app.Dialog; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v4.widget.SwipeRefreshLayout; | ||
import android.support.v7.widget.GridLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.android.volley.Request; | ||
import com.android.volley.RequestQueue; | ||
import com.android.volley.Response; | ||
import com.android.volley.VolleyError; | ||
import com.android.volley.toolbox.StringRequest; | ||
import com.android.volley.toolbox.Volley; | ||
import com.squareup.picasso.Picasso; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import butterknife.ButterKnife; | ||
import butterknife.InjectView; | ||
|
||
public class MainActivity extends AndelaActivity { | ||
|
||
@InjectView(R.id.rv_recycler) | ||
RecyclerView recyclerView; | ||
@InjectView(R.id.srl_refresh) | ||
SwipeRefreshLayout refreshLayout; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
ButterKnife.inject(this); | ||
getLagosGithubUsers(); | ||
|
||
|
||
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { | ||
@Override | ||
public void onRefresh() { | ||
getLagosGithubUsers(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private void getLagosGithubUsers() | ||
{ | ||
refreshLayout.setRefreshing(true); | ||
RequestQueue queue = Volley.newRequestQueue(this); | ||
StringRequest stringRequest = new StringRequest(Request.Method.GET, "https://api.github.com/search/users?q=location:lagos+language:java", | ||
new Response.Listener<String>() { | ||
@Override | ||
public void onResponse(String response) { | ||
refreshLayout.setRefreshing(false); | ||
log(response); | ||
try{ | ||
processUsers(response);} | ||
catch (JSONException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
}, new Response.ErrorListener() { | ||
@Override | ||
public void onErrorResponse(VolleyError error) { | ||
shortToast("Unable to load list"); | ||
refreshLayout.setRefreshing(false); | ||
error.printStackTrace(); | ||
} | ||
}); | ||
// Add the request to the RequestQueue. | ||
queue.add(stringRequest); | ||
} | ||
private void processUsers (String j)throws JSONException { | ||
JSONObject jsonObject = new JSONObject(j); | ||
JSONArray users = jsonObject.getJSONArray("items"); | ||
List<GithubUser> githubUsers = new ArrayList<>(); | ||
|
||
for (int i = 0; i < users.length(); i++) | ||
{ | ||
githubUsers.add(new GithubUser(users.getJSONObject(i))); | ||
} | ||
|
||
recyclerView.setAdapter(new Adapter(githubUsers)); | ||
recyclerView.setLayoutManager(new GridLayoutManager(this,2)); | ||
} | ||
|
||
|
||
private void showUserDetails(final GithubUser user) | ||
{ | ||
|
||
Dialog dialog= new Dialog(this); | ||
dialog.setContentView(R.layout.user_details); | ||
TextView tvUsername= (TextView)dialog.findViewById(R.id.tv_user_details_username); | ||
TextView tvGithubUrl=(TextView)dialog.findViewById(R.id.tv_user_details_github_url); | ||
ImageView ivPicture=(ImageView)dialog.findViewById(R.id.iv_user_details_picture); | ||
Button button =(Button)dialog.findViewById(R.id.bt_user_details_share); | ||
tvUsername.setText(user.getUsername()); | ||
tvGithubUrl.setText(user.getURL()); | ||
Picasso.with(this).load(user.getAvatarUrl()).into(ivPicture); | ||
|
||
|
||
|
||
button.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
Intent shareIntent = new Intent(); | ||
shareIntent.setAction(Intent.ACTION_SEND); | ||
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check out this awesome developer @"+user.getUsername()+", "+user.getURL()); | ||
shareIntent.setType("text/plain"); | ||
startActivity(shareIntent); | ||
} | ||
}); | ||
|
||
|
||
dialog.setCancelable(true); | ||
dialog.show(); | ||
|
||
|
||
|
||
} | ||
public class Adapter extends RecyclerView.Adapter<ViewHolder>{ | ||
|
||
List<GithubUser> lagosUsers; | ||
Adapter(List<GithubUser> lagosUsers) | ||
{ | ||
this.lagosUsers=lagosUsers; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return new ViewHolder(LayoutInflater.from(getApplicationContext()).inflate(R.layout.user_item,parent,false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, int position) { | ||
GithubUser githubUser = lagosUsers.get(position); | ||
holder.itemView.setTag(githubUser); | ||
holder.tvUsername.setText(githubUser.getUsername()); | ||
Picasso.with(getApplicationContext()).load(githubUser.getAvatarUrl()).into(holder.ivPicture); | ||
holder.itemView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
showUserDetails((GithubUser)v.getTag()); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return lagosUsers.size(); | ||
} | ||
} | ||
|
||
public class ViewHolder extends RecyclerView.ViewHolder{ | ||
@InjectView(R.id.iv_user_picture) | ||
ImageView ivPicture; | ||
@InjectView(R.id.tv_user_username) | ||
TextView tvUsername; | ||
|
||
|
||
ViewHolder(View v) | ||
{ | ||
super(v); | ||
ButterKnife.inject(this,v); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.