fix application preference bug on library EG server change
authordrizea <danielrizea27@gmail.com>
Mon, 25 Jun 2012 19:17:53 +0000 (22:17 +0300)
committerdrizea <danielrizea27@gmail.com>
Mon, 25 Jun 2012 19:17:53 +0000 (22:17 +0300)
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/ItemsCheckOutListView.java
Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java
Open-ILS/src/Android/src/org/evergreen/android/views/ApplicationPreferences.java

index 973b3c2..89212b3 100644 (file)
@@ -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});
index f14095a..9938212 100644 (file)
@@ -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();
 
        }
        
index efc64c2..a5fc6f1 100644 (file)
@@ -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;
                }
        }
 }
index 416f00d..0dd5f0f 100644 (file)
@@ -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");