diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt new file mode 100644 index 0000000..65455f7 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt @@ -0,0 +1,204 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.EventSearchListAdapter +import com.casic.birmm.inspect.base.BaseViewModelActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.EventListModel +import com.casic.birmm.inspect.utils.Constant +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.casic.birmm.inspect.utils.TimeOrDateUtil +import com.casic.birmm.inspect.vm.EventQueryViewModel +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_event.* +import kotlinx.android.synthetic.main.activity_query_inspect.emptyView +import kotlinx.android.synthetic.main.activity_query_inspect.endDateView +import kotlinx.android.synthetic.main.activity_query_inspect.inputTipsView +import kotlinx.android.synthetic.main.activity_query_inspect.refreshLayout +import kotlinx.android.synthetic.main.activity_query_inspect.searchView +import kotlinx.android.synthetic.main.activity_query_inspect.startDateView +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeEventQueryActivity : BaseViewModelActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: EventSearchListAdapter + + override fun createViewModelByClass(): Class? = + EventQueryViewModel::class.java + + override fun initLayoutView(): Int = R.layout.activity_query_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "事件查询(单机模式)" + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(this) + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + //查询都从第一页开始查 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + viewModel.resultModel.observe(this, Observer { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(20210712) + } + }) + viewModel.loadState.observe(this, Observer { + "抱歉,无法查询到相关记录".show(this) + }) + } + + private class WeakReferenceHandler(activity: SingleModeEventQueryActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210712) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + EventSearchListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.eventRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.eventRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + EventSearchListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = Intent(resultActivity, EventDetailActivity::class.java) + val rowsBean = resultActivity.dataBeans[position] + intent.putExtra("createTime", rowsBean.createTime) + intent.putExtra( + "description", + rowsBean.description!!.filterString() + ) + intent.putExtra("data", rowsBean.data) + intent.putExtra("images", rowsBean.images) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt new file mode 100644 index 0000000..65455f7 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt @@ -0,0 +1,204 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.EventSearchListAdapter +import com.casic.birmm.inspect.base.BaseViewModelActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.EventListModel +import com.casic.birmm.inspect.utils.Constant +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.casic.birmm.inspect.utils.TimeOrDateUtil +import com.casic.birmm.inspect.vm.EventQueryViewModel +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_event.* +import kotlinx.android.synthetic.main.activity_query_inspect.emptyView +import kotlinx.android.synthetic.main.activity_query_inspect.endDateView +import kotlinx.android.synthetic.main.activity_query_inspect.inputTipsView +import kotlinx.android.synthetic.main.activity_query_inspect.refreshLayout +import kotlinx.android.synthetic.main.activity_query_inspect.searchView +import kotlinx.android.synthetic.main.activity_query_inspect.startDateView +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeEventQueryActivity : BaseViewModelActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: EventSearchListAdapter + + override fun createViewModelByClass(): Class? = + EventQueryViewModel::class.java + + override fun initLayoutView(): Int = R.layout.activity_query_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "事件查询(单机模式)" + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(this) + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + //查询都从第一页开始查 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + viewModel.resultModel.observe(this, Observer { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(20210712) + } + }) + viewModel.loadState.observe(this, Observer { + "抱歉,无法查询到相关记录".show(this) + }) + } + + private class WeakReferenceHandler(activity: SingleModeEventQueryActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210712) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + EventSearchListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.eventRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.eventRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + EventSearchListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = Intent(resultActivity, EventDetailActivity::class.java) + val rowsBean = resultActivity.dataBeans[position] + intent.putExtra("createTime", rowsBean.createTime) + intent.putExtra( + "description", + rowsBean.description!!.filterString() + ) + intent.putExtra("data", rowsBean.data) + intent.putExtra("images", rowsBean.images) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt new file mode 100644 index 0000000..ff846e1 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt @@ -0,0 +1,131 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.graphics.Color +import android.os.Bundle +import android.util.Log +import androidx.core.content.ContextCompat +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.BitmapDescriptorFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.utils.DataBaseManager +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import kotlinx.android.synthetic.main.activity_inspect_route.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeInspectRouteActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeInspectRoute" + } + + private lateinit var aMap: AMap + private lateinit var id: String + + override fun initLayoutView(): Int = R.layout.activity_inspect_route + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + PageNavigationManager.addActivity(this) + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + + //根据id查询详情 + id = intent.getStringExtra("id")!! + val detailData = DataBaseManager.instance.queryInspectDetailById(id) + inspectNameView.text = detailData.name + userNameView.text = detailData.user + startTimeView.text = detailData.startTime + endTimeView.text = detailData.endTime + //移动到巡检起始经纬度 + aMap.moveCamera( + CameraUpdateFactory.changeLatLng( + LatLng( + detailData.startLat, + detailData.startLng + ) + ) + ) + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + //设置起点 + addMarker(LatLng(detailData.startLat, detailData.startLng), R.mipmap.qidian) + //设置终点 + addMarker(LatLng(detailData.endLat, detailData.endLng), R.mipmap.zhongdian) + //瞄点画线 + val routeJson = detailData.routes!! + if (routeJson.isEmpty()) { + return + } + //[{"lat":39.917433,"lng":116.269525},{"lat":39.917433,"lng":116.269525}] + Log.d(Tag, "路线: $routeJson") + val type = object : TypeToken>() {}.type + val routeModels = Gson().fromJson>(routeJson, type) + //画线 + val latLngPoints: ArrayList = ArrayList() + routeModels.forEach { routeModel -> + latLngPoints.add(LatLng(routeModel.lat, routeModel.lng)) + } + aMap.addPolyline( + PolylineOptions().addAll(latLngPoints).width(10.toFloat()).color(Color.RED) + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + eventButton.setChangeAlphaWhenPress(true) + eventButton.setOnClickListener { + val intent = Intent(this, EventListActivity::class.java) + intent.putExtra("id", id) + startActivity(intent) + } + } + + private fun addMarker(point: LatLng, res: Int) { + val markerOption = MarkerOptions() + markerOption.position(point) + markerOption.icon(BitmapDescriptorFactory.fromResource(res)) + aMap.addMarker(markerOption) + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt new file mode 100644 index 0000000..65455f7 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt @@ -0,0 +1,204 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.EventSearchListAdapter +import com.casic.birmm.inspect.base.BaseViewModelActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.EventListModel +import com.casic.birmm.inspect.utils.Constant +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.casic.birmm.inspect.utils.TimeOrDateUtil +import com.casic.birmm.inspect.vm.EventQueryViewModel +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_event.* +import kotlinx.android.synthetic.main.activity_query_inspect.emptyView +import kotlinx.android.synthetic.main.activity_query_inspect.endDateView +import kotlinx.android.synthetic.main.activity_query_inspect.inputTipsView +import kotlinx.android.synthetic.main.activity_query_inspect.refreshLayout +import kotlinx.android.synthetic.main.activity_query_inspect.searchView +import kotlinx.android.synthetic.main.activity_query_inspect.startDateView +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeEventQueryActivity : BaseViewModelActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: EventSearchListAdapter + + override fun createViewModelByClass(): Class? = + EventQueryViewModel::class.java + + override fun initLayoutView(): Int = R.layout.activity_query_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "事件查询(单机模式)" + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(this) + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + //查询都从第一页开始查 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + viewModel.resultModel.observe(this, Observer { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(20210712) + } + }) + viewModel.loadState.observe(this, Observer { + "抱歉,无法查询到相关记录".show(this) + }) + } + + private class WeakReferenceHandler(activity: SingleModeEventQueryActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210712) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + EventSearchListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.eventRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.eventRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + EventSearchListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = Intent(resultActivity, EventDetailActivity::class.java) + val rowsBean = resultActivity.dataBeans[position] + intent.putExtra("createTime", rowsBean.createTime) + intent.putExtra( + "description", + rowsBean.description!!.filterString() + ) + intent.putExtra("data", rowsBean.data) + intent.putExtra("images", rowsBean.images) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt new file mode 100644 index 0000000..ff846e1 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt @@ -0,0 +1,131 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.graphics.Color +import android.os.Bundle +import android.util.Log +import androidx.core.content.ContextCompat +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.BitmapDescriptorFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.utils.DataBaseManager +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import kotlinx.android.synthetic.main.activity_inspect_route.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeInspectRouteActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeInspectRoute" + } + + private lateinit var aMap: AMap + private lateinit var id: String + + override fun initLayoutView(): Int = R.layout.activity_inspect_route + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + PageNavigationManager.addActivity(this) + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + + //根据id查询详情 + id = intent.getStringExtra("id")!! + val detailData = DataBaseManager.instance.queryInspectDetailById(id) + inspectNameView.text = detailData.name + userNameView.text = detailData.user + startTimeView.text = detailData.startTime + endTimeView.text = detailData.endTime + //移动到巡检起始经纬度 + aMap.moveCamera( + CameraUpdateFactory.changeLatLng( + LatLng( + detailData.startLat, + detailData.startLng + ) + ) + ) + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + //设置起点 + addMarker(LatLng(detailData.startLat, detailData.startLng), R.mipmap.qidian) + //设置终点 + addMarker(LatLng(detailData.endLat, detailData.endLng), R.mipmap.zhongdian) + //瞄点画线 + val routeJson = detailData.routes!! + if (routeJson.isEmpty()) { + return + } + //[{"lat":39.917433,"lng":116.269525},{"lat":39.917433,"lng":116.269525}] + Log.d(Tag, "路线: $routeJson") + val type = object : TypeToken>() {}.type + val routeModels = Gson().fromJson>(routeJson, type) + //画线 + val latLngPoints: ArrayList = ArrayList() + routeModels.forEach { routeModel -> + latLngPoints.add(LatLng(routeModel.lat, routeModel.lng)) + } + aMap.addPolyline( + PolylineOptions().addAll(latLngPoints).width(10.toFloat()).color(Color.RED) + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + eventButton.setChangeAlphaWhenPress(true) + eventButton.setOnClickListener { + val intent = Intent(this, EventListActivity::class.java) + intent.putExtra("id", id) + startActivity(intent) + } + } + + private fun addMarker(point: LatLng, res: Int) { + val markerOption = MarkerOptions() + markerOption.position(point) + markerOption.icon(BitmapDescriptorFactory.fromResource(res)) + aMap.addMarker(markerOption) + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt new file mode 100644 index 0000000..d17a827 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt @@ -0,0 +1,191 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Bundle +import android.os.CountDownTimer +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.InspectListAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_inspect.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + + +class SingleModeInspectionQueryActivity : BaseSingleModeActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + + //本地数据库页码从0开始 + private var pageIndex = 0 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: InspectListAdapter + + override fun initLayoutView(): Int = R.layout.activity_query_inspect + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录查询(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + weakReferenceHandler = WeakReferenceHandler(this) + dataBeans = DataBaseManager.instance.queryAllInspection(pageIndex) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //开始时间 + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + //结束时间 + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + //开始搜索 + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + pageIndex = 0 + dataBeans = + DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 0 + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + dataBeans.clear() + dataBeans = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + refreshLayout.finishRefresh() + isRefresh = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + val dataRows = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + if (dataRows.size == 0) { + "到底了,别拉了".show(this@SingleModeInspectionQueryActivity) + } + dataBeans.addAll(dataRows) + refreshLayout.finishLoadMore() + isLoadMore = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + } + + private class WeakReferenceHandler(activity: SingleModeInspectionQueryActivity) : Handler() { + private val reference: WeakReference = + WeakReference(activity) + + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210819) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + InspectListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.inspectRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.inspectRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + InspectListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = + Intent( + resultActivity, + SingleModeInspectRouteActivity::class.java + ) + intent.putExtra("id", resultActivity.dataBeans[position].id) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt new file mode 100644 index 0000000..65455f7 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt @@ -0,0 +1,204 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.EventSearchListAdapter +import com.casic.birmm.inspect.base.BaseViewModelActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.EventListModel +import com.casic.birmm.inspect.utils.Constant +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.casic.birmm.inspect.utils.TimeOrDateUtil +import com.casic.birmm.inspect.vm.EventQueryViewModel +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_event.* +import kotlinx.android.synthetic.main.activity_query_inspect.emptyView +import kotlinx.android.synthetic.main.activity_query_inspect.endDateView +import kotlinx.android.synthetic.main.activity_query_inspect.inputTipsView +import kotlinx.android.synthetic.main.activity_query_inspect.refreshLayout +import kotlinx.android.synthetic.main.activity_query_inspect.searchView +import kotlinx.android.synthetic.main.activity_query_inspect.startDateView +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeEventQueryActivity : BaseViewModelActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: EventSearchListAdapter + + override fun createViewModelByClass(): Class? = + EventQueryViewModel::class.java + + override fun initLayoutView(): Int = R.layout.activity_query_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "事件查询(单机模式)" + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(this) + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + //查询都从第一页开始查 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + viewModel.resultModel.observe(this, Observer { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(20210712) + } + }) + viewModel.loadState.observe(this, Observer { + "抱歉,无法查询到相关记录".show(this) + }) + } + + private class WeakReferenceHandler(activity: SingleModeEventQueryActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210712) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + EventSearchListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.eventRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.eventRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + EventSearchListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = Intent(resultActivity, EventDetailActivity::class.java) + val rowsBean = resultActivity.dataBeans[position] + intent.putExtra("createTime", rowsBean.createTime) + intent.putExtra( + "description", + rowsBean.description!!.filterString() + ) + intent.putExtra("data", rowsBean.data) + intent.putExtra("images", rowsBean.images) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt new file mode 100644 index 0000000..ff846e1 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt @@ -0,0 +1,131 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.graphics.Color +import android.os.Bundle +import android.util.Log +import androidx.core.content.ContextCompat +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.BitmapDescriptorFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.utils.DataBaseManager +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import kotlinx.android.synthetic.main.activity_inspect_route.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeInspectRouteActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeInspectRoute" + } + + private lateinit var aMap: AMap + private lateinit var id: String + + override fun initLayoutView(): Int = R.layout.activity_inspect_route + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + PageNavigationManager.addActivity(this) + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + + //根据id查询详情 + id = intent.getStringExtra("id")!! + val detailData = DataBaseManager.instance.queryInspectDetailById(id) + inspectNameView.text = detailData.name + userNameView.text = detailData.user + startTimeView.text = detailData.startTime + endTimeView.text = detailData.endTime + //移动到巡检起始经纬度 + aMap.moveCamera( + CameraUpdateFactory.changeLatLng( + LatLng( + detailData.startLat, + detailData.startLng + ) + ) + ) + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + //设置起点 + addMarker(LatLng(detailData.startLat, detailData.startLng), R.mipmap.qidian) + //设置终点 + addMarker(LatLng(detailData.endLat, detailData.endLng), R.mipmap.zhongdian) + //瞄点画线 + val routeJson = detailData.routes!! + if (routeJson.isEmpty()) { + return + } + //[{"lat":39.917433,"lng":116.269525},{"lat":39.917433,"lng":116.269525}] + Log.d(Tag, "路线: $routeJson") + val type = object : TypeToken>() {}.type + val routeModels = Gson().fromJson>(routeJson, type) + //画线 + val latLngPoints: ArrayList = ArrayList() + routeModels.forEach { routeModel -> + latLngPoints.add(LatLng(routeModel.lat, routeModel.lng)) + } + aMap.addPolyline( + PolylineOptions().addAll(latLngPoints).width(10.toFloat()).color(Color.RED) + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + eventButton.setChangeAlphaWhenPress(true) + eventButton.setOnClickListener { + val intent = Intent(this, EventListActivity::class.java) + intent.putExtra("id", id) + startActivity(intent) + } + } + + private fun addMarker(point: LatLng, res: Int) { + val markerOption = MarkerOptions() + markerOption.position(point) + markerOption.icon(BitmapDescriptorFactory.fromResource(res)) + aMap.addMarker(markerOption) + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt new file mode 100644 index 0000000..d17a827 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt @@ -0,0 +1,191 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Bundle +import android.os.CountDownTimer +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.InspectListAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_inspect.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + + +class SingleModeInspectionQueryActivity : BaseSingleModeActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + + //本地数据库页码从0开始 + private var pageIndex = 0 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: InspectListAdapter + + override fun initLayoutView(): Int = R.layout.activity_query_inspect + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录查询(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + weakReferenceHandler = WeakReferenceHandler(this) + dataBeans = DataBaseManager.instance.queryAllInspection(pageIndex) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //开始时间 + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + //结束时间 + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + //开始搜索 + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + pageIndex = 0 + dataBeans = + DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 0 + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + dataBeans.clear() + dataBeans = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + refreshLayout.finishRefresh() + isRefresh = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + val dataRows = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + if (dataRows.size == 0) { + "到底了,别拉了".show(this@SingleModeInspectionQueryActivity) + } + dataBeans.addAll(dataRows) + refreshLayout.finishLoadMore() + isLoadMore = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + } + + private class WeakReferenceHandler(activity: SingleModeInspectionQueryActivity) : Handler() { + private val reference: WeakReference = + WeakReference(activity) + + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210819) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + InspectListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.inspectRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.inspectRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + InspectListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = + Intent( + resultActivity, + SingleModeInspectRouteActivity::class.java + ) + intent.putExtra("id", resultActivity.dataBeans[position].id) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt new file mode 100644 index 0000000..34c7047 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt @@ -0,0 +1,624 @@ +package com.casic.birmm.inspect.view + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothGatt +import android.bluetooth.BluetoothGattCharacteristic +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import android.os.Message +import android.os.Vibrator +import android.util.Log +import androidx.core.content.ContextCompat +import com.aihook.alertview.library.AlertView +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.AMapUtils +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MyLocationStyle +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.bean.BlueToothBean +import com.casic.birmm.inspect.bean.InspectionLocalBean +import com.casic.birmm.inspect.extensions.* +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.model.NewTaskEventModel +import com.casic.birmm.inspect.utils.* +import com.casic.birmm.inspect.utils.callback.OnBleConnectListener +import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener +import com.casic.birmm.inspect.widgets.InputDialog +import com.casic.birmm.inspect.widgets.SingleChoiceDialog +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet +import kotlinx.android.synthetic.main.activity_map.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeMapActivity : BaseSingleModeActivity() { + companion object { + private const val Tag = "SingleModeMapActivity" + private lateinit var weakReferenceHandler: WeakReferenceHandler + + fun sendEmptyMessage(what: Int) { + weakReferenceHandler.sendEmptyMessage(what) + } + } + + private val itemList: List = arrayListOf("报警事件", "自定义事件") + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean + private var gson: Gson = Gson() + private var isBluetoothOn = true + private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 + private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 + private var curConnectState = false + private var isGeneratingTask = false + private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var vibrator: Vibrator + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var taskId: String + + init { + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initLayoutView(): Int = R.layout.activity_map + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + //初始化地图 + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = + Intent( + this@SingleModeMapActivity, + SingleModeNewEventActivity::class.java + ) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * */ + private fun stopInspection() { + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + DataBaseManager.instance.insertInspectionData( + NewInspectionModel( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = currentLng.toDouble(), + endLat = currentLat.toDouble(), + routes = model.routes, + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = model.id, isInspection = true)) { + "巡检记录保存成功".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + "巡检记录保存失败,已替您缓存到本地".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", resources.getString(R.string.app_name) + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + + private class WeakReferenceHandler(activity: SingleModeMapActivity) : Handler() { + private val activity: WeakReference = WeakReference(activity) + + @SuppressLint("SetTextI18n") + override fun handleMessage(msg: Message) { + val mapActivity = activity.get() ?: return + when (msg.what) { + Constant.BLUETOOTH_ON -> { + "蓝牙已开启".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + mapActivity.isBluetoothOn = true + } + Constant.BLUETOOTH_OFF -> { + "蓝牙已关闭".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + mapActivity.isBluetoothOn = false + } + Constant.DISCOVERY_DEVICE -> { + val bean = msg.obj as BlueToothBean +// if (bean.bluetoothDevice.name.isDigitOnly()) { + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break + } + } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } +// } + } + Constant.DISCOVERY_OUT_TIME -> { + OtherUtils.dismissLoadingDialog() + if (mapActivity.blueToothBeans.size == 0) { + "无可用设备,请确认设备是否已经开启".show(mapActivity) + } else { + val sheetBuilder = + QMUIBottomSheet.BottomListSheetBuilder(mapActivity) + sheetBuilder.setTitle("请选择要连接的设备") + mapActivity.blueToothBeans.forEach { + sheetBuilder.addItem(it.bluetoothDevice.name) + Log.d(Tag, it.bluetoothDevice.name) + } + sheetBuilder.setGravityCenter(true).setAddCancelBtn(true) + .setOnSheetItemClickListener { dialog, _, position, _ -> + dialog.dismiss() + //连接点击的设备 + mapActivity.startConnectDevice( + mapActivity.blueToothBeans[position].bluetoothDevice + ) + }.build().show() + } + } + Constant.CONNECT_SUCCESS -> { + OtherUtils.dismissLoadingDialog() + mapActivity.curConnectState = true + BLEManager.sendCommand(Constant.ASK_DEV_CODE_COMMAND) + } + Constant.CONNECT_FAILURE -> { + mapActivity.curConnectState = false + } + Constant.SEND_SUCCESS -> { + val sendSuccess = msg.obj as ByteArray + Log.d(Tag, "发送成功->sendSuccessBuffer: ${sendSuccess.toList()}") + } + Constant.SEND_FAILURE -> { + val sendFail = msg.obj as ByteArray + Log.d(Tag, "发送失败->sendFailBuffer: ${sendFail.toList()}") + } + Constant.RECEIVE_SUCCESS -> { + //TODO 接收成功 + val receiveByteArray = msg.obj as ByteArray + //根据返回值标头判断是设备编号还是数据值 + val firstByte = receiveByteArray[0] + if (firstByte == 0xAA.toByte()) { + //解析测量数据 +// Log.d(Tag, "实际数据: ${receiveByteArray.toList()}") + if (receiveByteArray.size == 14) { + val dataHexString = receiveByteArray.toHexString() +// Log.d(Tag, "十六进制: $dataHexString") + val dataModel = dataHexString.toDataModel() +// Log.d(Tag, "数据模型: ${Gson().toJson(dataModel)}") + mapActivity.currentValueView.text = dataModel.potency.toString() + mapActivity.settingsValueView.text = dataModel.alarmValue.toString() + mapActivity.maxValueView.text = dataModel.maxPotency.toString() + //判断是否需要报警 + if (mapActivity.isOpenWarning) { + if (dataModel.potency >= dataModel.alarmValue) { + //当前值大于设置值,需要报警 + OtherUtils.playSound(mapActivity, R.raw.alarm) + mapActivity.vibrator.vibrate(1000) + if (mapActivity.isAutoRecord) { + //如果连续超过10个报警,自动生成报警事件 + mapActivity.alarmCount++ + if (mapActivity.alarmCount >= 10) { + mapActivity.generateAlarmTask(dataModel.maxPotency) + } + } + } else { + //当测量值小于设置值,报警还未结束,需要停止响铃 + OtherUtils.playSound(mapActivity, 0) + } + } else { + Log.d(Tag, "报警开关未打开,不处理") + } + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else if (firstByte == 51.toByte()) { + //解析deviceCode + //51, 51, 50, 48, 50, 49, 48, 49, 48, 48, 48, 51, 13, 10, -86, 0, 0, 0, 0, 0 + if (receiveByteArray.size >= 12) { + mapActivity.deviceStatusView.text = + "设备编号: ${receiveByteArray.toDeviceCode()}" + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else { + Log.d(Tag, "未知返回值,无法解析") + } + } + Constant.RECEIVE_FAILURE -> { + val receiveString = msg.obj as String + Log.d(Tag, "接收失败->receiveString: $receiveString") + } + Constant.DISCONNECT_SUCCESS -> { + mapActivity.curConnectState = false + } + } + } + } + + private fun startConnectDevice(device: BluetoothDevice) { + this.currentDevice = device + if (!curConnectState) { + OtherUtils.showLoadingDialog(this, "正在连接[${currentDevice!!.name}]...") + BLEManager.connectBleDevice( + this, currentDevice!!, 10000, + Constant.SERVICE_UUID, + Constant.READ_CHARACTERISTIC_UUID, + Constant.WRITE_CHARACTERISTIC_UUID, + onBleConnectListener + ) + } + } + + private val onBleConnectListener = object : OnBleConnectListener { + override fun onConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onConnectSuccess(bluetoothGatt: BluetoothGatt?, status: Int) { + + } + + override fun onConnectFailure( + bluetoothGatt: BluetoothGatt?, exception: String?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onDisConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onDisConnectSuccess( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCONNECT_SUCCESS + message.obj = status + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoverySucceed( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_SUCCESS + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoveryFailed( + bluetoothGatt: BluetoothGatt?, msg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveMessage( + bluetoothGatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_SUCCESS + message.obj = characteristic!!.value + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveError(errorMsg: String?) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteSuccess( + bluetoothGatt: BluetoothGatt?, msg: ByteArray? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_SUCCESS + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteFailure( + bluetoothGatt: BluetoothGatt?, msg: ByteArray?, errorMsg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_FAILURE + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onReadRssi(bluetoothGatt: BluetoothGatt?, rssi: Int, status: Int) { + + } + } + + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return + } + isGeneratingTask = true + + this.taskId = "t".id() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + DataBaseManager.instance.insertEventData( + NewTaskEventModel( + taskId = taskId, + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = taskId, isInspection = false)) { + "保存成功".show(this) + isGeneratingTask = false + alarmCount = 0 + } + } + + /***以下是地图生命周期管理************************************************************************/ + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + BLEManager.disConnectDevice() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt new file mode 100644 index 0000000..65455f7 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt @@ -0,0 +1,204 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.EventSearchListAdapter +import com.casic.birmm.inspect.base.BaseViewModelActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.EventListModel +import com.casic.birmm.inspect.utils.Constant +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.casic.birmm.inspect.utils.TimeOrDateUtil +import com.casic.birmm.inspect.vm.EventQueryViewModel +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_event.* +import kotlinx.android.synthetic.main.activity_query_inspect.emptyView +import kotlinx.android.synthetic.main.activity_query_inspect.endDateView +import kotlinx.android.synthetic.main.activity_query_inspect.inputTipsView +import kotlinx.android.synthetic.main.activity_query_inspect.refreshLayout +import kotlinx.android.synthetic.main.activity_query_inspect.searchView +import kotlinx.android.synthetic.main.activity_query_inspect.startDateView +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeEventQueryActivity : BaseViewModelActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: EventSearchListAdapter + + override fun createViewModelByClass(): Class? = + EventQueryViewModel::class.java + + override fun initLayoutView(): Int = R.layout.activity_query_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "事件查询(单机模式)" + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(this) + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + //查询都从第一页开始查 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + viewModel.resultModel.observe(this, Observer { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(20210712) + } + }) + viewModel.loadState.observe(this, Observer { + "抱歉,无法查询到相关记录".show(this) + }) + } + + private class WeakReferenceHandler(activity: SingleModeEventQueryActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210712) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + EventSearchListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.eventRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.eventRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + EventSearchListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = Intent(resultActivity, EventDetailActivity::class.java) + val rowsBean = resultActivity.dataBeans[position] + intent.putExtra("createTime", rowsBean.createTime) + intent.putExtra( + "description", + rowsBean.description!!.filterString() + ) + intent.putExtra("data", rowsBean.data) + intent.putExtra("images", rowsBean.images) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt new file mode 100644 index 0000000..ff846e1 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt @@ -0,0 +1,131 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.graphics.Color +import android.os.Bundle +import android.util.Log +import androidx.core.content.ContextCompat +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.BitmapDescriptorFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.utils.DataBaseManager +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import kotlinx.android.synthetic.main.activity_inspect_route.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeInspectRouteActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeInspectRoute" + } + + private lateinit var aMap: AMap + private lateinit var id: String + + override fun initLayoutView(): Int = R.layout.activity_inspect_route + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + PageNavigationManager.addActivity(this) + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + + //根据id查询详情 + id = intent.getStringExtra("id")!! + val detailData = DataBaseManager.instance.queryInspectDetailById(id) + inspectNameView.text = detailData.name + userNameView.text = detailData.user + startTimeView.text = detailData.startTime + endTimeView.text = detailData.endTime + //移动到巡检起始经纬度 + aMap.moveCamera( + CameraUpdateFactory.changeLatLng( + LatLng( + detailData.startLat, + detailData.startLng + ) + ) + ) + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + //设置起点 + addMarker(LatLng(detailData.startLat, detailData.startLng), R.mipmap.qidian) + //设置终点 + addMarker(LatLng(detailData.endLat, detailData.endLng), R.mipmap.zhongdian) + //瞄点画线 + val routeJson = detailData.routes!! + if (routeJson.isEmpty()) { + return + } + //[{"lat":39.917433,"lng":116.269525},{"lat":39.917433,"lng":116.269525}] + Log.d(Tag, "路线: $routeJson") + val type = object : TypeToken>() {}.type + val routeModels = Gson().fromJson>(routeJson, type) + //画线 + val latLngPoints: ArrayList = ArrayList() + routeModels.forEach { routeModel -> + latLngPoints.add(LatLng(routeModel.lat, routeModel.lng)) + } + aMap.addPolyline( + PolylineOptions().addAll(latLngPoints).width(10.toFloat()).color(Color.RED) + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + eventButton.setChangeAlphaWhenPress(true) + eventButton.setOnClickListener { + val intent = Intent(this, EventListActivity::class.java) + intent.putExtra("id", id) + startActivity(intent) + } + } + + private fun addMarker(point: LatLng, res: Int) { + val markerOption = MarkerOptions() + markerOption.position(point) + markerOption.icon(BitmapDescriptorFactory.fromResource(res)) + aMap.addMarker(markerOption) + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt new file mode 100644 index 0000000..d17a827 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt @@ -0,0 +1,191 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Bundle +import android.os.CountDownTimer +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.InspectListAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_inspect.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + + +class SingleModeInspectionQueryActivity : BaseSingleModeActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + + //本地数据库页码从0开始 + private var pageIndex = 0 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: InspectListAdapter + + override fun initLayoutView(): Int = R.layout.activity_query_inspect + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录查询(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + weakReferenceHandler = WeakReferenceHandler(this) + dataBeans = DataBaseManager.instance.queryAllInspection(pageIndex) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //开始时间 + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + //结束时间 + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + //开始搜索 + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + pageIndex = 0 + dataBeans = + DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 0 + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + dataBeans.clear() + dataBeans = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + refreshLayout.finishRefresh() + isRefresh = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + val dataRows = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + if (dataRows.size == 0) { + "到底了,别拉了".show(this@SingleModeInspectionQueryActivity) + } + dataBeans.addAll(dataRows) + refreshLayout.finishLoadMore() + isLoadMore = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + } + + private class WeakReferenceHandler(activity: SingleModeInspectionQueryActivity) : Handler() { + private val reference: WeakReference = + WeakReference(activity) + + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210819) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + InspectListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.inspectRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.inspectRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + InspectListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = + Intent( + resultActivity, + SingleModeInspectRouteActivity::class.java + ) + intent.putExtra("id", resultActivity.dataBeans[position].id) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt new file mode 100644 index 0000000..34c7047 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt @@ -0,0 +1,624 @@ +package com.casic.birmm.inspect.view + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothGatt +import android.bluetooth.BluetoothGattCharacteristic +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import android.os.Message +import android.os.Vibrator +import android.util.Log +import androidx.core.content.ContextCompat +import com.aihook.alertview.library.AlertView +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.AMapUtils +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MyLocationStyle +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.bean.BlueToothBean +import com.casic.birmm.inspect.bean.InspectionLocalBean +import com.casic.birmm.inspect.extensions.* +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.model.NewTaskEventModel +import com.casic.birmm.inspect.utils.* +import com.casic.birmm.inspect.utils.callback.OnBleConnectListener +import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener +import com.casic.birmm.inspect.widgets.InputDialog +import com.casic.birmm.inspect.widgets.SingleChoiceDialog +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet +import kotlinx.android.synthetic.main.activity_map.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeMapActivity : BaseSingleModeActivity() { + companion object { + private const val Tag = "SingleModeMapActivity" + private lateinit var weakReferenceHandler: WeakReferenceHandler + + fun sendEmptyMessage(what: Int) { + weakReferenceHandler.sendEmptyMessage(what) + } + } + + private val itemList: List = arrayListOf("报警事件", "自定义事件") + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean + private var gson: Gson = Gson() + private var isBluetoothOn = true + private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 + private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 + private var curConnectState = false + private var isGeneratingTask = false + private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var vibrator: Vibrator + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var taskId: String + + init { + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initLayoutView(): Int = R.layout.activity_map + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + //初始化地图 + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = + Intent( + this@SingleModeMapActivity, + SingleModeNewEventActivity::class.java + ) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * */ + private fun stopInspection() { + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + DataBaseManager.instance.insertInspectionData( + NewInspectionModel( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = currentLng.toDouble(), + endLat = currentLat.toDouble(), + routes = model.routes, + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = model.id, isInspection = true)) { + "巡检记录保存成功".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + "巡检记录保存失败,已替您缓存到本地".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", resources.getString(R.string.app_name) + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + + private class WeakReferenceHandler(activity: SingleModeMapActivity) : Handler() { + private val activity: WeakReference = WeakReference(activity) + + @SuppressLint("SetTextI18n") + override fun handleMessage(msg: Message) { + val mapActivity = activity.get() ?: return + when (msg.what) { + Constant.BLUETOOTH_ON -> { + "蓝牙已开启".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + mapActivity.isBluetoothOn = true + } + Constant.BLUETOOTH_OFF -> { + "蓝牙已关闭".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + mapActivity.isBluetoothOn = false + } + Constant.DISCOVERY_DEVICE -> { + val bean = msg.obj as BlueToothBean +// if (bean.bluetoothDevice.name.isDigitOnly()) { + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break + } + } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } +// } + } + Constant.DISCOVERY_OUT_TIME -> { + OtherUtils.dismissLoadingDialog() + if (mapActivity.blueToothBeans.size == 0) { + "无可用设备,请确认设备是否已经开启".show(mapActivity) + } else { + val sheetBuilder = + QMUIBottomSheet.BottomListSheetBuilder(mapActivity) + sheetBuilder.setTitle("请选择要连接的设备") + mapActivity.blueToothBeans.forEach { + sheetBuilder.addItem(it.bluetoothDevice.name) + Log.d(Tag, it.bluetoothDevice.name) + } + sheetBuilder.setGravityCenter(true).setAddCancelBtn(true) + .setOnSheetItemClickListener { dialog, _, position, _ -> + dialog.dismiss() + //连接点击的设备 + mapActivity.startConnectDevice( + mapActivity.blueToothBeans[position].bluetoothDevice + ) + }.build().show() + } + } + Constant.CONNECT_SUCCESS -> { + OtherUtils.dismissLoadingDialog() + mapActivity.curConnectState = true + BLEManager.sendCommand(Constant.ASK_DEV_CODE_COMMAND) + } + Constant.CONNECT_FAILURE -> { + mapActivity.curConnectState = false + } + Constant.SEND_SUCCESS -> { + val sendSuccess = msg.obj as ByteArray + Log.d(Tag, "发送成功->sendSuccessBuffer: ${sendSuccess.toList()}") + } + Constant.SEND_FAILURE -> { + val sendFail = msg.obj as ByteArray + Log.d(Tag, "发送失败->sendFailBuffer: ${sendFail.toList()}") + } + Constant.RECEIVE_SUCCESS -> { + //TODO 接收成功 + val receiveByteArray = msg.obj as ByteArray + //根据返回值标头判断是设备编号还是数据值 + val firstByte = receiveByteArray[0] + if (firstByte == 0xAA.toByte()) { + //解析测量数据 +// Log.d(Tag, "实际数据: ${receiveByteArray.toList()}") + if (receiveByteArray.size == 14) { + val dataHexString = receiveByteArray.toHexString() +// Log.d(Tag, "十六进制: $dataHexString") + val dataModel = dataHexString.toDataModel() +// Log.d(Tag, "数据模型: ${Gson().toJson(dataModel)}") + mapActivity.currentValueView.text = dataModel.potency.toString() + mapActivity.settingsValueView.text = dataModel.alarmValue.toString() + mapActivity.maxValueView.text = dataModel.maxPotency.toString() + //判断是否需要报警 + if (mapActivity.isOpenWarning) { + if (dataModel.potency >= dataModel.alarmValue) { + //当前值大于设置值,需要报警 + OtherUtils.playSound(mapActivity, R.raw.alarm) + mapActivity.vibrator.vibrate(1000) + if (mapActivity.isAutoRecord) { + //如果连续超过10个报警,自动生成报警事件 + mapActivity.alarmCount++ + if (mapActivity.alarmCount >= 10) { + mapActivity.generateAlarmTask(dataModel.maxPotency) + } + } + } else { + //当测量值小于设置值,报警还未结束,需要停止响铃 + OtherUtils.playSound(mapActivity, 0) + } + } else { + Log.d(Tag, "报警开关未打开,不处理") + } + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else if (firstByte == 51.toByte()) { + //解析deviceCode + //51, 51, 50, 48, 50, 49, 48, 49, 48, 48, 48, 51, 13, 10, -86, 0, 0, 0, 0, 0 + if (receiveByteArray.size >= 12) { + mapActivity.deviceStatusView.text = + "设备编号: ${receiveByteArray.toDeviceCode()}" + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else { + Log.d(Tag, "未知返回值,无法解析") + } + } + Constant.RECEIVE_FAILURE -> { + val receiveString = msg.obj as String + Log.d(Tag, "接收失败->receiveString: $receiveString") + } + Constant.DISCONNECT_SUCCESS -> { + mapActivity.curConnectState = false + } + } + } + } + + private fun startConnectDevice(device: BluetoothDevice) { + this.currentDevice = device + if (!curConnectState) { + OtherUtils.showLoadingDialog(this, "正在连接[${currentDevice!!.name}]...") + BLEManager.connectBleDevice( + this, currentDevice!!, 10000, + Constant.SERVICE_UUID, + Constant.READ_CHARACTERISTIC_UUID, + Constant.WRITE_CHARACTERISTIC_UUID, + onBleConnectListener + ) + } + } + + private val onBleConnectListener = object : OnBleConnectListener { + override fun onConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onConnectSuccess(bluetoothGatt: BluetoothGatt?, status: Int) { + + } + + override fun onConnectFailure( + bluetoothGatt: BluetoothGatt?, exception: String?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onDisConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onDisConnectSuccess( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCONNECT_SUCCESS + message.obj = status + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoverySucceed( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_SUCCESS + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoveryFailed( + bluetoothGatt: BluetoothGatt?, msg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveMessage( + bluetoothGatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_SUCCESS + message.obj = characteristic!!.value + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveError(errorMsg: String?) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteSuccess( + bluetoothGatt: BluetoothGatt?, msg: ByteArray? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_SUCCESS + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteFailure( + bluetoothGatt: BluetoothGatt?, msg: ByteArray?, errorMsg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_FAILURE + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onReadRssi(bluetoothGatt: BluetoothGatt?, rssi: Int, status: Int) { + + } + } + + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return + } + isGeneratingTask = true + + this.taskId = "t".id() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + DataBaseManager.instance.insertEventData( + NewTaskEventModel( + taskId = taskId, + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = taskId, isInspection = false)) { + "保存成功".show(this) + isGeneratingTask = false + alarmCount = 0 + } + } + + /***以下是地图生命周期管理************************************************************************/ + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + BLEManager.disConnectDevice() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt new file mode 100644 index 0000000..e00d0dd --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt @@ -0,0 +1,193 @@ +package com.casic.birmm.inspect.view + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.core.content.ContextCompat +import com.aihook.alertview.library.AlertView +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.ImageGridViewAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.id +import com.casic.birmm.inspect.extensions.reformat +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.NewTaskEventModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.PictureSelector +import com.luck.picture.lib.config.PictureConfig +import com.luck.picture.lib.config.PictureMimeType +import kotlinx.android.synthetic.main.activity_new_event.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeNewEventActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeNewEvent" + } + + private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var isWarning: Boolean = true + private var longitude: Double = 0.0 + private var latitude: Double = 0.0 + private var data = -1.0//泄露默认值 + private lateinit var inspectionId: String + private lateinit var inspectionName: String + private lateinit var type: String + private lateinit var imageAdapter: ImageGridViewAdapter + private lateinit var taskId: String + + override fun initLayoutView(): Int = R.layout.activity_new_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + override fun initData(savedInstanceState: Bundle?) { + isWarning = intent.getBooleanExtra("isWarning", true) + inspectionId = intent.getStringExtra("inspectionId")!! + inspectionName = intent.getStringExtra("inspectionName")!! + longitude = intent.getDoubleExtra("longitude", 0.0) + latitude = intent.getDoubleExtra("latitude", 0.0) + if (isWarning) { + titleView.text = "报警事件记录(单机模式)" + inspectCardView.visibility = View.VISIBLE + } else { + titleView.text = "自定义事件记录(单机模式)" + inspectCardView.visibility = View.GONE + } + eventCreateTimeView.text = + TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + + //初始化图片九宫格 + imageAdapter = ImageGridViewAdapter(this) + imageGridView.adapter = imageAdapter + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + addImageView.setOnClickListener { + AlertView( + "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) + } + } + }.setCancelable(true).show() + } + + addEventButton.setChangeAlphaWhenPress(true) + addEventButton.setOnClickListener { + this.taskId = "t".id() + if (eventEditTextView.text.toString().filterString().isEmpty()) { + "事件情况说明还未填写,请检查".show(this) + return@setOnClickListener + } + if (isWarning) { + if (inspectNumberView.text.toString().filterString().isEmpty()) { + "最大泄露值还未填写,请检查".show(this) + return@setOnClickListener + } + type = "报警事件" + data = inspectNumberView.text.toString().filterString().toDouble() + } else { + type = "自定义事件" + } + DataBaseManager.instance.insertEventData( + NewTaskEventModel( + taskId = taskId, + inspectionId = inspectionId, + name = inspectionName, + createTime = eventCreateTimeView.text.toString(), + type = type, + lng = longitude, + lat = latitude, + data = data, + images = realPaths.reformat(), + description = eventEditTextView.text.toString().filterString(), + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = taskId, isInspection = false)) { + "保存成功".show(this) + finish() + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == Activity.RESULT_OK) { + when (requestCode) { + PictureConfig.CHOOSE_REQUEST -> { + val selectResult = PictureSelector.obtainMultipleResult(data) + for (res in selectResult) { + realPaths.add(res.compressPath) + } + } + PictureConfig.REQUEST_CAMERA -> { + val cameraResult = PictureSelector.obtainMultipleResult(data)[0] + realPaths.add(cameraResult.compressPath) + } + } + showSelectedPicture() + } + } + + private fun showSelectedPicture() { + /** + * 显示图片 + * path: /storage/emulated/0/Android/data/com.casic.birmm.inspect/files/Pictures/IMG_CMP_53734632.jpeg + * */ + imageGridView.visibility = View.VISIBLE + val sumItemCount: Int = imageAdapter.count + 1 //每上传一张图片,图片总数都是在原有的基础上+1 + if (sumItemCount <= 3) { + if (realPaths.size == 3) { + addImageView.visibility = View.GONE + } + imageAdapter.setImageList(imageUrls = realPaths) + imageGridView.setOnItemClickListener { _, _, position, _ -> + OtherUtils.showBigImage(this, position, realPaths) + } + //删除按钮点击事件 + imageAdapter.setOnDeleteClickListener(object : + ImageGridViewAdapter.OnDeleteItemClickListener { + @Override + override fun onDeleteItemClick(position: Int) { + realPaths.removeAt(position) + imageAdapter.setImageList(imageUrls = realPaths) + if (realPaths.size != 3) { + addImageView.visibility = View.VISIBLE + } + } + }) + } else { + "最多只能选择3张图片".show(this) + } + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt new file mode 100644 index 0000000..65455f7 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt @@ -0,0 +1,204 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.EventSearchListAdapter +import com.casic.birmm.inspect.base.BaseViewModelActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.EventListModel +import com.casic.birmm.inspect.utils.Constant +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.casic.birmm.inspect.utils.TimeOrDateUtil +import com.casic.birmm.inspect.vm.EventQueryViewModel +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_event.* +import kotlinx.android.synthetic.main.activity_query_inspect.emptyView +import kotlinx.android.synthetic.main.activity_query_inspect.endDateView +import kotlinx.android.synthetic.main.activity_query_inspect.inputTipsView +import kotlinx.android.synthetic.main.activity_query_inspect.refreshLayout +import kotlinx.android.synthetic.main.activity_query_inspect.searchView +import kotlinx.android.synthetic.main.activity_query_inspect.startDateView +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeEventQueryActivity : BaseViewModelActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: EventSearchListAdapter + + override fun createViewModelByClass(): Class? = + EventQueryViewModel::class.java + + override fun initLayoutView(): Int = R.layout.activity_query_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "事件查询(单机模式)" + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(this) + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + //查询都从第一页开始查 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + viewModel.resultModel.observe(this, Observer { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(20210712) + } + }) + viewModel.loadState.observe(this, Observer { + "抱歉,无法查询到相关记录".show(this) + }) + } + + private class WeakReferenceHandler(activity: SingleModeEventQueryActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210712) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + EventSearchListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.eventRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.eventRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + EventSearchListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = Intent(resultActivity, EventDetailActivity::class.java) + val rowsBean = resultActivity.dataBeans[position] + intent.putExtra("createTime", rowsBean.createTime) + intent.putExtra( + "description", + rowsBean.description!!.filterString() + ) + intent.putExtra("data", rowsBean.data) + intent.putExtra("images", rowsBean.images) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt new file mode 100644 index 0000000..ff846e1 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt @@ -0,0 +1,131 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.graphics.Color +import android.os.Bundle +import android.util.Log +import androidx.core.content.ContextCompat +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.BitmapDescriptorFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.utils.DataBaseManager +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import kotlinx.android.synthetic.main.activity_inspect_route.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeInspectRouteActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeInspectRoute" + } + + private lateinit var aMap: AMap + private lateinit var id: String + + override fun initLayoutView(): Int = R.layout.activity_inspect_route + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + PageNavigationManager.addActivity(this) + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + + //根据id查询详情 + id = intent.getStringExtra("id")!! + val detailData = DataBaseManager.instance.queryInspectDetailById(id) + inspectNameView.text = detailData.name + userNameView.text = detailData.user + startTimeView.text = detailData.startTime + endTimeView.text = detailData.endTime + //移动到巡检起始经纬度 + aMap.moveCamera( + CameraUpdateFactory.changeLatLng( + LatLng( + detailData.startLat, + detailData.startLng + ) + ) + ) + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + //设置起点 + addMarker(LatLng(detailData.startLat, detailData.startLng), R.mipmap.qidian) + //设置终点 + addMarker(LatLng(detailData.endLat, detailData.endLng), R.mipmap.zhongdian) + //瞄点画线 + val routeJson = detailData.routes!! + if (routeJson.isEmpty()) { + return + } + //[{"lat":39.917433,"lng":116.269525},{"lat":39.917433,"lng":116.269525}] + Log.d(Tag, "路线: $routeJson") + val type = object : TypeToken>() {}.type + val routeModels = Gson().fromJson>(routeJson, type) + //画线 + val latLngPoints: ArrayList = ArrayList() + routeModels.forEach { routeModel -> + latLngPoints.add(LatLng(routeModel.lat, routeModel.lng)) + } + aMap.addPolyline( + PolylineOptions().addAll(latLngPoints).width(10.toFloat()).color(Color.RED) + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + eventButton.setChangeAlphaWhenPress(true) + eventButton.setOnClickListener { + val intent = Intent(this, EventListActivity::class.java) + intent.putExtra("id", id) + startActivity(intent) + } + } + + private fun addMarker(point: LatLng, res: Int) { + val markerOption = MarkerOptions() + markerOption.position(point) + markerOption.icon(BitmapDescriptorFactory.fromResource(res)) + aMap.addMarker(markerOption) + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt new file mode 100644 index 0000000..d17a827 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt @@ -0,0 +1,191 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Bundle +import android.os.CountDownTimer +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.InspectListAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_inspect.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + + +class SingleModeInspectionQueryActivity : BaseSingleModeActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + + //本地数据库页码从0开始 + private var pageIndex = 0 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: InspectListAdapter + + override fun initLayoutView(): Int = R.layout.activity_query_inspect + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录查询(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + weakReferenceHandler = WeakReferenceHandler(this) + dataBeans = DataBaseManager.instance.queryAllInspection(pageIndex) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //开始时间 + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + //结束时间 + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + //开始搜索 + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + pageIndex = 0 + dataBeans = + DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 0 + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + dataBeans.clear() + dataBeans = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + refreshLayout.finishRefresh() + isRefresh = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + val dataRows = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + if (dataRows.size == 0) { + "到底了,别拉了".show(this@SingleModeInspectionQueryActivity) + } + dataBeans.addAll(dataRows) + refreshLayout.finishLoadMore() + isLoadMore = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + } + + private class WeakReferenceHandler(activity: SingleModeInspectionQueryActivity) : Handler() { + private val reference: WeakReference = + WeakReference(activity) + + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210819) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + InspectListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.inspectRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.inspectRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + InspectListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = + Intent( + resultActivity, + SingleModeInspectRouteActivity::class.java + ) + intent.putExtra("id", resultActivity.dataBeans[position].id) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt new file mode 100644 index 0000000..34c7047 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt @@ -0,0 +1,624 @@ +package com.casic.birmm.inspect.view + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothGatt +import android.bluetooth.BluetoothGattCharacteristic +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import android.os.Message +import android.os.Vibrator +import android.util.Log +import androidx.core.content.ContextCompat +import com.aihook.alertview.library.AlertView +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.AMapUtils +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MyLocationStyle +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.bean.BlueToothBean +import com.casic.birmm.inspect.bean.InspectionLocalBean +import com.casic.birmm.inspect.extensions.* +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.model.NewTaskEventModel +import com.casic.birmm.inspect.utils.* +import com.casic.birmm.inspect.utils.callback.OnBleConnectListener +import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener +import com.casic.birmm.inspect.widgets.InputDialog +import com.casic.birmm.inspect.widgets.SingleChoiceDialog +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet +import kotlinx.android.synthetic.main.activity_map.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeMapActivity : BaseSingleModeActivity() { + companion object { + private const val Tag = "SingleModeMapActivity" + private lateinit var weakReferenceHandler: WeakReferenceHandler + + fun sendEmptyMessage(what: Int) { + weakReferenceHandler.sendEmptyMessage(what) + } + } + + private val itemList: List = arrayListOf("报警事件", "自定义事件") + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean + private var gson: Gson = Gson() + private var isBluetoothOn = true + private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 + private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 + private var curConnectState = false + private var isGeneratingTask = false + private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var vibrator: Vibrator + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var taskId: String + + init { + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initLayoutView(): Int = R.layout.activity_map + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + //初始化地图 + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = + Intent( + this@SingleModeMapActivity, + SingleModeNewEventActivity::class.java + ) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * */ + private fun stopInspection() { + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + DataBaseManager.instance.insertInspectionData( + NewInspectionModel( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = currentLng.toDouble(), + endLat = currentLat.toDouble(), + routes = model.routes, + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = model.id, isInspection = true)) { + "巡检记录保存成功".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + "巡检记录保存失败,已替您缓存到本地".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", resources.getString(R.string.app_name) + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + + private class WeakReferenceHandler(activity: SingleModeMapActivity) : Handler() { + private val activity: WeakReference = WeakReference(activity) + + @SuppressLint("SetTextI18n") + override fun handleMessage(msg: Message) { + val mapActivity = activity.get() ?: return + when (msg.what) { + Constant.BLUETOOTH_ON -> { + "蓝牙已开启".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + mapActivity.isBluetoothOn = true + } + Constant.BLUETOOTH_OFF -> { + "蓝牙已关闭".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + mapActivity.isBluetoothOn = false + } + Constant.DISCOVERY_DEVICE -> { + val bean = msg.obj as BlueToothBean +// if (bean.bluetoothDevice.name.isDigitOnly()) { + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break + } + } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } +// } + } + Constant.DISCOVERY_OUT_TIME -> { + OtherUtils.dismissLoadingDialog() + if (mapActivity.blueToothBeans.size == 0) { + "无可用设备,请确认设备是否已经开启".show(mapActivity) + } else { + val sheetBuilder = + QMUIBottomSheet.BottomListSheetBuilder(mapActivity) + sheetBuilder.setTitle("请选择要连接的设备") + mapActivity.blueToothBeans.forEach { + sheetBuilder.addItem(it.bluetoothDevice.name) + Log.d(Tag, it.bluetoothDevice.name) + } + sheetBuilder.setGravityCenter(true).setAddCancelBtn(true) + .setOnSheetItemClickListener { dialog, _, position, _ -> + dialog.dismiss() + //连接点击的设备 + mapActivity.startConnectDevice( + mapActivity.blueToothBeans[position].bluetoothDevice + ) + }.build().show() + } + } + Constant.CONNECT_SUCCESS -> { + OtherUtils.dismissLoadingDialog() + mapActivity.curConnectState = true + BLEManager.sendCommand(Constant.ASK_DEV_CODE_COMMAND) + } + Constant.CONNECT_FAILURE -> { + mapActivity.curConnectState = false + } + Constant.SEND_SUCCESS -> { + val sendSuccess = msg.obj as ByteArray + Log.d(Tag, "发送成功->sendSuccessBuffer: ${sendSuccess.toList()}") + } + Constant.SEND_FAILURE -> { + val sendFail = msg.obj as ByteArray + Log.d(Tag, "发送失败->sendFailBuffer: ${sendFail.toList()}") + } + Constant.RECEIVE_SUCCESS -> { + //TODO 接收成功 + val receiveByteArray = msg.obj as ByteArray + //根据返回值标头判断是设备编号还是数据值 + val firstByte = receiveByteArray[0] + if (firstByte == 0xAA.toByte()) { + //解析测量数据 +// Log.d(Tag, "实际数据: ${receiveByteArray.toList()}") + if (receiveByteArray.size == 14) { + val dataHexString = receiveByteArray.toHexString() +// Log.d(Tag, "十六进制: $dataHexString") + val dataModel = dataHexString.toDataModel() +// Log.d(Tag, "数据模型: ${Gson().toJson(dataModel)}") + mapActivity.currentValueView.text = dataModel.potency.toString() + mapActivity.settingsValueView.text = dataModel.alarmValue.toString() + mapActivity.maxValueView.text = dataModel.maxPotency.toString() + //判断是否需要报警 + if (mapActivity.isOpenWarning) { + if (dataModel.potency >= dataModel.alarmValue) { + //当前值大于设置值,需要报警 + OtherUtils.playSound(mapActivity, R.raw.alarm) + mapActivity.vibrator.vibrate(1000) + if (mapActivity.isAutoRecord) { + //如果连续超过10个报警,自动生成报警事件 + mapActivity.alarmCount++ + if (mapActivity.alarmCount >= 10) { + mapActivity.generateAlarmTask(dataModel.maxPotency) + } + } + } else { + //当测量值小于设置值,报警还未结束,需要停止响铃 + OtherUtils.playSound(mapActivity, 0) + } + } else { + Log.d(Tag, "报警开关未打开,不处理") + } + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else if (firstByte == 51.toByte()) { + //解析deviceCode + //51, 51, 50, 48, 50, 49, 48, 49, 48, 48, 48, 51, 13, 10, -86, 0, 0, 0, 0, 0 + if (receiveByteArray.size >= 12) { + mapActivity.deviceStatusView.text = + "设备编号: ${receiveByteArray.toDeviceCode()}" + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else { + Log.d(Tag, "未知返回值,无法解析") + } + } + Constant.RECEIVE_FAILURE -> { + val receiveString = msg.obj as String + Log.d(Tag, "接收失败->receiveString: $receiveString") + } + Constant.DISCONNECT_SUCCESS -> { + mapActivity.curConnectState = false + } + } + } + } + + private fun startConnectDevice(device: BluetoothDevice) { + this.currentDevice = device + if (!curConnectState) { + OtherUtils.showLoadingDialog(this, "正在连接[${currentDevice!!.name}]...") + BLEManager.connectBleDevice( + this, currentDevice!!, 10000, + Constant.SERVICE_UUID, + Constant.READ_CHARACTERISTIC_UUID, + Constant.WRITE_CHARACTERISTIC_UUID, + onBleConnectListener + ) + } + } + + private val onBleConnectListener = object : OnBleConnectListener { + override fun onConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onConnectSuccess(bluetoothGatt: BluetoothGatt?, status: Int) { + + } + + override fun onConnectFailure( + bluetoothGatt: BluetoothGatt?, exception: String?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onDisConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onDisConnectSuccess( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCONNECT_SUCCESS + message.obj = status + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoverySucceed( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_SUCCESS + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoveryFailed( + bluetoothGatt: BluetoothGatt?, msg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveMessage( + bluetoothGatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_SUCCESS + message.obj = characteristic!!.value + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveError(errorMsg: String?) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteSuccess( + bluetoothGatt: BluetoothGatt?, msg: ByteArray? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_SUCCESS + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteFailure( + bluetoothGatt: BluetoothGatt?, msg: ByteArray?, errorMsg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_FAILURE + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onReadRssi(bluetoothGatt: BluetoothGatt?, rssi: Int, status: Int) { + + } + } + + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return + } + isGeneratingTask = true + + this.taskId = "t".id() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + DataBaseManager.instance.insertEventData( + NewTaskEventModel( + taskId = taskId, + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = taskId, isInspection = false)) { + "保存成功".show(this) + isGeneratingTask = false + alarmCount = 0 + } + } + + /***以下是地图生命周期管理************************************************************************/ + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + BLEManager.disConnectDevice() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt new file mode 100644 index 0000000..e00d0dd --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt @@ -0,0 +1,193 @@ +package com.casic.birmm.inspect.view + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.core.content.ContextCompat +import com.aihook.alertview.library.AlertView +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.ImageGridViewAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.id +import com.casic.birmm.inspect.extensions.reformat +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.NewTaskEventModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.PictureSelector +import com.luck.picture.lib.config.PictureConfig +import com.luck.picture.lib.config.PictureMimeType +import kotlinx.android.synthetic.main.activity_new_event.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeNewEventActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeNewEvent" + } + + private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var isWarning: Boolean = true + private var longitude: Double = 0.0 + private var latitude: Double = 0.0 + private var data = -1.0//泄露默认值 + private lateinit var inspectionId: String + private lateinit var inspectionName: String + private lateinit var type: String + private lateinit var imageAdapter: ImageGridViewAdapter + private lateinit var taskId: String + + override fun initLayoutView(): Int = R.layout.activity_new_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + override fun initData(savedInstanceState: Bundle?) { + isWarning = intent.getBooleanExtra("isWarning", true) + inspectionId = intent.getStringExtra("inspectionId")!! + inspectionName = intent.getStringExtra("inspectionName")!! + longitude = intent.getDoubleExtra("longitude", 0.0) + latitude = intent.getDoubleExtra("latitude", 0.0) + if (isWarning) { + titleView.text = "报警事件记录(单机模式)" + inspectCardView.visibility = View.VISIBLE + } else { + titleView.text = "自定义事件记录(单机模式)" + inspectCardView.visibility = View.GONE + } + eventCreateTimeView.text = + TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + + //初始化图片九宫格 + imageAdapter = ImageGridViewAdapter(this) + imageGridView.adapter = imageAdapter + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + addImageView.setOnClickListener { + AlertView( + "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) + } + } + }.setCancelable(true).show() + } + + addEventButton.setChangeAlphaWhenPress(true) + addEventButton.setOnClickListener { + this.taskId = "t".id() + if (eventEditTextView.text.toString().filterString().isEmpty()) { + "事件情况说明还未填写,请检查".show(this) + return@setOnClickListener + } + if (isWarning) { + if (inspectNumberView.text.toString().filterString().isEmpty()) { + "最大泄露值还未填写,请检查".show(this) + return@setOnClickListener + } + type = "报警事件" + data = inspectNumberView.text.toString().filterString().toDouble() + } else { + type = "自定义事件" + } + DataBaseManager.instance.insertEventData( + NewTaskEventModel( + taskId = taskId, + inspectionId = inspectionId, + name = inspectionName, + createTime = eventCreateTimeView.text.toString(), + type = type, + lng = longitude, + lat = latitude, + data = data, + images = realPaths.reformat(), + description = eventEditTextView.text.toString().filterString(), + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = taskId, isInspection = false)) { + "保存成功".show(this) + finish() + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == Activity.RESULT_OK) { + when (requestCode) { + PictureConfig.CHOOSE_REQUEST -> { + val selectResult = PictureSelector.obtainMultipleResult(data) + for (res in selectResult) { + realPaths.add(res.compressPath) + } + } + PictureConfig.REQUEST_CAMERA -> { + val cameraResult = PictureSelector.obtainMultipleResult(data)[0] + realPaths.add(cameraResult.compressPath) + } + } + showSelectedPicture() + } + } + + private fun showSelectedPicture() { + /** + * 显示图片 + * path: /storage/emulated/0/Android/data/com.casic.birmm.inspect/files/Pictures/IMG_CMP_53734632.jpeg + * */ + imageGridView.visibility = View.VISIBLE + val sumItemCount: Int = imageAdapter.count + 1 //每上传一张图片,图片总数都是在原有的基础上+1 + if (sumItemCount <= 3) { + if (realPaths.size == 3) { + addImageView.visibility = View.GONE + } + imageAdapter.setImageList(imageUrls = realPaths) + imageGridView.setOnItemClickListener { _, _, position, _ -> + OtherUtils.showBigImage(this, position, realPaths) + } + //删除按钮点击事件 + imageAdapter.setOnDeleteClickListener(object : + ImageGridViewAdapter.OnDeleteItemClickListener { + @Override + override fun onDeleteItemClick(position: Int) { + realPaths.removeAt(position) + imageAdapter.setImageList(imageUrls = realPaths) + if (realPaths.size != 3) { + addImageView.visibility = View.VISIBLE + } + } + }) + } else { + "最多只能选择3张图片".show(this) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt index 6dafd7f..5fa5a60 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt @@ -2,11 +2,12 @@ import android.content.Context import android.content.Intent +import android.os.Bundle import android.os.Vibrator import androidx.core.content.ContextCompat import com.casic.birmm.inspect.BuildConfig import com.casic.birmm.inspect.R -import com.casic.birmm.inspect.base.BaseActivity +import com.casic.birmm.inspect.base.BaseSingleModeActivity import com.casic.birmm.inspect.extensions.show import com.casic.birmm.inspect.utils.* import com.gyf.immersionbar.ImmersionBar @@ -17,7 +18,7 @@ import kotlinx.android.synthetic.main.include_base_title.* -class SingleModeUserSettingsActivity : BaseActivity() { +class SingleModeUserSettingsActivity : BaseSingleModeActivity() { private lateinit var vibrator: Vibrator @@ -27,10 +28,10 @@ PageNavigationManager.addActivity(this) StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "系统设置" + titleView.text = "系统设置(单机模式)" } - override fun initData() { + override fun initData(savedInstanceState: Bundle?) { val isOpen = SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean warningSwitch.isChecked = isOpen val isRecord = SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0dd2d85..7f9b4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,15 +48,20 @@ + + + + + >, DaoConfig> daoConfigMap) { @@ -36,27 +36,27 @@ inspectionLocalBeanDaoConfig = daoConfigMap.get(InspectionLocalBeanDao.class).clone(); inspectionLocalBeanDaoConfig.initIdentityScope(type); - taskEventBeanDaoConfig = daoConfigMap.get(TaskEventBeanDao.class).clone(); - taskEventBeanDaoConfig.initIdentityScope(type); + taskEventLocalBeanDaoConfig = daoConfigMap.get(TaskEventLocalBeanDao.class).clone(); + taskEventLocalBeanDaoConfig.initIdentityScope(type); inspectionLocalBeanDao = new InspectionLocalBeanDao(inspectionLocalBeanDaoConfig, this); - taskEventBeanDao = new TaskEventBeanDao(taskEventBeanDaoConfig, this); + taskEventLocalBeanDao = new TaskEventLocalBeanDao(taskEventLocalBeanDaoConfig, this); registerDao(InspectionLocalBean.class, inspectionLocalBeanDao); - registerDao(TaskEventBean.class, taskEventBeanDao); + registerDao(TaskEventLocalBean.class, taskEventLocalBeanDao); } public void clear() { inspectionLocalBeanDaoConfig.clearIdentityScope(); - taskEventBeanDaoConfig.clearIdentityScope(); + taskEventLocalBeanDaoConfig.clearIdentityScope(); } public InspectionLocalBeanDao getInspectionLocalBeanDao() { return inspectionLocalBeanDao; } - public TaskEventBeanDao getTaskEventBeanDao() { - return taskEventBeanDao; + public TaskEventLocalBeanDao getTaskEventLocalBeanDao() { + return taskEventLocalBeanDao; } } diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java deleted file mode 100644 index 3f040d3..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventBeanDao.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.casic.birmm.inspect.greendao; - -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; - -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; - -import com.casic.birmm.inspect.bean.TaskEventBean; - -// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** - * DAO for table "TASK_EVENT_BEAN". -*/ -public class TaskEventBeanDao extends AbstractDao { - - public static final String TABLENAME = "TASK_EVENT_BEAN"; - - /** - * Properties of entity TaskEventBean.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property ServerMainId = new Property(1, String.class, "serverMainId", false, "SERVER_MAIN_ID"); - public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); - public final static Property Name = new Property(3, String.class, "name", false, "NAME"); - public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); - public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); - public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); - public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); - public final static Property Data = new Property(8, double.class, "data", false, "DATA"); - public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); - public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); - public final static Property User = new Property(11, String.class, "user", false, "USER"); - } - - - public TaskEventBeanDao(DaoConfig config) { - super(config); - } - - public TaskEventBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_BEAN\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"SERVER_MAIN_ID\" TEXT," + // 1: serverMainId - "\"INSPECTION_ID\" TEXT," + // 2: inspectionId - "\"NAME\" TEXT," + // 3: name - "\"CREATE_TIME\" TEXT," + // 4: createTime - "\"LNG\" REAL NOT NULL ," + // 5: lng - "\"LAT\" REAL NOT NULL ," + // 6: lat - "\"TYPE\" TEXT," + // 7: type - "\"DATA\" REAL NOT NULL ," + // 8: data - "\"IMAGES\" TEXT," + // 9: images - "\"DESCRIPTION\" TEXT," + // 10: description - "\"USER\" TEXT);"); // 11: user - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_BEAN\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, TaskEventBean entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - - String serverMainId = entity.getServerMainId(); - if (serverMainId != null) { - stmt.bindString(2, serverMainId); - } - - String inspectionId = entity.getInspectionId(); - if (inspectionId != null) { - stmt.bindString(3, inspectionId); - } - - String name = entity.getName(); - if (name != null) { - stmt.bindString(4, name); - } - - String createTime = entity.getCreateTime(); - if (createTime != null) { - stmt.bindString(5, createTime); - } - stmt.bindDouble(6, entity.getLng()); - stmt.bindDouble(7, entity.getLat()); - - String type = entity.getType(); - if (type != null) { - stmt.bindString(8, type); - } - stmt.bindDouble(9, entity.getData()); - - String images = entity.getImages(); - if (images != null) { - stmt.bindString(10, images); - } - - String description = entity.getDescription(); - if (description != null) { - stmt.bindString(11, description); - } - - String user = entity.getUser(); - if (user != null) { - stmt.bindString(12, user); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public TaskEventBean readEntity(Cursor cursor, int offset) { - TaskEventBean entity = new TaskEventBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // serverMainId - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime - cursor.getDouble(offset + 5), // lng - cursor.getDouble(offset + 6), // lat - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type - cursor.getDouble(offset + 8), // data - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images - cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description - cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, TaskEventBean entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setServerMainId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLng(cursor.getDouble(offset + 5)); - entity.setLat(cursor.getDouble(offset + 6)); - entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setData(cursor.getDouble(offset + 8)); - entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); - entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); - } - - @Override - protected final Long updateKeyAfterInsert(TaskEventBean entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(TaskEventBean entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(TaskEventBean entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java new file mode 100644 index 0000000..5bab21b --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/greendao/TaskEventLocalBeanDao.java @@ -0,0 +1,245 @@ +package com.casic.birmm.inspect.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import com.casic.birmm.inspect.bean.TaskEventLocalBean; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "TASK_EVENT_LOCAL_BEAN". +*/ +public class TaskEventLocalBeanDao extends AbstractDao { + + public static final String TABLENAME = "TASK_EVENT_LOCAL_BEAN"; + + /** + * Properties of entity TaskEventLocalBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property TaskId = new Property(1, String.class, "taskId", false, "TASK_ID"); + public final static Property InspectionId = new Property(2, String.class, "inspectionId", false, "INSPECTION_ID"); + public final static Property Name = new Property(3, String.class, "name", false, "NAME"); + public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME"); + public final static Property Lng = new Property(5, double.class, "lng", false, "LNG"); + public final static Property Lat = new Property(6, double.class, "lat", false, "LAT"); + public final static Property Type = new Property(7, String.class, "type", false, "TYPE"); + public final static Property Data = new Property(8, double.class, "data", false, "DATA"); + public final static Property Images = new Property(9, String.class, "images", false, "IMAGES"); + public final static Property Description = new Property(10, String.class, "description", false, "DESCRIPTION"); + public final static Property User = new Property(11, String.class, "user", false, "USER"); + } + + + public TaskEventLocalBeanDao(DaoConfig config) { + super(config); + } + + public TaskEventLocalBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"TASK_EVENT_LOCAL_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"TASK_ID\" TEXT," + // 1: taskId + "\"INSPECTION_ID\" TEXT," + // 2: inspectionId + "\"NAME\" TEXT," + // 3: name + "\"CREATE_TIME\" TEXT," + // 4: createTime + "\"LNG\" REAL NOT NULL ," + // 5: lng + "\"LAT\" REAL NOT NULL ," + // 6: lat + "\"TYPE\" TEXT," + // 7: type + "\"DATA\" REAL NOT NULL ," + // 8: data + "\"IMAGES\" TEXT," + // 9: images + "\"DESCRIPTION\" TEXT," + // 10: description + "\"USER\" TEXT);"); // 11: user + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TASK_EVENT_LOCAL_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, TaskEventLocalBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(2, taskId); + } + + String inspectionId = entity.getInspectionId(); + if (inspectionId != null) { + stmt.bindString(3, inspectionId); + } + + String name = entity.getName(); + if (name != null) { + stmt.bindString(4, name); + } + + String createTime = entity.getCreateTime(); + if (createTime != null) { + stmt.bindString(5, createTime); + } + stmt.bindDouble(6, entity.getLng()); + stmt.bindDouble(7, entity.getLat()); + + String type = entity.getType(); + if (type != null) { + stmt.bindString(8, type); + } + stmt.bindDouble(9, entity.getData()); + + String images = entity.getImages(); + if (images != null) { + stmt.bindString(10, images); + } + + String description = entity.getDescription(); + if (description != null) { + stmt.bindString(11, description); + } + + String user = entity.getUser(); + if (user != null) { + stmt.bindString(12, user); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public TaskEventLocalBean readEntity(Cursor cursor, int offset) { + TaskEventLocalBean entity = new TaskEventLocalBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // taskId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime + cursor.getDouble(offset + 5), // lng + cursor.getDouble(offset + 6), // lat + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // type + cursor.getDouble(offset + 8), // data + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // images + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // description + cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // user + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, TaskEventLocalBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setTaskId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setLng(cursor.getDouble(offset + 5)); + entity.setLat(cursor.getDouble(offset + 6)); + entity.setType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setData(cursor.getDouble(offset + 8)); + entity.setImages(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setDescription(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + entity.setUser(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11)); + } + + @Override + protected final Long updateKeyAfterInsert(TaskEventLocalBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(TaskEventLocalBean entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(TaskEventLocalBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt new file mode 100644 index 0000000..9300e82 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/model/NewTaskEventModel.kt @@ -0,0 +1,15 @@ +package com.casic.birmm.inspect.model + +class NewTaskEventModel( + var taskId: String, + var inspectionId: String, + var name: String, + var createTime: String, + var lng: Double, + var lat: Double, + var type: String, + var data: Double, + var images: String, + var description: String, + var user: String +) \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt index 9b87bcb..960d08b 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/BluetoothStateBroadcastReceiver.kt @@ -1,11 +1,11 @@ package com.casic.birmm.inspect.utils import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.casic.birmm.inspect.view.MapActivity +import com.casic.birmm.inspect.view.SingleModeMapActivity class BluetoothStateBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { @@ -14,9 +14,11 @@ when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) { BluetoothAdapter.STATE_OFF -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } BluetoothAdapter.STATE_ON -> { MapActivity.sendEmptyMessage(Constant.BLUETOOTH_ON) + SingleModeMapActivity.sendEmptyMessage(Constant.BLUETOOTH_OFF) } } } diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt deleted file mode 100644 index 8201cb4..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/BroadcastManager.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.util.Log -import com.casic.birmm.inspect.base.BaseApplication - - -class BroadcastManager private constructor() { - - private var mContext: Context = BaseApplication.instance - private var receiverMap: HashMap = HashMap() - - companion object { - private const val Tag = "BroadcastManager" - - val instance: BroadcastManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - BroadcastManager() - } - } - - /** - * 添加单个Action,广播的初始化 - */ - fun addAction(action: String, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - filter.addAction(action) - mContext.registerReceiver(receiver, filter) - receiverMap[action] = receiver - } catch (e: Exception) { - e.printStackTrace() - } - } - - /** - * 添加多个Action,广播的初始化 - */ - fun addAction(actions: Array, receiver: BroadcastReceiver) { - try { - val filter = IntentFilter() - actions.forEach { - filter.addAction(it) - receiverMap[it] = receiver - } - mContext.registerReceiver(receiver, filter) - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 发送广播 - * - * @param action 唯一码 - * @param msg 参数 - */ - fun sendBroadcast(action: String, msg: String) { - try { - val intent = Intent() - intent.action = action - intent.putExtra("data", msg) - mContext.sendBroadcast(intent) - Log.d(Tag, "发送广播: $msg") - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - } - - /** - * 销毁广播 - * - * @param actions action集合 - */ - fun destroy(vararg actions: String) { - try { - actions.forEach { - val receiver = receiverMap[it] - if (receiver != null) { - mContext.unregisterReceiver(receiver) - } - } - } catch (e: IllegalArgumentException) { - e.printStackTrace() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt index 893a376..f80b012 100644 --- a/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt +++ b/app/src/main/java/com/casic/birmm/inspect/utils/DataBaseManager.kt @@ -2,53 +2,172 @@ import com.casic.birmm.inspect.base.BaseApplication import com.casic.birmm.inspect.bean.InspectionLocalBean -import com.casic.birmm.inspect.bean.TaskEventBean -import com.casic.birmm.inspect.greendao.TaskEventBeanDao -import com.casic.birmm.inspect.model.TaskRecordModel +import com.casic.birmm.inspect.bean.TaskEventLocalBean +import com.casic.birmm.inspect.greendao.InspectionLocalBeanDao +import com.casic.birmm.inspect.greendao.TaskEventLocalBeanDao +import com.casic.birmm.inspect.model.InspectDetailModel +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewTaskEventModel class DataBaseManager private constructor() { companion object { + private const val Tag = "DataBaseManager" + //Kotlin委托模式双重锁单例 val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { DataBaseManager() } } + private var inspectionDao: InspectionLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao + private var taskEventDao: TaskEventLocalBeanDao = + BaseApplication.obtainInstance().obtainDaoSession().taskEventLocalBeanDao + /** * 保存巡检记录到本地 * */ - fun insertData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.insert(bean) + fun insertInspectionData(model: NewInspectionModel) { + val bean = InspectionLocalBean() + bean.id = System.currentTimeMillis() + bean.inspectionId = model.id + bean.name = model.name + bean.startTime = model.startTime + bean.endTime = model.endTime + bean.date = model.date + bean.startLng = model.startLng + bean.startLat = model.startLat + bean.endLng = model.endLng + bean.endLat = model.endLat + bean.routes = model.routes + bean.user = model.user + inspectionDao.insert(bean) } /** * 删除本地巡检记录 * */ - fun deleteData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.delete(bean) + fun deleteInspectionData(model: NewInspectionModel) { + /** + * @return Entity or null if no matching entity was found + * */ + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(model.id)) + .unique() + ?: return + inspectionDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllInspection() { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.deleteAll() + inspectionDao.deleteAll() } /** - * 更新数据库 + * 查询所有巡检数据 */ - fun updateData(bean: InspectionLocalBean) { - BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao.update(bean) + fun queryAllInspection(offset: Int): MutableList { + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) } /** - * 查询所有数据 + * 条件查询巡检数据 */ - fun queryAllInspection(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().inspectionLocalBeanDao?.queryBuilder() - ?.build()?.list() + fun queryInspectionByCondition( + startDate: String, + endDate: String, + name: String, + offset: Int + ): MutableList { + //条件都不为"",精确查询 + if (startDate != "" && endDate != "" && name != "") { + val queryBuilder = inspectionDao.queryBuilder() + //查询条件 + val condition = queryBuilder.and( + InspectionLocalBeanDao.Properties.Date.between(startDate, endDate), + InspectionLocalBeanDao.Properties.Name.like(name) + ) + return addQueryResult( + queryBuilder.where(condition) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else if (startDate == "" && endDate == "" && name == "") { + //都为"",查询全部 + return addQueryResult( + inspectionDao.queryBuilder() + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } else { + //其他只查询巡检名 + return addQueryResult( + inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.Name.like(name)) + .orderDesc(InspectionLocalBeanDao.Properties.StartTime)//按时间顺序最新顺序排序 + .offset(offset * Constant.PAGE_LIMIT) + .limit(Constant.PAGE_LIMIT) + .list() + ) + } + } + + private fun addQueryResult(list: List?): MutableList { + val resultList = ArrayList() + list?.forEach { + val rowsBean = InspectListModel.DataBean.RowsBean() + + rowsBean.id = it.inspectionId + rowsBean.name = it.name + rowsBean.startTime = it.startTime + rowsBean.endTime = it.endTime + rowsBean.date = it.date + rowsBean.startLng = it.startLng + rowsBean.startLat = it.startLat + rowsBean.endLng = it.endLng + rowsBean.endLat = it.endLat + rowsBean.routes = it.routes + rowsBean.user = it.user + + resultList.add(rowsBean) + } + return resultList + } + + /** + * id查询巡检数据 + */ + fun queryInspectDetailById(id: String): InspectDetailModel.DataBean { + val dataModel = InspectDetailModel.DataBean() + val localBean = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .unique() + + dataModel.id = localBean.inspectionId + dataModel.name = localBean.name + dataModel.date = localBean.date + dataModel.startTime = localBean.startTime + dataModel.endTime = localBean.endTime + dataModel.startLat = localBean.startLat + dataModel.startLng = localBean.startLng + dataModel.endLat = localBean.endLat + dataModel.endLng = localBean.endLng + dataModel.routes = localBean.routes + dataModel.user = localBean.user + + return dataModel } /**********************************************************************************************/ @@ -56,68 +175,109 @@ /** * 保存事件记录到本地 * */ - fun insertData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.insert(bean) + fun insertEventData(model: NewTaskEventModel) { + val bean = TaskEventLocalBean() + bean.id = System.currentTimeMillis() + bean.taskId = model.taskId + bean.inspectionId = model.inspectionId + bean.name = model.name + bean.createTime = model.createTime + bean.lng = model.lng + bean.lat = model.lat + bean.type = model.type + bean.data = model.data + bean.images = model.images + bean.description = model.description + bean.user = model.user + taskEventDao.insert(bean) } /** * 删除本地事件记录 * */ - fun deleteData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.delete(bean) + fun deleteEventData(model: NewTaskEventModel) { + val localBean = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(model.taskId)) + .unique() + ?: return + taskEventDao.delete(localBean) } /** * 删除全部数据 */ fun deleteAllTask() { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.deleteAll() - } - - /** - * 更新数据库 - */ - fun updateData(bean: TaskEventBean) { - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao.update(bean) + taskEventDao.deleteAll() } /** * 根据巡检Id查询事件数据 */ - fun queryTaskByInspection(inspectionId: String): MutableList? { - val dataBeans: MutableList = ArrayList() - BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.where(TaskEventBeanDao.Properties.InspectionId.eq(inspectionId)) - ?.orderDesc(TaskEventBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 - ?.build() - ?.list()?.let { - it.forEach { taskBean -> - val listBean = TaskRecordModel.DataBean.ListBean() - listBean.createTime = taskBean.createTime - listBean.data = taskBean.data.toInt() - listBean.description = taskBean.description - listBean.id = taskBean.serverMainId - listBean.images = taskBean.images - listBean.inspectionId = taskBean.inspectionId - listBean.lat = taskBean.lat - listBean.lng = taskBean.lng - listBean.name = taskBean.name - listBean.type = taskBean.type - listBean.user = taskBean.user - dataBeans.add(listBean) - } + fun queryTaskByInspection(inspectionId: String): MutableList? { + val resultList = ArrayList() + taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.InspectionId.eq(inspectionId)) + .orderDesc(TaskEventLocalBeanDao.Properties.CreateTime)//按时间顺序最新顺序排序 + .list()?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) } - return dataBeans + return resultList } /** * 查询所有数据 */ - fun queryAllTask(): MutableList? { - return BaseApplication.obtainInstance().obtainDaoSession().taskEventBeanDao - ?.queryBuilder() - ?.build() - ?.list() + fun queryAllTask(): MutableList? { + val list = taskEventDao.queryBuilder().build().list() + val resultList = ArrayList() + list?.forEach { + resultList.add( + NewTaskEventModel( + taskId = it.taskId, + inspectionId = it.inspectionId, + name = it.name, + createTime = it.createTime, + type = it.type, + lng = it.lng, + lat = it.lat, + data = it.data, + images = it.images, + description = it.description, + user = it.user + ) + ) + } + return resultList + } + + /** + * 判断是否插入数据成功 + */ + fun isInsertSuccess(id: String, isInspection: Boolean): Boolean { + return if (isInspection) { + val count = inspectionDao.queryBuilder() + .where(InspectionLocalBeanDao.Properties.InspectionId.eq(id)) + .count().toInt() + count != 0 + } else { + val count = taskEventDao.queryBuilder() + .where(TaskEventLocalBeanDao.Properties.TaskId.eq(id)) + .count().toInt() + count != 0 + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt b/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt deleted file mode 100644 index 3eb72a6..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/LocationHelper.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.casic.birmm.inspect.utils - -import android.content.Context -import android.util.Log -import com.amap.api.location.AMapLocationClient -import com.amap.api.location.AMapLocationClientOption -import com.casic.birmm.inspect.utils.callback.ILocationListener - -object LocationHelper { - private const val Tag = "LocationHelper" - - fun obtainCurrentLocation(context: Context, listener: ILocationListener) { - val locationClient = AMapLocationClient(context) - val locationOption = AMapLocationClientOption() - locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy - locationOption.isNeedAddress = true//设置是否返回地址信息(默认返回地址信息) - locationOption.isOnceLocation = true//设置是否只定位一次,默认为false - locationOption.isMockEnable = false//设置是否允许模拟位置,默认为false,不允许模拟位置 - locationOption.isLocationCacheEnable = false //可选,设置是否使用缓存定位,默认为true - locationClient.setLocationOption(locationOption) - locationClient.setLocationListener { - if (it != null) { - if (it.errorCode == 0) { - listener.onAMapLocationGet(it) - } else { - Log.e( - Tag, "location Error, ErrCode:" + it.errorCode + ", errInfo:" + it.errorInfo - ) - } - } - } - locationClient.startLocation() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt deleted file mode 100644 index a4def44..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/ILocationListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import com.amap.api.location.AMapLocation - - -interface ILocationListener { - fun onAMapLocationGet(aMapLocation: AMapLocation) //高德定位数据 -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt b/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt deleted file mode 100644 index 8e3041e..0000000 --- a/app/src/main/java/com/casic/birmm/inspect/utils/callback/IWaterMarkAddListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.casic.birmm.inspect.utils.callback - -import java.io.File - -interface IWaterMarkAddListener { - fun onSuccess(file: File?) - fun onError(e: Throwable?) -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt index f370c99..9a23888 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/InspectionQueryActivity.kt @@ -70,8 +70,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - startTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) startDateView.setText(startTime) } .build().show(supportFragmentManager, "startDate") @@ -86,8 +86,8 @@ .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) .setMaxMillseconds(System.currentTimeMillis()) .setType(Type.YEAR_MONTH_DAY) - .setCallBack { _, millseconds -> - endTime = TimeOrDateUtil.timestampToDate(millseconds) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) endDateView.setText(endTime) } .build().show(supportFragmentManager, "startDate") diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt index 6481f0c..3ed63d0 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MainActivity.kt @@ -76,7 +76,7 @@ //新建巡检 createIssueLayout.setOnClickListener { if (isSingleMode) { - + startActivity(Intent(this, SingleModeMapActivity::class.java)) } else { startActivity(Intent(this, MapActivity::class.java)) } @@ -92,7 +92,12 @@ when (position) { 0 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeInspectionQueryActivity::class.java + ) + ) } else { startActivity( Intent( @@ -104,7 +109,12 @@ } 1 -> { if (isSingleMode) { - + startActivity( + Intent( + this@MainActivity, + SingleModeEventQueryActivity::class.java + ) + ) } else { startActivity( Intent( diff --git a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt index 059ef77..05b1fd5 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/MapActivity.kt @@ -16,7 +16,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.aihook.alertview.library.AlertView -import com.amap.api.location.AMapLocation import com.amap.api.maps.AMap import com.amap.api.maps.AMapOptions import com.amap.api.maps.AMapUtils @@ -31,7 +30,6 @@ import com.casic.birmm.inspect.model.NewRouteModel import com.casic.birmm.inspect.model.UserInfoModel import com.casic.birmm.inspect.utils.* -import com.casic.birmm.inspect.utils.callback.ILocationListener import com.casic.birmm.inspect.utils.callback.OnBleConnectListener import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener import com.casic.birmm.inspect.vm.AddInspectionViewModel @@ -63,34 +61,325 @@ } private val itemList: List = arrayListOf("报警事件", "自定义事件") - private lateinit var aMap: AMap - private lateinit var locationStyle: MyLocationStyle - private lateinit var inspectionName: String - private lateinit var inspectionId: String - private lateinit var userDataModel: UserInfoModel.DataBean - private lateinit var model: NewInspectionModel//新建巡检数据结构模型 - private lateinit var vibrator: Vibrator - private var routeList: MutableList = ArrayList()//路线点集和 + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean private var gson: Gson = Gson() private var isBluetoothOn = true private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 private var curConnectState = false - private var isInspectionCompleted = - SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean - private val isOpenWarning = - SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean - private val isAutoRecord = - SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean private var isGeneratingTask = false - private lateinit var eventViewModel: NewEventViewModel private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var userDataModel: UserInfoModel.DataBean + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var vibrator: Vibrator + private lateinit var eventViewModel: NewEventViewModel private lateinit var addInspectionViewModel: AddInspectionViewModel init { weakReferenceHandler = WeakReferenceHandler(this) } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_map) + PageNavigationManager.addActivity(this) + setupTopBarLayout() + if (OtherUtils.isNetworkConnected(this)) { + initData() + initMap(savedInstanceState) + initEvent() + } else { + "糟糕,没有接入任何网络~".show(this) + } + } + + fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检" + } + + fun initData() { + val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String + userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) + addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + } + + private fun initMap(savedInstanceState: Bundle?) { + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = Intent(this@MapActivity, NewEventActivity::class.java) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 + * */ + private fun stopInspection() { + /** + * 提交数据到后台 + * 上传成功之后finish当前页面并提示 + * 提交失败按照保存本地的逻辑走 + * + * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 + * */ + if (OtherUtils.isNetworkConnected(this@MapActivity)) { + val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + addInspectionViewModel.addInspection( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = endLng.toDouble(), + endLat = endLat.toDouble(), + routes = model.routes, + user = userDataModel.name!! + ) + addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "巡检记录保存成功".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + //有网但是因为别的情况导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + }) + addInspectionViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") + } + else -> OtherUtils.dismissLoadingDialog() + } + }) + } else { + //无网导致提交失败 + "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + finish() + } + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", userDataModel.name!! + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + private class WeakReferenceHandler(activity: MapActivity) : Handler() { private val activity: WeakReference = WeakReference(activity) @@ -111,21 +400,21 @@ Constant.DISCOVERY_DEVICE -> { val bean = msg.obj as BlueToothBean // if (bean.bluetoothDevice.name.isDigitOnly()) { - if (mapActivity.blueToothBeans.size == 0) { - mapActivity.blueToothBeans.add(bean) - } else { - //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 - var judge = 0 - for (it in mapActivity.blueToothBeans) { - if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { - judge = 1 - break - } - } - if (judge == 0) { - mapActivity.blueToothBeans.add(bean) + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break } } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } // } } Constant.DISCOVERY_OUT_TIME -> { @@ -230,80 +519,6 @@ } } - //生成报警事件 - private fun generateAlarmTask(maxValue: Int) { - if (isGeneratingTask) return - isGeneratingTask = true - LocationHelper.obtainCurrentLocation(this, object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - eventViewModel.addEventTask( - id = "t".id(), - inspectionId = inspectionId, - name = inspectionName, - createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - type = "报警事件", - lng = aMapLocation.longitude, - lat = aMapLocation.latitude, - data = maxValue.toDouble(), - images = "", - description = "自动报警记录", - user = userDataModel.name!! - ) - eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "保存成功".show(this@MapActivity) - isGeneratingTask = false - alarmCount = 0 - } - }) - eventViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } - }) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_map) - PageNavigationManager.addActivity(this) - setupTopBarLayout() - if (OtherUtils.isNetworkConnected(this)) { - initData() - initMap(savedInstanceState) - initEvent() - } else { - "糟糕,没有接入任何网络~".show(this) - } - } - - fun setupTopBarLayout() { - QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) - ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "巡检" - } - - fun initData() { - val userModelJson = SaveKeyValues.getValue(Constant.USER_OBJECT, "") as String - userDataModel = gson.fromJson(userModelJson, UserInfoModel::class.java).data!! - vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator - eventViewModel = ViewModelProvider(this).get(NewEventViewModel::class.java) - addInspectionViewModel = ViewModelProvider(this).get(AddInspectionViewModel::class.java) - if (BLEManager.initBle(this)) { - if (!BLEManager.isEnable()) { - BLEManager.openBluetooth(false) - } - } else { - "该设备不支持低功耗蓝牙".show(this) - } - } - private fun startConnectDevice(device: BluetoothDevice) { this.currentDevice = device if (!curConnectState) { @@ -402,266 +617,43 @@ } } - private fun initMap(savedInstanceState: Bundle?) { - mapView.onCreate(savedInstanceState) - aMap = mapView.map - val uiSettings = aMap.uiSettings - uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 - //显示定位小蓝点 - locationStyle = MyLocationStyle() - locationStyle - locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 - locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 - aMap.myLocationStyle = locationStyle - aMap.isMyLocationEnabled = true - aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) - } - - fun initEvent() { - leftBackView.setOnClickListener { this.finish() } - //地图左边三个按钮事件 - menuButtonEvent() - //需要判断是否是上次未完的巡检 - selectInspectMode() - - newEventButton.setChangeAlphaWhenPress(true) - newEventButton.setOnClickListener { - SingleChoiceDialog.Builder() - .setContext(this) - .setTitle("选择事件类型") - .setChoiceItemButton(itemList) - .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { - override fun onItemClick(position: Int) { - val intent = Intent(this@MapActivity, NewEventActivity::class.java) - when (position) { - 0 -> { - intent.putExtra("isWarning", true) - } - 1 -> { - intent.putExtra("isWarning", false) - } - } - //获取当前定位 - LocationHelper.obtainCurrentLocation(this@MapActivity, - object : ILocationListener { - override fun onAMapLocationGet(aMapLocation: AMapLocation) { - intent.putExtra("inspectionId", inspectionId) - intent.putExtra("inspectionName", inspectionName) - intent.putExtra("longitude", aMapLocation.longitude) - intent.putExtra("latitude", aMapLocation.latitude) - startActivity(intent) - } - }) - } - }) - .build().show() + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return } - } + isGeneratingTask = true - private fun menuButtonEvent() { - //结束巡检 - stopInspectButton.setOnClickListener { - AlertView( - "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), - null, this, AlertView.Style.Alert - ) { _, position -> - if (position == 0) { - stopInspection() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + eventViewModel.addEventTask( + id = "t".id(), + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = userDataModel.name!! + ) + eventViewModel.resultModel.observe(this@MapActivity, Observer { model -> + if (model.code == 200) { + "保存成功".show(this@MapActivity) + isGeneratingTask = false + alarmCount = 0 + } + }) + eventViewModel.loadState.observe(this@MapActivity, Observer { + when (it) { + is LoadState.Loading -> { + OtherUtils.showLoadingDialog(this@MapActivity, "生成事件中,请稍后...") } - }.show() - } - - //蓝牙按钮 - if (isBluetoothOn) { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) - bluetoothButton.setOnClickListener { - if (curConnectState) { - //断开连接 - BLEManager.disConnectDevice() - currentValueView.text = "--" - settingsValueView.text = "--" - maxValueView.text = "--" - deviceStatusView.text = "设备编号:未连接" - "设备已断开连接".show(this) - } else { - searchDevice() - } + else -> OtherUtils.dismissLoadingDialog() } - } else { - bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) - } - - //重新发送指令按钮 - refreshButton.setOnClickListener { - if (curConnectState) { - BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) - } else { - "请先连接设备".show(this) - } - } - } - - private fun searchDevice() { - //搜索蓝牙 - if (BLEManager.isDiscovery()) {//当前正在搜索设备... - BLEManager.stopDiscoveryDevice() - } - OtherUtils.showLoadingDialog(this, "设备搜索中..."); - BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { - override fun onDeviceFound(blueToothBean: BlueToothBean) { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_DEVICE - message.obj = blueToothBean - weakReferenceHandler.sendMessage(message) - } - - override fun onDiscoveryOutTime() { - val message = weakReferenceHandler.obtainMessage() - message.what = Constant.DISCOVERY_OUT_TIME - weakReferenceHandler.sendMessage(message) - } - }, 3 * 1000) - } - - private fun selectInspectMode() { - if (isInspectionCompleted) { - InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") - .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") - .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { - override fun onConfirmClick(input: String) { - val currentTimeMillis = System.currentTimeMillis() - //新建巡检,inspectionId必为空 - inspectionId = currentTimeMillis.id() - inspectionName = input - - //设置标题和时间 - inspectNameView.text = inspectionName - val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) - inspectTimeView.text = completeDate - - model = NewInspectionModel( - inspectionId, inspectionName, completeDate, - "", TimeOrDateUtil.timestampToDate(currentTimeMillis), - 0.0, 0.0, 0.0, 0.0, - "", userDataModel.name!! - ) - startInspection() - } - - override fun onCancelClick() { - finish() - } - }) - .build().show() - } else { - val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String - val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) - model = NewInspectionModel( - localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, - localBean.startLng, localBean.startLat, 0.0, 0.0, - localBean.routes, localBean.user - ) - "欢迎回来,继续未完成巡检".show(this) - startInspection() - } - } - - /** - * 开始巡检,获取坐标 - * */ - private fun startInspection() { - aMap.addOnMyLocationChangeListener { -// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") - // 保存最新的一次位置,sp不支持保存double - SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) - SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) - //设置起始经纬度 - if (model.startLng == 0.0 || model.startLat == 0.0) { - model.startLng = it.longitude - model.startLat = it.latitude - } - // 包装routes - if (routeList.size <= 2) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } else { - //计算上一个点和当前点的距离 - val last = routeList.size - 1 - val distance = AMapUtils.calculateLineDistance( - LatLng(routeList[last].lat, routeList[last].lng), - LatLng(it.latitude, it.longitude) - ) - if (distance >= 10) { - val route = NewRouteModel() - route.lng = it.longitude - route.lat = it.latitude - routeList.add(route) - } - } - model.routes = gson.toJson(routeList) -// Log.d(Tag, gson.toJson(routeList)) - //根据定位时间间隔不停的覆盖保存巡检记录 - SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) - } - } - - /** - * 结束巡检 - * 不管是手动结束还是页面销毁导致的结束,都保存巡检数据 - * */ - private fun stopInspection() { - /** - * 提交数据到后台 - * 上传成功之后finish当前页面并提示 - * 提交失败按照保存本地的逻辑走 - * - * 如果保存到本地,则需要设置标识位,然后finish当前页面并提示 - * */ - if (OtherUtils.isNetworkConnected(this@MapActivity)) { - val endLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String - val endLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String - - addInspectionViewModel.addInspection( - id = model.id, - name = model.name, - startTime = model.startTime, - endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), - date = model.date, - startLng = model.startLng, - startLat = model.startLat, - endLng = endLng.toDouble(), - endLat = endLat.toDouble(), - routes = model.routes, - user = userDataModel.name!! - ) - addInspectionViewModel.resultModel.observe(this@MapActivity, Observer { model -> - if (model.code == 200) { - "巡检记录保存成功".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) - } else { - //有网但是因为别的情况导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - } - finish() - }) - addInspectionViewModel.loadState.observe(this@MapActivity, Observer { - when (it) { - is LoadState.Loading -> { - OtherUtils.showLoadingDialog(this@MapActivity, "保存中,请稍后...") - } - else -> OtherUtils.dismissLoadingDialog() - } - }) - } else { - //无网导致提交失败 - "巡检记录保存失败,已替您缓存到本地".show(this@MapActivity) - SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) - finish() - } + }) } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt index 210bb3b..5cb5c7e 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/NewEventActivity.kt @@ -31,7 +31,6 @@ private lateinit var uploadImageViewModel: UploadImageViewModel private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 - private lateinit var targetDir: String//压缩图片文件夹 private lateinit var imageAdapter: ImageGridViewAdapter private var isWarning: Boolean = true private lateinit var inspectionId: String @@ -71,8 +70,6 @@ eventCreateTimeView.text = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) - targetDir = FileUtils.imageCompressPath - //初始化图片九宫格 imageAdapter = ImageGridViewAdapter(this) imageGridView.adapter = imageAdapter @@ -84,33 +81,32 @@ addImageView.setOnClickListener { AlertView( "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), - this, AlertView.Style.ActionSheet, - OnItemClickListener { _, position -> - when (position) { - 0 -> { - PictureSelector.create(this) - .openCamera(PictureMimeType.ofImage()) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .forResult(PictureConfig.REQUEST_CAMERA) - } - 1 -> { - PictureSelector.create(this) - .openGallery(PictureMimeType.ofImage()) - .isWeChatStyle(true) - .isCamera(false) - .isCompress(true) - .compressQuality(65) - .compressSavePath(FileUtils.imageCompressPath) - .imageEngine(GlideLoadEngine.createGlideEngine()) - .maxSelectNum(3) - .forResult(PictureConfig.CHOOSE_REQUEST) - } + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressQuality(65) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) } } - ).setCancelable(true).show() + }.setCancelable(true).show() } uploadImageViewModel.resultModel.observe(this, Observer { model -> if (model.code == 200) { diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt new file mode 100644 index 0000000..65455f7 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeEventQueryActivity.kt @@ -0,0 +1,204 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.EventSearchListAdapter +import com.casic.birmm.inspect.base.BaseViewModelActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.EventListModel +import com.casic.birmm.inspect.utils.Constant +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.casic.birmm.inspect.utils.TimeOrDateUtil +import com.casic.birmm.inspect.vm.EventQueryViewModel +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_event.* +import kotlinx.android.synthetic.main.activity_query_inspect.emptyView +import kotlinx.android.synthetic.main.activity_query_inspect.endDateView +import kotlinx.android.synthetic.main.activity_query_inspect.inputTipsView +import kotlinx.android.synthetic.main.activity_query_inspect.refreshLayout +import kotlinx.android.synthetic.main.activity_query_inspect.searchView +import kotlinx.android.synthetic.main.activity_query_inspect.startDateView +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeEventQueryActivity : BaseViewModelActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: EventSearchListAdapter + + override fun createViewModelByClass(): Class? = + EventQueryViewModel::class.java + + override fun initLayoutView(): Int = R.layout.activity_query_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "事件查询(单机模式)" + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(this) + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + //查询都从第一页开始查 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + viewModel.queryEvent( + keywords = keywords, + startTime = startTime, + endTime = endTime, + pageIndex = pageIndex + ) + } + + viewModel.resultModel.observe(this, Observer { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(20210712) + } + }) + viewModel.loadState.observe(this, Observer { + "抱歉,无法查询到相关记录".show(this) + }) + } + + private class WeakReferenceHandler(activity: SingleModeEventQueryActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210712) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + EventSearchListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.eventRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.eventRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + EventSearchListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = Intent(resultActivity, EventDetailActivity::class.java) + val rowsBean = resultActivity.dataBeans[position] + intent.putExtra("createTime", rowsBean.createTime) + intent.putExtra( + "description", + rowsBean.description!!.filterString() + ) + intent.putExtra("data", rowsBean.data) + intent.putExtra("images", rowsBean.images) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt new file mode 100644 index 0000000..ff846e1 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectRouteActivity.kt @@ -0,0 +1,131 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.graphics.Color +import android.os.Bundle +import android.util.Log +import androidx.core.content.ContextCompat +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.BitmapDescriptorFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.utils.DataBaseManager +import com.casic.birmm.inspect.utils.PageNavigationManager +import com.casic.birmm.inspect.utils.StatusBarColorUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import kotlinx.android.synthetic.main.activity_inspect_route.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeInspectRouteActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeInspectRoute" + } + + private lateinit var aMap: AMap + private lateinit var id: String + + override fun initLayoutView(): Int = R.layout.activity_inspect_route + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + PageNavigationManager.addActivity(this) + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + + //根据id查询详情 + id = intent.getStringExtra("id")!! + val detailData = DataBaseManager.instance.queryInspectDetailById(id) + inspectNameView.text = detailData.name + userNameView.text = detailData.user + startTimeView.text = detailData.startTime + endTimeView.text = detailData.endTime + //移动到巡检起始经纬度 + aMap.moveCamera( + CameraUpdateFactory.changeLatLng( + LatLng( + detailData.startLat, + detailData.startLng + ) + ) + ) + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + //设置起点 + addMarker(LatLng(detailData.startLat, detailData.startLng), R.mipmap.qidian) + //设置终点 + addMarker(LatLng(detailData.endLat, detailData.endLng), R.mipmap.zhongdian) + //瞄点画线 + val routeJson = detailData.routes!! + if (routeJson.isEmpty()) { + return + } + //[{"lat":39.917433,"lng":116.269525},{"lat":39.917433,"lng":116.269525}] + Log.d(Tag, "路线: $routeJson") + val type = object : TypeToken>() {}.type + val routeModels = Gson().fromJson>(routeJson, type) + //画线 + val latLngPoints: ArrayList = ArrayList() + routeModels.forEach { routeModel -> + latLngPoints.add(LatLng(routeModel.lat, routeModel.lng)) + } + aMap.addPolyline( + PolylineOptions().addAll(latLngPoints).width(10.toFloat()).color(Color.RED) + ) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + eventButton.setChangeAlphaWhenPress(true) + eventButton.setOnClickListener { + val intent = Intent(this, EventListActivity::class.java) + intent.putExtra("id", id) + startActivity(intent) + } + } + + private fun addMarker(point: LatLng, res: Int) { + val markerOption = MarkerOptions() + markerOption.position(point) + markerOption.icon(BitmapDescriptorFactory.fromResource(res)) + aMap.addMarker(markerOption) + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt new file mode 100644 index 0000000..d17a827 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeInspectionQueryActivity.kt @@ -0,0 +1,191 @@ +package com.casic.birmm.inspect.view + +import android.content.Intent +import android.os.Bundle +import android.os.CountDownTimer +import android.os.Handler +import android.os.Message +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.InspectListAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.InspectListModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.jzxiang.pickerview.TimePickerDialog +import com.jzxiang.pickerview.data.Type +import kotlinx.android.synthetic.main.activity_query_inspect.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + + +class SingleModeInspectionQueryActivity : BaseSingleModeActivity() { + + private var keywords = "" + private var startTime = "" + private var endTime = "" + + //本地数据库页码从0开始 + private var pageIndex = 0 + private var isRefresh = false + private var isLoadMore = false + private var dataBeans: MutableList = ArrayList() + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var adapter: InspectListAdapter + + override fun initLayoutView(): Int = R.layout.activity_query_inspect + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检记录查询(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + weakReferenceHandler = WeakReferenceHandler(this) + dataBeans = DataBaseManager.instance.queryAllInspection(pageIndex) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //开始时间 + startDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择起始时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + startTime = TimeOrDateUtil.timestampToDate(millsSeconds) + startDateView.setText(startTime) + } + .build().show(supportFragmentManager, "startDate") + } + //结束时间 + endDateView.setOnClickListener { + TimePickerDialog.Builder() + .setThemeColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + .setTitleStringId("请选择结束时间") + .setWheelItemTextSize(16) + .setCyclic(false) + .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS) + .setMaxMillseconds(System.currentTimeMillis()) + .setType(Type.YEAR_MONTH_DAY) + .setCallBack { _, millsSeconds -> + endTime = TimeOrDateUtil.timestampToDate(millsSeconds) + endDateView.setText(endTime) + } + .build().show(supportFragmentManager, "startDate") + } + + //开始搜索 + searchView.setOnClickListener { + keywords = inputTipsView.text.toString() + pageIndex = 0 + dataBeans = + DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + weakReferenceHandler.sendEmptyMessage(20210819) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 0 + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + dataBeans.clear() + dataBeans = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + refreshLayout.finishRefresh() + isRefresh = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + //延时1.5s加载 + object : CountDownTimer(1500, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + val dataRows = DataBaseManager.instance.queryInspectionByCondition( + startTime, + endTime, + keywords, + pageIndex + ) + if (dataRows.size == 0) { + "到底了,别拉了".show(this@SingleModeInspectionQueryActivity) + } + dataBeans.addAll(dataRows) + refreshLayout.finishLoadMore() + isLoadMore = false + weakReferenceHandler.sendEmptyMessage(20210819) + } + }.start() + } + } + + private class WeakReferenceHandler(activity: SingleModeInspectionQueryActivity) : Handler() { + private val reference: WeakReference = + WeakReference(activity) + + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val resultActivity = reference.get() + if (msg.what == 20210819) { + if (resultActivity!!.isRefresh || resultActivity.isLoadMore) { + resultActivity.adapter.notifyDataSetChanged() + } else { //首次加载数据 + if (resultActivity.dataBeans.size == 0) { + resultActivity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + resultActivity.emptyView!!.hide() + resultActivity.adapter = + InspectListAdapter(resultActivity, resultActivity.dataBeans) + resultActivity.inspectRecyclerView!!.layoutManager = + LinearLayoutManager(resultActivity) + resultActivity.inspectRecyclerView!!.adapter = resultActivity.adapter + resultActivity.adapter.setOnItemClickListener(object : + InspectListAdapter.OnItemClickListener { + override fun onClick(position: Int) { + val intent = + Intent( + resultActivity, + SingleModeInspectRouteActivity::class.java + ) + intent.putExtra("id", resultActivity.dataBeans[position].id) + resultActivity.startActivity(intent) + } + }) + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt new file mode 100644 index 0000000..34c7047 --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeMapActivity.kt @@ -0,0 +1,624 @@ +package com.casic.birmm.inspect.view + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothGatt +import android.bluetooth.BluetoothGattCharacteristic +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import android.os.Message +import android.os.Vibrator +import android.util.Log +import androidx.core.content.ContextCompat +import com.aihook.alertview.library.AlertView +import com.amap.api.maps.AMap +import com.amap.api.maps.AMapOptions +import com.amap.api.maps.AMapUtils +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.MyLocationStyle +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.bean.BlueToothBean +import com.casic.birmm.inspect.bean.InspectionLocalBean +import com.casic.birmm.inspect.extensions.* +import com.casic.birmm.inspect.model.NewInspectionModel +import com.casic.birmm.inspect.model.NewRouteModel +import com.casic.birmm.inspect.model.NewTaskEventModel +import com.casic.birmm.inspect.utils.* +import com.casic.birmm.inspect.utils.callback.OnBleConnectListener +import com.casic.birmm.inspect.utils.callback.OnDeviceSearchListener +import com.casic.birmm.inspect.widgets.InputDialog +import com.casic.birmm.inspect.widgets.SingleChoiceDialog +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.qmuiteam.qmui.util.QMUIStatusBarHelper +import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet +import kotlinx.android.synthetic.main.activity_map.* +import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference + +class SingleModeMapActivity : BaseSingleModeActivity() { + companion object { + private const val Tag = "SingleModeMapActivity" + private lateinit var weakReferenceHandler: WeakReferenceHandler + + fun sendEmptyMessage(what: Int) { + weakReferenceHandler.sendEmptyMessage(what) + } + } + + private val itemList: List = arrayListOf("报警事件", "自定义事件") + private val isOpenWarning = + SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean + private val isAutoRecord = + SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean + private var isInspectionCompleted = + SaveKeyValues.getValue(Constant.INSPECTION_COMPLETED, true) as Boolean + private var gson: Gson = Gson() + private var isBluetoothOn = true + private var blueToothBeans: MutableList = ArrayList()//搜索展示列表 + private var currentDevice: BluetoothDevice? = null// 当前蓝牙设备 + private var curConnectState = false + private var isGeneratingTask = false + private var alarmCount = 0 + private var routeList: MutableList = ArrayList()//路线点集和 + private lateinit var vibrator: Vibrator + private lateinit var aMap: AMap + private lateinit var locationStyle: MyLocationStyle + private lateinit var model: NewInspectionModel//新建巡检数据结构模型 + private lateinit var taskId: String + + init { + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initLayoutView(): Int = R.layout.activity_map + + override fun setupTopBarLayout() { + QMUIStatusBarHelper.translucent(this) //沉浸式状态栏 + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + titleView.text = "巡检(单机模式)" + } + + override fun initData(savedInstanceState: Bundle?) { + vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + if (BLEManager.initBle(this)) { + if (!BLEManager.isEnable()) { + BLEManager.openBluetooth(false) + } + } else { + "该设备不支持低功耗蓝牙".show(this) + } + //初始化地图 + mapView.onCreate(savedInstanceState) + aMap = mapView.map + val uiSettings = aMap.uiSettings + uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER + uiSettings.isRotateGesturesEnabled = false//不许地图随手势旋转角度 + //显示定位小蓝点 + locationStyle = MyLocationStyle() + locationStyle + locationStyle.showMyLocation(true)//设置是否显示定位小蓝点 + locationStyle.interval(10 * 1000)////设置连续定位模式下的定位间隔,只在连续定位模式下生效。单位为毫秒 + aMap.myLocationStyle = locationStyle + aMap.isMyLocationEnabled = true + aMap.moveCamera(CameraUpdateFactory.zoomTo(16.toFloat())) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + //地图左边三个按钮事件 + menuButtonEvent() + //需要判断是否是上次未完的巡检 + selectInspectMode() + + newEventButton.setChangeAlphaWhenPress(true) + newEventButton.setOnClickListener { + SingleChoiceDialog.Builder() + .setContext(this) + .setTitle("选择事件类型") + .setChoiceItemButton(itemList) + .setOnDialogClickListener(object : SingleChoiceDialog.OnDialogItemClickListener { + override fun onItemClick(position: Int) { + val intent = + Intent( + this@SingleModeMapActivity, + SingleModeNewEventActivity::class.java + ) + when (position) { + 0 -> { + intent.putExtra("isWarning", true) + } + 1 -> { + intent.putExtra("isWarning", false) + } + } + //获取当前定位 + val currentLng = + SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = + SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + intent.putExtra("inspectionId", model.id) + intent.putExtra("inspectionName", model.name) + intent.putExtra("longitude", currentLng.toDouble()) + intent.putExtra("latitude", currentLat.toDouble()) + startActivity(intent) + } + }) + .build().show() + } + } + + private fun menuButtonEvent() { + //结束巡检 + stopInspectButton.setOnClickListener { + AlertView( + "温馨提示", "确定结束巡检吗?", "取消", arrayOf("确定"), + null, this, AlertView.Style.Alert + ) { _, position -> + if (position == 0) { + stopInspection() + } + }.show() + } + + //蓝牙按钮 + if (isBluetoothOn) { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + bluetoothButton.setOnClickListener { + if (curConnectState) { + //断开连接 + BLEManager.disConnectDevice() + currentValueView.text = "--" + settingsValueView.text = "--" + maxValueView.text = "--" + deviceStatusView.text = "设备编号:未连接" + "设备已断开连接".show(this) + } else { + searchDevice() + } + } + } else { + bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + } + + //重新发送指令按钮 + refreshButton.setOnClickListener { + if (curConnectState) { + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + "请先连接设备".show(this) + } + } + } + + /** + * 结束巡检 + * */ + private fun stopInspection() { + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + DataBaseManager.instance.insertInspectionData( + NewInspectionModel( + id = model.id, + name = model.name, + startTime = model.startTime, + endTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + date = model.date, + startLng = model.startLng, + startLat = model.startLat, + endLng = currentLng.toDouble(), + endLat = currentLat.toDouble(), + routes = model.routes, + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = model.id, isInspection = true)) { + "巡检记录保存成功".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, true) + } else { + "巡检记录保存失败,已替您缓存到本地".show(this) + SaveKeyValues.putValue(Constant.INSPECTION_COMPLETED, false) + } + finish() + } + + private fun searchDevice() { + //搜索蓝牙 + if (BLEManager.isDiscovery()) {//当前正在搜索设备... + BLEManager.stopDiscoveryDevice() + } + OtherUtils.showLoadingDialog(this, "设备搜索中..."); + BLEManager.startDiscoveryDevice(object : OnDeviceSearchListener { + override fun onDeviceFound(blueToothBean: BlueToothBean) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_DEVICE + message.obj = blueToothBean + weakReferenceHandler.sendMessage(message) + } + + override fun onDiscoveryOutTime() { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCOVERY_OUT_TIME + weakReferenceHandler.sendMessage(message) + } + }, 3 * 1000) + } + + private fun selectInspectMode() { + if (isInspectionCompleted) { + InputDialog.Builder().setContext(this).setTitle("请输入巡检标签") + .setHintText("如:xxx区间巡检").setNegativeButton("放弃").setPositiveButton("开始巡检") + .setOnDialogClickListener(object : InputDialog.OnDialogButtonClickListener { + override fun onConfirmClick(input: String) { + val currentTimeMillis = System.currentTimeMillis() + //设置标题和时间 + inspectNameView.text = input + val completeDate = TimeOrDateUtil.timestampToCompleteDate(currentTimeMillis) + inspectTimeView.text = completeDate + + model = NewInspectionModel( + currentTimeMillis.id(), input, completeDate, + "", TimeOrDateUtil.timestampToDate(currentTimeMillis), + 0.0, 0.0, 0.0, 0.0, + "", resources.getString(R.string.app_name) + ) + startInspection() + } + + override fun onCancelClick() { + finish() + } + }) + .build().show() + } else { + val currentInspection = SaveKeyValues.getValue(Constant.INSPECTION_OBJECT, "") as String + val localBean = gson.fromJson(currentInspection, InspectionLocalBean::class.java) + model = NewInspectionModel( + localBean.inspectionId, localBean.name, localBean.startTime, "", localBean.date, + localBean.startLng, localBean.startLat, 0.0, 0.0, + localBean.routes, localBean.user + ) + "欢迎回来,继续未完成巡检".show(this) + startInspection() + } + } + + /** + * 开始巡检,获取坐标 + * */ + private fun startInspection() { + aMap.addOnMyLocationChangeListener { +// Log.d(Tag, "位置信息: [${it.longitude},${it.latitude}]") + // 保存最新的一次位置,sp不支持保存double + SaveKeyValues.putValue(Constant.CURRENT_LONGITUDE, it.longitude.toString()) + SaveKeyValues.putValue(Constant.CURRENT_LATITUDE, it.latitude.toString()) + //设置起始经纬度 + if (model.startLng == 0.0 || model.startLat == 0.0) { + model.startLng = it.longitude + model.startLat = it.latitude + } + // 包装routes + if (routeList.size <= 2) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } else { + //计算上一个点和当前点的距离 + val last = routeList.size - 1 + val distance = AMapUtils.calculateLineDistance( + LatLng(routeList[last].lat, routeList[last].lng), + LatLng(it.latitude, it.longitude) + ) + if (distance >= 10) { + val route = NewRouteModel() + route.lng = it.longitude + route.lat = it.latitude + routeList.add(route) + } + } + model.routes = gson.toJson(routeList) +// Log.d(Tag, gson.toJson(routeList)) + //根据定位时间间隔不停的覆盖保存巡检记录 + SaveKeyValues.putValue(Constant.INSPECTION_OBJECT, gson.toJson(model)) + } + } + + private class WeakReferenceHandler(activity: SingleModeMapActivity) : Handler() { + private val activity: WeakReference = WeakReference(activity) + + @SuppressLint("SetTextI18n") + override fun handleMessage(msg: Message) { + val mapActivity = activity.get() ?: return + when (msg.what) { + Constant.BLUETOOTH_ON -> { + "蓝牙已开启".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_enable) + mapActivity.isBluetoothOn = true + } + Constant.BLUETOOTH_OFF -> { + "蓝牙已关闭".show(mapActivity) + mapActivity.bluetoothButton.setImageResource(R.drawable.ic_bluetooth_disabled) + mapActivity.isBluetoothOn = false + } + Constant.DISCOVERY_DEVICE -> { + val bean = msg.obj as BlueToothBean +// if (bean.bluetoothDevice.name.isDigitOnly()) { + if (mapActivity.blueToothBeans.size == 0) { + mapActivity.blueToothBeans.add(bean) + } else { + //0表示未添加到list的新设备,1表示已经扫描并添加到list的设备 + var judge = 0 + for (it in mapActivity.blueToothBeans) { + if (it.bluetoothDevice.address == bean.bluetoothDevice.address) { + judge = 1 + break + } + } + if (judge == 0) { + mapActivity.blueToothBeans.add(bean) + } + } +// } + } + Constant.DISCOVERY_OUT_TIME -> { + OtherUtils.dismissLoadingDialog() + if (mapActivity.blueToothBeans.size == 0) { + "无可用设备,请确认设备是否已经开启".show(mapActivity) + } else { + val sheetBuilder = + QMUIBottomSheet.BottomListSheetBuilder(mapActivity) + sheetBuilder.setTitle("请选择要连接的设备") + mapActivity.blueToothBeans.forEach { + sheetBuilder.addItem(it.bluetoothDevice.name) + Log.d(Tag, it.bluetoothDevice.name) + } + sheetBuilder.setGravityCenter(true).setAddCancelBtn(true) + .setOnSheetItemClickListener { dialog, _, position, _ -> + dialog.dismiss() + //连接点击的设备 + mapActivity.startConnectDevice( + mapActivity.blueToothBeans[position].bluetoothDevice + ) + }.build().show() + } + } + Constant.CONNECT_SUCCESS -> { + OtherUtils.dismissLoadingDialog() + mapActivity.curConnectState = true + BLEManager.sendCommand(Constant.ASK_DEV_CODE_COMMAND) + } + Constant.CONNECT_FAILURE -> { + mapActivity.curConnectState = false + } + Constant.SEND_SUCCESS -> { + val sendSuccess = msg.obj as ByteArray + Log.d(Tag, "发送成功->sendSuccessBuffer: ${sendSuccess.toList()}") + } + Constant.SEND_FAILURE -> { + val sendFail = msg.obj as ByteArray + Log.d(Tag, "发送失败->sendFailBuffer: ${sendFail.toList()}") + } + Constant.RECEIVE_SUCCESS -> { + //TODO 接收成功 + val receiveByteArray = msg.obj as ByteArray + //根据返回值标头判断是设备编号还是数据值 + val firstByte = receiveByteArray[0] + if (firstByte == 0xAA.toByte()) { + //解析测量数据 +// Log.d(Tag, "实际数据: ${receiveByteArray.toList()}") + if (receiveByteArray.size == 14) { + val dataHexString = receiveByteArray.toHexString() +// Log.d(Tag, "十六进制: $dataHexString") + val dataModel = dataHexString.toDataModel() +// Log.d(Tag, "数据模型: ${Gson().toJson(dataModel)}") + mapActivity.currentValueView.text = dataModel.potency.toString() + mapActivity.settingsValueView.text = dataModel.alarmValue.toString() + mapActivity.maxValueView.text = dataModel.maxPotency.toString() + //判断是否需要报警 + if (mapActivity.isOpenWarning) { + if (dataModel.potency >= dataModel.alarmValue) { + //当前值大于设置值,需要报警 + OtherUtils.playSound(mapActivity, R.raw.alarm) + mapActivity.vibrator.vibrate(1000) + if (mapActivity.isAutoRecord) { + //如果连续超过10个报警,自动生成报警事件 + mapActivity.alarmCount++ + if (mapActivity.alarmCount >= 10) { + mapActivity.generateAlarmTask(dataModel.maxPotency) + } + } + } else { + //当测量值小于设置值,报警还未结束,需要停止响铃 + OtherUtils.playSound(mapActivity, 0) + } + } else { + Log.d(Tag, "报警开关未打开,不处理") + } + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else if (firstByte == 51.toByte()) { + //解析deviceCode + //51, 51, 50, 48, 50, 49, 48, 49, 48, 48, 48, 51, 13, 10, -86, 0, 0, 0, 0, 0 + if (receiveByteArray.size >= 12) { + mapActivity.deviceStatusView.text = + "设备编号: ${receiveByteArray.toDeviceCode()}" + BLEManager.sendCommand(Constant.OPEN_TRANSFER_COMMAND) + } else { + Log.d(Tag, "设备返回值长度异常,无法解析") + } + } else { + Log.d(Tag, "未知返回值,无法解析") + } + } + Constant.RECEIVE_FAILURE -> { + val receiveString = msg.obj as String + Log.d(Tag, "接收失败->receiveString: $receiveString") + } + Constant.DISCONNECT_SUCCESS -> { + mapActivity.curConnectState = false + } + } + } + } + + private fun startConnectDevice(device: BluetoothDevice) { + this.currentDevice = device + if (!curConnectState) { + OtherUtils.showLoadingDialog(this, "正在连接[${currentDevice!!.name}]...") + BLEManager.connectBleDevice( + this, currentDevice!!, 10000, + Constant.SERVICE_UUID, + Constant.READ_CHARACTERISTIC_UUID, + Constant.WRITE_CHARACTERISTIC_UUID, + onBleConnectListener + ) + } + } + + private val onBleConnectListener = object : OnBleConnectListener { + override fun onConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onConnectSuccess(bluetoothGatt: BluetoothGatt?, status: Int) { + + } + + override fun onConnectFailure( + bluetoothGatt: BluetoothGatt?, exception: String?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onDisConnecting(bluetoothGatt: BluetoothGatt?) { + + } + + override fun onDisConnectSuccess( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.DISCONNECT_SUCCESS + message.obj = status + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoverySucceed( + bluetoothGatt: BluetoothGatt?, status: Int + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_SUCCESS + weakReferenceHandler.sendMessage(message) + } + + override fun onServiceDiscoveryFailed( + bluetoothGatt: BluetoothGatt?, msg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.CONNECT_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveMessage( + bluetoothGatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_SUCCESS + message.obj = characteristic!!.value + weakReferenceHandler.sendMessage(message) + } + + override fun onReceiveError(errorMsg: String?) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.RECEIVE_FAILURE + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteSuccess( + bluetoothGatt: BluetoothGatt?, msg: ByteArray? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_SUCCESS + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onWriteFailure( + bluetoothGatt: BluetoothGatt?, msg: ByteArray?, errorMsg: String? + ) { + val message = weakReferenceHandler.obtainMessage() + message.what = Constant.SEND_FAILURE + message.obj = msg + weakReferenceHandler.sendMessage(message) + } + + override fun onReadRssi(bluetoothGatt: BluetoothGatt?, rssi: Int, status: Int) { + + } + } + + //生成报警事件 + private fun generateAlarmTask(maxValue: Int) { + if (isGeneratingTask) { + return + } + isGeneratingTask = true + + this.taskId = "t".id() + val currentLng = SaveKeyValues.getValue(Constant.CURRENT_LONGITUDE, "0.0") as String + val currentLat = SaveKeyValues.getValue(Constant.CURRENT_LATITUDE, "0.0") as String + + DataBaseManager.instance.insertEventData( + NewTaskEventModel( + taskId = taskId, + inspectionId = model.id, + name = model.name, + createTime = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()), + type = "报警事件", + lng = currentLng.toDouble(), + lat = currentLat.toDouble(), + data = maxValue.toDouble(), + images = "", + description = "自动报警记录", + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = taskId, isInspection = false)) { + "保存成功".show(this) + isGeneratingTask = false + alarmCount = 0 + } + } + + /***以下是地图生命周期管理************************************************************************/ + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } + + override fun onDestroy() { + super.onDestroy() + BLEManager.disConnectDevice() + mapView.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt new file mode 100644 index 0000000..e00d0dd --- /dev/null +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeNewEventActivity.kt @@ -0,0 +1,193 @@ +package com.casic.birmm.inspect.view + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.core.content.ContextCompat +import com.aihook.alertview.library.AlertView +import com.casic.birmm.inspect.R +import com.casic.birmm.inspect.adapter.ImageGridViewAdapter +import com.casic.birmm.inspect.base.BaseSingleModeActivity +import com.casic.birmm.inspect.extensions.filterString +import com.casic.birmm.inspect.extensions.id +import com.casic.birmm.inspect.extensions.reformat +import com.casic.birmm.inspect.extensions.show +import com.casic.birmm.inspect.model.NewTaskEventModel +import com.casic.birmm.inspect.utils.* +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.PictureSelector +import com.luck.picture.lib.config.PictureConfig +import com.luck.picture.lib.config.PictureMimeType +import kotlinx.android.synthetic.main.activity_new_event.* +import kotlinx.android.synthetic.main.include_base_title.* + + +class SingleModeNewEventActivity : BaseSingleModeActivity() { + + companion object { + private const val Tag = "SingleModeNewEvent" + } + + private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var isWarning: Boolean = true + private var longitude: Double = 0.0 + private var latitude: Double = 0.0 + private var data = -1.0//泄露默认值 + private lateinit var inspectionId: String + private lateinit var inspectionName: String + private lateinit var type: String + private lateinit var imageAdapter: ImageGridViewAdapter + private lateinit var taskId: String + + override fun initLayoutView(): Int = R.layout.activity_new_event + + override fun setupTopBarLayout() { + PageNavigationManager.addActivity(this) + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + override fun initData(savedInstanceState: Bundle?) { + isWarning = intent.getBooleanExtra("isWarning", true) + inspectionId = intent.getStringExtra("inspectionId")!! + inspectionName = intent.getStringExtra("inspectionName")!! + longitude = intent.getDoubleExtra("longitude", 0.0) + latitude = intent.getDoubleExtra("latitude", 0.0) + if (isWarning) { + titleView.text = "报警事件记录(单机模式)" + inspectCardView.visibility = View.VISIBLE + } else { + titleView.text = "自定义事件记录(单机模式)" + inspectCardView.visibility = View.GONE + } + eventCreateTimeView.text = + TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + + //初始化图片九宫格 + imageAdapter = ImageGridViewAdapter(this) + imageGridView.adapter = imageAdapter + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + + addImageView.setOnClickListener { + AlertView( + "请选择图片来源", null, "取消", null, arrayOf("拍照", "相册"), + this, AlertView.Style.ActionSheet + ) { _, position -> + when (position) { + 0 -> { + PictureSelector.create(this) + .openCamera(PictureMimeType.ofImage()) + .isCompress(true) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .forResult(PictureConfig.REQUEST_CAMERA) + } + 1 -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage()) + .isWeChatStyle(true) + .isCamera(false) + .isCompress(true) + .compressSavePath(FileUtils.imageCompressPath) + .imageEngine(GlideLoadEngine.createGlideEngine()) + .maxSelectNum(3) + .forResult(PictureConfig.CHOOSE_REQUEST) + } + } + }.setCancelable(true).show() + } + + addEventButton.setChangeAlphaWhenPress(true) + addEventButton.setOnClickListener { + this.taskId = "t".id() + if (eventEditTextView.text.toString().filterString().isEmpty()) { + "事件情况说明还未填写,请检查".show(this) + return@setOnClickListener + } + if (isWarning) { + if (inspectNumberView.text.toString().filterString().isEmpty()) { + "最大泄露值还未填写,请检查".show(this) + return@setOnClickListener + } + type = "报警事件" + data = inspectNumberView.text.toString().filterString().toDouble() + } else { + type = "自定义事件" + } + DataBaseManager.instance.insertEventData( + NewTaskEventModel( + taskId = taskId, + inspectionId = inspectionId, + name = inspectionName, + createTime = eventCreateTimeView.text.toString(), + type = type, + lng = longitude, + lat = latitude, + data = data, + images = realPaths.reformat(), + description = eventEditTextView.text.toString().filterString(), + user = resources.getString(R.string.app_name) + ) + ) + if (DataBaseManager.instance.isInsertSuccess(id = taskId, isInspection = false)) { + "保存成功".show(this) + finish() + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == Activity.RESULT_OK) { + when (requestCode) { + PictureConfig.CHOOSE_REQUEST -> { + val selectResult = PictureSelector.obtainMultipleResult(data) + for (res in selectResult) { + realPaths.add(res.compressPath) + } + } + PictureConfig.REQUEST_CAMERA -> { + val cameraResult = PictureSelector.obtainMultipleResult(data)[0] + realPaths.add(cameraResult.compressPath) + } + } + showSelectedPicture() + } + } + + private fun showSelectedPicture() { + /** + * 显示图片 + * path: /storage/emulated/0/Android/data/com.casic.birmm.inspect/files/Pictures/IMG_CMP_53734632.jpeg + * */ + imageGridView.visibility = View.VISIBLE + val sumItemCount: Int = imageAdapter.count + 1 //每上传一张图片,图片总数都是在原有的基础上+1 + if (sumItemCount <= 3) { + if (realPaths.size == 3) { + addImageView.visibility = View.GONE + } + imageAdapter.setImageList(imageUrls = realPaths) + imageGridView.setOnItemClickListener { _, _, position, _ -> + OtherUtils.showBigImage(this, position, realPaths) + } + //删除按钮点击事件 + imageAdapter.setOnDeleteClickListener(object : + ImageGridViewAdapter.OnDeleteItemClickListener { + @Override + override fun onDeleteItemClick(position: Int) { + realPaths.removeAt(position) + imageAdapter.setImageList(imageUrls = realPaths) + if (realPaths.size != 3) { + addImageView.visibility = View.VISIBLE + } + } + }) + } else { + "最多只能选择3张图片".show(this) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt index 6dafd7f..5fa5a60 100644 --- a/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt +++ b/app/src/main/java/com/casic/birmm/inspect/view/SingleModeUserSettingsActivity.kt @@ -2,11 +2,12 @@ import android.content.Context import android.content.Intent +import android.os.Bundle import android.os.Vibrator import androidx.core.content.ContextCompat import com.casic.birmm.inspect.BuildConfig import com.casic.birmm.inspect.R -import com.casic.birmm.inspect.base.BaseActivity +import com.casic.birmm.inspect.base.BaseSingleModeActivity import com.casic.birmm.inspect.extensions.show import com.casic.birmm.inspect.utils.* import com.gyf.immersionbar.ImmersionBar @@ -17,7 +18,7 @@ import kotlinx.android.synthetic.main.include_base_title.* -class SingleModeUserSettingsActivity : BaseActivity() { +class SingleModeUserSettingsActivity : BaseSingleModeActivity() { private lateinit var vibrator: Vibrator @@ -27,10 +28,10 @@ PageNavigationManager.addActivity(this) StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) ImmersionBar.with(this).statusBarDarkFont(false).init() - titleView.text = "系统设置" + titleView.text = "系统设置(单机模式)" } - override fun initData() { + override fun initData(savedInstanceState: Bundle?) { val isOpen = SaveKeyValues.getValue(Constant.OPEN_WARNING, false) as Boolean warningSwitch.isChecked = isOpen val isRecord = SaveKeyValues.getValue(Constant.AUTO_RECORD, false) as Boolean diff --git a/app/src/main/res/layout/activity_query_inspect.xml b/app/src/main/res/layout/activity_query_inspect.xml index 945dfb6..b43a377 100644 --- a/app/src/main/res/layout/activity_query_inspect.xml +++ b/app/src/main/res/layout/activity_query_inspect.xml @@ -105,6 +105,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" + android:hint="请输入想要查询的巡检标签" android:paddingHorizontal="5dp" android:paddingVertical="7dp" android:textColor="@color/black"