package com.partynetwork.iparty.app.manager;
import java.util.ArrayList;
import java.util.List;
import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.db.table.DbModel;
import com.lidroid.xutils.exception.DbException;
import com.partynetwork.iparty.app.entities.ChartHisBean;
import com.partynetwork.iparty.app.entities.Notice;
import android.content.Context;
/**
*
* 通知管理
*
*/
public class NoticeManager extends BaseManager {
private static NoticeManager noticeManager = null;
private NoticeManager(Context context) {
super(context);
}
public static NoticeManager getInstance(Context context) {
if (noticeManager == null) {
noticeManager = new NoticeManager(context);
}
return noticeManager;
}
/**
*
* 保存通知
*
*/
public void saveNotice(Notice notice) {
try {
db.saveBindingId(notice);
} catch (DbException e) {
e.printStackTrace();
}
}
/**
* 保存所有通知
*
* @param notices
*/
public void saveAllNotice(List<Notice> notices) {
try {
db.saveAll(notices);
} catch (DbException e) {
e.printStackTrace();
}
}
/**
*
* 更新通知
*
*/
public void updataNotice(Notice notice) {
try {
db.update(notice);
} catch (DbException e) {
e.printStackTrace();
}
}
/**
*
* 查找某类别的记录
*
* @param pageNum
* 第几页
* @param pageSize
* 要查的记录条数
* @return
* @throws DbException
*/
public List<Notice> getNoticeListByType(int type) {
List<Notice> list = new ArrayList<Notice>();
try {
list = db.findAll(Selector.from(Notice.class).where("notice_type",
"=", type));
} catch (DbException e) {
e.printStackTrace();
}
return list;
}
/**
*
* 查找某类别的数量
*
* @throws DbException
*
*/
public long getCountByType(int type) throws DbException {
return db.count(Selector.from(Notice.class).where("notice_type", "=",
type));
}
/**
* 删除某类的所有记录
*
* @param fromUser
*/
public void delNoticeByType(int type) {
List<Notice> list;
try {
list = db.findAll(Selector.from(Notice.class).where("notice_type",
"=", type));
db.deleteAll(list);
} catch (DbException e) {
e.printStackTrace();
}
}
/**
* 获取所有存在的类别
*
* @return
* @throws DbException
*/
public List<ChartHisBean> getRecentContactsWithLastMsg() {
List<ChartHisBean> list = new ArrayList<ChartHisBean>();
try {
List<DbModel> dbModels = db.findDbModelAll(Selector
.from(Notice.class).groupBy("notice_type")
.select("notice_type"));
if (dbModels == null) {
return list;
}
for (DbModel model : dbModels) {
ChartHisBean bean = new ChartHisBean();
bean.setFrom(model.getString("notice_type"));
bean.setNoticeType(ChartHisBean.SYS_MSG);
list.add(bean);
}
} catch (DbException e) {
}
return list;
}
public void cleanManager() {
noticeManager=null;
}
}