From 1e9ff2a313a4e6757c5f1fa8ee4d6bbb5ecf7f21 Mon Sep 17 00:00:00 2001 From: drizea Date: Mon, 25 Jun 2012 22:17:53 +0300 Subject: [PATCH] fix application preference bug on library EG server change --- .../android/accountAccess/AccountAccess.java | 16 ++++++++-- .../accountAccess/ItemsCheckOutListView.java | 35 +++++++++++++++++----- .../evergreen/android/globals/GlobalConfigs.java | 11 +++++-- .../android/views/ApplicationPreferences.java | 31 ++++++++++++++++++- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java index 973b3c2810..89212b351e 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java @@ -201,7 +201,7 @@ public class AccountAccess { public HttpConnection conn; /** The http address. */ - public String httpAddress = "http://ulysses.calvin.edu"; + private String httpAddress = "http://ulysses.calvin.edu"; /** The TAG. */ public String TAG = "AuthenticareUser"; @@ -245,11 +245,20 @@ public class AccountAccess { } + public boolean isAuthenticated(){ + + if(authToken != null) + return true; + + return false; + } + public static AccountAccess getAccountAccess(String httpAddress){ if(accountAccess == null){ accountAccess = new AccountAccess(httpAddress); } + System.out.println(" Addresses " + httpAddress + " " + accountAccess.httpAddress); if(!httpAddress.equals(accountAccess.httpAddress)) accountAccess.updateHttpAddress(httpAddress); @@ -269,10 +278,10 @@ public class AccountAccess { * Change the Http conn to a new library address */ public void updateHttpAddress(String httpAddress){ - + System.out.println("update http address of account access to " + httpAddress); try { // configure the connection - + this.httpAddress = httpAddress; System.out.println("Connection with " + httpAddress); conn = new HttpConnection(httpAddress + "/osrf-gateway-v1"); @@ -395,6 +404,7 @@ public class AccountAccess { complexParam.put("username", userName); complexParam.put("password", hash); + System.out.println("Password " + password); System.out.println("Compelx param " + complexParam); Object resp = Utils.doRequest(conn, SERVICE_AUTH, METHOD_AUTH_COMPLETE, new Object[]{complexParam}); diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/ItemsCheckOutListView.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/ItemsCheckOutListView.java index f14095aaac..9938212e09 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/ItemsCheckOutListView.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/ItemsCheckOutListView.java @@ -45,16 +45,37 @@ public class ItemsCheckOutListView extends Activity{ context = this; accountAccess = AccountAccess.getAccountAccess(); - lv = (ListView) findViewById(R.id.checkout_items_list); - - circRecords = accountAccess.getItemsCheckedOut(); + Thread getCirc = new Thread(new Runnable() { + + @Override + public void run() { + lv = (ListView) findViewById(R.id.checkout_items_list); + circRecords = accountAccess.getItemsCheckedOut(); + listAdapter = new CheckOutArrayAdapter(context, R.layout.checkout_list_item, circRecords); + lv.setAdapter(listAdapter); + + listAdapter.notifyDataSetChanged(); + + runOnUiThread(new Runnable() { + + @Override + public void run() { + progressDialog.dismiss(); + } + }); + } + }); - listAdapter = new CheckOutArrayAdapter(this, R.layout.checkout_list_item, circRecords); - lv.setAdapter(listAdapter); + if(accountAccess.isAuthenticated()){ + progressDialog = new ProgressDialog(context); + progressDialog.setMessage("Please wait while retrieving circ data"); + getCirc.start(); + + } + else + Toast.makeText(context, "You must be authenticated to retrieve circ records", Toast.LENGTH_LONG); - - listAdapter.notifyDataSetChanged(); } diff --git a/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java b/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java index efc64c2c7d..a5fc6f1e66 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java @@ -25,6 +25,10 @@ public class GlobalConfigs { private static String TAG = "GlobalConfigs"; + public static boolean loadedIDL = false; + + public static boolean loadedOrgTree = false; + /** The locale. */ public String locale = "en-US"; @@ -89,7 +93,7 @@ public class GlobalConfigs { return false; } - private static void loadIDLFile(){ + public void loadIDLFile(){ String idlFile = "/reports/fm_IDL.xml"; try{ @@ -101,6 +105,7 @@ public class GlobalConfigs { System.err.println("Error in parsing IDL file " + idlFile + " " + e.getMessage()); }; + loadedIDL = true; } /** @@ -108,7 +113,7 @@ public class GlobalConfigs { * * @return the organisations */ - private void getOrganisations(){ + public void getOrganisations(){ String orgFile = null; try{ @@ -242,6 +247,8 @@ public class GlobalConfigs { level ++; } organisations = orgs; + + loadedOrgTree = true; } } } diff --git a/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java b/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java index 416f00da18..0dd5f0f809 100644 --- a/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java +++ b/Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java @@ -34,13 +34,14 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar private String TAG = "ApplicationPreferences"; private Thread connectionThread = null; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.application_preference_screen); - + context = this; reference = this; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); @@ -85,8 +86,36 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar }else if(key.equals("library_url")){ GlobalConfigs.httpAddress = sharedPreferences.getString("library_url", ""); + + if(GlobalConfigs.loadedIDL == false){ + + progressDialog = new ProgressDialog(context); + progressDialog.setMessage("Please wait while downloading FM IDL file and OrgTree"); + + Thread loadIDLThread = new Thread(new Runnable() { + + @Override + public void run() { + System.out.println("FM idl download"); + GlobalConfigs sg = GlobalConfigs.getGlobalConfigs(context); + sg.loadIDLFile(); + sg.getOrganisations(); + } + }); + + loadIDLThread.start(); + + //wait for execution + try{ + loadIDLThread.join(); + }catch(Exception e){} + + progressDialog.dismiss(); + } + } + //test connection if(!isFinishing()) progressDialog = ProgressDialog.show(this, "Account login", "Please wait while we test the new user account information"); -- 2.11.0