Changeset 297


Ignore:
Timestamp:
07/29/06 06:32:09 (18 years ago)
Author:
Nicholas Riley
Message:

Store deleted alarms creation IDs (timestamps) in on-device datastore, delete/omit on sync from service.

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

Legend:

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

    r296 r297  
    2828    private Date mDate;
    2929    private RingToneObject mAlert;
     30    private int mCreationID;
    3031
    3132    // transient
     
    3940        mState = STATE_INVALID;
    4041        mAlarm = new danger.app.Alarm(0, Application.getCurrentApp(), this);
     42        mCreationID = Hardware.getSystemTime();
    4143        mUID = 0;
    4244        mAbsoluteFireTime = -1;
     
    6365    public int getUID() {
    6466        return mUID;
     67    }
     68    public int getCreationID() {
     69        return mCreationID;
    6570    }
    6671
     
    100105            dataStream.writeInt(mType);
    101106            dataStream.writeInt(mAlert == null ? 0 : mAlert.getID());
     107            dataStream.writeInt(mCreationID);
    102108            dataStream.flush();
    103109            return byteStream.toByteArray();
    104110        } catch (Exception e) {
    105111            // XXX do something
    106             DEBUG.p("failed to write alarm:" + e);
     112            DEBUG.p("failed to write alarm: " + e);
    107113        }
    108114        return null;
     
    124130            int alertID = dataStream.readInt();
    125131            mAlert = (alertID == 0 ? null : new RingToneObject(alertID));
     132            mCreationID = dataStream.readInt();
    126133            mAbsoluteFireTime = -1; // just in case
    127134        } catch (Exception e) {
    128             // XXX do something
    129             DEBUG.p("failed to read alarm:" + e);
     135            // XXX do something, prevernt alarm from being activated
     136            DEBUG.p("failed to read alarm: " + e);
    130137        }
    131138    }
  • trunk/hiptop/pester/net/sabi/pester/Alarms.java

    r296 r297  
    11package net.sabi.pester;
    22
     3import java.util.Arrays;
    34import java.util.Comparator;
    45import danger.app.Application;
     
    89import danger.app.SettingsDBException;
    910import danger.internal.Date;
     11import danger.util.ByteArray;
    1012import danger.util.StdActiveList;
    1113import danger.util.DEBUG;
     
    1820    private static Listener sListener;
    1921    private static SettingsDB sSettingsDB;
     22    private static DataStore sDeletedAlarms;
    2023
    2124    private DataStore mDataStore;
     
    2831        mDataStore.setAutoSyncNotifyee(sListener);
    2932        refreshFromDataStore(false);
     33    }
     34
     35    private int[] deletedAlarmsCreationIDs() {
     36        byte[][] deletedAlarmsData = sDeletedAlarms.getRecords();
     37        int[] ids = new int[deletedAlarmsData.length];
     38        for (int i = 0 ; i < deletedAlarmsData.length ; ++i)
     39            ids[i] = ByteArray.readInt(deletedAlarmsData[i], 0);
     40        Arrays.sort(ids);
     41        return ids;
    3042    }
    3143
     
    5163    void refreshFromDataStore(boolean datastoreRestored) {
    5264        sAlarmList = null;
     65        int[] deleted = null;
    5366        if (datastoreRestored) {
     67            deleted = deletedAlarmsCreationIDs();
    5468            DEBUG.p("+++ BEFORE RESOLUTION +++");
    5569            dumpAlarms();
     
    6983            alarm.fromByteArray(alarmsData[i]);
    7084            alarm.setUID(mDataStore.getRecordUID(i));
     85            if (Arrays.binarySearch(deleted, alarm.getCreationID()) >= 0) {
     86                mDataStore.removeRecord(i);
     87                continue;
     88            }
    7189            insertItemSorted(alarm, alarm);
    7290            alarm.resume();
     
    86104        if (sAlarmList == null) {
    87105            sSettingsDB = new SettingsDB("settings", true /* auto sync */);
     106            sDeletedAlarms = DataStore.createDataStore("deleted alarms");
    88107            sListener = new Listener();
    89108            new Alarms();
     
    126145        if (uid < 0)
    127146            mDataStore.removeRecordByUID(-uid);
     147        while (sDeletedAlarms.getRecordCount() >= MAX_ALARM_COUNT)
     148            sDeletedAlarms.removeRecord(0);
     149        byte[] idBytes = new byte[4];
     150        ByteArray.writeInt(idBytes, 0, alarm.getCreationID());
     151        sDeletedAlarms.addRecord(idBytes);
    128152        DEBUG.p("DEL" + alarm.description());
    129153    }
Note: See TracChangeset for help on using the changeset viewer.