Ignore:
Timestamp:
07/23/06 08:33:15 (18 years ago)
Author:
Nicholas Riley
Message:

Display message on empty list (no longer need to add/remove border). Don't let alarms go off while you're deciding whether to discard them. First, untested attempt at handling hard resets (waiting on advice from Danger). Very ugly rewrite of alarm alert; needs much fixing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hiptop/pester/net/sabi/pester/Alarms.java

    r276 r278  
    2323    private Alarms() {
    2424        mDataStore = DataStore.createDataStore("alarms", true /* auto sync */);
     25        // register us for Event.EVENT_DATASTORE_RESTORED, which only
     26        // seems to be documented at:
     27        // <http://developer.danger.com/forum/index.php?t=msg&th=27>
     28        mDataStore.setAutoSyncNotifyee(sListener);
     29        refreshFromDataStore(false);
     30    }
     31
     32    void refreshFromDataStore(boolean datastoreRestored) {
     33        sAlarmList = null;
     34        removeAllItems();
     35        if (datastoreRestored)
     36            mDataStore.doneResolvingConflict(); // resolves UID conflicts
    2537        byte[][] alarmsData = mDataStore.getRecords();
    2638        int i;
     
    3244            alarm.resume();
    3345        }
     46        sAlarmList = this;
    3447    }
    3548
     
    3952            sSettingsDB = new SettingsDB("settings", true /* auto sync */);
    4053            sListener = new Listener();
    41             sAlarmList = new Alarms();
     54            new Alarms();
    4255        }
    4356        return sAlarmList;
     
    5164    }
    5265
    53     // XXX handle EVENT_DATASTORE_RESTORED: note that in the event of
    54     // a hard reset, items may come back out of order, so we need to
    55     // implement an in-place sort, then insert the current alarm list.
    56     // Aiee.  Also, what on earth happens when UIDs aren't synchronized?
    57    
    5866    protected void onItemAdded(Object item, int index) {
    5967        if (sAlarmList == null) // restoring from service
     
    6270        DEBUG.p("adding: " + alarm +
    6371                " next UID: " + mDataStore.getAutoSyncNextUID());
    64         index = mDataStore.addRecord(alarm.toByteArray(), index);
     72        index = mDataStore.addRecord(alarm.toByteArray());
    6573        alarm.setUID(mDataStore.getRecordUID(index));
    6674        DEBUG.p("added UID " + alarm.getUID() + " @ " + index);
     
    6876
    6977    protected void onItemRemoved(Object item, int index) {
     78        if (sAlarmList == null) // restoring from service (after hard reset)
     79            return;
    7080        Alarm alarm = (Alarm)item;
    71         // XXX make sure +/- UIDs are OK
    7281        int uid = alarm.getUID();
    7382        if (uid == 0)
    7483            return;
    75         DEBUG.p("removing; " + alarm + " UID " + uid);
    7684        mDataStore.removeRecordByUID(uid);
    7785    }
     
    8189            return;
    8290        Alarm alarm = (Alarm)item;
    83         // XXX check that updating a + UID by a - one is OK
    8491        mDataStore.setRecordDataByUID(alarm.getUID(), alarm.toByteArray(), true);
    8592        DEBUG.p("updated: " + alarm + " UID " + alarm.getUID());
     
    114121                Alarms.getList().forEach(this);
    115122                return true;
     123            } else if (e.type == Event.EVENT_DATASTORE_RESTORED) {
     124                String dbName = (String)e.argument;
     125                DEBUG.p("DATASTORE_RESTORED: " + dbName);
     126                if (!dbName.endsWith("alarms")) {
     127                    // because we only get/set the default alarm on demand
     128                    // there's no need to handle conflicts with the settings...
     129                    // XXX but what happens if we set a (default) alarm, then
     130                    // the SettingsDB restores?
     131                    Alarms.getList().refreshFromDataStore(true);
     132                }
    116133            }
    117134            return super.receiveEvent(e);
Note: See TracChangeset for help on using the changeset viewer.