private OQuery setSelection(Context context, OQuery query, Type type) { switch (type) { case Inbox: query.addWhere("to_read", "=", 1); query.addWhere("starred", "=", 0); query.addWhere("id", "!=", 0); break; case ToMe: query.addWhere("to_read", "=", 1); query.addWhere("starred", "=", 0); query.addWhere("res_id", "=", 0); break; case ToDo: query.addWhere("to_read", "=", 1); query.addWhere("starred", "=", 1); break; case Outbox: query.addWhere("id", "=", 0); break; case Group: Integer group_id = getArguments().getInt(Groups.KEY); query.addWhere("res_id", "=", group_id); query.addWhere("model", "=", "mail.group"); break; case Archives: query.addWhere("id", "!=", 0); break; default: break; } return query; }
private int count_total(Context context, Type key) { if (db == null) db = new MailMessage(context); OQuery q = db.browse().columns("id"); q = setSelection(context, q, key); return q.fetch().size(); }