Ejemplo n.º 1
0
  /** 获取所有社区消息 */
  public static List<ModelPushTie> getCommunity() {
    List<ModelPushTie> list = new ArrayList<ModelPushTie>();
    SQLiteDatabase db =
        new PushMessHelper(PutaoApplication.getContext(), "Pushmess.db", null, 2)
            .getWritableDatabase();
    String currUserid = String.valueOf(UserPreUtil.getUserid());

    Cursor cursor =
        db.query(
            "Pushmess",
            null,
            "type=? and userid=?",
            new String[] {"4", currUserid},
            null,
            null,
            "receivetime desc");
    if (cursor.moveToFirst()) {
      Gson gson = new Gson();
      do {
        String str = cursor.getString(cursor.getColumnIndex("community"));
        if (str != null && str.length() > 0) {
          list.add(gson.fromJson(str, ModelPushTie.class));
        }
      } while (cursor.moveToNext());
      gson = null;
    }
    cursor.close();
    db.close();

    return list;
  }
Ejemplo n.º 2
0
  /** 写入一条消息至数据库 */
  public static void receiveMess(int type, Object object) {
    SQLiteDatabase db =
        new PushMessHelper(PutaoApplication.getContext(), "Pushmess.db", null, 2)
            .getWritableDatabase();
    String objstr = new Gson().toJson(object);

    ContentValues dbvalues = new ContentValues();
    dbvalues.put("type", type);
    dbvalues.put("hasread", 0);
    dbvalues.put("receivetime", Calendar.getInstance().getTimeInMillis());
    dbvalues.put("userid", UserPreUtil.getUserid());
    switch (type) {
      case 0: // 0和1都是comment
        dbvalues.put("comment", objstr);
        break;
      case 1:
        dbvalues.put("comment", objstr);
        break;
      case 2:
        dbvalues.put("good", objstr);
        break;
      case 3:
        dbvalues.put("system", objstr);
        break;
      case 4: // 社区
        dbvalues.put("community", objstr);
        break;
    }

    // 插入
    db.insert("Pushmess", null, dbvalues);
    db.close();
  }
Ejemplo n.º 3
0
 public static void resetUnreadBBS() {
   SQLiteDatabase db =
       new PushMessHelper(PutaoApplication.getContext(), "Pushmess.db", null, 2)
           .getWritableDatabase();
   String currUserid = String.valueOf(UserPreUtil.getUserid());
   ContentValues value = new ContentValues();
   value.put("hasread", 1);
   db.update("Pushmess", value, "type=4 and userid=?", new String[] {currUserid});
   db.close();
 }
Ejemplo n.º 4
0
 /** 获取未读系统消息数量 */
 public static int getUnreadSysCou() {
   int count = 0;
   String currUserid = String.valueOf(UserPreUtil.getUserid());
   SQLiteDatabase db =
       new PushMessHelper(PutaoApplication.getContext(), "Pushmess.db", null, 2)
           .getWritableDatabase();
   Cursor cursor =
       db.rawQuery(
           "select count(*) from Pushmess where hasread=0 and type=3 and userid=?",
           new String[] {currUserid});
   cursor.moveToFirst();
   //		LogUtil.v("PushMessUtil info: ", cursor.getString(0));
   count = cursor.getInt(0);
   db.close();
   cursor.close();
   return count;
 }