Commit e518b71b3c77fc0c7c79641912113bc25c5b3d71
1 parent
3ad71d87
Exists in
yxb_dev
and in
2 other branches
no message
Showing
5 changed files
with
279 additions
and
6 deletions
Show diff stats
.gitignore
app/build.gradle
| @@ -32,7 +32,9 @@ android { | @@ -32,7 +32,9 @@ android { | ||
| 32 | productFlavors { | 32 | productFlavors { |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| 35 | - | 35 | +greendao{ |
| 36 | + schemaVersion 1//数据库版本升级 | ||
| 37 | +} | ||
| 36 | dependencies { | 38 | dependencies { |
| 37 | implementation fileTree(include: ['*.jar'], dir: 'libs') | 39 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
| 38 | implementation 'com.android.support:appcompat-v7:26.1.0' | 40 | implementation 'com.android.support:appcompat-v7:26.1.0' |
app/src/main/java/com/shunzhi/parent/AppContext.java
| @@ -15,6 +15,12 @@ import com.netease.nimlib.sdk.StatusBarNotificationConfig; | @@ -15,6 +15,12 @@ import com.netease.nimlib.sdk.StatusBarNotificationConfig; | ||
| 15 | import com.netease.nimlib.sdk.auth.LoginInfo; | 15 | import com.netease.nimlib.sdk.auth.LoginInfo; |
| 16 | import com.share.mvpsdk.global.GlobalApplication; | 16 | import com.share.mvpsdk.global.GlobalApplication; |
| 17 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; | 17 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; |
| 18 | +import com.shunzhi.parent.bean.message.DaoMaster; | ||
| 19 | +import com.shunzhi.parent.bean.message.DaoMaster.DevOpenHelper; | ||
| 20 | +import com.shunzhi.parent.bean.message.DaoSession; | ||
| 21 | +import com.shunzhi.parent.ui.MainActivity; | ||
| 22 | + | ||
| 23 | +import org.greenrobot.greendao.database.Database; | ||
| 18 | 24 | ||
| 19 | /** | 25 | /** |
| 20 | * Created by Administrator on 2018/3/7 0007. | 26 | * Created by Administrator on 2018/3/7 0007. |
| @@ -27,6 +33,12 @@ public class AppContext extends GlobalApplication { | @@ -27,6 +33,12 @@ public class AppContext extends GlobalApplication { | ||
| 27 | 33 | ||
| 28 | public String cityName = "", district = ""; | 34 | public String cityName = "", district = ""; |
| 29 | 35 | ||
| 36 | + public DaoSession getDaoSession() { | ||
| 37 | + return daoSession; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + private DaoSession daoSession; | ||
| 41 | + | ||
| 30 | public static AppContext getInstance() { | 42 | public static AppContext getInstance() { |
| 31 | return appContext; | 43 | return appContext; |
| 32 | } | 44 | } |
| @@ -44,6 +56,18 @@ public class AppContext extends GlobalApplication { | @@ -44,6 +56,18 @@ public class AppContext extends GlobalApplication { | ||
| 44 | //开启地图地位 | 56 | //开启地图地位 |
| 45 | initMapLocal(); | 57 | initMapLocal(); |
| 46 | NIMClient.init(this, loginInfo(), options()); | 58 | NIMClient.init(this, loginInfo(), options()); |
| 59 | + initDB(); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + private void initDB() { | ||
| 63 | + //如果需要对数据库加密可以使用注释掉的方法,密码设置方式可以参考微信的数据密码生成方式: | ||
| 64 | + //读取手机的IMEI与APP安装时生成的随机码(微信是在登录账号以后为不同的账号创建不同的文件夹微信随机码是微信账号的id)拼接, | ||
| 65 | + // 经md5加密后取前n位做密码 | ||
| 66 | +// DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, ENCRYPTED ? "notes-db-encrypted" : "notes-db"); | ||
| 67 | +// Database db = ENCRYPTED ? helper.getEncryptedWritableDb("super-secret") : helper.getWritableDb(); | ||
| 68 | + DevOpenHelper helper = new DevOpenHelper(this, "pw_messages"); | ||
| 69 | + Database db = helper.getWritableDb(); | ||
| 70 | + daoSession = new DaoMaster(db).newSession(); | ||
| 47 | } | 71 | } |
| 48 | 72 | ||
| 49 | private SDKOptions options() { | 73 | private SDKOptions options() { |
| @@ -51,7 +75,7 @@ public class AppContext extends GlobalApplication { | @@ -51,7 +75,7 @@ public class AppContext extends GlobalApplication { | ||
| 51 | 75 | ||
| 52 | // 如果将新消息通知提醒托管给 SDK 完成,需要添加以下配置。否则无需设置。 | 76 | // 如果将新消息通知提醒托管给 SDK 完成,需要添加以下配置。否则无需设置。 |
| 53 | StatusBarNotificationConfig config = new StatusBarNotificationConfig(); | 77 | StatusBarNotificationConfig config = new StatusBarNotificationConfig(); |
| 54 | - //config.notificationEntrance = MainActivity.class; // 点击通知栏跳转到该Activity | 78 | + config.notificationEntrance = MainActivity.class; // 点击通知栏跳转到该Activity |
| 55 | config.notificationSmallIconId = R.mipmap.ic_launcher; | 79 | config.notificationSmallIconId = R.mipmap.ic_launcher; |
| 56 | options.sdkStorageRootPath = getExternalFilesDir(null).getPath() + "/nim"; | 80 | options.sdkStorageRootPath = getExternalFilesDir(null).getPath() + "/nim"; |
| 57 | options.statusBarNotificationConfig = config; | 81 | options.statusBarNotificationConfig = config; |
app/src/main/java/com/shunzhi/parent/bean/message/PHMessage.java
| 1 | package com.shunzhi.parent.bean.message; | 1 | package com.shunzhi.parent.bean.message; |
| 2 | 2 | ||
| 3 | +import org.greenrobot.greendao.annotation.Entity; | ||
| 4 | +import org.greenrobot.greendao.annotation.Id; | ||
| 5 | +import org.greenrobot.greendao.annotation.NotNull; | ||
| 6 | + | ||
| 7 | +import java.util.Date; | ||
| 8 | + | ||
| 9 | +import org.greenrobot.greendao.annotation.Generated; | ||
| 10 | + | ||
| 3 | /** | 11 | /** |
| 4 | - * Created by 10501 on 2018/3/19. | 12 | + * 内部变量可能存在值为null,使用时要注意 |
| 5 | */ | 13 | */ |
| 14 | +@Entity(nameInDb = "message") | ||
| 15 | +public class PHMessage { | ||
| 16 | + @Id(autoincrement = true) | ||
| 17 | + private Long id; | ||
| 18 | + | ||
| 19 | + private Date date; | ||
| 20 | + private String messageId; | ||
| 21 | + private String sessionId; | ||
| 22 | + @NotNull | ||
| 23 | + private String messageText; | ||
| 24 | + private String exValue;//消息扩展字段 | ||
| 25 | + private String filePath; | ||
| 26 | + private String fileUrl; | ||
| 27 | + private String messageType; | ||
| 28 | + private Integer sendState;//消息发送的状态 1未发送(或者null,不建议使用null) 2发送中 3发送成功 4发送失败 | ||
| 29 | + | ||
| 30 | + @Generated(hash = 1293964777) | ||
| 31 | + public PHMessage(Long id, Date date, String messageId, String sessionId, | ||
| 32 | + @NotNull String messageText, String exValue, String filePath, | ||
| 33 | + String fileUrl, String messageType, Integer sendState) { | ||
| 34 | + this.id = id; | ||
| 35 | + this.date = date; | ||
| 36 | + this.messageId = messageId; | ||
| 37 | + this.sessionId = sessionId; | ||
| 38 | + this.messageText = messageText; | ||
| 39 | + this.exValue = exValue; | ||
| 40 | + this.filePath = filePath; | ||
| 41 | + this.fileUrl = fileUrl; | ||
| 42 | + this.messageType = messageType; | ||
| 43 | + this.sendState = sendState; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Generated(hash = 1001489632) | ||
| 47 | + public PHMessage() { | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public Long getId() { | ||
| 51 | + return this.id; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public void setId(Long id) { | ||
| 55 | + this.id = id; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public Date getDate() { | ||
| 59 | + return this.date; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setDate(Date date) { | ||
| 63 | + this.date = date; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public String getMessageId() { | ||
| 67 | + return this.messageId; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public void setMessageId(String messageId) { | ||
| 71 | + this.messageId = messageId; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public String getSessionId() { | ||
| 75 | + return this.sessionId; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public void setSessionId(String sessionId) { | ||
| 79 | + this.sessionId = sessionId; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public String getMessageText() { | ||
| 83 | + return this.messageText; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public void setMessageText(String messageText) { | ||
| 87 | + this.messageText = messageText; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public String getExValue() { | ||
| 91 | + return this.exValue; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public void setExValue(String exValue) { | ||
| 95 | + this.exValue = exValue; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public String getFilePath() { | ||
| 99 | + return this.filePath; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public void setFilePath(String filePath) { | ||
| 103 | + this.filePath = filePath; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public String getFileUrl() { | ||
| 107 | + return this.fileUrl; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public void setFileUrl(String fileUrl) { | ||
| 111 | + this.fileUrl = fileUrl; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public String getMessageType() { | ||
| 115 | + return this.messageType; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + public void setMessageType(String messageType) { | ||
| 119 | + this.messageType = messageType; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public Integer getSendState() { | ||
| 123 | + return this.sendState; | ||
| 124 | + } | ||
| 6 | 125 | ||
| 7 | -public class PHMessage { | 126 | + public void setSendState(Integer sendState) { |
| 127 | + this.sendState = sendState; | ||
| 128 | + } | ||
| 8 | } | 129 | } |
app/src/main/java/com/shunzhi/parent/bean/message/PHMessageSession.java
0 → 100644
| @@ -0,0 +1,127 @@ | @@ -0,0 +1,127 @@ | ||
| 1 | +package com.shunzhi.parent.bean.message; | ||
| 2 | + | ||
| 3 | +import org.greenrobot.greendao.annotation.Entity; | ||
| 4 | +import org.greenrobot.greendao.annotation.Id; | ||
| 5 | + | ||
| 6 | +import java.util.Date; | ||
| 7 | + | ||
| 8 | +import org.greenrobot.greendao.annotation.Generated; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * Created by 10501 on 2018/3/20. | ||
| 12 | + */ | ||
| 13 | +@Entity(nameInDb = "messageSession") | ||
| 14 | +public class PHMessageSession { | ||
| 15 | + @Id(autoincrement = true) | ||
| 16 | + private Long id; | ||
| 17 | + private String sessionId; | ||
| 18 | + private String sessionText; | ||
| 19 | + private String sessionName; | ||
| 20 | + private Date date; | ||
| 21 | + private Integer sessionType; | ||
| 22 | + private Integer newMessageCount;//接收和发送的消息总数 | ||
| 23 | + private Integer unReadMessageCount;//未读消息总数 | ||
| 24 | + private String exValues; | ||
| 25 | + private Boolean isTop; | ||
| 26 | + | ||
| 27 | + @Generated(hash = 1156938953) | ||
| 28 | + public PHMessageSession(Long id, String sessionId, String sessionText, String sessionName, | ||
| 29 | + Date date, Integer sessionType, Integer newMessageCount, Integer unReadMessageCount, | ||
| 30 | + String exValues, Boolean isTop) { | ||
| 31 | + this.id = id; | ||
| 32 | + this.sessionId = sessionId; | ||
| 33 | + this.sessionText = sessionText; | ||
| 34 | + this.sessionName = sessionName; | ||
| 35 | + this.date = date; | ||
| 36 | + this.sessionType = sessionType; | ||
| 37 | + this.newMessageCount = newMessageCount; | ||
| 38 | + this.unReadMessageCount = unReadMessageCount; | ||
| 39 | + this.exValues = exValues; | ||
| 40 | + this.isTop = isTop; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Generated(hash = 390248330) | ||
| 44 | + public PHMessageSession() { | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public Long getId() { | ||
| 48 | + return this.id; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setId(Long id) { | ||
| 52 | + this.id = id; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getSessionId() { | ||
| 56 | + return this.sessionId; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setSessionId(String sessionId) { | ||
| 60 | + this.sessionId = sessionId; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getSessionText() { | ||
| 64 | + return this.sessionText; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setSessionText(String sessionText) { | ||
| 68 | + this.sessionText = sessionText; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public String getSessionName() { | ||
| 72 | + return this.sessionName; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setSessionName(String sessionName) { | ||
| 76 | + this.sessionName = sessionName; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public Integer getSessionType() { | ||
| 80 | + return this.sessionType; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void setSessionType(Integer sessionType) { | ||
| 84 | + this.sessionType = sessionType; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public Integer getNewMessageCount() { | ||
| 88 | + return this.newMessageCount; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public void setNewMessageCount(Integer newMessageCount) { | ||
| 92 | + this.newMessageCount = newMessageCount; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public Integer getUnReadMessageCount() { | ||
| 96 | + return this.unReadMessageCount; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public void setUnReadMessageCount(Integer unReadMessageCount) { | ||
| 100 | + this.unReadMessageCount = unReadMessageCount; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public String getExValues() { | ||
| 104 | + return this.exValues; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public void setExValues(String exValues) { | ||
| 108 | + this.exValues = exValues; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public Boolean getIsTop() { | ||
| 112 | + if (isTop == null) return false; | ||
| 113 | + return this.isTop; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public void setIsTop(Boolean isTop) { | ||
| 117 | + this.isTop = isTop; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public Date getDate() { | ||
| 121 | + return this.date; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public void setDate(Date date) { | ||
| 125 | + this.date = date; | ||
| 126 | + } | ||
| 127 | +} |