Android Open Source - T-CEP-Alert Alert Update Data






From Project

Back to project page T-CEP-Alert.

License

The source code is released under:

MIT License

If you think the Android project T-CEP-Alert listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.ruscoe.tcepalert.dao;
/*  w w  w . j av a 2s.c o m*/
import static android.provider.BaseColumns._ID;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Extends the game Data Access Object to provide access to the alert
 * update data.
 * 
 * Used to determine the ID of the last alert received.
 * 
 * @author Dan Ruscoe
 */
public class AlertUpdateData extends AlertDAO
{
  public static final String TABLE_NAME = "gamePrefsData";
  
  public static final String ALERT_ID = "alertId";
  public static final String UPDATED_TIMESTAMP = "updatedTimestamp";
  
  // Only ever one row in alert update table.
  private static final int ROW_ID = 1;
  
  public AlertUpdateData(Context ctx)
  {
    super(ctx);
  }
  
  /**
   * Gets the ID of the last alert received during an update.
   * 
   * @return String
   */
  public String getLastUpdatedAlertId()
  {
      SQLiteDatabase db = this.getReadableDatabase();
      
      String[] from = { _ID, ALERT_ID };
      Cursor cursor = db.query(TABLE_NAME, from, _ID + "=" + ROW_ID, null, null, null, null);
      
      String lastAlertId = null;
      
      if (cursor != null)
      {
        while (cursor.moveToNext())
          {          
          lastAlertId = cursor.getString(1);
          }
        cursor.close();
      }
      
      db.close();
      return lastAlertId;
  }
    
  /**
   * Sets the ID of the last alert received during an update.
   * 
   * @param String alertId - The latest alert ID.
   */
  public void setLastUpdatedAlertIdValue(String alertId)
    {
      SQLiteDatabase db = this.getWritableDatabase();
      
      ContentValues values = new ContentValues();
      
      values.put(ALERT_ID, alertId);
      
      int affectedRows = db.update(TABLE_NAME, values, _ID + "=" + ROW_ID, null);
      
      if (affectedRows < 1)
      {
        values.put(_ID, ROW_ID);
        db.insertOrThrow(TABLE_NAME, null, values);
      }
      
      db.close();
    }
}




Java Source Code List

org.ruscoe.tcepalert.AboutActivity.java
org.ruscoe.tcepalert.AlertAdapter.java
org.ruscoe.tcepalert.AlertUpdateCheck.java
org.ruscoe.tcepalert.AlertView.java
org.ruscoe.tcepalert.AlertsActivity.java
org.ruscoe.tcepalert.LatestAlertsActivity.java
org.ruscoe.tcepalert.LinksActivity.java
org.ruscoe.tcepalert.MainActivity.java
org.ruscoe.tcepalert.SettingsActivity.java
org.ruscoe.tcepalert.constants.Constants.java
org.ruscoe.tcepalert.dao.AlertDAO.java
org.ruscoe.tcepalert.dao.AlertUpdateData.java
org.ruscoe.tcepalert.dao.CachedAlertData.java
org.ruscoe.tcepalert.dao.SettingsData.java
org.ruscoe.tcepalert.models.Alert.java
org.ruscoe.tcepalert.web.NetworkActivity.java
org.ruscoe.tcepalert.web.WebService.java