Checkout button renewal added
authordrizea <danielrizea27@gmail.com>
Sun, 24 Jun 2012 21:51:33 +0000 (00:51 +0300)
committerdrizea <danielrizea27@gmail.com>
Sun, 24 Jun 2012 21:51:33 +0000 (00:51 +0300)
25 files changed:
Open-ILS/src/Android/bin/EvergreenApp.apk
Open-ILS/src/Android/bin/classes.dex
Open-ILS/src/Android/bin/classes/org/evergreen/android/R$id.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/R$layout.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/R$string.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/R$style.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/accountAccess/AccountAccess.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/globals/GlobalConfigs.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/globals/Utils.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/RecordDetails_Info.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/RecordDetails_Simple.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/SearchCatalogListView$SearchArrayAdapter.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/SearchCatalogListView.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/views/AccountScreenDashboard.class
Open-ILS/src/Android/bin/classes/org/evergreen/android/views/MainScreenDashboard.class
Open-ILS/src/Android/bin/resources.ap_
Open-ILS/src/Android/gen/org/evergreen/android/R.java
Open-ILS/src/Android/res/layout/checkout_list_item.xml
Open-ILS/src/Android/res/values/strings.xml
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/CircRecord.java
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/ItemsCheckOutListView.java
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/MaxRenewalsException.java [new file with mode: 0644]
Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java
Open-ILS/src/Android/src/org/evergreen/android/globals/Utils.java

index 5da62bd..0ca3336 100644 (file)
Binary files a/Open-ILS/src/Android/bin/EvergreenApp.apk and b/Open-ILS/src/Android/bin/EvergreenApp.apk differ
index e581937..054c5a1 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes.dex and b/Open-ILS/src/Android/bin/classes.dex differ
index ad2bdbf..dccadd7 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$id.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$id.class differ
index a3691bd..8c8ff71 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$layout.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$layout.class differ
index 41838a3..56a2da5 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$string.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$string.class differ
index ec88073..fe1bd3f 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$style.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/R$style.class differ
index e5aa7a2..a404a61 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/accountAccess/AccountAccess.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/accountAccess/AccountAccess.class differ
index 11a444f..7401f5c 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/globals/GlobalConfigs.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/globals/GlobalConfigs.class differ
index cf77100..833b2ed 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/globals/Utils.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/globals/Utils.class differ
index 1508826..18a743f 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/RecordDetails_Info.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/RecordDetails_Info.class differ
index 91afbd0..763aeb6 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/RecordDetails_Simple.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/RecordDetails_Simple.class differ
index 6c41859..45826cb 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/SearchCatalogListView$SearchArrayAdapter.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/SearchCatalogListView$SearchArrayAdapter.class differ
index 210f902..8507896 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/SearchCatalogListView.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/searchCatalog/SearchCatalogListView.class differ
index 7843c35..ad50b41 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/views/AccountScreenDashboard.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/views/AccountScreenDashboard.class differ
index 32fcbeb..81e65b2 100644 (file)
Binary files a/Open-ILS/src/Android/bin/classes/org/evergreen/android/views/MainScreenDashboard.class and b/Open-ILS/src/Android/bin/classes/org/evergreen/android/views/MainScreenDashboard.class differ
index 622e538..ff9fb22 100644 (file)
Binary files a/Open-ILS/src/Android/bin/resources.ap_ and b/Open-ILS/src/Android/bin/resources.ap_ differ
index df2f635..fcd4b07 100644 (file)
@@ -48,38 +48,39 @@ public final class R {
         public static final int settings=0x7f02000a;
     }
     public static final class id {
-        public static final int account_btn_book_bags=0x7f090009;
-        public static final int account_btn_check_out=0x7f090006;
-        public static final int account_btn_fines=0x7f090008;
-        public static final int account_btn_holds=0x7f090007;
+        public static final int account_btn_book_bags=0x7f09000a;
+        public static final int account_btn_check_out=0x7f090007;
+        public static final int account_btn_fines=0x7f090009;
+        public static final int account_btn_holds=0x7f090008;
         public static final int checkout_due_date=0x7f090005;
         public static final int checkout_items_list=0x7f090001;
         public static final int checkout_record_author=0x7f090003;
         public static final int checkout_record_title=0x7f090002;
         public static final int checkout_renewals_remaining=0x7f090004;
-        public static final int chose_organisation=0x7f09001f;
-        public static final int main_btn_account=0x7f09000b;
-        public static final int main_btn_app_settings=0x7f09000c;
-        public static final int main_btn_search=0x7f09000a;
-        public static final int record_details_info_author=0x7f09000e;
-        public static final int record_details_info_publisher=0x7f09000f;
-        public static final int record_details_info_title=0x7f09000d;
-        public static final int record_details_simple_author=0x7f090011;
-        public static final int record_details_simple_isbn=0x7f090016;
-        public static final int record_details_simple_publisher=0x7f090012;
-        public static final int record_details_simple_series=0x7f090014;
-        public static final int record_details_simple_subject=0x7f090013;
-        public static final int record_details_simple_synopsis=0x7f090015;
-        public static final int record_details_simple_title=0x7f090010;
-        public static final int searchButton=0x7f09001d;
-        public static final int searchText=0x7f09001c;
-        public static final int search_more_items_button=0x7f090017;
-        public static final int search_record_author=0x7f09001a;
-        public static final int search_record_img=0x7f090018;
-        public static final int search_record_publishing=0x7f09001b;
-        public static final int search_record_title=0x7f090019;
+        public static final int chose_organisation=0x7f090020;
+        public static final int main_btn_account=0x7f09000c;
+        public static final int main_btn_app_settings=0x7f09000d;
+        public static final int main_btn_search=0x7f09000b;
+        public static final int record_details_info_author=0x7f09000f;
+        public static final int record_details_info_publisher=0x7f090010;
+        public static final int record_details_info_title=0x7f09000e;
+        public static final int record_details_simple_author=0x7f090012;
+        public static final int record_details_simple_isbn=0x7f090017;
+        public static final int record_details_simple_publisher=0x7f090013;
+        public static final int record_details_simple_series=0x7f090015;
+        public static final int record_details_simple_subject=0x7f090014;
+        public static final int record_details_simple_synopsis=0x7f090016;
+        public static final int record_details_simple_title=0x7f090011;
+        public static final int renew_button=0x7f090006;
+        public static final int searchButton=0x7f09001e;
+        public static final int searchText=0x7f09001d;
+        public static final int search_more_items_button=0x7f090018;
+        public static final int search_record_author=0x7f09001b;
+        public static final int search_record_img=0x7f090019;
+        public static final int search_record_publishing=0x7f09001c;
+        public static final int search_record_title=0x7f09001a;
         public static final int search_result_number=0x7f090000;
-        public static final int search_results_list=0x7f09001e;
+        public static final int search_results_list=0x7f09001f;
     }
     public static final class layout {
         public static final int checkout_list=0x7f030000;
@@ -96,6 +97,7 @@ public final class R {
     public static final class string {
         public static final int app_name=0x7f070001;
         public static final int hello=0x7f070000;
+        public static final int renew_button=0x7f07000a;
         public static final int search_result_text=0x7f070009;
         public static final int title_application_settings=0x7f070004;
         public static final int title_book_bags=0x7f070008;
index 5c28453..1ad3164 100644 (file)
@@ -3,18 +3,21 @@
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="left|center"
-       android:paddingBottom="3px"
-       android:paddingTop="3px
-       android:paddingLeft="3px
+       android:paddingBottom="3dip"
+       android:paddingTop="3dip
+       android:paddingLeft="3dip
     android:orientation="horizontal" >
 
        <LinearLayout 
-       android:layout_width="wrap_content"
-    android:layout_height="fill_parent"
+       android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
     android:orientation="vertical"
     android:gravity="center_vertical" 
        android:paddingLeft="4dip"
        >
+       
+       
+           
                <TextView
                android:id="@+id/checkout_record_title"
                style="@style/TitleSearchStyleList"
                android:id="@+id/checkout_due_date"
                style="@style/PubSearchStyleList"
                android:layout_width="wrap_content"
-               android:layout_height="wrap_content"/>
-
+               android:layout_height="wrap_content"
+               android:text="due date"
+               />
+               
        </LinearLayout>
+               <Button 
+                android:id="@+id/renew_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/renew_button" 
+                android:layout_gravity="right"  
+                   />
+
 </LinearLayout>
\ No newline at end of file
index e60cab9..38cd02e 100644 (file)
@@ -12,4 +12,6 @@
     <string name="title_fines">Fines</string>
     <string name="title_book_bags">Book bags</string>
     <string name="search_result_text"> Search result :</string>
+    <string name="renew_button">renew</string>
+    
 </resources>
\ No newline at end of file
index 1985ae1..973b3c2 100644 (file)
@@ -363,8 +363,10 @@ public class AccountAccess {
 
                String seed = null;
 
+               System.out.println("Send request to " + httpAddress);
                Object resp  = (Object) Utils.doRequest(conn, SERVICE_AUTH, METHOD_AUTH_INIT, new Object[]{userName});
-               seed = resp.toString();
+               if(resp != null)
+                       seed = resp.toString();
                
                System.out.println("Seed " + seed);
                
@@ -396,7 +398,9 @@ public class AccountAccess {
                System.out.println("Compelx param " + complexParam);
                
                Object resp  =  Utils.doRequest(conn, SERVICE_AUTH, METHOD_AUTH_COMPLETE, new Object[]{complexParam});
-
+               if(resp == null)
+                       return false;
+               
                        String queryResult = ((Map<String,String>) resp).get("textcode");
                         
                        System.out.println("Result " + queryResult);
@@ -557,14 +561,22 @@ public class AccountAccess {
        /* Method used to renew a circulation record based on target_copy_id
         * Returns many objects, don't think they are needed
         */
-       private void renewCirc(Integer target_copy){
+       public void renewCirc(Integer target_copy) throws MaxRenewalsException{
                
                HashMap<String,Integer> complexParam = new HashMap<String, Integer>();
                complexParam.put("patron", this.userID);                
                complexParam.put("copyid", target_copy);
                complexParam.put("opac_renewal", 1);
                
-               OSRFObject a_lot = (OSRFObject) Utils.doRequest(conn, SERVICE_CIRC, METHOD_RENEW_CIRC, new Object[]{complexParam});
+               Object a_lot = (Object) Utils.doRequest(conn, SERVICE_CIRC, METHOD_RENEW_CIRC, new Object[]{authToken,complexParam});
+               
+               Map<String,String> resp = (Map<String,String>)a_lot;
+               
+               if(resp.get("textcode") != null){
+                       if(resp.get("textcode").equals("MAX_RENEWALS_REACHED"))
+                               throw new MaxRenewalsException();
+               }
+               
                
        }
 
index d36693a..83be720 100644 (file)
@@ -97,14 +97,21 @@ public class CircRecord {
                return title;
        }
        
-       public String getRenewals(){
-               
+       public Integer getRenewals(){
+
                if(circ != null)
-                       circ.getInt("renewal_remaining");
+                       return circ.getInt("renewal_remaining");
                        
                return null;
        }
        
+       public Integer getTargetCopy(){
+               if(circ != null)
+                       return circ.getInt("target_copy");
+               
+               return null;
+       }
+       
        private void parseDate(OSRFObject circ){
                
                final SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
index 053fb36..bcdb9c0 100644 (file)
@@ -4,21 +4,20 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.evergreen.android.R;
-import org.evergreen.android.globals.GlobalConfigs;
-import org.evergreen.android.searchCatalog.RecordInfo;
-import org.opensrf.util.OSRFObject;
 
 import android.app.Activity;
+import android.app.ProgressDialog;
 import android.content.Context;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
-import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
+import android.widget.Toast;
 
 public class ItemsCheckOutListView extends Activity{
 
@@ -31,6 +30,10 @@ public class ItemsCheckOutListView extends Activity{
        private CheckOutArrayAdapter listAdapter = null;
 
        private ArrayList<CircRecord> circRecords = null;
+
+       private Context context;
+       
+       private ProgressDialog progressDialog;
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
@@ -39,6 +42,7 @@ public class ItemsCheckOutListView extends Activity{
                
                setContentView(R.layout.checkout_list);
                
+               context = this;
                accountAccess = AccountAccess.getAccountAccess();
                
                lv = (ListView) findViewById(R.id.checkout_items_list);
@@ -49,12 +53,11 @@ public class ItemsCheckOutListView extends Activity{
                lv.setAdapter(listAdapter);
                
 
-
+               
                listAdapter.notifyDataSetChanged();
 
        }
        
-       
          class CheckOutArrayAdapter extends ArrayAdapter<CircRecord> {
                private static final String tag = "CheckoutArrayAdapter";
                
@@ -62,6 +65,7 @@ public class ItemsCheckOutListView extends Activity{
                private TextView recordAuthor;
                private TextView recordDueDate;
                private TextView recordRenewals;
+               private TextView renewButton;
                
                private List<CircRecord> records = new ArrayList<CircRecord>();
 
@@ -83,7 +87,7 @@ public class ItemsCheckOutListView extends Activity{
                        View row = convertView;
                        
                        // Get item
-                       CircRecord record = getItem(position);
+                       final CircRecord record = getItem(position);
                        
                        
                        if(record == null)
@@ -120,12 +124,72 @@ public class ItemsCheckOutListView extends Activity{
                    
                                //Get remaining renewals
                                recordRenewals = (TextView) row.findViewById(R.id.checkout_renewals_remaining);
+                               
+                               renewButton = (TextView) row.findViewById(R.id.renew_button);
+                               
+                               renewButton.setText("renew : " + record.getRenewals());
+                               
+                               renewButton.setOnClickListener(new OnClickListener() {
+                                               
+                                               @Override
+                                               public void onClick(View v) {
+                                                               
+                                                               Thread renew = new Thread(new Runnable() {
+                                                                       
+                                                                       @Override
+                                                                       public void run() {
+                                                                               boolean refresh = true;
+                                                                               AccountAccess ac = AccountAccess.getAccountAccess();
+                                                                               
+                                                                               runOnUiThread(new Runnable() {  
+                                                                                       @Override
+                                                                                       public void run() {
+                                                                                               progressDialog = new ProgressDialog(context);
+                                                                                               progressDialog.show(context, "Renew item", "Please wait");
+                                                                                       }
+                                                                               });
+                                                                               
+                                                                               try{
+                                                                                       ac.renewCirc(record.getTargetCopy());
+                                                                               }catch(MaxRenewalsException e){
+                                                                                       runOnUiThread(new Runnable() {
+                                                                                               
+                                                                                               @Override
+                                                                                               public void run() {
+                                                                                                       progressDialog.dismiss();
+                                                                                                       Toast.makeText(context, "Max renewals reached", Toast.LENGTH_SHORT).show();
+                                                                                               }
+                                                                                       });
+                                                                                       
+                                                                                       refresh = false;
+                                                                               }
+                                                                               if(refresh){
+                                                                                       circRecords = accountAccess.getItemsCheckedOut();
+                                                                                       listAdapter.clear();
+                                                                                       for(int i=0;i<circRecords.size();i++){
+                                                                                               listAdapter.add(circRecords.get(i));
+                                                                                       }
+                                                                                       runOnUiThread(new Runnable() {
+                                                                                               
+                                                                                               @Override
+                                                                                               public void run() {
+                                                                                                       progressDialog.dismiss();
+                                                                                                       listAdapter.notifyDataSetChanged();
+                                                                                               }
+                                                                                       });
+                                                                               }
+                                                                       }
+                                                               });
+                                                               
+                                                               renew.start();
+                                               }
+                                       });
                                //set text
                                System.out.println("Row" + record.getTitle() + " " + record.getAuthor() + " " + record.getDueDate() + " " + record.getRenewals());
                                recordTitle.setText(record.getTitle());
                                recordAuthor.setText(record.getAuthor());
                                recordDueDate.setText(record.getDueDate());
-                               recordRenewals.setText(record.getRenewals());
+                               recordRenewals.setText(record.getRenewals()+"");
                        }
                        
                        return row;
diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/MaxRenewalsException.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/MaxRenewalsException.java
new file mode 100644 (file)
index 0000000..5b2eaaa
--- /dev/null
@@ -0,0 +1,10 @@
+package org.evergreen.android.accountAccess;
+
+public class MaxRenewalsException extends Exception{
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+
+}
index d6db656..efc64c2 100644 (file)
@@ -1,16 +1,19 @@
 package org.evergreen.android.globals;
 
 import java.io.InputStream;
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.StringTokenizer;
 
 import org.evergreen.android.accountAccess.AccountAccess;
 import org.evergreen.android.searchCatalog.Organisation;
+import org.evergreen.android.views.ApplicationPreferences;
 import org.open_ils.idl.IDLParser;
 
+import android.app.AlertDialog;
 import android.content.Context;
+import android.content.Intent;
 import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
 import android.preference.PreferenceManager;
 import android.util.Log;
 
@@ -59,6 +62,18 @@ public class GlobalConfigs {
                        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
                        GlobalConfigs.httpAddress = preferences.getString("library_url", "");
                        
+                       System.out.println("Check for network conenctivity");
+                       try{
+                               Utils.checkNetworkStatus((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE), context);
+                       }catch(NoNetworkAccessException e){
+                               
+                       }catch(NoAccessToHttpAddress e){
+
+                               System.out.println("No access to network");
+                               Intent preferencesAnctivity = new Intent(context, ApplicationPreferences.class);
+                               context.startActivity(preferencesAnctivity);
+                       }
+                       
                        loadIDLFile();
                        getOrganisations();
                
@@ -97,6 +112,7 @@ public class GlobalConfigs {
                
                String orgFile = null;
                try{
+                       //using https: address
                        orgFile = Utils.getNetPageContent(httpAddress+collectionsRequest);
                        System.out.println("Request org " + httpAddress + collectionsRequest );
                }catch(Exception e){};
@@ -107,6 +123,9 @@ public class GlobalConfigs {
                        organisations = new ArrayList<Organisation>();
                        
                        System.out.println("Page content " + orgFile);
+                       //in case of wrong file
+                       if(orgFile.indexOf("=") == -1)
+                               return;
                        
                        String orgArray = orgFile.substring( orgFile.indexOf("=")+1, orgFile.indexOf(";"));  
                        
index 333dc34..13b41eb 100644 (file)
@@ -135,12 +135,12 @@ public class Utils {
                        }
                }
 
+               System.out.println("Network access " + networkAccessEnabled);
                
                if(networkAccessEnabled){
                        //check to see if httpAddress is avaialble using the network connection 
                        // 2 seconds timeout
                        httpAddressAccessReachable = checkIfNetAddressIsReachable(GlobalConfigs.httpAddress);
-               
                        if(httpAddressAccessReachable == false)
                                throw new NoAccessToHttpAddress();
                }
@@ -161,11 +161,12 @@ public class Utils {
 
                    HttpParams httpParameters = new BasicHttpParams();  
 
-                   //timeout to 3 seconds
-                   HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
+                   //timeout to 1 seconds
+                   HttpConnectionParams.setConnectionTimeout(httpParameters, 1000);
                    HttpClient httpClient = new DefaultHttpClient(httpParameters);
                    HttpResponse response = httpClient.execute(request);
 
+                   //System.out.println("Check network response" + response);
                    int status = response.getStatusLine().getStatusCode();
 
                    if (status == HttpStatus.SC_OK)