diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt new file mode 100644 index 0000000..5c99522 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt @@ -0,0 +1,38 @@ +package com.casic.br.operationsite.utils + +import android.content.Context +import android.util.Log +import com.amap.api.location.AMapLocation +import com.amap.api.location.AMapLocationClient +import com.amap.api.location.AMapLocationClientOption + +object LocationHelper { + private const val kTag = "LocationHelper" + + fun obtainCurrentLocation(context: Context, listener: ILocationListener) { + val locationClient = AMapLocationClient(context) + val locationOption = AMapLocationClientOption() + //设置定位模式为高精度模式,AMapLocationMode.Battery_Saving为低功耗模式,AMapLocationMode.Device_Sensors是仅设备模式 + locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy + locationOption.isNeedAddress = true //设置是否返回地址信息(默认返回地址信息) + locationOption.isOnceLocation = true //仅定位一次 + //给定位客户端对象设置定位参数 + locationClient.setLocationOption(locationOption) + locationClient.setLocationListener { + if (it.errorCode == 0) { + listener.onAMapLocationGet(it) + } else { + listener.onAMapLocationGet(null) + //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 + Log.e( + kTag, "location Error, ErrCode: ${it.errorCode} , errInfo: ${it.errorInfo}" + ) + } + } + locationClient.startLocation() + } + + interface ILocationListener { + fun onAMapLocationGet(aMapLocation: AMapLocation?) //高德定位数据 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt new file mode 100644 index 0000000..5c99522 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt @@ -0,0 +1,38 @@ +package com.casic.br.operationsite.utils + +import android.content.Context +import android.util.Log +import com.amap.api.location.AMapLocation +import com.amap.api.location.AMapLocationClient +import com.amap.api.location.AMapLocationClientOption + +object LocationHelper { + private const val kTag = "LocationHelper" + + fun obtainCurrentLocation(context: Context, listener: ILocationListener) { + val locationClient = AMapLocationClient(context) + val locationOption = AMapLocationClientOption() + //设置定位模式为高精度模式,AMapLocationMode.Battery_Saving为低功耗模式,AMapLocationMode.Device_Sensors是仅设备模式 + locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy + locationOption.isNeedAddress = true //设置是否返回地址信息(默认返回地址信息) + locationOption.isOnceLocation = true //仅定位一次 + //给定位客户端对象设置定位参数 + locationClient.setLocationOption(locationOption) + locationClient.setLocationListener { + if (it.errorCode == 0) { + listener.onAMapLocationGet(it) + } else { + listener.onAMapLocationGet(null) + //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 + Log.e( + kTag, "location Error, ErrCode: ${it.errorCode} , errInfo: ${it.errorInfo}" + ) + } + } + locationClient.startLocation() + } + + interface ILocationListener { + fun onAMapLocationGet(aMapLocation: AMapLocation?) //高德定位数据 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt index d84692e..e872af1 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt @@ -10,13 +10,21 @@ import android.view.View import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import com.amap.api.location.AMapLocation import com.casic.br.operationsite.R import com.casic.br.operationsite.callback.OnImageCompressListener import com.casic.br.operationsite.extensions.combineImagePath import com.casic.br.operationsite.extensions.compressImage +import com.casic.br.operationsite.extensions.reformat +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.utils.DialogHelper import com.casic.br.operationsite.utils.GlideLoadEngine +import com.casic.br.operationsite.utils.LocaleConstant +import com.casic.br.operationsite.utils.LocationHelper +import com.casic.br.operationsite.vm.EventViewModel import com.casic.br.operationsite.vm.UploadFileViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.gyf.immersionbar.ImmersionBar import com.luck.picture.lib.basic.PictureSelector import com.luck.picture.lib.config.SelectMimeType @@ -24,11 +32,11 @@ import com.luck.picture.lib.interfaces.OnResultCallbackListener import com.pengxh.kt.lite.adapter.EditableImageAdapter import com.pengxh.kt.lite.base.KotlinBaseActivity -import com.pengxh.kt.lite.extensions.convertColor -import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.extensions.* import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.dialog.BottomActionSheet import kotlinx.android.synthetic.main.activity_upload_activity.* import kotlinx.android.synthetic.main.include_base_title.* @@ -40,9 +48,11 @@ private lateinit var imageAdapter: EditableImageAdapter private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var uploadFileViewModel: UploadFileViewModel + private lateinit var eventViewModel: EventViewModel private val context: Context = this@UploadEventActivity private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var mapLocation: AMapLocation? = null override fun initLayoutView(): Int = R.layout.activity_upload_activity @@ -55,16 +65,33 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDetail = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + uploadPersonView.text = userDetail.name + personNumberView.text = userDetail.phone + } + + weakReferenceHandler = WeakReferenceHandler(callback) uploadFileViewModel = ViewModelProvider(this).get(UploadFileViewModel::class.java) + eventViewModel = ViewModelProvider(this).get(EventViewModel::class.java) imageAdapter = EditableImageAdapter(this, 3) addImageRecyclerView.layoutManager = GridLayoutManager(this, 3) addImageRecyclerView.adapter = imageAdapter } + override fun onResume() { + obtainCurrentLocation() + super.onResume() + } + override fun initEvent() { + locationImageView.setOnClickListener { obtainCurrentLocation() } + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { override fun onAddImageClick() { selectPicture() @@ -125,8 +152,44 @@ }) uploadEventButton.setOnClickListener { + if (eventNameView.text.isNullOrBlank()) { + "请输入事件名称".show(this) + return@setOnClickListener + } + if (siteEditView.text.isNullOrBlank()) { + "请输入事件简要描述".show(this) + return@setOnClickListener + } + + eventViewModel.addEvent( + eventNameView.text.toString(), + uploadPersonView.text.toString(), + personNumberView.text.toString(), + siteEditView.text.toString(), + imagePaths.reformat(), + mapLocation?.longitude.toString(), + mapLocation?.latitude.toString(), + System.currentTimeMillis().timestampToCompleteDate() + ) } + + eventViewModel.resultModel.observe(this, { + if (it.code == 200) { + finish() + } + }) + + eventViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "事件提交中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } private fun selectPicture() { @@ -207,6 +270,22 @@ true } + private fun obtainCurrentLocation() { + eventLocationView.text = "定位中..." + LocationHelper.obtainCurrentLocation(this, object : LocationHelper.ILocationListener { + override fun onAMapLocationGet(aMapLocation: AMapLocation?) { + if (aMapLocation == null) { + eventLocationView.text = "定位失败" + eventLocationView.setTextColor(R.color.redTextColor.convertColor(context)) + } else { + mapLocation = aMapLocation + eventLocationView.text = aMapLocation.address + eventLocationView.setTextColor(R.color.subTextColor.convertColor(context)) + } + } + }) + } + private fun analyticalSelectResults(result: LocalMedia) { //压缩图片 // val realPath = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { @@ -230,20 +309,4 @@ } }) } - -// private lateinit var loadingDialog: QMUITipDialog -// -// private fun showLoadingDialog(context: Context?, message: String?) { -// loadingDialog = QMUITipDialog.Builder(context) -// .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) -// .setTipWord(message) -// .create() -// loadingDialog.show() -// } -// -// private fun dismissLoadingDialog() { -// if (loadingDialog.isShowing) { -// loadingDialog.dismiss() -// } -// } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt new file mode 100644 index 0000000..5c99522 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt @@ -0,0 +1,38 @@ +package com.casic.br.operationsite.utils + +import android.content.Context +import android.util.Log +import com.amap.api.location.AMapLocation +import com.amap.api.location.AMapLocationClient +import com.amap.api.location.AMapLocationClientOption + +object LocationHelper { + private const val kTag = "LocationHelper" + + fun obtainCurrentLocation(context: Context, listener: ILocationListener) { + val locationClient = AMapLocationClient(context) + val locationOption = AMapLocationClientOption() + //设置定位模式为高精度模式,AMapLocationMode.Battery_Saving为低功耗模式,AMapLocationMode.Device_Sensors是仅设备模式 + locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy + locationOption.isNeedAddress = true //设置是否返回地址信息(默认返回地址信息) + locationOption.isOnceLocation = true //仅定位一次 + //给定位客户端对象设置定位参数 + locationClient.setLocationOption(locationOption) + locationClient.setLocationListener { + if (it.errorCode == 0) { + listener.onAMapLocationGet(it) + } else { + listener.onAMapLocationGet(null) + //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 + Log.e( + kTag, "location Error, ErrCode: ${it.errorCode} , errInfo: ${it.errorInfo}" + ) + } + } + locationClient.startLocation() + } + + interface ILocationListener { + fun onAMapLocationGet(aMapLocation: AMapLocation?) //高德定位数据 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt index d84692e..e872af1 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt @@ -10,13 +10,21 @@ import android.view.View import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import com.amap.api.location.AMapLocation import com.casic.br.operationsite.R import com.casic.br.operationsite.callback.OnImageCompressListener import com.casic.br.operationsite.extensions.combineImagePath import com.casic.br.operationsite.extensions.compressImage +import com.casic.br.operationsite.extensions.reformat +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.utils.DialogHelper import com.casic.br.operationsite.utils.GlideLoadEngine +import com.casic.br.operationsite.utils.LocaleConstant +import com.casic.br.operationsite.utils.LocationHelper +import com.casic.br.operationsite.vm.EventViewModel import com.casic.br.operationsite.vm.UploadFileViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.gyf.immersionbar.ImmersionBar import com.luck.picture.lib.basic.PictureSelector import com.luck.picture.lib.config.SelectMimeType @@ -24,11 +32,11 @@ import com.luck.picture.lib.interfaces.OnResultCallbackListener import com.pengxh.kt.lite.adapter.EditableImageAdapter import com.pengxh.kt.lite.base.KotlinBaseActivity -import com.pengxh.kt.lite.extensions.convertColor -import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.extensions.* import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.dialog.BottomActionSheet import kotlinx.android.synthetic.main.activity_upload_activity.* import kotlinx.android.synthetic.main.include_base_title.* @@ -40,9 +48,11 @@ private lateinit var imageAdapter: EditableImageAdapter private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var uploadFileViewModel: UploadFileViewModel + private lateinit var eventViewModel: EventViewModel private val context: Context = this@UploadEventActivity private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var mapLocation: AMapLocation? = null override fun initLayoutView(): Int = R.layout.activity_upload_activity @@ -55,16 +65,33 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDetail = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + uploadPersonView.text = userDetail.name + personNumberView.text = userDetail.phone + } + + weakReferenceHandler = WeakReferenceHandler(callback) uploadFileViewModel = ViewModelProvider(this).get(UploadFileViewModel::class.java) + eventViewModel = ViewModelProvider(this).get(EventViewModel::class.java) imageAdapter = EditableImageAdapter(this, 3) addImageRecyclerView.layoutManager = GridLayoutManager(this, 3) addImageRecyclerView.adapter = imageAdapter } + override fun onResume() { + obtainCurrentLocation() + super.onResume() + } + override fun initEvent() { + locationImageView.setOnClickListener { obtainCurrentLocation() } + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { override fun onAddImageClick() { selectPicture() @@ -125,8 +152,44 @@ }) uploadEventButton.setOnClickListener { + if (eventNameView.text.isNullOrBlank()) { + "请输入事件名称".show(this) + return@setOnClickListener + } + if (siteEditView.text.isNullOrBlank()) { + "请输入事件简要描述".show(this) + return@setOnClickListener + } + + eventViewModel.addEvent( + eventNameView.text.toString(), + uploadPersonView.text.toString(), + personNumberView.text.toString(), + siteEditView.text.toString(), + imagePaths.reformat(), + mapLocation?.longitude.toString(), + mapLocation?.latitude.toString(), + System.currentTimeMillis().timestampToCompleteDate() + ) } + + eventViewModel.resultModel.observe(this, { + if (it.code == 200) { + finish() + } + }) + + eventViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "事件提交中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } private fun selectPicture() { @@ -207,6 +270,22 @@ true } + private fun obtainCurrentLocation() { + eventLocationView.text = "定位中..." + LocationHelper.obtainCurrentLocation(this, object : LocationHelper.ILocationListener { + override fun onAMapLocationGet(aMapLocation: AMapLocation?) { + if (aMapLocation == null) { + eventLocationView.text = "定位失败" + eventLocationView.setTextColor(R.color.redTextColor.convertColor(context)) + } else { + mapLocation = aMapLocation + eventLocationView.text = aMapLocation.address + eventLocationView.setTextColor(R.color.subTextColor.convertColor(context)) + } + } + }) + } + private fun analyticalSelectResults(result: LocalMedia) { //压缩图片 // val realPath = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { @@ -230,20 +309,4 @@ } }) } - -// private lateinit var loadingDialog: QMUITipDialog -// -// private fun showLoadingDialog(context: Context?, message: String?) { -// loadingDialog = QMUITipDialog.Builder(context) -// .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) -// .setTipWord(message) -// .create() -// loadingDialog.show() -// } -// -// private fun dismissLoadingDialog() { -// if (loadingDialog.isShowing) { -// loadingDialog.dismiss() -// } -// } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index b1daa34..59ed628 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -167,6 +167,13 @@ applyTextView.setOnClickListener { navigatePageTo() } + + /** + * TODO + * */ + warningTagView.setOnClickListener { + "需求不明,待完善".show(this) + } } /**地图相关*********/ diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt new file mode 100644 index 0000000..5c99522 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt @@ -0,0 +1,38 @@ +package com.casic.br.operationsite.utils + +import android.content.Context +import android.util.Log +import com.amap.api.location.AMapLocation +import com.amap.api.location.AMapLocationClient +import com.amap.api.location.AMapLocationClientOption + +object LocationHelper { + private const val kTag = "LocationHelper" + + fun obtainCurrentLocation(context: Context, listener: ILocationListener) { + val locationClient = AMapLocationClient(context) + val locationOption = AMapLocationClientOption() + //设置定位模式为高精度模式,AMapLocationMode.Battery_Saving为低功耗模式,AMapLocationMode.Device_Sensors是仅设备模式 + locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy + locationOption.isNeedAddress = true //设置是否返回地址信息(默认返回地址信息) + locationOption.isOnceLocation = true //仅定位一次 + //给定位客户端对象设置定位参数 + locationClient.setLocationOption(locationOption) + locationClient.setLocationListener { + if (it.errorCode == 0) { + listener.onAMapLocationGet(it) + } else { + listener.onAMapLocationGet(null) + //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 + Log.e( + kTag, "location Error, ErrCode: ${it.errorCode} , errInfo: ${it.errorInfo}" + ) + } + } + locationClient.startLocation() + } + + interface ILocationListener { + fun onAMapLocationGet(aMapLocation: AMapLocation?) //高德定位数据 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt index d84692e..e872af1 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt @@ -10,13 +10,21 @@ import android.view.View import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import com.amap.api.location.AMapLocation import com.casic.br.operationsite.R import com.casic.br.operationsite.callback.OnImageCompressListener import com.casic.br.operationsite.extensions.combineImagePath import com.casic.br.operationsite.extensions.compressImage +import com.casic.br.operationsite.extensions.reformat +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.utils.DialogHelper import com.casic.br.operationsite.utils.GlideLoadEngine +import com.casic.br.operationsite.utils.LocaleConstant +import com.casic.br.operationsite.utils.LocationHelper +import com.casic.br.operationsite.vm.EventViewModel import com.casic.br.operationsite.vm.UploadFileViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.gyf.immersionbar.ImmersionBar import com.luck.picture.lib.basic.PictureSelector import com.luck.picture.lib.config.SelectMimeType @@ -24,11 +32,11 @@ import com.luck.picture.lib.interfaces.OnResultCallbackListener import com.pengxh.kt.lite.adapter.EditableImageAdapter import com.pengxh.kt.lite.base.KotlinBaseActivity -import com.pengxh.kt.lite.extensions.convertColor -import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.extensions.* import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.dialog.BottomActionSheet import kotlinx.android.synthetic.main.activity_upload_activity.* import kotlinx.android.synthetic.main.include_base_title.* @@ -40,9 +48,11 @@ private lateinit var imageAdapter: EditableImageAdapter private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var uploadFileViewModel: UploadFileViewModel + private lateinit var eventViewModel: EventViewModel private val context: Context = this@UploadEventActivity private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var mapLocation: AMapLocation? = null override fun initLayoutView(): Int = R.layout.activity_upload_activity @@ -55,16 +65,33 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDetail = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + uploadPersonView.text = userDetail.name + personNumberView.text = userDetail.phone + } + + weakReferenceHandler = WeakReferenceHandler(callback) uploadFileViewModel = ViewModelProvider(this).get(UploadFileViewModel::class.java) + eventViewModel = ViewModelProvider(this).get(EventViewModel::class.java) imageAdapter = EditableImageAdapter(this, 3) addImageRecyclerView.layoutManager = GridLayoutManager(this, 3) addImageRecyclerView.adapter = imageAdapter } + override fun onResume() { + obtainCurrentLocation() + super.onResume() + } + override fun initEvent() { + locationImageView.setOnClickListener { obtainCurrentLocation() } + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { override fun onAddImageClick() { selectPicture() @@ -125,8 +152,44 @@ }) uploadEventButton.setOnClickListener { + if (eventNameView.text.isNullOrBlank()) { + "请输入事件名称".show(this) + return@setOnClickListener + } + if (siteEditView.text.isNullOrBlank()) { + "请输入事件简要描述".show(this) + return@setOnClickListener + } + + eventViewModel.addEvent( + eventNameView.text.toString(), + uploadPersonView.text.toString(), + personNumberView.text.toString(), + siteEditView.text.toString(), + imagePaths.reformat(), + mapLocation?.longitude.toString(), + mapLocation?.latitude.toString(), + System.currentTimeMillis().timestampToCompleteDate() + ) } + + eventViewModel.resultModel.observe(this, { + if (it.code == 200) { + finish() + } + }) + + eventViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "事件提交中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } private fun selectPicture() { @@ -207,6 +270,22 @@ true } + private fun obtainCurrentLocation() { + eventLocationView.text = "定位中..." + LocationHelper.obtainCurrentLocation(this, object : LocationHelper.ILocationListener { + override fun onAMapLocationGet(aMapLocation: AMapLocation?) { + if (aMapLocation == null) { + eventLocationView.text = "定位失败" + eventLocationView.setTextColor(R.color.redTextColor.convertColor(context)) + } else { + mapLocation = aMapLocation + eventLocationView.text = aMapLocation.address + eventLocationView.setTextColor(R.color.subTextColor.convertColor(context)) + } + } + }) + } + private fun analyticalSelectResults(result: LocalMedia) { //压缩图片 // val realPath = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { @@ -230,20 +309,4 @@ } }) } - -// private lateinit var loadingDialog: QMUITipDialog -// -// private fun showLoadingDialog(context: Context?, message: String?) { -// loadingDialog = QMUITipDialog.Builder(context) -// .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) -// .setTipWord(message) -// .create() -// loadingDialog.show() -// } -// -// private fun dismissLoadingDialog() { -// if (loadingDialog.isShowing) { -// loadingDialog.dismiss() -// } -// } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index b1daa34..59ed628 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -167,6 +167,13 @@ applyTextView.setOnClickListener { navigatePageTo() } + + /** + * TODO + * */ + warningTagView.setOnClickListener { + "需求不明,待完善".show(this) + } } /**地图相关*********/ diff --git a/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt new file mode 100644 index 0000000..cf311f5 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt @@ -0,0 +1,43 @@ +package com.casic.br.operationsite.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.extensions.separateResponseCode +import com.casic.br.operationsite.extensions.toErrorMessage +import com.casic.br.operationsite.model.CommonResultModel +import com.casic.br.operationsite.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState + +class EventViewModel : BaseViewModel() { + private val gson = Gson() + val resultModel = MutableLiveData() + + fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.addEvent( + eventTitle, uploadName, phoneNumber, eventDescription, + eventImage, lng, lat, createTime + ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + loadState.value = LoadState.Fail + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt new file mode 100644 index 0000000..5c99522 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt @@ -0,0 +1,38 @@ +package com.casic.br.operationsite.utils + +import android.content.Context +import android.util.Log +import com.amap.api.location.AMapLocation +import com.amap.api.location.AMapLocationClient +import com.amap.api.location.AMapLocationClientOption + +object LocationHelper { + private const val kTag = "LocationHelper" + + fun obtainCurrentLocation(context: Context, listener: ILocationListener) { + val locationClient = AMapLocationClient(context) + val locationOption = AMapLocationClientOption() + //设置定位模式为高精度模式,AMapLocationMode.Battery_Saving为低功耗模式,AMapLocationMode.Device_Sensors是仅设备模式 + locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy + locationOption.isNeedAddress = true //设置是否返回地址信息(默认返回地址信息) + locationOption.isOnceLocation = true //仅定位一次 + //给定位客户端对象设置定位参数 + locationClient.setLocationOption(locationOption) + locationClient.setLocationListener { + if (it.errorCode == 0) { + listener.onAMapLocationGet(it) + } else { + listener.onAMapLocationGet(null) + //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 + Log.e( + kTag, "location Error, ErrCode: ${it.errorCode} , errInfo: ${it.errorInfo}" + ) + } + } + locationClient.startLocation() + } + + interface ILocationListener { + fun onAMapLocationGet(aMapLocation: AMapLocation?) //高德定位数据 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt index d84692e..e872af1 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt @@ -10,13 +10,21 @@ import android.view.View import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import com.amap.api.location.AMapLocation import com.casic.br.operationsite.R import com.casic.br.operationsite.callback.OnImageCompressListener import com.casic.br.operationsite.extensions.combineImagePath import com.casic.br.operationsite.extensions.compressImage +import com.casic.br.operationsite.extensions.reformat +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.utils.DialogHelper import com.casic.br.operationsite.utils.GlideLoadEngine +import com.casic.br.operationsite.utils.LocaleConstant +import com.casic.br.operationsite.utils.LocationHelper +import com.casic.br.operationsite.vm.EventViewModel import com.casic.br.operationsite.vm.UploadFileViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.gyf.immersionbar.ImmersionBar import com.luck.picture.lib.basic.PictureSelector import com.luck.picture.lib.config.SelectMimeType @@ -24,11 +32,11 @@ import com.luck.picture.lib.interfaces.OnResultCallbackListener import com.pengxh.kt.lite.adapter.EditableImageAdapter import com.pengxh.kt.lite.base.KotlinBaseActivity -import com.pengxh.kt.lite.extensions.convertColor -import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.extensions.* import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.dialog.BottomActionSheet import kotlinx.android.synthetic.main.activity_upload_activity.* import kotlinx.android.synthetic.main.include_base_title.* @@ -40,9 +48,11 @@ private lateinit var imageAdapter: EditableImageAdapter private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var uploadFileViewModel: UploadFileViewModel + private lateinit var eventViewModel: EventViewModel private val context: Context = this@UploadEventActivity private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var mapLocation: AMapLocation? = null override fun initLayoutView(): Int = R.layout.activity_upload_activity @@ -55,16 +65,33 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDetail = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + uploadPersonView.text = userDetail.name + personNumberView.text = userDetail.phone + } + + weakReferenceHandler = WeakReferenceHandler(callback) uploadFileViewModel = ViewModelProvider(this).get(UploadFileViewModel::class.java) + eventViewModel = ViewModelProvider(this).get(EventViewModel::class.java) imageAdapter = EditableImageAdapter(this, 3) addImageRecyclerView.layoutManager = GridLayoutManager(this, 3) addImageRecyclerView.adapter = imageAdapter } + override fun onResume() { + obtainCurrentLocation() + super.onResume() + } + override fun initEvent() { + locationImageView.setOnClickListener { obtainCurrentLocation() } + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { override fun onAddImageClick() { selectPicture() @@ -125,8 +152,44 @@ }) uploadEventButton.setOnClickListener { + if (eventNameView.text.isNullOrBlank()) { + "请输入事件名称".show(this) + return@setOnClickListener + } + if (siteEditView.text.isNullOrBlank()) { + "请输入事件简要描述".show(this) + return@setOnClickListener + } + + eventViewModel.addEvent( + eventNameView.text.toString(), + uploadPersonView.text.toString(), + personNumberView.text.toString(), + siteEditView.text.toString(), + imagePaths.reformat(), + mapLocation?.longitude.toString(), + mapLocation?.latitude.toString(), + System.currentTimeMillis().timestampToCompleteDate() + ) } + + eventViewModel.resultModel.observe(this, { + if (it.code == 200) { + finish() + } + }) + + eventViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "事件提交中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } private fun selectPicture() { @@ -207,6 +270,22 @@ true } + private fun obtainCurrentLocation() { + eventLocationView.text = "定位中..." + LocationHelper.obtainCurrentLocation(this, object : LocationHelper.ILocationListener { + override fun onAMapLocationGet(aMapLocation: AMapLocation?) { + if (aMapLocation == null) { + eventLocationView.text = "定位失败" + eventLocationView.setTextColor(R.color.redTextColor.convertColor(context)) + } else { + mapLocation = aMapLocation + eventLocationView.text = aMapLocation.address + eventLocationView.setTextColor(R.color.subTextColor.convertColor(context)) + } + } + }) + } + private fun analyticalSelectResults(result: LocalMedia) { //压缩图片 // val realPath = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { @@ -230,20 +309,4 @@ } }) } - -// private lateinit var loadingDialog: QMUITipDialog -// -// private fun showLoadingDialog(context: Context?, message: String?) { -// loadingDialog = QMUITipDialog.Builder(context) -// .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) -// .setTipWord(message) -// .create() -// loadingDialog.show() -// } -// -// private fun dismissLoadingDialog() { -// if (loadingDialog.isShowing) { -// loadingDialog.dismiss() -// } -// } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index b1daa34..59ed628 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -167,6 +167,13 @@ applyTextView.setOnClickListener { navigatePageTo() } + + /** + * TODO + * */ + warningTagView.setOnClickListener { + "需求不明,待完善".show(this) + } } /**地图相关*********/ diff --git a/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt new file mode 100644 index 0000000..cf311f5 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt @@ -0,0 +1,43 @@ +package com.casic.br.operationsite.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.extensions.separateResponseCode +import com.casic.br.operationsite.extensions.toErrorMessage +import com.casic.br.operationsite.model.CommonResultModel +import com.casic.br.operationsite.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState + +class EventViewModel : BaseViewModel() { + private val gson = Gson() + val resultModel = MutableLiveData() + + fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.addEvent( + eventTitle, uploadName, phoneNumber, eventDescription, + eventImage, lng, lat, createTime + ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + loadState.value = LoadState.Fail + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt index cf6bd36..f5e5c7b 100644 --- a/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt @@ -2,19 +2,36 @@ import androidx.lifecycle.MutableLiveData import com.casic.br.operationsite.extensions.separateResponseCode +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.retrofit.RetrofitServiceManager +import com.casic.br.operationsite.utils.LocaleConstant +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.BaseViewModel class UserDetailViewModel : BaseViewModel() { + private val gson = Gson() + //用户信息不用现取现用,布尔值标志用户token是否失效 val flag = MutableLiveData() fun obtainUserDetail() = launch({ val response = RetrofitServiceManager.obtainUserDetail() val responseCode = response.separateResponseCode() - flag.value = responseCode == 200 + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(LocaleConstant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { + //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 + SaveKeyValues.removeKey(LocaleConstant.USER_DETAIL_MODEL) + flag.value = false + } }, { it.printStackTrace() }) diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt new file mode 100644 index 0000000..5c99522 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt @@ -0,0 +1,38 @@ +package com.casic.br.operationsite.utils + +import android.content.Context +import android.util.Log +import com.amap.api.location.AMapLocation +import com.amap.api.location.AMapLocationClient +import com.amap.api.location.AMapLocationClientOption + +object LocationHelper { + private const val kTag = "LocationHelper" + + fun obtainCurrentLocation(context: Context, listener: ILocationListener) { + val locationClient = AMapLocationClient(context) + val locationOption = AMapLocationClientOption() + //设置定位模式为高精度模式,AMapLocationMode.Battery_Saving为低功耗模式,AMapLocationMode.Device_Sensors是仅设备模式 + locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy + locationOption.isNeedAddress = true //设置是否返回地址信息(默认返回地址信息) + locationOption.isOnceLocation = true //仅定位一次 + //给定位客户端对象设置定位参数 + locationClient.setLocationOption(locationOption) + locationClient.setLocationListener { + if (it.errorCode == 0) { + listener.onAMapLocationGet(it) + } else { + listener.onAMapLocationGet(null) + //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 + Log.e( + kTag, "location Error, ErrCode: ${it.errorCode} , errInfo: ${it.errorInfo}" + ) + } + } + locationClient.startLocation() + } + + interface ILocationListener { + fun onAMapLocationGet(aMapLocation: AMapLocation?) //高德定位数据 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt index d84692e..e872af1 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt @@ -10,13 +10,21 @@ import android.view.View import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import com.amap.api.location.AMapLocation import com.casic.br.operationsite.R import com.casic.br.operationsite.callback.OnImageCompressListener import com.casic.br.operationsite.extensions.combineImagePath import com.casic.br.operationsite.extensions.compressImage +import com.casic.br.operationsite.extensions.reformat +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.utils.DialogHelper import com.casic.br.operationsite.utils.GlideLoadEngine +import com.casic.br.operationsite.utils.LocaleConstant +import com.casic.br.operationsite.utils.LocationHelper +import com.casic.br.operationsite.vm.EventViewModel import com.casic.br.operationsite.vm.UploadFileViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.gyf.immersionbar.ImmersionBar import com.luck.picture.lib.basic.PictureSelector import com.luck.picture.lib.config.SelectMimeType @@ -24,11 +32,11 @@ import com.luck.picture.lib.interfaces.OnResultCallbackListener import com.pengxh.kt.lite.adapter.EditableImageAdapter import com.pengxh.kt.lite.base.KotlinBaseActivity -import com.pengxh.kt.lite.extensions.convertColor -import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.extensions.* import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.dialog.BottomActionSheet import kotlinx.android.synthetic.main.activity_upload_activity.* import kotlinx.android.synthetic.main.include_base_title.* @@ -40,9 +48,11 @@ private lateinit var imageAdapter: EditableImageAdapter private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var uploadFileViewModel: UploadFileViewModel + private lateinit var eventViewModel: EventViewModel private val context: Context = this@UploadEventActivity private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var mapLocation: AMapLocation? = null override fun initLayoutView(): Int = R.layout.activity_upload_activity @@ -55,16 +65,33 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDetail = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + uploadPersonView.text = userDetail.name + personNumberView.text = userDetail.phone + } + + weakReferenceHandler = WeakReferenceHandler(callback) uploadFileViewModel = ViewModelProvider(this).get(UploadFileViewModel::class.java) + eventViewModel = ViewModelProvider(this).get(EventViewModel::class.java) imageAdapter = EditableImageAdapter(this, 3) addImageRecyclerView.layoutManager = GridLayoutManager(this, 3) addImageRecyclerView.adapter = imageAdapter } + override fun onResume() { + obtainCurrentLocation() + super.onResume() + } + override fun initEvent() { + locationImageView.setOnClickListener { obtainCurrentLocation() } + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { override fun onAddImageClick() { selectPicture() @@ -125,8 +152,44 @@ }) uploadEventButton.setOnClickListener { + if (eventNameView.text.isNullOrBlank()) { + "请输入事件名称".show(this) + return@setOnClickListener + } + if (siteEditView.text.isNullOrBlank()) { + "请输入事件简要描述".show(this) + return@setOnClickListener + } + + eventViewModel.addEvent( + eventNameView.text.toString(), + uploadPersonView.text.toString(), + personNumberView.text.toString(), + siteEditView.text.toString(), + imagePaths.reformat(), + mapLocation?.longitude.toString(), + mapLocation?.latitude.toString(), + System.currentTimeMillis().timestampToCompleteDate() + ) } + + eventViewModel.resultModel.observe(this, { + if (it.code == 200) { + finish() + } + }) + + eventViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "事件提交中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } private fun selectPicture() { @@ -207,6 +270,22 @@ true } + private fun obtainCurrentLocation() { + eventLocationView.text = "定位中..." + LocationHelper.obtainCurrentLocation(this, object : LocationHelper.ILocationListener { + override fun onAMapLocationGet(aMapLocation: AMapLocation?) { + if (aMapLocation == null) { + eventLocationView.text = "定位失败" + eventLocationView.setTextColor(R.color.redTextColor.convertColor(context)) + } else { + mapLocation = aMapLocation + eventLocationView.text = aMapLocation.address + eventLocationView.setTextColor(R.color.subTextColor.convertColor(context)) + } + } + }) + } + private fun analyticalSelectResults(result: LocalMedia) { //压缩图片 // val realPath = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { @@ -230,20 +309,4 @@ } }) } - -// private lateinit var loadingDialog: QMUITipDialog -// -// private fun showLoadingDialog(context: Context?, message: String?) { -// loadingDialog = QMUITipDialog.Builder(context) -// .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) -// .setTipWord(message) -// .create() -// loadingDialog.show() -// } -// -// private fun dismissLoadingDialog() { -// if (loadingDialog.isShowing) { -// loadingDialog.dismiss() -// } -// } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index b1daa34..59ed628 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -167,6 +167,13 @@ applyTextView.setOnClickListener { navigatePageTo() } + + /** + * TODO + * */ + warningTagView.setOnClickListener { + "需求不明,待完善".show(this) + } } /**地图相关*********/ diff --git a/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt new file mode 100644 index 0000000..cf311f5 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt @@ -0,0 +1,43 @@ +package com.casic.br.operationsite.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.extensions.separateResponseCode +import com.casic.br.operationsite.extensions.toErrorMessage +import com.casic.br.operationsite.model.CommonResultModel +import com.casic.br.operationsite.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState + +class EventViewModel : BaseViewModel() { + private val gson = Gson() + val resultModel = MutableLiveData() + + fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.addEvent( + eventTitle, uploadName, phoneNumber, eventDescription, + eventImage, lng, lat, createTime + ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + loadState.value = LoadState.Fail + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt index cf6bd36..f5e5c7b 100644 --- a/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt @@ -2,19 +2,36 @@ import androidx.lifecycle.MutableLiveData import com.casic.br.operationsite.extensions.separateResponseCode +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.retrofit.RetrofitServiceManager +import com.casic.br.operationsite.utils.LocaleConstant +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.BaseViewModel class UserDetailViewModel : BaseViewModel() { + private val gson = Gson() + //用户信息不用现取现用,布尔值标志用户token是否失效 val flag = MutableLiveData() fun obtainUserDetail() = launch({ val response = RetrofitServiceManager.obtainUserDetail() val responseCode = response.separateResponseCode() - flag.value = responseCode == 200 + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(LocaleConstant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { + //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 + SaveKeyValues.removeKey(LocaleConstant.USER_DETAIL_MODEL) + flag.value = false + } }, { it.printStackTrace() }) diff --git a/app/src/main/res/layout/activity_site_tab.xml b/app/src/main/res/layout/activity_site_tab.xml index a7dc6a0..c45ad28 100644 --- a/app/src/main/res/layout/activity_site_tab.xml +++ b/app/src/main/res/layout/activity_site_tab.xml @@ -25,6 +25,7 @@ - - - - - - - - - - - - - + diff --git a/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt new file mode 100644 index 0000000..29cf45e --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/extensions/ArrayList.kt @@ -0,0 +1,20 @@ +package com.casic.br.operationsite.extensions + +/** + * ArrayList扩展方法 + */ + +//将图片集合格式化成满足上传格式的数据 +fun ArrayList.reformat(): String { + if (this.isEmpty()) return "" + val builder = StringBuilder() + //循环遍历元素,同时得到元素index(下标) + this.forEachIndexed { index, s -> + if (index == this.size - 1) { + builder.append(s) + } else { + builder.append(s).append(",") + } + } + return builder.toString() +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java new file mode 100644 index 0000000..8b971b8 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/model/UserDetailModel.java @@ -0,0 +1,262 @@ +package com.casic.br.operationsite.model; + +import java.util.List; + +public class UserDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String account; + private String appId; + private String attr1; + private String avatar; + private String bizData; + private List dataScope; + private String deptId; + private String deptName; + private List devices; + private String id; + private String ipAddr; + private boolean isAppLogin; + private String name; + private String phone; + private List resourceUrls; + private List roleIds; + private List roleNames; + private List roleTips; + private String scopeType; + private String syncId; + private String syncName; + private String sysData; + private String tenantId; + private String userUniqueId; + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getAttr1() { + return attr1; + } + + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getBizData() { + return bizData; + } + + public void setBizData(String bizData) { + this.bizData = bizData; + } + + public List getDataScope() { + return dataScope; + } + + public void setDataScope(List dataScope) { + this.dataScope = dataScope; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIpAddr() { + return ipAddr; + } + + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + + public boolean isIsAppLogin() { + return isAppLogin; + } + + public void setIsAppLogin(boolean isAppLogin) { + this.isAppLogin = isAppLogin; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public List getResourceUrls() { + return resourceUrls; + } + + public void setResourceUrls(List resourceUrls) { + this.resourceUrls = resourceUrls; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } + + public List getRoleNames() { + return roleNames; + } + + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + public List getRoleTips() { + return roleTips; + } + + public void setRoleTips(List roleTips) { + this.roleTips = roleTips; + } + + public String getScopeType() { + return scopeType; + } + + public void setScopeType(String scopeType) { + this.scopeType = scopeType; + } + + public String getSyncId() { + return syncId; + } + + public void setSyncId(String syncId) { + this.syncId = syncId; + } + + public String getSyncName() { + return syncName; + } + + public void setSyncName(String syncName) { + this.syncName = syncName; + } + + public String getSysData() { + return sysData; + } + + public void setSysData(String sysData) { + this.sysData = sysData; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getUserUniqueId() { + return userUniqueId; + } + + public void setUserUniqueId(String userUniqueId) { + this.userUniqueId = userUniqueId; + } + } +} diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 552a08c..49a5b5e 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -83,4 +83,21 @@ @Header("token") token: String, @Part file: MultipartBody.Part ): String + + /** + * 新增事件 + */ + @FormUrlEncoded + @POST("/event/add") + suspend fun addEvent( + @Header("token") token: String, + @Field("eventTitle") eventTitle: String, + @Field("uploadName") uploadName: String, + @Field("phoneNumber") phoneNumber: String, + @Field("eventDescription") eventDescription: String, + @Field("eventImage") eventImage: String, + @Field("lng") lng: String, + @Field("lat") lat: String, + @Field("createTime") createTime: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 40ad053..3be66b4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -79,4 +79,17 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 新增事件 + */ + suspend fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ): String { + return api.addEvent( + AuthenticationHelper.token!!, + eventTitle, uploadName, phoneNumber, eventDescription, eventImage, lng, lat, createTime + ) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 12d2275..036c39d 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -19,6 +19,7 @@ const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" + const val USER_DETAIL_MODEL = "userDetailModel" const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt new file mode 100644 index 0000000..5c99522 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocationHelper.kt @@ -0,0 +1,38 @@ +package com.casic.br.operationsite.utils + +import android.content.Context +import android.util.Log +import com.amap.api.location.AMapLocation +import com.amap.api.location.AMapLocationClient +import com.amap.api.location.AMapLocationClientOption + +object LocationHelper { + private const val kTag = "LocationHelper" + + fun obtainCurrentLocation(context: Context, listener: ILocationListener) { + val locationClient = AMapLocationClient(context) + val locationOption = AMapLocationClientOption() + //设置定位模式为高精度模式,AMapLocationMode.Battery_Saving为低功耗模式,AMapLocationMode.Device_Sensors是仅设备模式 + locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy + locationOption.isNeedAddress = true //设置是否返回地址信息(默认返回地址信息) + locationOption.isOnceLocation = true //仅定位一次 + //给定位客户端对象设置定位参数 + locationClient.setLocationOption(locationOption) + locationClient.setLocationListener { + if (it.errorCode == 0) { + listener.onAMapLocationGet(it) + } else { + listener.onAMapLocationGet(null) + //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 + Log.e( + kTag, "location Error, ErrCode: ${it.errorCode} , errInfo: ${it.errorInfo}" + ) + } + } + locationClient.startLocation() + } + + interface ILocationListener { + fun onAMapLocationGet(aMapLocation: AMapLocation?) //高德定位数据 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt index d84692e..e872af1 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/UploadEventActivity.kt @@ -10,13 +10,21 @@ import android.view.View import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import com.amap.api.location.AMapLocation import com.casic.br.operationsite.R import com.casic.br.operationsite.callback.OnImageCompressListener import com.casic.br.operationsite.extensions.combineImagePath import com.casic.br.operationsite.extensions.compressImage +import com.casic.br.operationsite.extensions.reformat +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.utils.DialogHelper import com.casic.br.operationsite.utils.GlideLoadEngine +import com.casic.br.operationsite.utils.LocaleConstant +import com.casic.br.operationsite.utils.LocationHelper +import com.casic.br.operationsite.vm.EventViewModel import com.casic.br.operationsite.vm.UploadFileViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.gyf.immersionbar.ImmersionBar import com.luck.picture.lib.basic.PictureSelector import com.luck.picture.lib.config.SelectMimeType @@ -24,11 +32,11 @@ import com.luck.picture.lib.interfaces.OnResultCallbackListener import com.pengxh.kt.lite.adapter.EditableImageAdapter import com.pengxh.kt.lite.base.KotlinBaseActivity -import com.pengxh.kt.lite.extensions.convertColor -import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.extensions.* import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.dialog.BottomActionSheet import kotlinx.android.synthetic.main.activity_upload_activity.* import kotlinx.android.synthetic.main.include_base_title.* @@ -40,9 +48,11 @@ private lateinit var imageAdapter: EditableImageAdapter private lateinit var weakReferenceHandler: WeakReferenceHandler private lateinit var uploadFileViewModel: UploadFileViewModel + private lateinit var eventViewModel: EventViewModel private val context: Context = this@UploadEventActivity private val imagePaths: ArrayList = ArrayList() //服务器返回的拍照数据集 private val realPaths: ArrayList = ArrayList() //真实图片路径 + private var mapLocation: AMapLocation? = null override fun initLayoutView(): Int = R.layout.activity_upload_activity @@ -55,16 +65,33 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDetail = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + uploadPersonView.text = userDetail.name + personNumberView.text = userDetail.phone + } + + weakReferenceHandler = WeakReferenceHandler(callback) uploadFileViewModel = ViewModelProvider(this).get(UploadFileViewModel::class.java) + eventViewModel = ViewModelProvider(this).get(EventViewModel::class.java) imageAdapter = EditableImageAdapter(this, 3) addImageRecyclerView.layoutManager = GridLayoutManager(this, 3) addImageRecyclerView.adapter = imageAdapter } + override fun onResume() { + obtainCurrentLocation() + super.onResume() + } + override fun initEvent() { + locationImageView.setOnClickListener { obtainCurrentLocation() } + imageAdapter.setOnItemClickListener(object : EditableImageAdapter.OnItemClickListener { override fun onAddImageClick() { selectPicture() @@ -125,8 +152,44 @@ }) uploadEventButton.setOnClickListener { + if (eventNameView.text.isNullOrBlank()) { + "请输入事件名称".show(this) + return@setOnClickListener + } + if (siteEditView.text.isNullOrBlank()) { + "请输入事件简要描述".show(this) + return@setOnClickListener + } + + eventViewModel.addEvent( + eventNameView.text.toString(), + uploadPersonView.text.toString(), + personNumberView.text.toString(), + siteEditView.text.toString(), + imagePaths.reformat(), + mapLocation?.longitude.toString(), + mapLocation?.latitude.toString(), + System.currentTimeMillis().timestampToCompleteDate() + ) } + + eventViewModel.resultModel.observe(this, { + if (it.code == 200) { + finish() + } + }) + + eventViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "事件提交中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } private fun selectPicture() { @@ -207,6 +270,22 @@ true } + private fun obtainCurrentLocation() { + eventLocationView.text = "定位中..." + LocationHelper.obtainCurrentLocation(this, object : LocationHelper.ILocationListener { + override fun onAMapLocationGet(aMapLocation: AMapLocation?) { + if (aMapLocation == null) { + eventLocationView.text = "定位失败" + eventLocationView.setTextColor(R.color.redTextColor.convertColor(context)) + } else { + mapLocation = aMapLocation + eventLocationView.text = aMapLocation.address + eventLocationView.setTextColor(R.color.subTextColor.convertColor(context)) + } + } + }) + } + private fun analyticalSelectResults(result: LocalMedia) { //压缩图片 // val realPath = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { @@ -230,20 +309,4 @@ } }) } - -// private lateinit var loadingDialog: QMUITipDialog -// -// private fun showLoadingDialog(context: Context?, message: String?) { -// loadingDialog = QMUITipDialog.Builder(context) -// .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) -// .setTipWord(message) -// .create() -// loadingDialog.show() -// } -// -// private fun dismissLoadingDialog() { -// if (loadingDialog.isShowing) { -// loadingDialog.dismiss() -// } -// } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index b1daa34..59ed628 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -167,6 +167,13 @@ applyTextView.setOnClickListener { navigatePageTo() } + + /** + * TODO + * */ + warningTagView.setOnClickListener { + "需求不明,待完善".show(this) + } } /**地图相关*********/ diff --git a/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt new file mode 100644 index 0000000..cf311f5 --- /dev/null +++ b/app/src/main/java/com/casic/br/operationsite/vm/EventViewModel.kt @@ -0,0 +1,43 @@ +package com.casic.br.operationsite.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.extensions.separateResponseCode +import com.casic.br.operationsite.extensions.toErrorMessage +import com.casic.br.operationsite.model.CommonResultModel +import com.casic.br.operationsite.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState + +class EventViewModel : BaseViewModel() { + private val gson = Gson() + val resultModel = MutableLiveData() + + fun addEvent( + eventTitle: String, uploadName: String, phoneNumber: String, eventDescription: String, + eventImage: String, lng: String, lat: String, createTime: String + ) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.addEvent( + eventTitle, uploadName, phoneNumber, eventDescription, + eventImage, lng, lat, createTime + ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + loadState.value = LoadState.Fail + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt index cf6bd36..f5e5c7b 100644 --- a/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/br/operationsite/vm/UserDetailViewModel.kt @@ -2,19 +2,36 @@ import androidx.lifecycle.MutableLiveData import com.casic.br.operationsite.extensions.separateResponseCode +import com.casic.br.operationsite.model.UserDetailModel import com.casic.br.operationsite.retrofit.RetrofitServiceManager +import com.casic.br.operationsite.utils.LocaleConstant +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.vm.BaseViewModel class UserDetailViewModel : BaseViewModel() { + private val gson = Gson() + //用户信息不用现取现用,布尔值标志用户token是否失效 val flag = MutableLiveData() fun obtainUserDetail() = launch({ val response = RetrofitServiceManager.obtainUserDetail() val responseCode = response.separateResponseCode() - flag.value = responseCode == 200 + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(LocaleConstant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { + //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 + SaveKeyValues.removeKey(LocaleConstant.USER_DETAIL_MODEL) + flag.value = false + } }, { it.printStackTrace() }) diff --git a/app/src/main/res/layout/activity_site_tab.xml b/app/src/main/res/layout/activity_site_tab.xml index a7dc6a0..c45ad28 100644 --- a/app/src/main/res/layout/activity_site_tab.xml +++ b/app/src/main/res/layout/activity_site_tab.xml @@ -25,6 +25,7 @@ - - - - - - - - - - - - - + diff --git a/app/src/main/res/layout/activity_upload_activity.xml b/app/src/main/res/layout/activity_upload_activity.xml index 0630a07..a368e93 100644 --- a/app/src/main/res/layout/activity_upload_activity.xml +++ b/app/src/main/res/layout/activity_upload_activity.xml @@ -25,7 +25,9 @@ style="@style/LinearLayoutTextViewStyle" android:text="事件名称" /> - + @@ -36,7 +38,13 @@ style="@style/LinearLayoutTextViewStyle" android:text="上报人员" /> - + @@ -47,9 +55,38 @@ style="@style/LinearLayoutTextViewStyle" android:text="联系方式" /> - + + + + + + + + + + + + @@ -62,13 +99,11 @@ + android:textColor="@color/subTextColor" />