Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.akilloren.t2modus_android_test"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.code.gson:gson:2.6.1'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.android.support:cardview-v7:24.2.1'
testCompile 'junit:junit:4.12'
}
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 /home/alank/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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.akilloren.t2modus_android_test;

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.akilloren.t2modus_android_test", appContext.getPackageName());
}
}
28 changes: 28 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.akilloren.t2modus_android_test">

<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=".activity.MainActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activity.DetailActivity"
android:configChanges="orientation|screenSize">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
package com.akilloren.t2modus_android_test.activity;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.akilloren.t2modus_android_test.R;
import com.akilloren.t2modus_android_test.misc.AppConst;
import com.akilloren.t2modus_android_test.model.Friend;
import com.akilloren.t2modus_android_test.views.CircleTransform;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;

import org.json.JSONObject;

import java.io.IOException;

public class DetailActivity extends AppCompatActivity {

private ImageView personPhoto;
private TextView personName;
private TextView personStatus;
private TextView personContactInfo;
private TextView personBioInfo;
private ProgressDialog progressDialog;
private ImageView statusIndicator;

@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

initViews();

// get id from intent and call server to get details
if (getIntent().hasExtra("id")) {
int id = getIntent().getIntExtra("id", -1);
if (id > -1) {
getFriendDetails(id);
}
}

//get passed in status text for display since we don't get it from the details
if (getIntent().hasExtra("status")) {
personStatus.setText(getIntent().getStringExtra("status"));
}
}

/**
* Initialize the views used in this activity
*/
private void initViews() {

progressDialog = new ProgressDialog(this);
personPhoto = (ImageView) findViewById(R.id.personPhoto);
personName = (TextView) findViewById(R.id.personName);
personStatus = (TextView) findViewById(R.id.personStatus);
personContactInfo = (TextView) findViewById(R.id.personContactInfo);
personBioInfo = (TextView) findViewById(R.id.personBioInfo);
statusIndicator = (ImageView) findViewById(R.id.status_indicator);
}

/**
* Calls server API and returns details for a person - Uses OKHttpClient to save TONS of repetitive HTTP coding
*
* @param id Integer value representing the id of the person
*/
private void getFriendDetails(final int id) {

new AsyncTask<String, Void, Response>() {

@Override
protected void onPreExecute() {
super.onPreExecute();
showProgress(getString(R.string.text_loading));
}

@Override
protected Response doInBackground(String... strings) {
OkHttpClient client = new OkHttpClient();
Response response;
Request request = new Request.Builder().url(AppConst.BASE_FRIENDS_API_URL + "/" + id).build();

try {
response = client.newCall(request).execute();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return response;
}

@Override
protected void onPostExecute(Response response) {
super.onPostExecute(response);
hideProgress();

if (response != null) {
String sResponse;
try {
sResponse = response.body().string();

//parse JSON
parseJSON(sResponse);

} catch (Exception e) {
e.printStackTrace();
}
}
}
}.execute();
}

/**
* Helper method to parse thru returned JSON and populate Friend object
*
* @param json JSON String to parse
*/
private void parseJSON(String json) {

try {
JSONObject jObj = new JSONObject(json);
Friend friend = new Friend();
friend.setFirst_name(jObj.getString("first_name"));
friend.setLast_name(jObj.getString("last_name"));
friend.setImg(jObj.getString("img"));
friend.setPhone(jObj.getString("phone"));
friend.setAddress_1(jObj.getString("address_1"));
friend.setCity(jObj.getString("city"));
friend.setState(jObj.getString("state"));
friend.setZipcode(jObj.getString("zipcode"));
friend.setBio(jObj.getString("bio"));
friend.setAvailable(jObj.getBoolean("available"));

//update UI
updateUI(friend);

} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Helper method to update views with data from Friend object
*
* @param friend Friend object
*/
private void updateUI(Friend friend) {

Picasso.with(this).load(friend.getImg())
.transform(new CircleTransform())
.error(R.drawable.placeholder)
.placeholder(R.drawable.placeholder)
.into(personPhoto);
personName.setText(friend.getFirst_name() + " " + friend.getLast_name());
personContactInfo.setText(friend.getAddress_1()
+ "\n" + friend.getCity()
+ ", " + friend.getState().toUpperCase()
+ " " + friend.getZipcode()
+ "\n" + friend.getPhone());
personBioInfo.setText(friend.getBio());
if (friend.isAvailable()) {
statusIndicator.setImageResource(R.drawable.online);
} else {
statusIndicator.setImageResource(R.drawable.offline);
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}

/**
* Show a progress dialog
*
* @param msg String message to display
*/
private void showProgress(String msg) {

progressDialog.setMessage(msg);
progressDialog.show();
}

/**
* Hide progress dialog
*/
private void hideProgress() {
progressDialog.dismiss();
}
}
Loading