|
@@ -10,11 +10,8 @@ import android.util.Log;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+
|
|
|
|
|
|
import static android.content.Context.MODE_PRIVATE;
|
|
|
|
|
@@ -32,7 +29,7 @@ public class DbBase {
|
|
|
private static DbBase dbBase;
|
|
|
private static Context context;
|
|
|
|
|
|
- private final String LOG_TAG = "JC_WebView";
|
|
|
+ private final String LOG_TAG = "DbBase";
|
|
|
|
|
|
public DbBase(Context context){
|
|
|
this.context=context;
|
|
@@ -154,8 +151,8 @@ public class DbBase {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
- public boolean updateMessageState(String url) {
|
|
|
+ //根据消息的推送时间改变为已读信息
|
|
|
+ public boolean updateMessageState(String pushTime) {
|
|
|
boolean result = true;
|
|
|
DBHelper dbHelper = new DBHelper(context,DB_NAME,null,1);
|
|
|
SQLiteDatabase db =dbHelper.getWritableDatabase();
|
|
@@ -164,8 +161,8 @@ public class DbBase {
|
|
|
ContentValues cv = new ContentValues();
|
|
|
cv.put("readed", 1);
|
|
|
|
|
|
- String whereClause = "link=?";
|
|
|
- String[] whereArgs = {url};
|
|
|
+ String whereClause = "pushTime=?";
|
|
|
+ String[] whereArgs = {pushTime};
|
|
|
//参数1 是要更新的表名
|
|
|
//参数2 是一个ContentValeus对象
|
|
|
//参数3 是where子句
|
|
@@ -190,6 +187,26 @@ public class DbBase {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+ //根据推送时间获取信息id
|
|
|
+ public Integer getIDbypushTime(String pushTime){
|
|
|
+ Integer id=0;
|
|
|
+ DBHelper dbHelper = new DBHelper(context,DB_NAME,null,1);
|
|
|
+ SQLiteDatabase db =dbHelper.getReadableDatabase();
|
|
|
+ try{
|
|
|
+ Cursor cursor=db.query(MASSAHE_TABLE_NAME, new String[]{"id"}, "pushTime=?", new String[]{pushTime}, null, null, null);
|
|
|
+ if(cursor.moveToNext()){
|
|
|
+ id=cursor.getInt(cursor.getColumnIndex("id"));
|
|
|
+ }
|
|
|
+ return id;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if (null != db) {
|
|
|
+ db.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return id;
|
|
|
+ }
|
|
|
|
|
|
//删除一条信息
|
|
|
public boolean deleteMessageById(Integer id){
|
|
@@ -271,7 +288,12 @@ public class DbBase {
|
|
|
DBHelper dbHelper = new DBHelper(context,"jy_db",null,1);
|
|
|
SQLiteDatabase db =dbHelper.getWritableDatabase();
|
|
|
try{
|
|
|
- Cursor cursor = db.query("jy_message", new String[]{"id","title","content","link","category","openid","readed","comeintime","descript","extend"}, "openid=?", new String[]{openid}, null, null, "comeintime desc");
|
|
|
+ Cursor cursor=null;
|
|
|
+ if("".equals(openid)){
|
|
|
+ cursor = db.query("jy_message", new String[]{"id","title","content","link","category","openid","readed","comeintime","descript","extend"}, "openid=?", new String[]{""}, null, null, "comeintime desc");
|
|
|
+ }else{
|
|
|
+ cursor = db.query("jy_message", new String[]{"id","title","content","link","category","openid","readed","comeintime","descript","extend"}, "openid=? or openid=?", new String[]{openid,""}, null, null, "comeintime desc");
|
|
|
+ }
|
|
|
int count=0;
|
|
|
while(cursor.moveToNext()&&count<100){
|
|
|
count++;
|
|
@@ -315,7 +337,12 @@ public class DbBase {
|
|
|
//参数5:分组方式
|
|
|
//参数6:having条件
|
|
|
//参数7:排序方式
|
|
|
- Cursor cursor = db.query(MASSAHE_TABLE_NAME, new String[]{"id","title","content","link","category","openid","readed","comeintime","descript","extend"}, "openid=? and readed=?", new String[]{openid,"0"}, null, null, null);
|
|
|
+ Cursor cursor =null;
|
|
|
+ if("".equals(openid)){
|
|
|
+ cursor=db.query(MASSAHE_TABLE_NAME, new String[]{"id","title","content","link","category","openid","readed","comeintime","descript","extend"}, "openid=? and readed=?", new String[]{"","0"}, null, null, null);
|
|
|
+ }else{
|
|
|
+ cursor=db.query(MASSAHE_TABLE_NAME, new String[]{"id","title","content","link","category","openid","readed","comeintime","descript","extend"}, "(openid=? or openid=?)and readed=?", new String[]{openid,"","0"}, null, null, null);
|
|
|
+ }
|
|
|
return cursor.getCount();
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
@@ -324,7 +351,7 @@ public class DbBase {
|
|
|
db.close();
|
|
|
}
|
|
|
}
|
|
|
- return -1;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
//所有信息设置为已读
|
|
@@ -336,13 +363,13 @@ public class DbBase {
|
|
|
db.beginTransaction();
|
|
|
ContentValues cv = new ContentValues();
|
|
|
cv.put("readed", 1);
|
|
|
-
|
|
|
- String whereClause = "openid=?";
|
|
|
- String[] whereArgs = {openid};
|
|
|
- //参数1 是要更新的表名
|
|
|
- //参数2 是一个ContentValeus对象
|
|
|
- //参数3 是where子句
|
|
|
- num=db.update(MASSAHE_TABLE_NAME, cv, whereClause, whereArgs);
|
|
|
+ String[] whereArgs=null;
|
|
|
+ String whereClause;
|
|
|
+ if("".equals(openid)){
|
|
|
+ num=db.update(MASSAHE_TABLE_NAME, cv, "openid=?", new String[]{""});
|
|
|
+ }else{
|
|
|
+ num=db.update(MASSAHE_TABLE_NAME, cv, "openid=? or openid=?", new String[]{openid,""});
|
|
|
+ }
|
|
|
if (num>0) {
|
|
|
db.setTransactionSuccessful();
|
|
|
}
|