Skip to content

Commit

Permalink
profile
Browse files Browse the repository at this point in the history
O profile já funciona mas ainda falta a parte dos episodios.
  • Loading branch information
Rpaixao committed Feb 29, 2012
1 parent 39c0ada commit efadb23
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 8 deletions.
9 changes: 4 additions & 5 deletions res/layout/profile.xml
Expand Up @@ -95,9 +95,8 @@
android:layout_gravity="center_vertical"
android:orientation="vertical" >


<TextView
android:id="@+id/textView1"
android:id="@+id/episodeswatched"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
Expand Down Expand Up @@ -128,7 +127,7 @@
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:id="@+id/showswatched"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down Expand Up @@ -211,7 +210,7 @@
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:id="@+id/showsloved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down Expand Up @@ -294,7 +293,7 @@
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:id="@+id/showscollected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down
212 changes: 209 additions & 3 deletions src/com/tvshowtrakt/ProfileActivity.java
@@ -1,28 +1,51 @@
package com.tvshowtrakt;

import java.util.ArrayList;
import java.util.List;

import com.jakewharton.trakt.ServiceManager;
import com.jakewharton.trakt.entities.TvShow;
import com.tvshowtrakt.adapters.LazyAdapterGalleryTrending;

import greendroid.app.GDActivity;
import greendroid.widget.ActionBarItem;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.Gallery;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ProfileActivity extends GDActivity {

private boolean login;
private String username;
private String password;


private static final int SEARCH = 0;
private ProfileActivity profileActivity;
private String apikey = "a7b42c4fb5c50a85c68731b25cc3c1ed";


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setActionBarContentView(R.layout.profile);
setTitle("Profile");

profileActivity=this;
//Items da ActionBar
addActionBarItem(ActionBarItem.Type.Search, SEARCH);

//Obter as preferncias da aplica‹o
getPrefs();


new Watched().execute();
new Loved().execute();
new Collected().execute();

}

/**
Expand Down Expand Up @@ -51,5 +74,188 @@ public void onResume() {
username = prefs.getString("username", "username");
password = prefs.getString("password", "password");
}

//Asynctask para obten‹o dos Shows visualizados.
private class Watched extends
AsyncTask<String, Void, List<TvShow>> {
private Exception e = null;

/**
* primeiro mŽtodo a correr, usar o manager para obter os dados da api
*/
@Override
protected List<TvShow> doInBackground(String... params) {

try {

ServiceManager manager = new ServiceManager();
manager.setAuthentication(username,
new Password().parseSHA1Password(password));
manager.setApiKey(apikey);
return manager.userService().libraryShowsWatched(username).fire();



} catch (Exception e) {
this.e = e;
}
return null;
}

/**
* Os resultados s‹o passados para aqui e depois tratados aqui.
*/
protected void onPostExecute(List<TvShow> result) {
if (e == null) {

TextView showswatched = (TextView) findViewById(R.id.showswatched);
showswatched.setText(result.size()+"");
int watched_episodes =0;
// for(TvShow ts: result){
// watched_episodes = watched_episodes + ts.episodes.size();
// }
// TextView episodeswatched = (TextView) findViewById(R.id.episodeswatched);
// episodeswatched.setText(watched_episodes+"");

} else
goBlooey(e);
}

/**
* Em caso de erro a excep‹o ser‡ tratada aqui.
*/
private void goBlooey(Throwable t) {
AlertDialog.Builder builder = new AlertDialog.Builder(
getApplicationContext());

builder.setTitle("Connection Error")
.setMessage(
"Movie Trakt can not connect with trakt service")
.setPositiveButton("OK", null).show();
}

}

//Asynctask para obten‹o dos Shows que o utilizador Gosta.
private class Loved extends
AsyncTask<String, Void, List<TvShow>> {
private Exception e = null;

/**
* primeiro mŽtodo a correr, usar o manager para obter os dados da api
*/
@Override
protected List<TvShow> doInBackground(String... params) {

try {

ServiceManager manager = new ServiceManager();
manager.setAuthentication(username,
new Password().parseSHA1Password(password));
manager.setApiKey(apikey);
return manager.userService().libraryShowsLoved(username).fire();



} catch (Exception e) {
this.e = e;
}
return null;
}

/**
* Os resultados s‹o passados para aqui e depois tratados aqui.
*/
protected void onPostExecute(List<TvShow> result) {
if (e == null) {

TextView showsloved = (TextView) findViewById(R.id.showsloved);
showsloved.setText(result.size()+"");
int watched_episodes =0;
// for(TvShow ts: result){
// watched_episodes = watched_episodes + ts.episodes.size();
// }
// TextView episodeswatched = (TextView) findViewById(R.id.episodeswatched);
// episodeswatched.setText(watched_episodes+"");

} else
goBlooey(e);
}

/**
* Em caso de erro a excep‹o ser‡ tratada aqui.
*/
private void goBlooey(Throwable t) {
AlertDialog.Builder builder = new AlertDialog.Builder(
getApplicationContext());

builder.setTitle("Connection Error")
.setMessage(
"Movie Trakt can not connect with trakt service")
.setPositiveButton("OK", null).show();
}

}

//Asynctask para obten‹o dos Shows que o utilizador Gosta.
private class Collected extends
AsyncTask<String, Void, List<TvShow>> {
private Exception e = null;

/**
* primeiro mŽtodo a correr, usar o manager para obter os dados da api
*/
@Override
protected List<TvShow> doInBackground(String... params) {

try {

ServiceManager manager = new ServiceManager();
manager.setAuthentication(username,
new Password().parseSHA1Password(password));
manager.setApiKey(apikey);
return manager.userService().libraryShowsCollection(username).fire();



} catch (Exception e) {
this.e = e;
}
return null;
}

/**
* Os resultados s‹o passados para aqui e depois tratados aqui.
*/
protected void onPostExecute(List<TvShow> result) {
if (e == null) {

TextView showscollected = (TextView) findViewById(R.id.showscollected);
showscollected.setText(result.size()+"");
int watched_episodes =0;
// for(TvShow ts: result){
// watched_episodes = watched_episodes + ts.episodes.size();
// }
// TextView episodeswatched = (TextView) findViewById(R.id.episodeswatched);
// episodeswatched.setText(watched_episodes+"");

} else
goBlooey(e);
}

/**
* Em caso de erro a excep‹o ser‡ tratada aqui.
*/
private void goBlooey(Throwable t) {
AlertDialog.Builder builder = new AlertDialog.Builder(
getApplicationContext());

builder.setTitle("Connection Error")
.setMessage(
"Movie Trakt can not connect with trakt service")
.setPositiveButton("OK", null).show();
}

}

}

0 comments on commit efadb23

Please sign in to comment.