Skip to content

Commit

Permalink
New clasess to separate http operations of user account and user card
Browse files Browse the repository at this point in the history
and code adaption
  • Loading branch information
amcereijo committed Dec 27, 2012
1 parent 6abab18 commit 33e6afb
Show file tree
Hide file tree
Showing 10 changed files with 690 additions and 578 deletions.
8 changes: 4 additions & 4 deletions src/com/trcardmanager/TRCardManagerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.trcardmanager.dao.MovementDao;
import com.trcardmanager.dao.UserDao;
import com.trcardmanager.exception.TRCardManagerSessionException;
import com.trcardmanager.http.TRCardManagerHttpAction;
import com.trcardmanager.http.TRCardManagerHttpCardAction;
import com.trcardmanager.myaccount.TRCardManagerMyAccountActivity;
import com.trcardmanager.restaurant.TRCardManagerRestaurantsActivity;
import com.trcardmanager.settings.TRCardManagerSettingsActivity;
Expand Down Expand Up @@ -257,12 +257,12 @@ private void addCardsToView(final UserDao user){


private void loadMoreMovementsBackGround(final UserDao user){
final TRCardManagerHttpAction httpAction = new TRCardManagerHttpAction();

new Thread(new Runnable() {
public void run() {
try {
user.getActualCard().getMovementsData().setNextMovements(
httpAction.getNextMovements(user));
List<MovementDao> movements = new TRCardManagerHttpCardAction().getNextMovements(user);
user.getActualCard().getMovementsData().setNextMovements(movements);
} catch (IOException e) {
Log.e(this.getClass().toString(), e.getMessage(),e);
}catch(TRCardManagerSessionException se){
Expand Down
7 changes: 3 additions & 4 deletions src/com/trcardmanager/action/MovementListAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.trcardmanager.dao.UserDao;
import com.trcardmanager.exception.TRCardManagerSessionException;
import com.trcardmanager.http.TRCardManagerHttpAction;
import com.trcardmanager.http.TRCardManagerHttpCardAction;
import com.trcardmanager.views.TRCardManagerListView;
import com.trcardmanager.views.TRCardManagerListView.ScrollDirection;

Expand Down Expand Up @@ -70,9 +71,8 @@ protected void onPostExecute(Void result) {

private List<MovementDao> updateMovements() {
List<MovementDao> myListItems = new ArrayList<MovementDao>();
TRCardManagerHttpAction httpAction = new TRCardManagerHttpAction();
try {
myListItems = httpAction.updateLastMovementsAndBalance(user);
myListItems = new TRCardManagerHttpCardAction().updateLastMovementsAndBalance(user);
if(myListItems == null || myListItems.size()==0){
myListItems = new ArrayList<MovementDao>();
}
Expand Down Expand Up @@ -110,9 +110,8 @@ public void run() {

private List<MovementDao> callHttpFindMovements(){
List<MovementDao> myListItems = new ArrayList<MovementDao>();
final TRCardManagerHttpAction httpAction = new TRCardManagerHttpAction();
try {
myListItems = httpAction.getNextMovements(user);
myListItems = new TRCardManagerHttpCardAction().getNextMovements(user);
} catch (IOException e) {
Log.e(this.getClass().toString(), e.getMessage(),e);
}catch(TRCardManagerSessionException se){
Expand Down
5 changes: 2 additions & 3 deletions src/com/trcardmanager/action/TRCardManagerLoginAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.trcardmanager.exception.TRCardManagerDataException;
import com.trcardmanager.exception.TRCardManagerLoginException;
import com.trcardmanager.exception.TRCardManagerSessionException;
import com.trcardmanager.http.TRCardManagerHttpAction;
import com.trcardmanager.http.TRCardManagerHttpUserAction;

/**
*
Expand Down Expand Up @@ -99,8 +99,7 @@ protected Integer doInBackground(Void... params) {


private void httpLogin() throws TRCardManagerLoginException, ClientProtocolException, IOException{
TRCardManagerHttpAction httpAction = new TRCardManagerHttpAction();
httpAction.getCookieLogin(userDao);
new TRCardManagerHttpUserAction().getCookieLogin(userDao);
}


Expand Down
5 changes: 2 additions & 3 deletions src/com/trcardmanager/action/UpdateCardAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.trcardmanager.exception.TRCardManagerDataException;
import com.trcardmanager.exception.TRCardManagerSessionException;
import com.trcardmanager.exception.TRCardManagerUpdateCardException;
import com.trcardmanager.http.TRCardManagerHttpAction;
import com.trcardmanager.http.TRCardManagerHttpCardAction;


/**
Expand Down Expand Up @@ -53,8 +53,7 @@ private void updateCard(String cardNumber){
try {
if(cardDao != null){
//http active card
TRCardManagerHttpAction httpAction = new TRCardManagerHttpAction();
httpAction.activateCard(userDao, cardDao);
new TRCardManagerHttpCardAction().activateCard(userDao, cardDao);

publishProgress();

Expand Down
7 changes: 2 additions & 5 deletions src/com/trcardmanager/action/UpdatePasswordAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.trcardmanager.exception.TRCardManagerDataException;
import com.trcardmanager.exception.TRCardManagerSessionException;
import com.trcardmanager.exception.TRCardManagerUpdatePasswordException;
import com.trcardmanager.http.TRCardManagerHttpAction;
import com.trcardmanager.http.TRCardManagerHttpUserAction;

/**
*
Expand Down Expand Up @@ -50,18 +50,15 @@ protected Integer doInBackground(String... params) {
}

private void updatePassword(String newPassword){
TRCardManagerHttpAction httpAction = new TRCardManagerHttpAction();
try {
httpAction.changePassword(userDao, newPassword);
new TRCardManagerHttpUserAction().changePassword(userDao, newPassword);
CheckBox checkSave = (CheckBox)activity.findViewById(R.id.update_password_savedb);
//¿save in db?
if(checkSave.isChecked() && userDao.isRememberme()){
publishProgress();
TRCardManagerDbHelper dbHelper = new TRCardManagerDbHelper(activity.getApplicationContext());
dbHelper.updateUserPassword(userDao, newPassword);
}

//TODO return a code to principal activity to repaint screen
finalizeWithState(TRCardManagerApplication.PASSWORD_UPDATED);
} catch (ClientProtocolException e) {
Log.e(TAG,"Error updating password:"+e.getMessage(),e);
Expand Down
4 changes: 2 additions & 2 deletions src/com/trcardmanager/action/UserDataAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.trcardmanager.db.TRCardManagerDbHelper;
import com.trcardmanager.exception.TRCardManagerDataException;
import com.trcardmanager.exception.TRCardManagerSessionException;
import com.trcardmanager.http.TRCardManagerHttpAction;
import com.trcardmanager.http.TRCardManagerHttpCardAction;

/**
*
Expand All @@ -30,7 +30,7 @@ public class UserDataAction {
public void loadAndSaveUserData(UserDao userDao) throws ClientProtocolException, IOException,
TRCardManagerDataException, TRCardManagerSessionException{

TRCardManagerHttpAction httpAction = new TRCardManagerHttpAction();
TRCardManagerHttpCardAction httpAction = new TRCardManagerHttpCardAction();
TRCardManagerDbHelper dbHelper = new TRCardManagerDbHelper(TRCardManagerApplication.getActualActivity());
//http actions
httpAction.getActualCard(userDao);
Expand Down
Loading

0 comments on commit 33e6afb

Please sign in to comment.