Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boloutare Doubeni && Faraz Fazli - API and GSON lab #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions PokeDexApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
1 change: 1 addition & 0 deletions PokeDexApp/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions PokeDexApp/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions PokeDexApp/.idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions PokeDexApp/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions PokeDexApp/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions PokeDexApp/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions PokeDexApp/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions PokeDexApp/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions PokeDexApp/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions PokeDexApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.boloutaredoubeni.pokedex"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.google.code.gson:gson:2.6'
}
17 changes: 17 additions & 0 deletions PokeDexApp/app/proguard-rules.pro
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 /usr/local/opt/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 *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.boloutaredoubeni.pokedex;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
21 changes: 21 additions & 0 deletions PokeDexApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.boloutaredoubeni.pokedex"
xmlns:android="http://schemas.android.com/apk/res/android">
<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"
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.boloutaredoubeni.pokedex;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {

private ListView mListView;
private PokeDexArrayAdapter mAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mListView = (ListView)findViewById(R.id.pokedex);
mAdapter = new PokeDexArrayAdapter(this, new ArrayList<PokemonResource>());
mListView.setAdapter(mAdapter);
}

@Override
protected void onResume() {
super.onResume();
new PokedexTask().execute();
}

public class PokedexTask extends AsyncTask<Void, Void, ArrayList<PokemonResource>> {

@Override
protected ArrayList<PokemonResource> doInBackground(Void... params) {
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("http://pokeapi.co/api/v2/pokemon/").build();
Response response = client.newCall(request).execute();
Gson gson = new Gson();
Type pokemonResourceType = new TypeToken<ArrayList<PokemonResource>>() {}.getType();
return gson.fromJson(response.body().string(), pokemonResourceType);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(ArrayList<PokemonResource> pokemonResources) {
super.onPostExecute(pokemonResources);
mAdapter.clear();
mAdapter.addAll(pokemonResources);
mAdapter.notifyDataSetChanged();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.boloutaredoubeni.pokedex;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

/**
* Created by faraz on 3/1/16.
*/
public class PokeDexArrayAdapter extends ArrayAdapter<PokemonResource> {
private LayoutInflater mInflater;

public PokeDexArrayAdapter(Context context, List<PokemonResource> objects) {
super(context, R.layout.pokemon_item, objects);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.pokemon_item, parent, false);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String name = getItem(position).getName();
holder.name.setText(name);
return convertView;
}

static class ViewHolder {
TextView name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.boloutaredoubeni.pokedex;

import java.util.ArrayList;

/**
* Copyright 2016 Boloutare Doubeni
*/
public class PokeDexJSON {
private ArrayList<PokemonResource> mPokemon;

public PokeDexJSON(ArrayList<PokemonResource> pokemon) {
mPokemon = pokemon;
}

public ArrayList<PokemonResource> getPokemon() {
return mPokemon;
}

public void setPokemon(ArrayList<PokemonResource> mPokemon) {
this.mPokemon = mPokemon;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.boloutaredoubeni.pokedex;

/**
* Copyright 2016 Boloutare Doubeni
*/
public class PokeType {

private int mSlot;
private String mType;

public PokeType(int slot, String type) {
mSlot = slot;
mType = type;
}

public String getType() {
return mType;
}

public void setType(String mType) {
this.mType = mType;
}

public int getSlot() {
return mSlot;
}

public void setSlot(int mSlot) {
this.mSlot = mSlot;
}
}
Loading