added preferences for notifications and started work on alarms and notifications
authordrizea <danielrizea27@gmail.com>
Thu, 9 Aug 2012 09:33:11 +0000 (12:33 +0300)
committerdrizea <danielrizea27@gmail.com>
Thu, 9 Aug 2012 09:33:11 +0000 (12:33 +0300)
Open-ILS/src/Android/AndroidManifest.xml
Open-ILS/src/Android/res/layout/checkout_list.xml
Open-ILS/src/Android/res/layout/checkout_list_item.xml
Open-ILS/src/Android/res/values/resources.xml
Open-ILS/src/Android/res/values/strings.xml
Open-ILS/src/Android/res/xml/application_preference_screen.xml
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/checkout/CircRecord.java
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/checkout/ItemsCheckOutListView.java
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/checkout/NotificationReceiver.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/views/ApplicationPreferences.java

index f01cd3f..1558a74 100644 (file)
@@ -23,6 +23,9 @@
         android:label="@string/app_name" 
         android:theme="@style/EvergreenTheme"
         >
+        
+        <!-- Notification receiver -->
+        <receiver  android:process=":remote" android:name=".accountAccess.checkout.NotificationReceiver"></receiver>
 
         <activity
             android:name=".views.splashscreen.SplashActivity"
index 723a074..2dc5160 100644 (file)
@@ -5,25 +5,38 @@
     android:orientation="vertical"
     android:padding="4dip"
      >
-    
-    
+
        <include android:id="@+id/header_actionbar" layout="@layout/simple_actionbar"/>
     
     <LinearLayout android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="2dip"
+         android:orientation="horizontal"
          >
          <TextView 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/checkout_item_txt"
              />
-         
          <TextView 
              android:id="@+id/checkout_items_number"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textStyle="bold"
+             android:textSize="16sp"
+             />
+         <TextView 
+             android:layout_width="wrap_content"
+             android:layout_height="wrap_content"
+             android:text="@string/checkout_overdue_items"
+             />
+         <TextView 
+             android:id="@+id/checkout_items_overdue"
+             android:layout_width="wrap_content"
+             android:layout_height="wrap_content"
+             android:textColor="@color/red"
+             android:textStyle="bold"
+             android:textSize="16sp"
              />
          
     </LinearLayout>
index 80242e7..16c4793 100644 (file)
@@ -2,7 +2,7 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
-    android:orientation="vertical"
+    android:orientation="horizontal"
     android:paddingBottom="3dip"
     android:paddingLeft="3dip"
     android:paddingTop="3dip" >
     <LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
-        android:orientation="horizontal" >
+        android:orientation="vertical"
+         android:layout_weight="1" 
+         >
 
         <TextView
             android:id="@+id/checkout_record_title"
             style="@style/TitleSearchStyleList"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_weight="1" />
+           />
 
-        <Button
-            android:id="@+id/renew_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="@string/renew_button" />
-    </LinearLayout>
-
-    <LinearLayout
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal" >
-
-        <LinearLayout
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:orientation="vertical" >
-
-            <TextView
+          <TextView
                 android:id="@+id/checkout_record_author"
                 style="@style/AuthorSearchStyleList"
                 android:layout_width="fill_parent"
                 android:layout_width="fill_parent"
                 android:gravity="left"
                 android:layout_height="wrap_content" />
-        </LinearLayout>
 
-        
-        <TextView 
+    </LinearLayout>
+
+                <Button
+            android:id="@+id/renew_button"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/add_to_calendar"
+            android:text="@string/renew_button" 
+            android:layout_gravity="center_vertical"
             />
-        
-        <CheckBox
-            android:id="@+id/add_reminder_to_calendar"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content" />
-        
-    </LinearLayout>
+
 
 </LinearLayout>
\ No newline at end of file
index bda6a70..db6eaf0 100644 (file)
                <item>Matches exactly</item>
     </string-array>
     
+    <string-array name="notification_preferences_list_values">
+        <item >1</item>
+        <item >2</item>
+        <item >3</item>
+        <item >4</item>
+        <item >5</item>
+        <item >6</item>
+        <item >7</item>
+    </string-array>
+    
+    <string-array name="notification_preferences_list_entries">
+        <item >1 Day</item>
+        <item >2 Days</item>
+        <item >3 Days</item>
+        <item >4 Days</item>
+        <item >5 Days</item>
+        <item >6 Days</item>
+        <item >7 Days</item>
+    </string-array>
+
+    <integer name="notification_preferences_list_default_value">2</integer>
 </resources>
\ No newline at end of file
index 8098c89..c28797e 100644 (file)
@@ -25,8 +25,6 @@
     <string name="button_place_hold">Place Hold</string>
     <string name="button_add_to_bookbag">Add to Bookbag</string>
     
-
-    
     <string name="bookbag_choose_text">Choose a bookbag from the list.</string>
     
     <!-- first config activity -->
@@ -95,8 +93,8 @@
     <string name="hold_thaw_date_hint">Date when the hold is frozen</string>
     
     <!-- Checkout items -->
-    <string name="checkout_item_txt">Checkout items: </string>
-    <string name="add_to_calendar">Calendar reminder</string>
+    <string name="checkout_item_txt">Total items out: </string>
+    <string name="checkout_overdue_items">/ Overdue items: </string>
     
     <!-- Fines Activity -->
     <string name="total_owned">Total Owned </string>
     <string name="add_button">add</string>
     
     
-    <!--  Camera -->
+     <!--  Camera -->
      <string name="msg_camera_framework_bug">Sorry, the Android camera encountered a problem. You may need to restart the device.</string>
      <string name="button_ok">OK</string>
+     
+     <!-- Preference Activity -->
+     <string name="preference_login_information">Login information</string>
+     <string name="preference_login_informantion_summary">Username and password information</string>
+     
+     <string name="preference_username">Username</string>
+     <string name="preference_username_summary">Please enter your login username</string>
+     
+     <string name="preference_password">Password</string>
+     <string name="preference_password_summary">Enter your account password</string>
+     
+     <string name="preference_server_information_title">Server settings</string>
+     <string name="preference_server_information_summary">Library server settings</string>
+     
+     <string name="preference_library_url_address">Library url address</string>
+     <string name="preference_library_url_address_summary">Please enter the library url in format http://</string>
+     
+     <string name="preference_notification_preference_screen_title">Notification settings</string>
+     <string name="preference_notification_preference_screen_summary">Configure notifications and reminders for checkout items</string>
+     
+     <string name="preference_enable_notifications">Enable notifications</string>
+     <string name="preference_enable_notifications_summary_on">Uncheck this option to remove notifications when checkout items are about to expire</string>
+     <string name="preference_enable_notifications_summary_off">Check this option to enable notifications each time a checkout item will expire</string>
+     
+     <string name="preference_notifications_days_before">Days before expiration</string>
+     <string name="preference_notifications_days_before_summary">Chose how many days before the actual expiration date to set the reminder</string>
+     
+     <string name="preference_notifications_each_day">Each day notifications</string>
+     <string name="preference_notifications_each_day_summary">Give a notification in every day before the actual start notification period and due date</string>
 </resources>
\ No newline at end of file
index 907a1ff..18c489d 100644 (file)
@@ -3,29 +3,56 @@
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:key="first_preferencescreen">
         <PreferenceCategory
-          android:summary="Username and password information"
-          android:title="Login information" >
+          android:summary="@string/preference_login_information"
+          android:title="@string/preference_login_informantion_summary" >
                <EditTextPreference
             android:key="username"
-            android:summary="Please enter your login username"
-            android:title="Username" />
+            android:summary="@string/preference_username_summary"
+            android:title="@string/preference_username" />
                <EditTextPreference
             android:key="password"
-            android:summary="Enter your password"
-            android:title="Password"
+            android:summary="@string/preference_password_summary"
+            android:title="@string/preference_password"
             android:inputType="textPassword"
              />
         </PreferenceCategory>
    
         
                 <PreferenceCategory
-          android:summary="Username and password information"
-          android:title="Login information" >
+          android:summary="@string/preference_server_information_summary"
+          android:title="@string/preference_server_information_title" >
                <EditTextPreference
             android:key="library_url"
-            android:summary="Please enter the library url in format http://"
-            android:title="Library url address" />
+            android:summary="@string/preference_library_url_address_summary"
+            android:title="@string/preference_library_url_address" />
 
         </PreferenceCategory>
-   
+  
+         <PreferenceScreen
+                android:key="NotificationsPrefScreen"
+                android:title="@string/preference_notification_preference_screen_title"
+                android:summary="@string/preference_notification_preference_screen_summary">
+                               
+                               <CheckBoxPreference 
+                                   android:title="@string/preference_enable_notifications"
+                                   android:key="notifications_enabled"
+                                   android:summaryOn="@string/preference_enable_notifications_summary_on"
+                                   android:summaryOff="@string/preference_enable_notifications_summary_off"
+                                   />  
+             
+                               <ListPreference
+                                   android:title="@string/preference_notifications_days_before"
+                                   android:key="notifications_days_before_expiration"
+                                   android:summary="@string/preference_notifications_days_before_summary"
+                                   android:entries="@array/notification_preferences_list_entries"
+                                   android:entryValues="@array/notification_preferences_list_values"
+                                   android:defaultValue="@integer/notification_preferences_list_default_value"
+                                   />
+                               
+                               <CheckBoxPreference 
+                                   android:title="@string/preference_notifications_each_day"
+                                   android:key="notifications_each_day_before_expiration"
+                                   android:summary="@string/preference_notifications_each_day_summary"
+                                   />
+        </PreferenceScreen>
 </PreferenceScreen> 
\ No newline at end of file
index 6293396..ae9d797 100644 (file)
@@ -84,6 +84,10 @@ public class CircRecord {
                return circ_due_date.toLocaleString();
        }
        
+       public Date getDueDateObject(){
+               return circ_due_date;
+       }
+       
        public String getTitle(){
                
                String title = null;
index 42c0c06..a22054c 100644 (file)
@@ -1,8 +1,8 @@
 package org.evergreen.android.accountAccess.checkout;
 
-import java.sql.Date;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 import org.evergreen.android.R;
@@ -16,16 +16,12 @@ import org.evergreen.android.searchCatalog.SearchCatalogListView;
 import org.evergreen.android.views.AccountScreenDashboard;
 
 import android.app.Activity;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
 import android.app.ProgressDialog;
-import android.content.ContentResolver;
-import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
-import android.database.Cursor;
-import android.net.ParseException;
-import android.net.Uri;
 import android.os.Bundle;
-import android.text.format.Time;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -36,337 +32,397 @@ import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;
 
-public class ItemsCheckOutListView extends Activity{
+public class ItemsCheckOutListView extends Activity {
 
        private String TAG = "ItemsCheckOutListView";
-       
+
        private AccountAccess accountAccess = null;
-       
+
        private ListView lv;
-       
+
        private CheckOutArrayAdapter listAdapter = null;
 
        private ArrayList<CircRecord> circRecords = null;
 
        private Context context;
-       
+
        private ProgressDialog progressDialog;
-       
+
        private Button homeButton;
-       
+
        private Button myAccountButton;
-       
+
        private TextView headerTitle;
-       
+
        private TextView itemsNo;
-       
 
-       
        private Activity thisActivity;
+
+       private static int NOTIFICATION_INTENT = 123456;
+       
+       private TextView overdueItems;
        
+       private Date currentDate;
+
        @Override
        public void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);
-               
+
                thisActivity = this;
                setContentView(R.layout.checkout_list);
                setTitle("Checkout items");
+
+               currentDate = new Date(System.currentTimeMillis());
                
-                //header portion actions
-        homeButton = (Button) findViewById(R.id.library_logo);
-        myAccountButton = (Button) findViewById(R.id.my_account_button);
-        headerTitle = (TextView) findViewById(R.id.header_title);
-        headerTitle.setText(R.string.checkout_items_title);
-        
-        myAccountButton.setOnClickListener(new OnClickListener() {
+               // header portion actions
+               homeButton = (Button) findViewById(R.id.library_logo);
+               myAccountButton = (Button) findViewById(R.id.my_account_button);
+               headerTitle = (TextView) findViewById(R.id.header_title);
+               headerTitle.setText(R.string.checkout_items_title);
+
+               myAccountButton.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
-                               Intent intent = new Intent(getApplicationContext(),AccountScreenDashboard.class);
+                               Intent intent = new Intent(getApplicationContext(),
+                                               AccountScreenDashboard.class);
                                startActivity(intent);
                        }
                });
-        
-        homeButton.setOnClickListener(new OnClickListener() {
+
+               homeButton.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
-                               Intent intent = new Intent(getApplicationContext(),SearchCatalogListView.class);
+                               Intent intent = new Intent(getApplicationContext(),
+                                               SearchCatalogListView.class);
                                startActivity(intent);
                        }
                });
-        //end header portion actions
-               
+               // end header portion actions
+
                context = this;
                itemsNo = (TextView) findViewById(R.id.checkout_items_number);
+               overdueItems = (TextView) findViewById(R.id.checkout_items_overdue);
                accountAccess = AccountAccess.getAccountAccess();
                lv = (ListView) findViewById(R.id.checkout_items_list);
                circRecords = new ArrayList<CircRecord>();
-               listAdapter = new CheckOutArrayAdapter(context, R.layout.checkout_list_item, circRecords);
+               listAdapter = new CheckOutArrayAdapter(context,
+                               R.layout.checkout_list_item, circRecords);
                lv.setAdapter(listAdapter);
-               
+
                Thread getCirc = new Thread(new Runnable() {
-                       
+
                        @Override
                        public void run() {
-                               
-                               
+
                                try {
                                        circRecords = accountAccess.getItemsCheckedOut();
-                               }  catch (NoNetworkAccessException e) {
+                               } catch (NoNetworkAccessException e) {
                                        Utils.showNetworkNotAvailableDialog(context);
                                } catch (NoAccessToServer e) {
                                        Utils.showServerNotAvailableDialog(context);
-                                       
-                               }catch (SessionNotFoundException e) {
-                                       //TODO other way?
-                                       try{
-                                               
-                                               Log.d(TAG, "REAUTH " + "in process" );
-                                               
-                                               if(accountAccess.authenticate())
+
+                               } catch (SessionNotFoundException e) {
+                                       // TODO other way?
+                                       try {
+
+                                               Log.d(TAG, "REAUTH " + "in process");
+
+                                               if (accountAccess.authenticate())
                                                        circRecords = accountAccess.getItemsCheckedOut();
-                                       }catch(Exception eauth){
+                                       } catch (Exception eauth) {
                                                System.out.println("Exception in reAuth");
                                        }
-                               }                       
-       
+                               }
+
                                runOnUiThread(new Runnable() {
-                                       
+
                                        @Override
                                        public void run() {
-                                               for(int i=0;i<circRecords.size();i++)
+                                               for (int i = 0; i < circRecords.size(); i++)
                                                        listAdapter.add(circRecords.get(i));
+
+                                               itemsNo.setText(" " + circRecords.size() + " ");
+
+                                               int overdueNo = 0;
+                                               //find overdue items
+
+                                               for(int i=0;i<circRecords.size();i++){
+                                                       CircRecord circ = circRecords.get(i);
+                                                       
+                                                       if(circ.getDueDateObject().compareTo(currentDate) < 0)
+                                                               overdueNo++;
+                                               }
                                                
-                                               itemsNo.setText(" " + circRecords.size() + "");
-                                               
-                                               progressDialog.dismiss();       
-                                               
-                                               if(circRecords.size() == 0)
-                                                       Toast.makeText(context, "No circ records", Toast.LENGTH_LONG);
+                                               overdueItems.setText(" " + overdueNo);
                                                
+                                               // set alarms or renew them
+                                               setNotificationAlarms(circRecords);
+
+                                               progressDialog.dismiss();
+
+                                               if (circRecords.size() == 0)
+                                                       Toast.makeText(context, "No circ records",
+                                                                       Toast.LENGTH_LONG);
+
                                                listAdapter.notifyDataSetChanged();
                                        }
                                });
                        }
                });
-               
-               
-               if(accountAccess.isAuthenticated()){
+
+               if (accountAccess.isAuthenticated()) {
                        progressDialog = new ProgressDialog(context);
                        progressDialog.setMessage("Please wait while retrieving circ data");
                        progressDialog.show();
                        getCirc.start();
-                       
-               }
-               else
-                       Toast.makeText(context, "You must be authenticated to retrieve circ records", Toast.LENGTH_LONG);
 
-               
-               
-               
+               } else
+                       Toast.makeText(context,
+                                       "You must be authenticated to retrieve circ records",
+                                       Toast.LENGTH_LONG);
+
+       }
+
+       public void setNotificationAlarms(ArrayList<CircRecord> records) {
+
+               for (int i = 0; i < records.size(); i++) {
+
+                       CircRecord checkoutRecord = records.get(i);
+
+                       Date dueDate = checkoutRecord.getDueDateObject();
+
+                       // if due date in the future
+                       if (currentDate.compareTo(dueDate) <= 0) {
+                               // get a Calendar object with current time
+                               Calendar cal = Calendar.getInstance();
+                               // add 5 minutes to the calendar object
+                               //cal.add(Calendar.MINUTE, 5);
+
+                               cal.set(dueDate.getYear(), dueDate.getMonth(), dueDate.getDay(), dueDate.getHours(), dueDate.getMinutes());
+
+                               //just for test
+                               cal.add(Calendar.HOUR, 4);
+                               cal.add(Calendar.MINUTE, 37);
+                               
+                               Intent intent = new Intent(context, NotificationReceiver.class);
+
+                               System.out.println("Set due date " + cal
+                                               + " with intent val " + NOTIFICATION_INTENT
+                                               + checkoutRecord.circ_id);
+                               intent.putExtra("checkoutName", checkoutRecord.getAuthor());
+                               
+                               // In reality, you would want to have a static variable for the
+                               // request code instead of 192837
+                               // update the current intent if it exists
+                               PendingIntent sender = PendingIntent.getBroadcast(this,
+                                               NOTIFICATION_INTENT + checkoutRecord.circ_id, intent,
+                                               PendingIntent.FLAG_UPDATE_CURRENT);
+
+                               // Get the AlarmManager service
+                               AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
+                               am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
+                       }
+               }
 
        }
+
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                MenuInflater menuInflater = getMenuInflater();
-           menuInflater.inflate(R.menu.checkout_menu, menu);
+               menuInflater.inflate(R.menu.checkout_menu, menu);
                return super.onCreateOptionsMenu(menu);
-               
+
        }
-       
+
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
-               
+
                return super.onOptionsItemSelected(item);
        }
-       
-       
-         class CheckOutArrayAdapter extends ArrayAdapter<CircRecord> {
-               private static final String tag = "CheckoutArrayAdapter";
-               
-               private TextView recordTitle;
-               private TextView recordAuthor;
-               private TextView recordDueDate;
-               private TextView recordRenewals;
-               private TextView renewButton;
-               private CheckBox reminderNotification;
-               
-               private List<CircRecord> records = new ArrayList<CircRecord>();
-
-               public CheckOutArrayAdapter(Context context, int textViewResourceId,
-                               List<CircRecord> objects) {
-                       super(context, textViewResourceId, objects);
-                       this.records = objects;
-               }
-
-               public int getCount() {
-                       return this.records.size();
-               }
-
-               public CircRecord getItem(int index) {
-                       return this.records.get(index);
-               }
-
-               public View getView(int position, View convertView, ViewGroup parent) {
-                       View row = convertView;
-                       
-                       // Get item
-                       final CircRecord record = getItem(position);
-                       
-                       
-                       if(record == null)
-                       {
-                                       Log.d(tag, "Starting XML view more infaltion ... ");
-                               LayoutInflater inflater = (LayoutInflater) this.getContext()
-                                               .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-                               row = inflater.inflate(R.layout.search_result_footer_view, parent, false);
-                               Log.d(tag, "Successfully completed XML view more Inflation!");
-
-                               
+
+       class CheckOutArrayAdapter extends ArrayAdapter<CircRecord> {
+               private static final String tag = "CheckoutArrayAdapter";
+
+               private TextView recordTitle;
+               private TextView recordAuthor;
+               private TextView recordDueDate;
+               private TextView recordRenewals;
+               private TextView renewButton;
+
+               private List<CircRecord> records = new ArrayList<CircRecord>();
+
+               public CheckOutArrayAdapter(Context context, int textViewResourceId,
+                               List<CircRecord> objects) {
+                       super(context, textViewResourceId, objects);
+                       this.records = objects;
+               }
+
+               public int getCount() {
+                       return this.records.size();
+               }
+
+               public CircRecord getItem(int index) {
+                       return this.records.get(index);
+               }
+
+               public View getView(int position, View convertView, ViewGroup parent) {
+                       View row = convertView;
+
+                       // Get item
+                       final CircRecord record = getItem(position);
+
+                       if (record == null) {
+                               Log.d(tag, "Starting XML view more infaltion ... ");
+                               LayoutInflater inflater = (LayoutInflater) this.getContext()
+                                               .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+                               row = inflater.inflate(R.layout.search_result_footer_view,
+                                               parent, false);
+                               Log.d(tag, "Successfully completed XML view more Inflation!");
+
+                       } else {
+
+                               // if it is the right type of view
+                               if (row == null) {
+
+                                       Log.d(tag, "Starting XML Row Inflation ... ");
+                                       LayoutInflater inflater = (LayoutInflater) this
+                                                       .getContext().getSystemService(
+                                                                       Context.LAYOUT_INFLATER_SERVICE);
+                                       row = inflater.inflate(R.layout.checkout_list_item, parent,
+                                                       false);
+                                       Log.d(tag, "Successfully completed XML Row Inflation!");
+
                                }
-                       else{
-                       
-                               //if it is the right type of view
-                                       if (row == null ) {
-               
-                                                       Log.d(tag, "Starting XML Row Inflation ... ");
-                                                       LayoutInflater inflater = (LayoutInflater) this.getContext()
-                                                                       .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-                                                       row = inflater.inflate(R.layout.checkout_list_item, parent, false);
-                                                       Log.d(tag, "Successfully completed XML Row Inflation!");
-               
-                                       }
-
-                               // Get reference to TextView - title
-                               recordTitle = (TextView) row.findViewById(R.id.checkout_record_title);
-                               
-                               // Get reference to TextView - author
-                               recordAuthor = (TextView) row.findViewById(R.id.checkout_record_author);
-                               
-                               //Get reference to TextView - record Publisher date+publisher
-                               recordDueDate = (TextView) row.findViewById(R.id.checkout_due_date);
-                   
-                               renewButton = (TextView) row.findViewById(R.id.renew_button);
-                               
-                               reminderNotification = (CheckBox) row.findViewById(R.id.add_reminder_to_calendar);
-                               
-                               renewButton.setText("renew : " + record.getRenewals());
-                               
-                               renewButton.setOnClickListener(new OnClickListener() {
-                                               
-                                               @Override
-                                               public void onClick(View v) {
-                                                               
-                                                               Thread renew = new Thread(new Runnable() {
-                                                                       
+
+                               // Get reference to TextView - title
+                               recordTitle = (TextView) row
+                                               .findViewById(R.id.checkout_record_title);
+
+                               // Get reference to TextView - author
+                               recordAuthor = (TextView) row
+                                               .findViewById(R.id.checkout_record_author);
+
+                               // Get reference to TextView - record Publisher date+publisher
+                               recordDueDate = (TextView) row
+                                               .findViewById(R.id.checkout_due_date);
+
+                               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() {
-                                                                               boolean refresh = true;
-                                                                               AccountAccess ac = AccountAccess.getAccountAccess();
-                                                                               
-                                                                               runOnUiThread(new Runnable() {  
-                                                                                       @Override
-                                                                                       public void run() {
-                                                                                               progressDialog = new ProgressDialog(context);
-                                                                                               progressDialog.setMessage("Renew item please wait.");
-                                                                                               progressDialog.show();
-                                                                                       }
-                                                                               });
-                                                                               
-                                                                               
-                                                                                       try {
-                                                                                               ac.renewCirc(record.getTargetCopy());
-                                                                                       } catch (MaxRenewalsException e1) {
-                                                                                               runOnUiThread(new Runnable() {
-                                                                                                       
-                                                                                                       @Override
-                                                                                                       public void run() {
-                                                                                                               progressDialog.dismiss();
-                                                                                                               Toast.makeText(context, "Max renewals reached", Toast.LENGTH_SHORT).show();
-                                                                                                       }
-                                                                                               });
-                                                                                               
-                                                                                               refresh = false;
-                                                                                       } catch (SessionNotFoundException e1) {
-                                                                                               try{
-                                                                                                       if(accountAccess.authenticate())
-                                                                                                               ac.renewCirc(record.getTargetCopy());
-                                                                                               }catch(Exception eauth){
-                                                                                                       System.out.println("Exception in reAuth");
-                                                                                               }
-                                                                                       } catch (NoNetworkAccessException e1) {
-                                                                                               Utils.showNetworkNotAvailableDialog(context);
-                                                                                       } catch (NoAccessToServer e1) {
-                                                                                               Utils.showServerNotAvailableDialog(context);
-                                                                                       }
-                                                       
-                                                                               if(refresh){
-                                                                                       
-                                                                                       try {
-                                                                                               circRecords = accountAccess.getItemsCheckedOut();
-                                                                                       }  catch (NoNetworkAccessException e) {
-                                                                                               Utils.showNetworkNotAvailableDialog(context);
-                                                                                       } catch (NoAccessToServer e) {
-                                                                                               Utils.showServerNotAvailableDialog(context);
-                                                                                               
-                                                                                       }catch (SessionNotFoundException e) {
-                                                                                               //TODO other way?
-                                                                                               try{
-                                                                                                       if(accountAccess.authenticate())
-                                                                                                               circRecords = accountAccess.getItemsCheckedOut();
-                                                                                               }catch(Exception eauth){
-                                                                                                       System.out.println("Exception in reAuth");
-                                                                                               }
-                                                                                       }               
-                                                                                       
-                                                                                       
-                                                                                       runOnUiThread(new Runnable() {
-                                       
-                                                                                               @Override
-                                                                                               public void run() {
-                                                                                                       listAdapter.clear();
-                                                                                                       for(int i=0;i<circRecords.size();i++){
-                                                                                                               listAdapter.add(circRecords.get(i));
-                                                                                                       }
-                                                                                                       
-                                                                                                       progressDialog.dismiss();
-                                                                                                       listAdapter.notifyDataSetChanged();
-                                                                                               }
-                                                                                       });
-                                                                               }
+                                                                               progressDialog = new ProgressDialog(
+                                                                                               context);
+                                                                               progressDialog
+                                                                                               .setMessage("Renew item please wait.");
+                                                                               progressDialog.show();
                                                                        }
                                                                });
-                                                               
-                                                               renew.start();
-                                               }
-                                       });
-                               
-                               reminderNotification.setOnCheckedChangeListener(new OnCheckedChangeListener() {
-                                       
-                                       @Override
-                                       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-
-                                               if(isChecked == true){
-                                       Toast.makeText(context, "Add ", Toast.LENGTH_SHORT).show();
-                                               }
-                                       }
-                               });
-                               
-                               //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());
-                       }
-                       
-                       return row;
-               }
-           }
+
+                                                               try {
+                                                                       ac.renewCirc(record.getTargetCopy());
+                                                               } catch (MaxRenewalsException e1) {
+                                                                       runOnUiThread(new Runnable() {
+
+                                                                               @Override
+                                                                               public void run() {
+                                                                                       progressDialog.dismiss();
+                                                                                       Toast.makeText(context,
+                                                                                                       "Max renewals reached",
+                                                                                                       Toast.LENGTH_SHORT).show();
+                                                                               }
+                                                                       });
+
+                                                                       refresh = false;
+                                                               } catch (SessionNotFoundException e1) {
+                                                                       try {
+                                                                               if (accountAccess.authenticate())
+                                                                                       ac.renewCirc(record.getTargetCopy());
+                                                                       } catch (Exception eauth) {
+                                                                               System.out
+                                                                                               .println("Exception in reAuth");
+                                                                       }
+                                                               } catch (NoNetworkAccessException e1) {
+                                                                       Utils.showNetworkNotAvailableDialog(context);
+                                                               } catch (NoAccessToServer e1) {
+                                                                       Utils.showServerNotAvailableDialog(context);
+                                                               }
+
+                                                               if (refresh) {
+
+                                                                       try {
+                                                                               circRecords = accountAccess
+                                                                                               .getItemsCheckedOut();
+                                                                       } catch (NoNetworkAccessException e) {
+                                                                               Utils.showNetworkNotAvailableDialog(context);
+                                                                       } catch (NoAccessToServer e) {
+                                                                               Utils.showServerNotAvailableDialog(context);
+
+                                                                       } catch (SessionNotFoundException e) {
+                                                                               // TODO other way?
+                                                                               try {
+                                                                                       if (accountAccess.authenticate())
+                                                                                               circRecords = accountAccess
+                                                                                                               .getItemsCheckedOut();
+                                                                               } catch (Exception eauth) {
+                                                                                       System.out
+                                                                                                       .println("Exception in reAuth");
+                                                                               }
+                                                                       }
+
+                                                                       runOnUiThread(new Runnable() {
+
+                                                                               @Override
+                                                                               public void run() {
+                                                                                       listAdapter.clear();
+                                                                                       for (int i = 0; i < circRecords
+                                                                                                       .size(); i++) {
+                                                                                               listAdapter.add(circRecords
+                                                                                                               .get(i));
+                                                                                       }
+
+                                                                                       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());
+                       }
+
+                       return row;
+               }
+       }
 }
diff --git a/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/checkout/NotificationReceiver.java b/Open-ILS/src/Android/src/org/evergreen/android/accountAccess/checkout/NotificationReceiver.java
new file mode 100644 (file)
index 0000000..d05aeab
--- /dev/null
@@ -0,0 +1,26 @@
+package org.evergreen.android.accountAccess.checkout;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.Toast;
+
+public class NotificationReceiver extends BroadcastReceiver{
+
+       private String TAG = "NotificationManager";
+       @Override
+       public void onReceive(Context context, Intent intent) {
+
+                Bundle bundle = intent.getExtras();
+            String checkoutItemName = bundle.getString("checkoutName");
+            Toast.makeText(context, "Notification received", Toast.LENGTH_SHORT).show();
+            
+            Log.d(TAG, "The " + checkoutItemName + " is about to expire");
+            
+            //send notification
+       }
+
+       
+}
index 7731b27..26fd355 100644 (file)
@@ -33,6 +33,9 @@ public class GlobalConfigs {
        
        public static boolean loadedOrgTree = false;
        
+       //two days notification before checkout expires, this can be modified from preferences
+       public static int NOTIFICATION_BEFORE_CHECKOUT_EXPIRATION = 2; 
+       
        //to parse date from requests
        public static final String datePattern = "yyyy-MM-dd'T'hh:mm:ssZ";
 
index d0d73a5..9a1a10d 100644 (file)
@@ -167,13 +167,18 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar
                        }
                });     
                
+               boolean checkConnection = false;
+               
                if(key.equals("username")){
                        AccountAccess.userName = sharedPreferences.getString("username", "");
+                       checkConnection = true;
                }else
                        if(key.equals("password")){
                                AccountAccess.password = sharedPreferences.getString("password", "");
+                               checkConnection = true;
                        }else
                                if(key.equals("library_url")){
+                                       checkConnection = true;
                                        GlobalConfigs.httpAddress = sharedPreferences.getString("library_url", "");
        
                                        httpAddressChange = true;
@@ -207,7 +212,7 @@ public class ApplicationPreferences extends PreferenceActivity implements OnShar
                                        }
 
                //test connection
-               if(!isFinishing() && httpAddressChange == false){
+               if(!isFinishing() && httpAddressChange == false && checkConnection == true){
                        progressDialog = ProgressDialog.show(this, "Account login", "Please wait while we test the new user account information");      
 
                        connectionThread.start();