@@ -11,6 +11,10 @@ public class PhotoBean implements Serializable{
|
||
| 11 | 11 |
|
| 12 | 12 |
public String photoName; |
| 13 | 13 |
|
| 14 |
+ public int sessionSeq; |
|
| 15 |
+ |
|
| 16 |
+ public long sessionDate; |
|
| 17 |
+ |
|
| 14 | 18 |
public String sessionId; |
| 15 | 19 |
|
| 16 | 20 |
public String lensmanId; |
@@ -8,6 +8,7 @@ import ai.pai.lensman.bean.PhotoBean; |
||
| 8 | 8 |
public class SessionBean implements Serializable{
|
| 9 | 9 |
|
| 10 | 10 |
public int sessionSeq; |
| 11 |
+ public long sessionDate; |
|
| 11 | 12 |
public String sessionId; |
| 12 | 13 |
public ArrayList<PhotoBean> sessionPhotos; |
| 13 | 14 |
|
@@ -19,6 +19,8 @@ public class DBHelper extends SQLiteOpenHelper{
|
||
| 19 | 19 |
String CAPTURE_TIME = "capture_time"; |
| 20 | 20 |
String SESSION_ID = "session_id"; |
| 21 | 21 |
String LENSMAN_ID = "lensman_id"; |
| 22 |
+ String SESSION_DATE = "session_date"; |
|
| 23 |
+ String SESSION_SEQ = "session_seq"; |
|
| 22 | 24 |
String IS_RAW_PHOTO= "is_raw_photo"; |
| 23 | 25 |
String IS_UPLOADED = "is_uploaded"; |
| 24 | 26 |
|
@@ -61,6 +63,8 @@ public class DBHelper extends SQLiteOpenHelper{
|
||
| 61 | 63 |
sql.append(PHOTO_INFO_COLUMNS.LENSMAN_ID).append(" VARCHAR, ");
|
| 62 | 64 |
sql.append(PHOTO_INFO_COLUMNS.SESSION_ID).append(" VARCHAR, ");
|
| 63 | 65 |
sql.append(PHOTO_INFO_COLUMNS.IS_RAW_PHOTO).append(" INTEGER, ");
|
| 66 |
+ sql.append(PHOTO_INFO_COLUMNS.SESSION_SEQ).append(" INTEGER, ");
|
|
| 67 |
+ sql.append(PHOTO_INFO_COLUMNS.SESSION_DATE).append(" LONG, ");
|
|
| 64 | 68 |
sql.append(PHOTO_INFO_COLUMNS.IS_UPLOADED).append(" INTEGER, ");
|
| 65 | 69 |
sql.append(PHOTO_INFO_COLUMNS.CAPTURE_TIME).append(" LONG ");
|
| 66 | 70 |
sql.append(")");
|
@@ -5,7 +5,12 @@ import android.content.Context; |
||
| 5 | 5 |
import android.database.Cursor; |
| 6 | 6 |
import android.database.sqlite.SQLiteDatabase; |
| 7 | 7 |
|
| 8 |
+import com.android.common.utils.LogHelper; |
|
| 9 |
+ |
|
| 10 |
+import java.util.ArrayList; |
|
| 11 |
+ |
|
| 8 | 12 |
import ai.pai.lensman.bean.PhotoBean; |
| 13 |
+import ai.pai.lensman.bean.SessionBean; |
|
| 9 | 14 |
|
| 10 | 15 |
|
| 11 | 16 |
public class DBService {
|
@@ -42,6 +47,23 @@ public class DBService {
|
||
| 42 | 47 |
} |
| 43 | 48 |
} |
| 44 | 49 |
|
| 50 |
+ public void clearDB(){
|
|
| 51 |
+ SQLiteDatabase db = null; |
|
| 52 |
+ try{
|
|
| 53 |
+ db = dbHelper.getReadableDatabase(); |
|
| 54 |
+ db.beginTransaction(); |
|
| 55 |
+ db.execSQL("delete from "+ DBHelper.PHOTO_INFO_TABLE);
|
|
| 56 |
+ }catch (Exception e){
|
|
| 57 |
+ LogHelper.e(TAG,"clear db ,error occurs "+e); |
|
| 58 |
+ }finally {
|
|
| 59 |
+ try {
|
|
| 60 |
+ db.endTransaction(); |
|
| 61 |
+ } catch (Exception e) {
|
|
| 62 |
+ e.printStackTrace(); |
|
| 63 |
+ } |
|
| 64 |
+ closeDB(db); |
|
| 65 |
+ } |
|
| 66 |
+ } |
|
| 45 | 67 |
|
| 46 | 68 |
private PhotoBean cursor2PhotoBean(Cursor c) {
|
| 47 | 69 |
PhotoBean item = new PhotoBean(); |
@@ -53,6 +75,8 @@ public class DBService {
|
||
| 53 | 75 |
item.photoId = c.getLong(c.getColumnIndex(DBHelper.PHOTO_INFO_COLUMNS.PHOTO_ID)); |
| 54 | 76 |
item.photoName = c.getString(c.getColumnIndex(DBHelper.PHOTO_INFO_COLUMNS.PHOTO_NAME)); |
| 55 | 77 |
item.photoPath = c.getString(c.getColumnIndex(DBHelper.PHOTO_INFO_COLUMNS.PHOTO_PATH)); |
| 78 |
+ item.sessionDate = c.getLong(c.getColumnIndex(DBHelper.PHOTO_INFO_COLUMNS.SESSION_DATE)); |
|
| 79 |
+ item.sessionSeq = c.getInt(c.getColumnIndex(DBHelper.PHOTO_INFO_COLUMNS.SESSION_SEQ)); |
|
| 56 | 80 |
return item; |
| 57 | 81 |
} |
| 58 | 82 |
|
@@ -66,19 +90,64 @@ public class DBService {
|
||
| 66 | 90 |
cv.put(DBHelper.PHOTO_INFO_COLUMNS.SESSION_ID, item.sessionId); |
| 67 | 91 |
cv.put(DBHelper.PHOTO_INFO_COLUMNS.LENSMAN_ID,item.lensmanId); |
| 68 | 92 |
cv.put(DBHelper.PHOTO_INFO_COLUMNS.IS_UPLOADED,item.isUploaded); |
| 93 |
+ cv.put(DBHelper.PHOTO_INFO_COLUMNS.SESSION_DATE,item.sessionDate); |
|
| 94 |
+ cv.put(DBHelper.PHOTO_INFO_COLUMNS.SESSION_SEQ,item.sessionSeq); |
|
| 69 | 95 |
return cv; |
| 70 | 96 |
} |
| 71 | 97 |
|
| 72 | 98 |
public void addPhotoBean(PhotoBean bean){
|
| 73 |
- |
|
| 99 |
+ SQLiteDatabase db = null; |
|
| 100 |
+ synchronized (DB_LOCK) {
|
|
| 101 |
+ try {
|
|
| 102 |
+ db = dbHelper.getWritableDatabase(); |
|
| 103 |
+ db.beginTransaction(); |
|
| 104 |
+ db.insertWithOnConflict(DBHelper.PHOTO_INFO_TABLE, null, photoBean2ContentValues(bean), |
|
| 105 |
+ SQLiteDatabase.CONFLICT_REPLACE); |
|
| 106 |
+ db.setTransactionSuccessful(); |
|
| 107 |
+ } catch (Exception e) {
|
|
| 108 |
+ LogHelper.d(TAG, "dbservice addUploadPhoto error happen " + e); |
|
| 109 |
+ } finally {
|
|
| 110 |
+ try {
|
|
| 111 |
+ db.endTransaction(); |
|
| 112 |
+ } catch (Exception e) {
|
|
| 113 |
+ e.printStackTrace(); |
|
| 114 |
+ } |
|
| 115 |
+ closeDB(db); |
|
| 116 |
+ } |
|
| 117 |
+ } |
|
| 74 | 118 |
} |
| 75 | 119 |
|
| 76 | 120 |
public void updatePhotoBean(PhotoBean bean){
|
| 77 |
- |
|
| 121 |
+ addPhotoBean(bean); |
|
| 78 | 122 |
} |
| 79 | 123 |
|
| 80 | 124 |
public void deletePhotoBean(PhotoBean bean){
|
| 125 |
+ SQLiteDatabase db = null; |
|
| 126 |
+ synchronized (DB_LOCK) {
|
|
| 127 |
+ try {
|
|
| 128 |
+ db = dbHelper.getReadableDatabase(); |
|
| 129 |
+ db.beginTransaction(); |
|
| 130 |
+ db.execSQL("delete from " + DBHelper.PHOTO_INFO_TABLE + " where "
|
|
| 131 |
+ + DBHelper.PHOTO_INFO_COLUMNS.PHOTO_PATH + " = '" + bean.photoPath + "'"); |
|
| 132 |
+ db.setTransactionSuccessful(); |
|
| 133 |
+ } catch (Exception e) {
|
|
| 134 |
+ LogHelper.d(TAG, "dbservice deleteUploadPhoto error happen " + e); |
|
| 135 |
+ } finally {
|
|
| 136 |
+ try {
|
|
| 137 |
+ db.endTransaction(); |
|
| 138 |
+ } catch (Exception e) {
|
|
| 139 |
+ e.printStackTrace(); |
|
| 140 |
+ } |
|
| 141 |
+ closeCursorAndDB(null, db); |
|
| 142 |
+ } |
|
| 143 |
+ } |
|
| 144 |
+ } |
|
| 145 |
+ |
|
| 146 |
+ public ArrayList<SessionBean> getSessionBeanListByDay(){
|
|
| 147 |
+ ArrayList<SessionBean> sessionBeanArrayList = new ArrayList<>(); |
|
| 148 |
+ //TODO |
|
| 81 | 149 |
|
| 150 |
+ return sessionBeanArrayList; |
|
| 82 | 151 |
} |
| 83 | 152 |
|
| 84 | 153 |
} |