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.

Location:
trunk/hiptop/pester/net/sabi/pester
Files:
3 edited

Legend:

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

    r277 r278  
    55import danger.ui.AlertWindow;
    66import danger.ui.ActiveListView;
     7import danger.ui.Font;
     8import danger.ui.Pen;
    79import danger.ui.Rect;
     10import danger.ui.Style;
    811import danger.ui.ToolTipWindow;
    912import danger.util.ActiveList;
     
    2528        setAutoResize(true);
    2629        setList(Alarms.getList());
    27         if (alarmsSet() == 0)
    28             setHasBorder(false); // this doesn't work in the rsrc file
    2930        Application.registerForEvent(this, Event.EVENT_TIME_CHANGED);
    3031        super.onDecoded();
     
    5354            alarmSetDialog().editAlarm(new Alarm(), true);
    5455            return true;
    55         case EVENT_CONFIRM_DISCARD_ALARM:
     56        case EVENT_DISCARD_ALARM:
     57            mToolTipAlarm.deactivate();
     58            Alarm alarm = (Alarm)getFocusedItem();
     59            alarm.beginEditing();
    5660            AlertWindow alert =
    5761                Application.getCurrentApp().getAlert(ID_DISCARD_ALERT, this);
    58             // XXX localize
    5962            alert.setMessage("Permanently discard \u201c" +
    60                              ((Alarm)getFocusedItem()).getMessage() +
    61                              "\u201d?");
     63                             alarm.getMessage() + "\u201d?"); // XXX localize
    6264            alert.show();
    6365            return true;
    64         case EVENT_DISCARD_ALARM:
     66        case EVENT_CONFIRM_DISCARD:
    6567            Alarms.removeAlarm((Alarm)getFocusedItem());
    6668            return true;
    67         case Event.EVENT_TIME_CHANGED: // XXX EVENT_TIME_FORMAT_CHANGED too
     69        case EVENT_CANCEL_DISCARD:
     70            ((Alarm)getFocusedItem()).resume();
     71            return true;
     72        // XXX for EVENT_TIME_FORMAT_CHANGED, we also need to force a
     73        // full redraw (in addition to invalidating the tooltip)
     74        case Event.EVENT_TIME_CHANGED:
    6875            if (mToolTipWindow == null || !mToolTipWindow.isVisible())
    6976                return true;
     
    110117    }
    111118
     119    protected void paintEmptyList(Pen p, int width, int height) {
     120        Style style = getStyle();
     121        Font font = style.getFont(Style.DISABLED_LABEL_FONT);
     122        int y = (height / 4) - (font.getAscent() / 2);
     123        if (y < 0) {
     124            setHeight(sAlarmListWindow.getHeight());
     125            return;
     126        }
     127        // XXX localize
     128        String emptyMessage =
     129            "Press " + Font.GLYPH_MENU + " to set an alarm.";
     130        int x = (width / 2) - (font.getWidth(emptyMessage) / 2);
     131        p.setFont(font);
     132        p.setColor(style.getColor(Style.DISABLED_LABEL_COLOR));
     133        p.drawText(x, y, emptyMessage);
     134    }
     135
    112136    public int alarmsSet() {
    113137        return getListSize();
     
    119143        // which is admirable in general, but not what we want
    120144        setFocus(index);
    121         setHasBorder(true);
    122145    }
    123146    public void onItemRemoved(ActiveList list, Object item, int index) {
     
    125148        sAlarmListWindow.updateAlarmCount();
    126149        super.onItemRemoved(list, item, index);
    127         if (alarmsSet() == 0)
    128             setHasBorder(false);
    129150    }
    130151}
  • 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);
  • trunk/hiptop/pester/net/sabi/pester/Pester.java

    r244 r278  
    2323            Alarm alarm = (Alarm)e.argument;
    2424            AlertWindow alert = getAlert(ID_ALARM_ALERT, this);
    25             alert.setTitle(alert.getTitle() + ": " + alarm.getDateTimeString());
     25            alert.setTitle(alarm.getDateTimeString());
    2626            alert.setMessage(alarm.getMessage());
    2727            alert.setShowTone(alarm.getAlert());
Note: See TracChangeset for help on using the changeset viewer.